Search in sources :

Example 11 with ElementFilter

use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.

the class ViewTest method shouldAddGlobalPostTransformFiltersToGroup.

@Test
public void shouldAddGlobalPostTransformFiltersToGroup() {
    // Given
    final ElementFilter filter = new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new Exists()).build();
    final View view = new View.Builder().globalEntities(new GlobalViewElementDefinition.Builder().groups(TestGroups.ENTITY).postTransformFilter(filter).build()).entity(TestGroups.ENTITY).build();
    // When
    view.expandGlobalDefinitions();
    // Then
    assertTrue(view.hasPostTransformFilters());
    assertEquals(Exists.class.getSimpleName(), view.getEntity(TestGroups.ENTITY).getPostTransformFilter().getComponents().get(0).getPredicate().getClass().getSimpleName());
}
Also used : Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 12 with ElementFilter

use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.

the class ViewTest method shouldConcatGlobalPreAggFiltersWhenSpecificGroupPreAggFiltersSet.

@Test
public void shouldConcatGlobalPreAggFiltersWhenSpecificGroupPreAggFiltersSet() {
    // Given
    final ElementFilter globalFilter = new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new Exists()).build();
    final ElementFilter groupFilter = new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new ExampleFilterFunction()).build();
    final View view = new View.Builder().globalEntities(new GlobalViewElementDefinition.Builder().groups(TestGroups.ENTITY).preAggregationFilter(globalFilter).build()).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(groupFilter).build()).build();
    // When
    view.expandGlobalDefinitions();
    // Then
    assertTrue(view.hasPreAggregationFilters());
    assertEquals(Exists.class.getSimpleName(), view.getEntity(TestGroups.ENTITY).getPreAggregationFilter().getComponents().get(0).getPredicate().getClass().getSimpleName());
    assertEquals(ExampleFilterFunction.class.getSimpleName(), view.getEntity(TestGroups.ENTITY).getPreAggregationFilter().getComponents().get(1).getPredicate().getClass().getSimpleName());
}
Also used : Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ExampleFilterFunction(uk.gov.gchq.gaffer.function.ExampleFilterFunction) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 13 with ElementFilter

use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.

the class ElementValidatorTest method shouldReturnTrueWhenSchemaValidateWithValidElement.

@Test
public void shouldReturnTrueWhenSchemaValidateWithValidElement() {
    // 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.test(elm)).willReturn(true);
    // When
    final boolean isValid = validator.validate(elm);
    // Then
    assertTrue(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) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) Test(org.junit.jupiter.api.Test)

Example 14 with ElementFilter

use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.

the class ElementValidatorTest method shouldReturnTrueWhenSchemaValidateWithoutIsAWithValidElement.

@Test
public void shouldReturnTrueWhenSchemaValidateWithoutIsAWithValidElement() {
    // 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 = false;
    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.test(elm)).willReturn(true);
    // When
    final boolean isValid = validator.validate(elm);
    // Then
    assertTrue(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) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) Test(org.junit.jupiter.api.Test)

Example 15 with ElementFilter

use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.

the class ElementValidatorTest method shouldReturnFalseWhenSchemaValidateWithInvalidElement.

@Test
public void shouldReturnFalseWhenSchemaValidateWithInvalidElement() {
    // 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.test(elm)).willReturn(false);
    // When
    final boolean isValid = validator.validate(elm);
    // Then
    assertFalse(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) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) 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