use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateAndReturnFalseWhenNoAggregatorByGroupBysSet.
@Test
public void shouldValidateAndReturnFalseWhenNoAggregatorByGroupBysSet() {
// Given
Set<String> groupBys = new HashSet<>();
groupBys.add("int");
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");
given(elementDef.getGroupBy()).willReturn(groupBys);
given(elementDef.getProperties()).willReturn(properties.keySet());
given(elementDef.getPropertyMap()).willReturn(properties);
given(elementDef.getValidator()).willReturn(mock(ElementFilter.class));
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
assertFalse(result.isValid());
assertEquals("Validation errors: \nGroups with aggregation disabled should not have groupBy properties.", result.getErrorString());
verify(elementDef, Mockito.atLeastOnce()).getPropertyClass(TestPropertyNames.PROP_1);
verify(elementDef, Mockito.atLeastOnce()).getPropertyClass(TestPropertyNames.PROP_2);
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateAndReturnTrueWhenNoPropertiesSoAggregatorIsValid.
@Test
public void shouldValidateAndReturnTrueWhenNoPropertiesSoAggregatorIsValid() {
// Given
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
given(elementDef.getIdentifiers()).willReturn(new HashSet<>());
given(elementDef.getPropertyMap()).willReturn(Collections.emptyMap());
given(elementDef.getValidator()).willReturn(mock(ElementFilter.class));
given(elementDef.getFullAggregator()).willReturn(null);
given(elementDef.isAggregate()).willReturn(true);
// When
final ValidationResult result = validator.validate(elementDef);
// Then
assertTrue(result.isValid());
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateAndReturnFalseWhenVisibilityIsAggregatedWithOtherProperty.
@Test
public void shouldValidateAndReturnFalseWhenVisibilityIsAggregatedWithOtherProperty() {
// 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").property(TestPropertyNames.VISIBILITY, "string").aggregator(new ElementAggregator.Builder().select(TestPropertyNames.STRING, TestPropertyNames.VISIBILITY).execute(function1).build()).build()).visibilityProperty(TestPropertyNames.VISIBILITY).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("The visibility property must be aggregated by itself. It is currently aggregated in the tuple: [stringProperty, visibility], by aggregate function: " + function1.getClass().getName()), result.getErrors());
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateAndReturnFalseWhenTimestampIsAggregatedWithAGroupByProperty.
@Test
public void shouldValidateAndReturnFalseWhenTimestampIsAggregatedWithAGroupByProperty() {
// 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").property(TestPropertyNames.TIMESTAMP, "string").groupBy(TestPropertyNames.STRING).aggregator(new ElementAggregator.Builder().select(TestPropertyNames.STRING, TestPropertyNames.TIMESTAMP).execute(function1).build()).build()).timestampProperty(TestPropertyNames.TIMESTAMP).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("groupBy properties and non-groupBy properties (including timestamp) must be not be aggregated using the same BinaryOperator. Selection tuple: [stringProperty, timestamp], is aggregated by: " + function1.getClass().getName()), result.getErrors());
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaElementDefinitionValidatorTest method shouldValidateComponentTypesAndReturnTrueWhenIdentifiersAndPropertiesHaveClasses.
@Test
public void shouldValidateComponentTypesAndReturnTrueWhenIdentifiersAndPropertiesHaveClasses() {
// Given
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
given(elementDef.getIdentifiers()).willReturn(Sets.newSet(IdentifierType.DESTINATION, IdentifierType.SOURCE));
given(elementDef.getProperties()).willReturn(Sets.newSet(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2));
given(elementDef.getIdentifierClass(IdentifierType.DESTINATION)).willReturn((Class) Double.class);
given(elementDef.getIdentifierClass(IdentifierType.SOURCE)).willReturn((Class) Long.class);
given(elementDef.getPropertyClass(TestPropertyNames.PROP_1)).willReturn((Class) Integer.class);
given(elementDef.getPropertyClass(TestPropertyNames.PROP_2)).willReturn((Class) String.class);
// When
final ValidationResult result = validator.validateComponentTypes(elementDef);
// Then
assertTrue(result.isValid());
}
Aggregations