use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateFunctionSelectionsAndReturnTrueWhenNoFunctionsSet.
@Test
public void shouldValidateFunctionSelectionsAndReturnTrueWhenNoFunctionsSet() {
// Given
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final ElementFilter elementFilter = new ElementFilter();
final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
// When
final ValidationResult result = validator.validateFunctionArgumentTypes(elementFilter, elementDef);
// Then
assertTrue(result.isValid());
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateFunctionSelectionsAndReturnTrueWhenElementFilterIsNull.
@Test
public void shouldValidateFunctionSelectionsAndReturnTrueWhenElementFilterIsNull() {
// Given
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final ElementFilter elementFilter = null;
final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
// When
final ValidationResult result = validator.validateFunctionArgumentTypes(elementFilter, elementDef);
// Then
assertTrue(result.isValid());
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class FilterHandler method doOperation.
public Iterable<? extends Element> doOperation(final Filter operation, final Schema schema) throws OperationException {
if (null == operation.getInput()) {
throw new OperationException("Filter operation has null iterable of elements");
}
// all elements should be used. This matches the way a View works.
if (null == operation.getEntities() && null == operation.getEdges()) {
final Map<String, ElementFilter> entityMap = new HashMap<>();
schema.getEntityGroups().forEach(e -> entityMap.put(e, new ElementFilter()));
operation.setEntities(entityMap);
final Map<String, ElementFilter> edgeMap = new HashMap<>();
schema.getEdgeGroups().forEach(e -> edgeMap.put(e, new ElementFilter()));
operation.setEdges(edgeMap);
}
final ValidationResult result = validator.validate(operation, schema);
if (!result.isValid()) {
throw new OperationException("Filter operation is invalid. " + result.getErrorString());
}
return new StreamFilterIterable(operation);
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class GraphTest method shouldExpandGlobalEdges.
@Test
public void shouldExpandGlobalEdges() throws OperationException {
final Schema twoEdgesNoEntities = new Schema.Builder().type(TestTypes.PROP_STRING, new TypeDefinition.Builder().clazz(String.class).build()).type("vertex", new TypeDefinition.Builder().clazz(String.class).build()).edge("firstEdge", new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING).aggregate(false).source("vertex").destination("vertex").directed(DIRECTED_EITHER).build()).edge("secondEdge", new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING).aggregate(false).source("vertex").destination("vertex").directed(DIRECTED_EITHER).build()).build();
final Store store = mock(Store.class);
final ArgumentCaptor<OperationChain> capturedOperation = ArgumentCaptor.forClass(OperationChain.class);
final ArgumentCaptor<Context> capturedContext = ArgumentCaptor.forClass(Context.class);
given(store.getSchema()).willReturn(twoEdgesNoEntities);
given(store.getProperties()).willReturn(mock(StoreProperties.class));
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(twoEdgesNoEntities).build();
final ElementFilter filter = mock(ElementFilter.class);
final GlobalViewElementDefinition globalEdgeAggregate = new GlobalViewElementDefinition.Builder().postAggregationFilter(filter).build();
final View view = new View.Builder().globalEdges(globalEdgeAggregate).build();
operation = new GetElements.Builder().view(view).build();
opChain = new OperationChain.Builder().first(operation).build();
graph.execute(opChain, context);
Mockito.verify(store, Mockito.times(1)).execute(capturedOperation.capture(), capturedContext.capture());
assertEquals(1, capturedOperation.getAllValues().size());
final OperationChain transformedOpChain = capturedOperation.getAllValues().get(0);
assertEquals(1, transformedOpChain.getOperations().size());
assertEquals(GetElements.class, transformedOpChain.getOperations().get(0).getClass());
final View mergedView = ((GetElements) transformedOpChain.getOperations().get(0)).getView();
assertTrue(mergedView.getGlobalEdges() == null || mergedView.getGlobalEdges().size() == 0);
assertEquals(2, mergedView.getEdges().size());
for (final Map.Entry<String, ViewElementDefinition> e : mergedView.getEdges().entrySet()) {
assertNotNull(e.getValue().getPostAggregationFilter());
}
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class ValidateHandlerTest method shouldValidatedElements.
@Test
public void shouldValidatedElements() throws OperationException {
// Given
final ValidateHandler handler = new ValidateHandler();
final Store store = mock(Store.class);
final Validate validate = mock(Validate.class);
final Element elm1 = mock(Element.class);
final Iterable elements = Collections.singletonList(elm1);
final Schema schema = mock(Schema.class);
final Context context = new Context();
given(validate.getInput()).willReturn(elements);
given(validate.isSkipInvalidElements()).willReturn(false);
given(store.getSchema()).willReturn(schema);
final String group = "group";
given(elm1.getGroup()).willReturn(group);
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final ElementFilter validator = mock(ElementFilter.class);
given(validator.test(elm1)).willReturn(true);
given(elementDef.getValidator(true)).willReturn(validator);
given(schema.getElement(group)).willReturn(elementDef);
// When
final Iterable<? extends Element> result = handler.doOperation(validate, context, store);
// Then
final Iterator<? extends Element> itr = result.iterator();
final Element elm1Result = itr.next();
assertSame(elm1, elm1Result);
assertThat(itr).isExhausted();
}
Aggregations