use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateFunctionSelectionsAndReturnFalseWhenAFunctionIsNull.
@Test
public void shouldValidateFunctionSelectionsAndReturnFalseWhenAFunctionIsNull() {
// Given
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final ElementFilter elementFilter = new ElementFilter.Builder().select("selection").execute(null).build();
final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
// When
final ValidationResult result = validator.validateFunctionArgumentTypes(elementFilter, elementDef);
// Then
assertFalse(result.isValid());
assertTrue(result.getErrorString().contains("null function"));
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class FilterTest method shouldShallowCloneOperation.
@Test
@Override
public void shouldShallowCloneOperation() {
// Given
final List<Element> input = new ArrayList<>();
final Edge edge = new Edge("road");
input.add(edge);
final Filter filter = new Filter.Builder().input(input).globalElements(new ElementFilter()).build();
// When
final Filter clone = filter.shallowClone();
// Then
assertNotSame(filter, clone);
assertThat(clone.getInput().iterator().next()).isEqualTo(edge);
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class SchemaElementDefinitionValidator method validate.
/**
* Checks each identifier and property has a type associated with it.
* Checks all {@link java.util.function.Predicate}s and {@link java.util.function.BinaryOperator}s defined are
* compatible with the identifiers and properties - this is done by comparing the function input and output types with
* the identifier and property types.
*
* @param elementDef the {@link uk.gov.gchq.gaffer.data.elementdefinition.ElementDefinition} to validate
* @return true if the element definition is valid, otherwise false and an error is logged
*/
public ValidationResult validate(final SchemaElementDefinition elementDef) {
final ValidationResult result = new ValidationResult();
final ElementFilter validator = elementDef.getValidator();
final ElementAggregator aggregator = elementDef.getFullAggregator();
result.add(validateAggregator(aggregator, elementDef));
result.add(validateComponentTypes(elementDef));
result.add(validateFunctionArgumentTypes(validator, elementDef));
result.add(validateFunctionArgumentTypes(aggregator, elementDef));
result.add(validateRequiredParameters(elementDef));
result.add(validatePropertyNames(elementDef));
return result;
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class ElementValidator method validateAgainstViewFilter.
private boolean validateAgainstViewFilter(final Element element, final FilterType filterType) {
if (null == element) {
return false;
}
if (null == view) {
return true;
}
final ViewElementDefinition elementDef = view.getElement(element.getGroup());
if (null == elementDef) {
return false;
}
final ElementFilter validator = getElementFilter(elementDef, filterType);
return null == validator || validator.test(element);
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class ViewTest method shouldAddGlobalPostAggFiltersToGroup.
@Test
public void shouldAddGlobalPostAggFiltersToGroup() {
// 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).postAggregationFilter(filter).build()).entity(TestGroups.ENTITY).build();
// When
view.expandGlobalDefinitions();
// Then
assertTrue(view.hasPostAggregationFilters());
assertEquals(Exists.class.getSimpleName(), view.getEntity(TestGroups.ENTITY).getPostAggregationFilter().getComponents().get(0).getPredicate().getClass().getSimpleName());
}
Aggregations