use of uk.gov.gchq.koryphe.impl.function.Identity in project Gaffer by gchq.
the class ElementTransformerTest method shouldTransformElementUsingIdentityFunction.
@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"));
}
use of uk.gov.gchq.koryphe.impl.function.Identity in project Gaffer by gchq.
the class TransformHandlerTest method shouldTransformElementsUsingIdentityFunction.
@Test
public void shouldTransformElementsUsingIdentityFunction() throws OperationException {
// Given
given(store.getSchema()).willReturn(schema);
final Entity entity = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, TestPropertyNames.INT).property(TestPropertyNames.PROP_2, TestPropertyNames.STRING).build();
final Entity entity1 = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, TestPropertyNames.INT).build();
final ElementTransformer transformer = new ElementTransformer.Builder().select(TestPropertyNames.PROP_1).execute(new Identity()).project(TestPropertyNames.PROP_3).build();
final Entity expectedEntity = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_3, TestPropertyNames.INT).property(TestPropertyNames.PROP_2, TestPropertyNames.STRING).build();
final Entity expectedEntity1 = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_3, TestPropertyNames.INT).build();
final Transform transform = new Transform.Builder().input(input).entity(TestGroups.ENTITY, transformer).build();
input.add(entity);
input.add(entity1);
expected.add(expectedEntity);
expected.add(expectedEntity1);
// When
final Iterable<? extends Element> results = handler.doOperation(transform, context, store);
final List<Element> resultsList = Lists.newArrayList(results);
// Then
boolean isSame = false;
for (int i = 0; i < expected.size(); i++) {
isSame = expected.get(i).getProperty(TestPropertyNames.PROP_3).equals(resultsList.get(i).getProperty(TestPropertyNames.PROP_3));
}
assertTrue(isSame);
}
use of uk.gov.gchq.koryphe.impl.function.Identity in project Gaffer by gchq.
the class TransformHandlerTest method shouldFailValidationWhenSchemaElementDefinitionsAreNull.
@Test
public void shouldFailValidationWhenSchemaElementDefinitionsAreNull() {
// Given
given(store.getSchema()).willReturn(new Schema());
final Entity entity = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, TestPropertyNames.INT).property(TestPropertyNames.PROP_2, TestPropertyNames.STRING).build();
final Entity entity1 = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, TestPropertyNames.INT).build();
final ElementTransformer transformer = new ElementTransformer.Builder().select(TestPropertyNames.PROP_1).execute(new Identity()).project(TestPropertyNames.PROP_3).build();
input.add(entity);
input.add(entity1);
final Transform transform = new Transform.Builder().input(input).entity(TestGroups.ENTITY, transformer).build();
// When / Then
assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(transform, context, store)).withMessageContaining("Entity group: " + TestGroups.ENTITY + " does not exist in the schema.");
}
use of uk.gov.gchq.koryphe.impl.function.Identity in project Gaffer by gchq.
the class TransformHandlerTest method shouldSelectAdjacentMatchedVertexForTransform.
@Test
public void shouldSelectAdjacentMatchedVertexForTransform() throws OperationException {
// Given
given(store.getSchema()).willReturn(schema);
final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source("srcVal").dest("destVal").matchedVertex(EdgeId.MatchedVertex.SOURCE).build();
final Transform transform = new Transform.Builder().input(edge).edge(TestGroups.EDGE, new ElementTransformer.Builder().select(IdentifierType.ADJACENT_MATCHED_VERTEX.name()).execute(new Identity()).project(TestPropertyNames.PROP_3).build()).build();
// When
final Iterable<? extends Element> results = handler.doOperation(transform, context, store);
// Then
final Edge expectedEdge = new Edge.Builder().group(TestGroups.EDGE).source("srcVal").dest("destVal").matchedVertex(EdgeId.MatchedVertex.SOURCE).property(TestPropertyNames.PROP_3, "destVal").build();
ElementUtil.assertElementEquals(Collections.singletonList(expectedEdge), results);
}
use of uk.gov.gchq.koryphe.impl.function.Identity in project Gaffer by gchq.
the class ViewTest method shouldAddGlobalTransformToEdgeGroup.
@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()));
}
Aggregations