Search in sources :

Example 91 with ValidationResult

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

Example 92 with ValidationResult

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

Example 93 with ValidationResult

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

Example 94 with ValidationResult

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

Example 95 with ValidationResult

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());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) Not(uk.gov.gchq.koryphe.impl.predicate.Not) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) 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