Search in sources :

Example 96 with ValidationResult

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

the class ViewValidatorTest method shouldValidateAndReturnTrueWhenEntityTransformerSelectionUnknownProperty.

@Test
public void shouldValidateAndReturnTrueWhenEntityTransformerSelectionUnknownProperty() {
    // 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()).build()).build();
    final Schema schema = new Schema.Builder().type("obj", Object.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "obj").build()).build();
    // When
    final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS);
    // Then
    assertTrue(result.isValid());
}
Also used : ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) 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 97 with ValidationResult

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

the class ViewValidatorTest method shouldValidateAndReturnTrueWhenEdgeTransformerSelectionUnknownProperty.

@Test
public void shouldValidateAndReturnTrueWhenEdgeTransformerSelectionUnknownProperty() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().edge(TestGroups.EDGE, 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()).build()).build();
    final Schema schema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, "obj").build()).build();
    // When
    final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS);
    // Then
    assertTrue(result.isValid());
}
Also used : ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) 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 98 with ValidationResult

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

the class ViewValidatorTest method shouldValidateAndReturnFalseWhenEntityTransientPropertyIsInSchema.

@Test
public void shouldValidateAndReturnFalseWhenEntityTransientPropertyIsInSchema() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.PROP_1, String.class).build()).build();
    final Schema schema = new Schema.Builder().type("prop1", Object.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "prop1").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) Test(org.junit.jupiter.api.Test)

Example 99 with ValidationResult

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

the class ViewValidatorTest method shouldValidateAndReturnFalseForAndFilterWithIncompatibleProperties.

@Test
public void shouldValidateAndReturnFalseForAndFilterWithIncompatibleProperties() {
    // 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 And.Builder().select(0).execute(new IsMoreThan(2)).select(1).execute(new IsEqual("some other value")).build()).build()).build()).build();
    final Schema schema = new Schema.Builder().type("obj", Object.class).type("string", String.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "obj").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) And(uk.gov.gchq.koryphe.impl.predicate.And) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Test(org.junit.jupiter.api.Test)

Example 100 with ValidationResult

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

the class ViewValidatorTest method shouldValidateAndReturnFalseWhenMissingTraits.

@Test
public void shouldValidateAndReturnFalseWhenMissingTraits() {
    // Given
    final ViewValidator validator = new ViewValidator();
    final View view = new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.PROP_3, String.class).preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new Exists()).build()).aggregator(new ElementAggregator.Builder().select(TestPropertyNames.PROP_1).execute(new StringConcat()).build()).postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_2).execute(new Exists()).build()).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.PROP_3).execute(new Exists()).build()).build()).build();
    final Schema schema = new Schema.Builder().type("obj", String.class).type("string", String.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, "obj").property(TestPropertyNames.PROP_2, "string").build()).build();
    // When
    final ValidationResult result = validator.validate(view, schema, NO_STORE_TRAITS);
    // Then
    final String errPrefix = "This store does not currently support ";
    assertFalse(result.isValid());
    assertEquals(Sets.newHashSet(errPrefix + StoreTrait.PRE_AGGREGATION_FILTERING.name(), errPrefix + StoreTrait.QUERY_AGGREGATION.name(), errPrefix + StoreTrait.POST_AGGREGATION_FILTERING.name(), errPrefix + StoreTrait.TRANSFORMATION.name(), errPrefix + StoreTrait.POST_TRANSFORMATION_FILTERING.name()), result.getErrors());
}
Also used : StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ExampleTransformFunction(uk.gov.gchq.gaffer.function.ExampleTransformFunction) 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