use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class ElementValidatorTest method shouldReturnFalseWhenViewValidateWithInvalidElement.
@Test
public void shouldReturnFalseWhenViewValidateWithInvalidElement() {
// Given
final View view = mock(View.class);
final String group = TestGroups.EDGE;
final Element elm = mock(Element.class);
final ViewElementDefinition elementDef = mock(ViewElementDefinition.class);
final ElementFilter filter = mock(ElementFilter.class);
final ElementValidator validator = new ElementValidator(view);
given(elm.getGroup()).willReturn(group);
given(view.getElement(group)).willReturn(elementDef);
given(elementDef.getPreAggregationFilter()).willReturn(filter);
given(filter.test(elm)).willReturn(false);
// When
final boolean isValid = validator.validate(elm);
// Then
assertFalse(isValid);
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class ElementValidatorTest method shouldReturnValidValidationResultWhenSchemaValidateWithValidElement.
@Test
public void shouldReturnValidValidationResultWhenSchemaValidateWithValidElement() {
// Given
final Schema schema = mock(Schema.class);
final String group = TestGroups.EDGE;
final Element elm = mock(Element.class);
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final ElementFilter filter = mock(ElementFilter.class);
final boolean includeIsA = true;
final ElementValidator validator = new ElementValidator(schema, includeIsA);
given(elm.getGroup()).willReturn(group);
given(schema.getElement(group)).willReturn(elementDef);
given(elementDef.getValidator(includeIsA)).willReturn(filter);
given(filter.testWithValidationResult(elm)).willReturn(new ValidationResult());
// When
final ValidationResult result = validator.validateWithValidationResult(elm);
// Then
assertTrue(result.isValid());
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class FilterHandlerTest method shouldThrowErrorForNullInput.
@Test
public void shouldThrowErrorForNullInput() {
// Given
given(store.getSchema()).willReturn(SCHEMA);
final Filter filter = new Filter.Builder().globalElements(new ElementFilter()).build();
// When / Then
try {
handler.doOperation(filter, context, store);
fail("Exception expected");
} catch (OperationException e) {
assertEquals("Filter operation has null iterable of elements", e.getMessage());
}
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class GraphTest method preserveAllEntitiesIfNoEntitiesInSchema.
@Test
public void preserveAllEntitiesIfNoEntitiesInSchema() 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.getOriginalSchema()).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().allEntities(true).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.isAllEntities());
assertEquals(0, mergedView.getEntities().size());
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class GraphTest method shouldNotExpandGlobalEdgesWhereNotPresentInSchema.
@Test
public void shouldNotExpandGlobalEdgesWhereNotPresentInSchema() throws OperationException {
final Schema federatedStoreSchema = new Schema.Builder().build();
final Store store = mock(Store.class);
given(store.getSchema()).willReturn(federatedStoreSchema);
given(store.getProperties()).willReturn(mock(StoreProperties.class));
final ArgumentCaptor<OperationChain> capturedOperation = ArgumentCaptor.forClass(OperationChain.class);
final ArgumentCaptor<Context> capturedContext = ArgumentCaptor.forClass(Context.class);
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(federatedStoreSchema).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();
assertEquals(0, mergedView.getEdges().size());
assertEquals(1, mergedView.getGlobalEdges().size());
assertNotNull(mergedView.getGlobalEdges().get(0).getPostAggregationFilter());
}
Aggregations