@Test public void shouldAddGlobalElementTransformToEntityGroupFromBuilder() { // Given final ElementTransformer elementTransformer = new ElementTransformer.Builder() .select(TestPropertyNames.PROP_3) .execute(new Identity()) .project(TestPropertyNames.PROP_1) .build(); // When final View view = new View.Builder() .globalElements(new GlobalViewElementDefinition.Builder() .groups(TestGroups.ENTITY) .transformer(elementTransformer) .build()) .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .excludeProperties(TestPropertyNames.PROP_3) .build()) .expandGlobalDefinitions() .build(); // Then assertEquals(elementTransformer.getComponents().get(0).getFunction().getClass().getSimpleName(), view.getEntity(TestGroups.ENTITY).getTransformer().getComponents().get(0).getFunction().getClass().getSimpleName()); assertEquals(Sets.newHashSet(TestPropertyNames.PROP_3), Sets.newHashSet(view.getEntity(TestGroups.ENTITY).getExcludeProperties())); }
@Test public void shouldAddGlobalTransformToEntityGroup() { // Given final ElementTransformer elementTransformer = new ElementTransformer.Builder() .select(TestPropertyNames.PROP_3) .execute(new Identity()) .project(TestPropertyNames.PROP_1) .build(); final View view = new View.Builder() .globalEntities(new GlobalViewElementDefinition.Builder() .groups(TestGroups.ENTITY) .transformer(elementTransformer) .build()) .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .excludeProperties(TestPropertyNames.PROP_3) .build()) .build(); // When view.expandGlobalDefinitions(); // Then assertEquals(elementTransformer.getComponents().get(0).getFunction().getClass().getSimpleName(), view.getEntity(TestGroups.ENTITY).getTransformer().getComponents().get(0).getFunction().getClass().getSimpleName()); assertEquals(Sets.newHashSet(TestPropertyNames.PROP_3), Sets.newHashSet(view.getEntity(TestGroups.ENTITY).getExcludeProperties())); }
@Test public void shouldAddGlobalElementTransformToEntityGroup() { // Given final ElementTransformer elementTransformer = new ElementTransformer.Builder() .select(TestPropertyNames.PROP_3) .execute(new Identity()) .project(TestPropertyNames.PROP_1) .build(); final View view = new View.Builder() .globalElements(new GlobalViewElementDefinition.Builder() .groups(TestGroups.ENTITY) .transformer(elementTransformer) .build()) .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .excludeProperties(TestPropertyNames.PROP_3) .build()) .build(); // When view.expandGlobalDefinitions(); // Then assertEquals(elementTransformer.getComponents().get(0).getFunction().getClass().getSimpleName(), view.getEntity(TestGroups.ENTITY).getTransformer().getComponents().get(0).getFunction().getClass().getSimpleName()); assertEquals(Sets.newHashSet(TestPropertyNames.PROP_3), Sets.newHashSet(view.getEntity(TestGroups.ENTITY).getExcludeProperties())); }
.select("thing", "count") .project("mean") .execute(new MeanTransform())
.select(Property.RATING, Property.COUNT) .project(TransientProperty.FIVE_STAR_RATING) .execute(new StarRatingTransform())
.transientProperty("score", Integer.class) .transformer(new ElementTransformer.Builder() .select("VERTEX", "count") .execute(new ExampleScoreFunction()) .project("score") .transientProperty("score", Integer.class) .transformer(new ElementTransformer.Builder() .select("DESTINATION", "count") .execute(new ExampleScoreFunction()) .project("score")
.transientProperty("score", Integer.class) .transformer(new ElementTransformer.Builder() .select("VERTEX", "count") .execute(new ExampleScoreFunction()) .project("score") .transientProperty("score", Integer.class) .transformer(new ElementTransformer.Builder() .select("DESTINATION", "count") .execute(new ExampleScoreFunction()) .project("score")
.transientProperty("score", Integer.class) .transformer(new ElementTransformer.Builder() .select("VERTEX", "count") .execute(new ExampleScoreFunction()) .project("score") .transientProperty("score", Integer.class) .transformer(new ElementTransformer.Builder() .select("DESTINATION", "count") .execute(new ExampleScoreFunction()) .project("score")
private void addOldGroupTransform() { if (null != oldGroup && !oldGroup.equals(newGroup)) { toOldPrivateTransform = new Builder() .select("GROUP") .execute(new SetValue(oldGroup)) .project("GROUP") .build(); } }
private void addNewGroupTransform() { if (null != newGroup && !newGroup.equals(oldGroup)) { toNewPrivateTransform = new Builder() .select("GROUP") .execute(new SetValue(newGroup)) .project("GROUP") .build(); } }
.transientProperty(TestPropertyNames.PROP_3, String.class) .transformer(new ElementTransformer.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new ExampleTransformFunction()) .project(TestPropertyNames.PROP_3)
.build()) .transformer(new ElementTransformer.Builder() .select(TestPropertyNames.COUNT) .execute(new TestTransform()) .project(TestPropertyNames.PROP_1)
.transientProperty(TestPropertyNames.PROP_3, String.class) .transformer(new ElementTransformer.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new ExampleTransformFunction()) .project(TestPropertyNames.PROP_3)
.transientProperty(TestPropertyNames.PROP_3, String.class) .transformer(new ElementTransformer.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new ExampleTransformFunction()) .project(TestPropertyNames.PROP_3)
.transientProperty(TestPropertyNames.PROP_3, String.class) .transformer(new ElementTransformer.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new ExampleTransformFunction()) .project(TestPropertyNames.PROP_3)
@Test public void shouldAddGlobalTransformToEdgeGroup() { // Given final ElementTransformer elementTransformer = new ElementTransformer.Builder() .select(TestPropertyNames.PROP_3) .execute(new Identity()) .project(TestPropertyNames.PROP_1) .build(); final View view = new View.Builder() .globalEdges(new GlobalViewElementDefinition.Builder() .groups(TestGroups.EDGE) .transformer(elementTransformer) .build()) .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .excludeProperties(TestPropertyNames.PROP_3) .build()) .build(); // When view.expandGlobalDefinitions(); // Then assertEquals(elementTransformer.getComponents().get(0).getFunction().getClass().getSimpleName(), view.getEdge(TestGroups.EDGE).getTransformer().getComponents().get(0).getFunction().getClass().getSimpleName()); assertEquals(Sets.newHashSet(TestPropertyNames.PROP_3), Sets.newHashSet(view.getEdge(TestGroups.EDGE).getExcludeProperties())); }
@Test public void shouldTransformElementUsingInlineFunction() { // Given final Function<String, Integer> function = String::length; final ElementTransformer transformer = new ElementTransformer.Builder() .select("prop1") .execute(function) .project("prop3") .build(); final Entity element = new Entity.Builder() .group("test") .property("prop1", "value") .property("prop2", 1) .build(); // When final Element result = transformer.apply(element); // Then assertEquals("prop1".length(), result.getProperty("prop3")); }
@Test public void shouldTransformElementUsingMockFunction() { // Given final String selection = "reference1"; final String projection = "reference1"; final Integer valueResult = 3; final Function<String, Integer> function = mock(Function.class); given(function.apply("value1")).willReturn(valueResult); final ElementTransformer transformer = new ElementTransformer.Builder() .select(selection) .execute(function) .project(projection) .build(); final Edge edge = new Edge.Builder() .property(selection, "value1") .build(); // When final Element result = transformer.apply(edge); // Then assertEquals(valueResult, result.getProperty(projection)); }
@Test public void shouldTransformElementUsingIdentityFunction() { // Given final ElementTransformer transformer = new ElementTransformer.Builder() .select("prop1") .execute(new Identity()) .project("prop3") .build(); final Entity element = new Entity.Builder() .group("test") .property("prop1", "value") .property("prop2", 1) .build(); // When final Element result = transformer.apply(element); // Then assertEquals(element.getProperty("prop1"), result.getProperty("prop3")); }