Search in sources :

Example 1 with ExampleTransformFunction

use of uk.gov.gchq.gaffer.function.ExampleTransformFunction in project Gaffer by gchq.

the class ViewIT method shouldDeserialiseJsonView.

@Test
public void shouldDeserialiseJsonView() throws IOException {
    // Given
    // When
    View view = loadView();
    // Then
    final ViewElementDefinition edge = view.getEdge(TestGroups.EDGE);
    final ElementTransformer transformer = edge.getTransformer();
    assertNotNull(transformer);
    final List<ConsumerProducerFunctionContext<String, TransformFunction>> contexts = transformer.getFunctions();
    assertEquals(1, contexts.size());
    final List<String> selection = contexts.get(0).getSelection();
    assertEquals(2, selection.size());
    assertEquals(TestPropertyNames.PROP_1, selection.get(0));
    assertEquals(IdentifierType.SOURCE.name(), selection.get(1));
    final List<String> projection = contexts.get(0).getProjection();
    assertEquals(1, projection.size());
    assertEquals(TestPropertyNames.TRANSIENT_1, projection.get(0));
    assertTrue(contexts.get(0).getFunction() instanceof ExampleTransformFunction);
    final ElementFilter postFilter = edge.getPostTransformFilter();
    assertNotNull(postFilter);
    final List<ConsumerFunctionContext<String, FilterFunction>> filterContexts = postFilter.getFunctions();
    assertEquals(1, contexts.size());
    final List<String> postFilterSelection = filterContexts.get(0).getSelection();
    assertEquals(1, postFilterSelection.size());
    assertEquals(TestPropertyNames.TRANSIENT_1, postFilterSelection.get(0));
    assertTrue(filterContexts.get(0).getFunction() instanceof ExampleFilterFunction);
}
Also used : ConsumerProducerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerProducerFunctionContext) ConsumerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) ExampleFilterFunction(uk.gov.gchq.gaffer.function.ExampleFilterFunction) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ExampleTransformFunction(uk.gov.gchq.gaffer.function.ExampleTransformFunction) Test(org.junit.Test)

Example 2 with ExampleTransformFunction

use of uk.gov.gchq.gaffer.function.ExampleTransformFunction in project Gaffer by gchq.

the class ViewValidatorTest method shouldValidateAndReturnFalseWhenEdgeTransformerProjectsToMissingProperty.

@Test
public void shouldValidateAndReturnFalseWhenEdgeTransformerProjectsToMissingProperty() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().transformer(new ElementTransformer.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).project(TestPropertyNames.PROP_3).execute(new ExampleTransformFunction()).build()).build()).build();
    final Schema schema = new Schema.Builder().type("int", Integer.class).type("string", String.class).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, "int").property(TestPropertyNames.PROP_2, "string").build()).build();
    // When
    final boolean isValid = validator.validate(view, schema, false);
    // Then
    assertFalse(isValid);
}
Also used : View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ExampleTransformFunction(uk.gov.gchq.gaffer.function.ExampleTransformFunction) Test(org.junit.Test)

Example 3 with ExampleTransformFunction

use of uk.gov.gchq.gaffer.function.ExampleTransformFunction in project Gaffer by gchq.

the class ViewValidatorTest method shouldValidateAndReturnFalseWhenEntityTransformerSelectionMissingProperty.

@Test
public void shouldValidateAndReturnFalseWhenEntityTransformerSelectionMissingProperty() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.PROP_3, String.class).transformer(new ElementTransformer.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).project(TestPropertyNames.PROP_3).execute(new ExampleTransformFunction()).build()).build()).build();
    final Schema schema = new Schema.Builder().type("obj", Object.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "obj").build()).build();
    // When
    final boolean isValid = validator.validate(view, schema, false);
    // Then
    assertFalse(isValid);
}
Also used : ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ExampleTransformFunction(uk.gov.gchq.gaffer.function.ExampleTransformFunction) Test(org.junit.Test)

Example 4 with ExampleTransformFunction

use of uk.gov.gchq.gaffer.function.ExampleTransformFunction in project Gaffer by gchq.

the class ViewValidatorTest method shouldValidateAndReturnTrueWhenEntityTransformerIsValid.

@Test
public void shouldValidateAndReturnTrueWhenEntityTransformerIsValid() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().transformer(new ElementTransformer.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).project(TestPropertyNames.PROP_3).execute(new ExampleTransformFunction()).build()).build()).build();
    final Schema schema = new Schema.Builder().type("double", Double.class).type("int", Integer.class).type("string", String.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "double").property(TestPropertyNames.PROP_2, "int").property(TestPropertyNames.PROP_3, "string").build()).build();
    // When
    final boolean isValid = validator.validate(view, schema, false);
    // Then
    assertTrue(isValid);
}
Also used : View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ExampleTransformFunction(uk.gov.gchq.gaffer.function.ExampleTransformFunction) Test(org.junit.Test)

Example 5 with ExampleTransformFunction

use of uk.gov.gchq.gaffer.function.ExampleTransformFunction in project Gaffer by gchq.

the class ViewValidatorTest method shouldValidateAndReturnTrueWhenPostTransformerFilterSet.

@Test
public void shouldValidateAndReturnTrueWhenPostTransformerFilterSet() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.PROP_3, String.class).transformer(new ElementTransformer.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).project(TestPropertyNames.PROP_3).execute(new ExampleTransformFunction()).build()).postTransformFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_3).execute(new ExampleFilterFunction()).build()).build()).build();
    final Schema schema = new Schema.Builder().type("obj", Object.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "obj").property(TestPropertyNames.PROP_2, "obj").build()).build();
    // When
    final boolean isValid = validator.validate(view, schema, false);
    // Then
    assertTrue(isValid);
}
Also used : ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ExampleFilterFunction(uk.gov.gchq.gaffer.function.ExampleFilterFunction) ExampleTransformFunction(uk.gov.gchq.gaffer.function.ExampleTransformFunction) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 ExampleTransformFunction (uk.gov.gchq.gaffer.function.ExampleTransformFunction)10 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)9 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)4 ExampleFilterFunction (uk.gov.gchq.gaffer.function.ExampleFilterFunction)4 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)3 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)3 ConsumerFunctionContext (uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext)1 ConsumerProducerFunctionContext (uk.gov.gchq.gaffer.function.context.ConsumerProducerFunctionContext)1