Search in sources :

Example 16 with ElementFilter

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);
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Example 17 with ElementFilter

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());
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) Test(org.junit.jupiter.api.Test)

Example 18 with ElementFilter

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());
    }
}
Also used : Filter(uk.gov.gchq.gaffer.operation.impl.function.Filter) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Test(org.junit.jupiter.api.Test)

Example 19 with ElementFilter

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());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) GlobalViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 20 with ElementFilter

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());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) GlobalViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Aggregations

ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)43 Test (org.junit.jupiter.api.Test)35 Schema (uk.gov.gchq.gaffer.store.schema.Schema)11 Element (uk.gov.gchq.gaffer.data.element.Element)10 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)10 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)8 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)6 Context (uk.gov.gchq.gaffer.store.Context)6 Store (uk.gov.gchq.gaffer.store.Store)6 Exists (uk.gov.gchq.koryphe.impl.predicate.Exists)6 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)5 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)5 GlobalViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition)5 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)5 ExampleFilterFunction (uk.gov.gchq.gaffer.function.ExampleFilterFunction)5 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)5 HashMap (java.util.HashMap)4 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)4 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)4 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)4