use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateFunctionSelectionsAndReturnTrueWhenElementFilterIsNull.
@Test
public void shouldValidateFunctionSelectionsAndReturnTrueWhenElementFilterIsNull() {
// Given
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final ElementFilter elementFilter = null;
final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
// When
final ValidationResult result = validator.validateFunctionArgumentTypes(elementFilter, elementDef);
// Then
assertTrue(result.isValid());
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateAndReturnFalseWhenAggregatorHasNoFunction.
@Test
public void shouldValidateAndReturnFalseWhenAggregatorHasNoFunction() {
// 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").property(TestPropertyNames.PROP_1, "string").aggregator(new ElementAggregator.Builder().select(TestPropertyNames.PROP_1).execute(null).build()).build()).type("id", new TypeDefinition.Builder().clazz(String.class).build()).type("string", 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("ElementAggregator contains a null function."), result.getErrors());
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateComponentTypesAndReturnTrueWhenNoIdentifiersOrProperties.
@Test
public void shouldValidateComponentTypesAndReturnTrueWhenNoIdentifiersOrProperties() {
// Given
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
given(elementDef.getIdentifiers()).willReturn(new HashSet<>());
given(elementDef.getProperties()).willReturn(new HashSet<>());
// When
final ValidationResult result = validator.validateComponentTypes(elementDef);
// Then
assertTrue(result.isValid());
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateAndReturnFalseWhenAggregatorSelectionHasUnknownProperty.
@Test
public void shouldValidateAndReturnFalseWhenAggregatorSelectionHasUnknownProperty() {
// 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").property(TestPropertyNames.STRING, "string").aggregator(new ElementAggregator.Builder().select(TestPropertyNames.STRING, TestPropertyNames.PROP_1).execute(function1).build()).build()).type("id", new TypeDefinition.Builder().clazz(String.class).build()).type("string", new TypeDefinition.Builder().clazz(String.class).aggregateFunction(function1).build()).build();
// When
final ValidationResult result = validator.validate(schema.getElement(TestGroups.ENTITY));
// Then
assertFalse(result.isValid());
assertEquals(com.google.common.collect.Sets.newHashSet("Unknown property used in an aggregator: " + TestPropertyNames.PROP_1), result.getErrors());
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateAndReturnTrueWhenAggregationIsDisabled.
@Test
public void shouldValidateAndReturnTrueWhenAggregationIsDisabled() {
// Given
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
final Map<String, String> properties = new HashMap<>();
properties.put(TestPropertyNames.PROP_1, "int");
properties.put(TestPropertyNames.PROP_2, "string");
final BinaryOperator<Integer> function1 = mock(BinaryOperator.class);
final ElementAggregator aggregator = new ElementAggregator.Builder().select(TestPropertyNames.PROP_1).execute(function1).build();
given(elementDef.getIdentifiers()).willReturn(new HashSet<>());
given(elementDef.getProperties()).willReturn(properties.keySet());
given(elementDef.getPropertyMap()).willReturn(properties);
given(elementDef.getValidator()).willReturn(mock(ElementFilter.class));
given(elementDef.getFullAggregator()).willReturn(aggregator);
given(elementDef.getPropertyClass(TestPropertyNames.PROP_1)).willReturn((Class) Integer.class);
given(elementDef.getPropertyClass(TestPropertyNames.PROP_2)).willReturn((Class) String.class);
given(elementDef.isAggregate()).willReturn(false);
// When
final ValidationResult result = validator.validate(elementDef);
// Then
assertTrue(result.isValid());
}
Aggregations