Search in sources :

Example 6 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class SchemaElementDefinitionValidatorTest method shouldValidateAndReturnFalseWhenAggregatorHasIdentifierInSelection.

@Test
public void shouldValidateAndReturnFalseWhenAggregatorHasIdentifierInSelection() {
    // 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(IdentifierType.VERTEX.name()).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("Identifiers cannot be selected for aggregation: " + IdentifierType.VERTEX.name()), result.getErrors());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Test(org.junit.jupiter.api.Test)

Example 7 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class SchemaElementDefinitionValidatorTest method shouldValidateAndReturnTrueWhenTimestampIsAggregatedWithANonGroupByProperty.

@Test
public void shouldValidateAndReturnTrueWhenTimestampIsAggregatedWithANonGroupByProperty() {
    // 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").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
    assertTrue(result.isValid());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 8 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class SchemaElementDefinitionValidatorTest method shouldValidateFunctionSelectionsAndReturnTrueWhenAllFunctionsAreValid.

@Test
public void shouldValidateFunctionSelectionsAndReturnTrueWhenAllFunctionsAreValid() {
    // Given
    final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
    given(elementDef.getPropertyClass("selectionStr")).willReturn((Class) String.class);
    given(elementDef.getPropertyClass("selectionInt")).willReturn((Class) Integer.class);
    final Predicate<String> function1 = a -> a.contains("true");
    final Predicate<Integer> function2 = a -> a > 0;
    final ElementFilter elementFilter = new ElementFilter.Builder().select("selectionStr").execute(function1).select("selectionInt").execute(function2).build();
    final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
    // When
    final ValidationResult result = validator.validateFunctionArgumentTypes(elementFilter, elementDef);
    // Then
    assertTrue(result.isValid());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Predicate(java.util.function.Predicate) TestPropertyNames(uk.gov.gchq.gaffer.commonutil.TestPropertyNames) Set(java.util.Set) HashMap(java.util.HashMap) BinaryOperator(java.util.function.BinaryOperator) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) HashSet(java.util.HashSet) Mockito(org.mockito.Mockito) IdentifierType(uk.gov.gchq.gaffer.data.element.IdentifierType) Sets(org.mockito.internal.util.collections.Sets) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BDDMockito.given(org.mockito.BDDMockito.given) Map(java.util.Map) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) Collections(java.util.Collections) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Mockito.mock(org.mockito.Mockito.mock) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 9 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class SchemaElementDefinitionValidatorTest method shouldValidateAndReturnFalseWhenAggregatorIsInvalid.

@Test
public void shouldValidateAndReturnFalseWhenAggregatorIsInvalid() {
    // 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(true);
    // When
    final ValidationResult result = validator.validate(elementDef);
    // Then
    assertFalse(result.isValid());
    assertTrue(result.getErrorString().contains("No aggregator found for properties"));
    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) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Test(org.junit.jupiter.api.Test)

Example 10 with ValidationResult

use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.

the class SchemaElementDefinitionValidatorTest method shouldValidateFunctionSelectionsAndReturnTrueWhenNoFunctionsSet.

@Test
public void shouldValidateFunctionSelectionsAndReturnTrueWhenNoFunctionsSet() {
    // Given
    final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
    final ElementFilter elementFilter = new ElementFilter();
    final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
    // When
    final ValidationResult result = validator.validateFunctionArgumentTypes(elementFilter, 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)

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