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());
}
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());
}
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());
}
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());
}
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;
}
Aggregations