use of uk.gov.gchq.gaffer.function.ExampleTransformFunction in project Gaffer by gchq.
the class ViewValidatorTest method shouldValidateAndReturnFalseWhenEdgeTransformerSelectionMissingProperty.
@Test
public void shouldValidateAndReturnFalseWhenEdgeTransformerSelectionMissingProperty() {
// Given
final ViewValidator validator = new ViewValidator();
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()).build()).build();
final Schema schema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, "obj").build()).build();
// When
final boolean isValid = validator.validate(view, schema, false);
// Then
assertFalse(isValid);
}
use of uk.gov.gchq.gaffer.function.ExampleTransformFunction 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);
}
use of uk.gov.gchq.gaffer.function.ExampleTransformFunction in project Gaffer by gchq.
the class ViewValidatorTest method shouldValidateAndReturnFalseWhenEntityTransformerProjectsToMissingProperty.
@Test
public void shouldValidateAndReturnFalseWhenEntityTransformerProjectsToMissingProperty() {
// 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("string", Object.class).type("int", Object.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "string").property(TestPropertyNames.PROP_2, "int").build()).build();
// When
final boolean isValid = validator.validate(view, schema, false);
// Then
assertFalse(isValid);
}
use of uk.gov.gchq.gaffer.function.ExampleTransformFunction in project Gaffer by gchq.
the class ViewValidatorTest method shouldValidateAndReturnTrueWhenEdgeTransformerIsValid.
@Test
public void shouldValidateAndReturnTrueWhenEdgeTransformerIsValid() {
// 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("double", Double.class).type("int", Integer.class).type("string", String.class).edge(TestGroups.EDGE, new SchemaEdgeDefinition.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);
}
use of uk.gov.gchq.gaffer.function.ExampleTransformFunction 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));
}
Aggregations