Search in sources :

Example 46 with ValidationResult

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

the class GetGraphFrameOfElementsTest method shouldValidateOperationWhenViewContainsElementsWithReservedPropertyNames.

@Test
public void shouldValidateOperationWhenViewContainsElementsWithReservedPropertyNames() {
    // Given
    final Operation op = new GetGraphFrameOfElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().properties("vertex").build()).edge(TestGroups.EDGE).build()).build();
    // When
    final ValidationResult validationResult = op.validate();
    // Then
    assertTrue(validationResult.isValid());
}
Also used : ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) Operation(uk.gov.gchq.gaffer.operation.Operation) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest)

Example 47 with ValidationResult

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

the class AlwaysValidTrue method shouldReturnValidationResultForNullAndString.

@ParameterizedTest
@NullSource
@ValueSource(strings = { "test" })
public void shouldReturnValidationResultForNullAndString(String input) {
    final AlwaysValid<String> validator = new AlwaysValid<>();
    final ValidationResult result = validator.validateWithValidationResult(input);
    assertTrue(result.isValid());
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) NullSource(org.junit.jupiter.params.provider.NullSource)

Example 48 with ValidationResult

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

the class FieldUtilTest method testNotNullField.

@Test
public void testNotNullField() {
    final Pair nonNullPair = new Pair("Test", "Test");
    final ValidationResult validationResult = FieldUtil.validateRequiredFields(nonNullPair);
    final Set<String> expected = new LinkedHashSet<>();
    assertEquals(expected, validationResult.getErrors());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair) Test(org.junit.jupiter.api.Test)

Example 49 with ValidationResult

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

the class FieldUtilTest method testNullField.

@Test
public void testNullField() {
    final Pair nullPair = new Pair("Test", null);
    final ValidationResult validationResult = FieldUtil.validateRequiredFields(nullPair);
    final Set<String> expected = new LinkedHashSet<>();
    expected.add("Test is required.");
    assertEquals(expected, validationResult.getErrors());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair) Test(org.junit.jupiter.api.Test)

Example 50 with ValidationResult

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

the class Validator method validateWithValidationResult.

/**
 * <p>
 * Validates the given object and results a ValidationResult that can
 * contain information as to why validation fails.
 * </p>
 * <p>
 * It is less efficient than just calling validate as complex validation
 * strings may be built to detail why objects are invalid.
 * </p>
 *
 * @param obj an object of type T to validate.
 * @return the ValidationResult.
 */
default ValidationResult validateWithValidationResult(final T obj) {
    final boolean result = validate(obj);
    final ValidationResult validationResult = new ValidationResult();
    if (!result) {
        validationResult.addError("Validation failed for obj: " + obj);
    }
    return validationResult;
}
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