Search in sources :

Example 1 with Identity

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"));
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) Identity(uk.gov.gchq.koryphe.impl.function.Identity) FunctionTest(uk.gov.gchq.koryphe.function.FunctionTest) Test(org.junit.jupiter.api.Test)

Example 2 with Identity

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);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) Element(uk.gov.gchq.gaffer.data.element.Element) Identity(uk.gov.gchq.koryphe.impl.function.Identity) Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform) Test(org.junit.jupiter.api.Test)

Example 3 with Identity

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.");
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Identity(uk.gov.gchq.koryphe.impl.function.Identity) Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform) Test(org.junit.jupiter.api.Test)

Example 4 with Identity

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);
}
Also used : Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform) Identity(uk.gov.gchq.koryphe.impl.function.Identity) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Example 5 with Identity

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()));
}
Also used : ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) Identity(uk.gov.gchq.koryphe.impl.function.Identity) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Identity (uk.gov.gchq.koryphe.impl.function.Identity)13 Test (org.junit.jupiter.api.Test)9 Entity (uk.gov.gchq.gaffer.data.element.Entity)6 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)6 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)4 Transform (uk.gov.gchq.gaffer.operation.impl.function.Transform)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 ExtractProperty (uk.gov.gchq.gaffer.data.element.function.ExtractProperty)3 Map (uk.gov.gchq.gaffer.operation.impl.Map)3 Join (uk.gov.gchq.gaffer.operation.impl.join.Join)3 KeyFunctionMatch (uk.gov.gchq.gaffer.store.operation.handler.join.match.KeyFunctionMatch)3 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 ToLong (uk.gov.gchq.koryphe.impl.function.ToLong)2 Schema (uk.gov.gchq.gaffer.store.schema.Schema)1 FunctionTest (uk.gov.gchq.koryphe.function.FunctionTest)1