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