Search in sources :

Example 6 with ExampleFilterFunction

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

the class ViewValidatorTest method shouldValidateAndReturnFalseWhenEntityFilterSelectionMissingProperty.

@Test
public void shouldValidateAndReturnFalseWhenEntityFilterSelectionMissingProperty() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.PROP_3, String.class).preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new ExampleFilterFunction()).build()).build()).build();
    final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().build()).build();
    // When
    final boolean isValid = validator.validate(view, schema, false);
    // Then
    assertFalse(isValid);
}
Also used : 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) Test(org.junit.Test)

Example 7 with ExampleFilterFunction

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

the class ViewValidatorTest method shouldValidateAndReturnFalseWhenPostTransformerSelectionDoesNotExist.

@Test
public void shouldValidateAndReturnFalseWhenPostTransformerSelectionDoesNotExist() {
    // 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.TRANSIENT_1).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
    assertFalse(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)

Example 8 with ExampleFilterFunction

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

the class ViewTest method shouldSerialiseToJson.

@Test
public void shouldSerialiseToJson() {
    // Given
    final View view = new View.Builder().edge(TestGroups.EDGE, 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()).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new ExampleFilterFunction()).build()).build()).build();
    // When
    byte[] json = view.toJson(true);
    // Then
    JsonUtil.assertEquals(String.format("{%n" + "  \"edges\" : {%n" + "    \"BasicEdge\" : {%n" + "      \"transientProperties\" : {%n" + "        \"property3\" : \"java.lang.String\"%n" + "      },%n" + "      \"postTransformFilterFunctions\" : [ {%n" + "        \"function\" : {%n" + "          \"class\" : \"uk.gov.gchq.gaffer.function.ExampleFilterFunction\"%n" + "        },%n" + "        \"selection\" : [ \"property3\" ]%n" + "      } ],%n" + "      \"transformFunctions\" : [ {%n" + "        \"function\" : {%n" + "          \"class\" : \"uk.gov.gchq.gaffer.function.ExampleTransformFunction\"%n" + "        },%n" + "        \"selection\" : [ \"property1\", \"property2\" ],%n" + "        \"projection\" : [ \"property3\" ]%n" + "      } ]%n" + "    }%n" + "  },%n" + "  \"entities\" : {%n" + "    \"BasicEntity\" : {%n" + "      \"transientProperties\" : { },%n" + "      \"preAggregationFilterFunctions\" : [ {%n" + "        \"function\" : {%n" + "          \"class\" : \"uk.gov.gchq.gaffer.function.ExampleFilterFunction\"%n" + "        },%n" + "        \"selection\" : [ \"property1\" ]%n" + "      } ]%n" + "    }%n" + "  }%n" + "}"), new String(json));
}
Also used : 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)8 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)8 ExampleFilterFunction (uk.gov.gchq.gaffer.function.ExampleFilterFunction)8 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)5 ExampleTransformFunction (uk.gov.gchq.gaffer.function.ExampleTransformFunction)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)2 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)1 AggregateFunction (uk.gov.gchq.gaffer.function.AggregateFunction)1 ExampleAggregateFunction (uk.gov.gchq.gaffer.function.ExampleAggregateFunction)1 FilterFunction (uk.gov.gchq.gaffer.function.FilterFunction)1 IsA (uk.gov.gchq.gaffer.function.IsA)1 ConsumerProducerFunctionContext (uk.gov.gchq.gaffer.function.context.ConsumerProducerFunctionContext)1 PassThroughFunctionContext (uk.gov.gchq.gaffer.function.context.PassThroughFunctionContext)1