use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateAndReturnFalseWhenAggregatorProvidedWithNoProperties.
@Test
public void shouldValidateAndReturnFalseWhenAggregatorProvidedWithNoProperties() {
// Given
final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
final BinaryOperator<Integer> function1 = mock(BinaryOperator.class);
final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().vertex("id").aggregator(new ElementAggregator.Builder().select(IdentifierType.VERTEX.name()).execute(function1).build()).build()).type("id", new TypeDefinition.Builder().clazz(String.class).build()).build();
// When
final ValidationResult result = validator.validate(schema.getElement(TestGroups.ENTITY));
// Then
assertFalse(result.isValid());
assertEquals(com.google.common.collect.Sets.newHashSet("Groups with no properties should not have any aggregators"), result.getErrors());
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateAndReturnTrueWhenAggregatorIsValid.
@Test
public void shouldValidateAndReturnTrueWhenAggregatorIsValid() {
// Given
final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
final BinaryOperator<Integer> function1 = mock(BinaryOperator.class);
final BinaryOperator function2 = mock(BinaryOperator.class);
final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().vertex("int1").property(TestPropertyNames.PROP_1, "int1").property(TestPropertyNames.PROP_2, "int2").build()).type("int1", new TypeDefinition.Builder().clazz(Integer.class).aggregateFunction(function1).build()).type("int2", new TypeDefinition.Builder().clazz(Integer.class).aggregateFunction(function2).build()).build();
// When
final ValidationResult result = validator.validate(schema.getEntity(TestGroups.ENTITY));
// Then
assertTrue(result.isValid());
}
use of uk.gov.gchq.koryphe.ValidationResult 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.koryphe.ValidationResult in project Gaffer by gchq.
the class ViewValidatorTest method shouldValidateAndReturnTrueWhenPostTransformerSelectionIsUnknown.
@Test
public void shouldValidateAndReturnTrueWhenPostTransformerSelectionIsUnknown() {
// Given
final ViewValidator validator = new ViewValidator();
final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.PROP_3, String.class).transformer(new ElementTransformer.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new ExampleTransformFunction()).project(TestPropertyNames.PROP_3).build()).postTransformFilter(new ElementFilter.Builder().select(TestPropertyNames.TRANSIENT_1).execute(new ExampleFilterFunction()).build()).build()).build();
final Schema schema = new Schema.Builder().type("obj", Object.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "obj").property(TestPropertyNames.PROP_2, "obj").build()).build();
// When
final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS);
// Then
assertTrue(result.isValid());
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class ViewValidatorTest method shouldValidateAndReturnFalseForNotFilterWithIncompatibleProperties.
@Test
public void shouldValidateAndReturnFalseForNotFilterWithIncompatibleProperties() {
// Given
final ViewValidator validator = new ViewValidator();
final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new Not<>(new Or.Builder<>().select(0).execute(new IsMoreThan("abcd")).select(1).execute(new IsEqual("some other value")).build())).build()).build()).build();
final Schema schema = new Schema.Builder().type("int", Integer.class).type("string", String.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "int").property(TestPropertyNames.PROP_2, "string").build()).build();
// When
final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS);
// Then
assertFalse(result.isValid());
}
Aggregations