Search in sources :

Example 81 with ValidationResult

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

the class ViewValidatorTest method shouldValidateAndReturnTrueWhenEntityTransformerResult.

@Test
public void shouldValidateAndReturnTrueWhenEntityTransformerResult() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().transformer(new ElementTransformer.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new ExampleTransformFunction()).project(TestPropertyNames.PROP_3).build()).build()).build();
    final Schema schema = new Schema.Builder().type("double", Double.class).type("int", Integer.class).type("string", String.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "double").property(TestPropertyNames.PROP_2, "int").property(TestPropertyNames.PROP_3, "string").build()).build();
    // When
    final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS);
    // Then
    assertTrue(result.isValid());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ExampleTransformFunction(uk.gov.gchq.gaffer.function.ExampleTransformFunction) Test(org.junit.jupiter.api.Test)

Example 82 with ValidationResult

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

the class SchemaEdgeDefinitionTest method shouldPassValidationWhenEdgeSourceAndDestinationDefined.

@Test
public void shouldPassValidationWhenEdgeSourceAndDestinationDefined() {
    // Given
    final SchemaEdgeDefinition elementDef = new SchemaEdgeDefinition.Builder().source("src").destination("dest").directed(DIRECTED_EITHER).build();
    final Schema schema = new Schema.Builder().edge(TestGroups.EDGE, elementDef).type("src", String.class).type("dest", String.class).type(DIRECTED_EITHER, Boolean.class).build();
    final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
    // When
    final ValidationResult result = validator.validate(elementDef);
    // Then
    assertTrue(result.isValid());
}
Also used : Builder(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition.Builder) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 83 with ValidationResult

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

the class SchemaElementDefinitionValidatorTest method shouldValidateAndReturnFalseWhenGroupByIsAggregatedWithNonGroupByProperty.

@Test
public void shouldValidateAndReturnFalseWhenGroupByIsAggregatedWithNonGroupByProperty() {
    // 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").property(TestPropertyNames.PROP_2, "string").groupBy(TestPropertyNames.PROP_1).aggregator(new ElementAggregator.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).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("groupBy properties and non-groupBy properties (including timestamp) must be not be aggregated using the same BinaryOperator. Selection tuple: [property1, property2], is aggregated by: " + function1.getClass().getName()), 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 84 with ValidationResult

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

the class SchemaElementDefinitionValidatorTest method shouldValidateComponentTypesAndReturnFalseForInvalidPropertyClass.

@Test
public void shouldValidateComponentTypesAndReturnFalseForInvalidPropertyClass() {
    // Given
    final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
    final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
    given(elementDef.getIdentifiers()).willReturn(new HashSet<>());
    given(elementDef.getProperties()).willReturn(Sets.newSet(TestPropertyNames.PROP_1));
    given(elementDef.getPropertyClass(TestPropertyNames.PROP_1)).willThrow(new IllegalArgumentException());
    // When
    final ValidationResult result = validator.validateComponentTypes(elementDef);
    // Then
    assertFalse(result.isValid());
    assertEquals("Validation errors: \nClass null for property property1 could not be found", result.getErrorString());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 85 with ValidationResult

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

the class SchemaElementDefinitionValidatorTest method shouldValidateFunctionSelectionsAndReturnFalseWhenFunctionTypeDoesNotEqualSelectionType.

@Test
public void shouldValidateFunctionSelectionsAndReturnFalseWhenFunctionTypeDoesNotEqualSelectionType() {
    // Given
    final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
    given(elementDef.getPropertyClass("selection")).willReturn((Class) String.class);
    final IsMoreThan function = new IsMoreThan(5);
    final ElementFilter elementFilter = new ElementFilter.Builder().select("selection").execute(function).build();
    final SchemaElementDefinitionValidator validator = new SchemaElementDefinitionValidator();
    // When
    final ValidationResult result = validator.validateFunctionArgumentTypes(elementFilter, elementDef);
    // Then
    assertFalse(result.isValid());
    assertEquals("Validation errors: \nControl value class java.lang.Integer is not compatible" + " with the input type: class java.lang.String", result.getErrorString());
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) 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