Search in sources :

Example 56 with ValidationResult

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

the class OperationChainValidatorTest method shouldNotValidateInvalidOperationChain.

@Test
public void shouldNotValidateInvalidOperationChain() {
    // Given
    Operation operation = Mockito.mock(Operation.class);
    given(operation.validate()).willReturn(new ValidationResult("SparkContext is required"));
    OperationChain opChain = new OperationChain(operation);
    // When
    validateOperationChain(opChain, false);
    // Then
    verify(operation).validate();
}
Also used : OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Operation(uk.gov.gchq.gaffer.operation.Operation) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 57 with ValidationResult

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

the class GraphForExportDelegate method validateGraph.

@Override
public void validateGraph(final Store store, final String graphId, final Schema schema, final StoreProperties storeProperties, final List<String> parentSchemaIds, final String parentStorePropertiesId, final Pair<Schema, StoreProperties> existingGraphPair) {
    ValidationResult result = super.validate(store, graphId, schema, storeProperties, parentSchemaIds, parentStorePropertiesId, existingGraphPair, new ValidationResult());
    Set<String> errors = result.getErrors();
    result.getErrors().removeIf(s -> s.equals(String.format(CANT_BOTH_BE_NULL, SCHEMA_STRING, PARENT_SCHEMA_IDS)) || s.equals(String.format(CANT_BOTH_BE_NULL, STORE_PROPERTIES_STRING, PARENT_STORE_PROPERTIES_ID)));
    result = new ValidationResult();
    for (final String error : errors) {
        result.addError(error);
    }
    if (graphId.equals(store.getGraphId())) {
        result.addError(String.format(CANNOT_EXPORT_TO_THE_SAME_GRAPH_S, graphId));
    }
    if (!result.isValid()) {
        throw new IllegalArgumentException(result.getErrorString());
    }
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Example 58 with ValidationResult

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

the class SampleElementsForSplitPointsTest method shouldFailValidationIfProportionToSampleIsNotIn0_1Range.

@Test
public void shouldFailValidationIfProportionToSampleIsNotIn0_1Range() {
    // Given
    final SampleElementsForSplitPoints op = new SampleElementsForSplitPoints.Builder<>().proportionToSample(1.1f).build();
    // When
    final ValidationResult result = op.validate();
    // Then
    assertFalse(result.isValid());
    assertTrue(result.getErrorString().contains("proportionToSample must within range: [0, 1]"), result.getErrorString());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest)

Example 59 with ValidationResult

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

the class SampleElementsForSplitPointsTest method shouldFailValidationIfNumSplitsIsLessThan1.

@Test
public void shouldFailValidationIfNumSplitsIsLessThan1() {
    // Given
    final SampleElementsForSplitPoints op = new SampleElementsForSplitPoints.Builder<>().numSplits(0).build();
    // When
    final ValidationResult result = op.validate();
    // Then
    assertFalse(result.isValid());
    assertTrue(result.getErrorString().contains("numSplits must be null or greater than 0"), result.getErrorString());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Test(org.junit.jupiter.api.Test) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest)

Example 60 with ValidationResult

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

the class InputImplTest method shouldValidateASingleMissingRequiredField.

@Test
public void shouldValidateASingleMissingRequiredField() {
    // Given
    final String requiredField1 = "value1";
    final Date optionalField1 = new Date(1L);
    final CustomVertex optionalField2 = new CustomVertex("type2", "value2");
    final List<String> input = Arrays.asList("1", "2", "3", "4");
    final InputImpl op = new InputImpl.Builder().requiredField1(requiredField1).optionalField1(optionalField1).optionalField2(optionalField2).input(input).build();
    // When
    final ValidationResult validationResult = op.validate();
    // Then
    assertTrue(validationResult.getErrorString().contains("requiredField2 is required"));
}
Also used : CustomVertex(uk.gov.gchq.gaffer.operation.data.CustomVertex) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Date(java.util.Date) Test(org.junit.jupiter.api.Test) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest)

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