use of uk.gov.gchq.gaffer.function.ExampleFilterFunction 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);
}
use of uk.gov.gchq.gaffer.function.ExampleFilterFunction in project Gaffer by gchq.
the class SchemaTest method testLoadingSchemaFromJson.
@Test
public void testLoadingSchemaFromJson() {
// Edge definitions
SchemaElementDefinition edgeDefinition = schema.getEdge(TestGroups.EDGE);
assertNotNull(edgeDefinition);
assertEquals(EDGE_DESCRIPTION, edgeDefinition.getDescription());
final Map<String, String> propertyMap = edgeDefinition.getPropertyMap();
assertEquals(3, propertyMap.size());
assertEquals("prop.string", propertyMap.get(TestPropertyNames.PROP_2));
assertEquals("prop.date", propertyMap.get(TestPropertyNames.DATE));
assertEquals("timestamp", propertyMap.get(TestPropertyNames.TIMESTAMP));
assertEquals(Sets.newLinkedHashSet(Collections.singletonList(TestPropertyNames.DATE)), edgeDefinition.getGroupBy());
// Check validator
ElementFilter validator = edgeDefinition.getValidator();
final List<ConsumerFunctionContext<String, FilterFunction>> valContexts = validator.getFunctions();
int index = 0;
ConsumerFunctionContext<String, FilterFunction> valContext = valContexts.get(index++);
assertTrue(valContext.getFunction() instanceof IsA);
assertEquals(1, valContext.getSelection().size());
assertEquals(IdentifierType.SOURCE.name(), valContext.getSelection().get(0));
valContext = valContexts.get(index++);
assertTrue(valContext.getFunction() instanceof IsA);
assertEquals(1, valContext.getSelection().size());
assertEquals(IdentifierType.DESTINATION.name(), valContext.getSelection().get(0));
valContext = valContexts.get(index++);
assertTrue(valContext.getFunction() instanceof IsA);
assertEquals(1, valContext.getSelection().size());
assertEquals(IdentifierType.DIRECTED.name(), valContext.getSelection().get(0));
valContext = valContexts.get(index++);
assertTrue(valContext.getFunction() instanceof ExampleFilterFunction);
assertEquals(1, valContext.getSelection().size());
assertEquals(IdentifierType.DIRECTED.name(), valContext.getSelection().get(0));
valContext = valContexts.get(index++);
assertTrue(valContext.getFunction() instanceof IsA);
assertEquals(1, valContext.getSelection().size());
assertEquals(TestPropertyNames.PROP_2, valContext.getSelection().get(0));
valContext = valContexts.get(index++);
assertTrue(valContext.getFunction() instanceof ExampleFilterFunction);
assertEquals(1, valContext.getSelection().size());
assertEquals(TestPropertyNames.PROP_2, valContext.getSelection().get(0));
valContext = valContexts.get(index++);
assertTrue(valContext.getFunction() instanceof IsA);
assertEquals(1, valContext.getSelection().size());
assertEquals(TestPropertyNames.DATE, valContext.getSelection().get(0));
valContext = valContexts.get(index++);
assertTrue(valContext.getFunction() instanceof IsA);
assertEquals(1, valContext.getSelection().size());
assertEquals(TestPropertyNames.TIMESTAMP, valContext.getSelection().get(0));
assertEquals(index, valContexts.size());
TypeDefinition type = edgeDefinition.getPropertyTypeDef(TestPropertyNames.DATE);
assertEquals(Date.class, type.getClazz());
assertEquals(DATE_TYPE_DESCRIPTION, type.getDescription());
assertNull(type.getSerialiser());
assertTrue(type.getAggregateFunction() instanceof ExampleAggregateFunction);
// Entity definitions
SchemaElementDefinition entityDefinition = schema.getEntity(TestGroups.ENTITY);
assertNotNull(entityDefinition);
assertEquals(ENTITY_DESCRIPTION, entityDefinition.getDescription());
assertTrue(entityDefinition.containsProperty(TestPropertyNames.PROP_1));
type = entityDefinition.getPropertyTypeDef(TestPropertyNames.PROP_1);
assertEquals(0, entityDefinition.getGroupBy().size());
assertEquals(STRING_TYPE_DESCRIPTION, type.getDescription());
assertEquals(String.class, type.getClazz());
assertNull(type.getSerialiser());
assertTrue(type.getAggregateFunction() instanceof ExampleAggregateFunction);
ElementAggregator aggregator = edgeDefinition.getAggregator();
List<PassThroughFunctionContext<String, AggregateFunction>> aggContexts = aggregator.getFunctions();
assertEquals(3, aggContexts.size());
PassThroughFunctionContext<String, AggregateFunction> aggContext = aggContexts.get(0);
assertTrue(aggContext.getFunction() instanceof ExampleAggregateFunction);
assertEquals(1, aggContext.getSelection().size());
assertEquals(TestPropertyNames.PROP_2, aggContext.getSelection().get(0));
aggContext = aggContexts.get(1);
assertTrue(aggContext.getFunction() instanceof ExampleAggregateFunction);
assertEquals(1, aggContext.getSelection().size());
assertEquals(TestPropertyNames.DATE, aggContext.getSelection().get(0));
}
use of uk.gov.gchq.gaffer.function.ExampleFilterFunction 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);
}
use of uk.gov.gchq.gaffer.function.ExampleFilterFunction in project Gaffer by gchq.
the class SchemaElementDefinitionTest method shouldMergeDifferentSchemaElementDefinitions.
@Test
public void shouldMergeDifferentSchemaElementDefinitions() {
// Given
// When
final T elementDef1 = createBuilder().property(TestPropertyNames.PROP_1, "property.integer").validator(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new ExampleFilterFunction()).build()).build();
final T elementDef2 = createBuilder().property(TestPropertyNames.PROP_2, "property.object").validator(new ElementFilter.Builder().select(TestPropertyNames.PROP_2).execute(new ExampleFilterFunction()).build()).groupBy(TestPropertyNames.PROP_2).build();
// When
final T mergedDef = createEmptyBuilder().merge(elementDef1).merge(elementDef2).build();
// Then
assertEquals(2, mergedDef.getProperties().size());
assertNotNull(mergedDef.getPropertyTypeDef(TestPropertyNames.PROP_1));
assertNotNull(mergedDef.getPropertyTypeDef(TestPropertyNames.PROP_2));
assertEquals(Sets.newLinkedHashSet(Collections.singletonList(TestPropertyNames.PROP_2)), mergedDef.getGroupBy());
}
use of uk.gov.gchq.gaffer.function.ExampleFilterFunction in project Gaffer by gchq.
the class ViewValidatorTest method shouldValidateAndReturnFalseWhenEdgeFilterSelectionMissingProperty.
@Test
public void shouldValidateAndReturnFalseWhenEdgeFilterSelectionMissingProperty() {
// Given
final ViewValidator validator = new ViewValidator();
final View view = new View.Builder().edge(TestGroups.EDGE, 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().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().build()).build();
// When
final boolean isValid = validator.validate(view, schema, false);
// Then
assertFalse(isValid);
}
Aggregations