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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations