Search in sources :

Example 61 with ValidationResult

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

the class StoreTest method setup.

@BeforeEach
public void setup() {
    System.clearProperty(JSONSerialiser.JSON_SERIALISER_CLASS_KEY);
    System.clearProperty(JSONSerialiser.JSON_SERIALISER_MODULES);
    JSONSerialiser.update();
    schemaOptimiser = mock(SchemaOptimiser.class);
    operationChainValidator = mock(OperationChainValidator.class);
    store = new StoreImpl();
    given(operationChainValidator.validate(any(OperationChain.class), any(User.class), any(Store.class))).willReturn(new ValidationResult());
    addElementsHandler = mock(OperationHandler.class);
    getElementsHandler = mock(OutputOperationHandler.class);
    getAllElementsHandler = mock(OutputOperationHandler.class);
    getAdjacentIdsHandler = mock(OutputOperationHandler.class);
    validateHandler = mock(OperationHandler.class);
    exportToGafferResultCacheHandler = mock(OperationHandler.class);
    getGafferResultCacheExportHandler = mock(OperationHandler.class);
    jobTracker = mock(JobTracker.class);
    schema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source("string").destination("string").directed("true").property(TestPropertyNames.PROP_1, "string").property(TestPropertyNames.PROP_2, "string").build()).edge(TestGroups.EDGE_2, new SchemaEdgeDefinition.Builder().source("string").destination("string").directed("true").property(TestPropertyNames.PROP_1, "string").property(TestPropertyNames.PROP_2, "string").build()).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().vertex("string").property(TestPropertyNames.PROP_1, "string").property(TestPropertyNames.PROP_2, "string").build()).entity(TestGroups.ENTITY_2, new SchemaEntityDefinition.Builder().vertex("string").property(TestPropertyNames.PROP_1, "string").property(TestPropertyNames.PROP_2, "string").build()).type("string", new TypeDefinition.Builder().clazz(String.class).serialiser(new StringSerialiser()).aggregateFunction(new StringConcat()).build()).type("true", Boolean.class).build();
}
Also used : StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) StringToStringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser) StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) User(uk.gov.gchq.gaffer.user.User) JobTracker(uk.gov.gchq.gaffer.jobtracker.JobTracker) OutputOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) SchemaOptimiser(uk.gov.gchq.gaffer.store.schema.SchemaOptimiser) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) OutputOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler) OperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OperationHandler) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 62 with ValidationResult

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

the class StoreTest method shouldThrowExceptionIfOperationChainIsInvalid.

@Test
public void shouldThrowExceptionIfOperationChainIsInvalid() throws OperationException, StoreException {
    // Given
    // Given
    final Schema schema = createSchemaMock();
    final StoreProperties properties = mock(StoreProperties.class);
    final OperationChain opChain = new OperationChain();
    final StoreImpl store = new StoreImpl();
    given(properties.getJobExecutorThreadCount()).willReturn(1);
    given(schema.validate()).willReturn(new ValidationResult());
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError("error");
    given(operationChainValidator.validate(opChain, user, store)).willReturn(validationResult);
    store.initialise("graphId", schema, properties);
    // When / Then
    try {
        store.execute(opChain, context);
        fail("Exception expected");
    } catch (final IllegalArgumentException e) {
        verify(operationChainValidator).validate(opChain, user, store);
        assertTrue(e.getMessage().contains("Operation chain"));
    }
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetSchema(uk.gov.gchq.gaffer.store.operation.GetSchema) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Test(org.junit.jupiter.api.Test)

Example 63 with ValidationResult

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

the class ValidatedElementsTest method setup.

@BeforeEach
public void setup() {
    elements = new ArrayList<>();
    filters = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        elements.add(mock(Element.class));
        filters.add(mock(ElementFilter.class));
        final String group = "group " + i;
        lenient().when(elements.get(i).getGroup()).thenReturn(group);
        lenient().when(filters.get(i).test(elements.get(i))).thenReturn(true);
        lenient().when(filters.get(i).testWithValidationResult(elements.get(i))).thenReturn(new ValidationResult());
        final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
        lenient().when(schema.getElement(group)).thenReturn(elementDef);
        lenient().when(elementDef.getValidator(true)).thenReturn(filters.get(i));
    }
    lenient().when(filters.get(1).test(elements.get(1))).thenReturn(false);
    lenient().when(filters.get(1).testWithValidationResult(elements.get(1))).thenReturn(new ValidationResult("Some error"));
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 64 with ValidationResult

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

the class AggregateValidator method validateOperation.

@Override
protected ValidationResult validateOperation(final Aggregate operation, final Schema schema) {
    final ValidationResult result = new ValidationResult();
    final Map<String, ?> entities = null != operation.getEntities() ? operation.getEntities() : new HashMap<>();
    final Map<String, ?> edges = null != operation.getEdges() ? operation.getEdges() : new HashMap<>();
    for (final Map.Entry<String, ?> entry : edges.entrySet()) {
        result.add(validateEdge(entry, schema));
        result.add(validateElementAggregator(entry, schema));
        result.add(validateAggregatePropertyClasses(schema.getEdge(entry.getKey()), (AggregatePair) entry.getValue()));
    }
    for (final Map.Entry<String, ?> entry : entities.entrySet()) {
        result.add(validateEntity(entry, schema));
        result.add(validateElementAggregator(entry, schema));
        result.add(validateAggregatePropertyClasses(schema.getEntity(entry.getKey()), (AggregatePair) entry.getValue()));
    }
    return result;
}
Also used : AggregatePair(uk.gov.gchq.gaffer.operation.util.AggregatePair) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) HashMap(java.util.HashMap) Map(java.util.Map)

Example 65 with ValidationResult

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

the class FunctionValidator method validate.

public ValidationResult validate(final T operation, final Schema schema) {
    final ValidationResult result = new ValidationResult();
    if (null == operation) {
        result.addError("Operation cannot be null.");
    }
    if (null == schema) {
        result.addError("Schema cannot be null.");
    }
    result.add(validateOperation(operation, schema));
    return result;
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

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