Search in sources :

Example 86 with ValidationResult

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);
}
Also used : HashMap(java.util.HashMap) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 87 with ValidationResult

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());
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 88 with ValidationResult

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());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 89 with ValidationResult

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());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 90 with ValidationResult

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());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationResult (uk.gov.gchq.koryphe.ValidationResult)132 Test (org.junit.jupiter.api.Test)86 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)32 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)27 HashMap (java.util.HashMap)13 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)12 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)11 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)11 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)9 ExampleTransformFunction (uk.gov.gchq.gaffer.function.ExampleTransformFunction)9 OperationChainValidator (uk.gov.gchq.gaffer.store.operation.OperationChainValidator)9 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)8 Schema (uk.gov.gchq.gaffer.store.schema.Schema)8 Signature (uk.gov.gchq.koryphe.signature.Signature)8 Map (java.util.Map)7 OperationChainOptimiser (uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser)7 Set (java.util.Set)6 Operation (uk.gov.gchq.gaffer.operation.Operation)6 Element (uk.gov.gchq.gaffer.data.element.Element)5 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)5