use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaOperationChainUtilTest method shouldValidateValidOperationChainAgainstSchema.
@Test
public void shouldValidateValidOperationChainAgainstSchema() {
// When
final ValidationResult validationResult = SchemaOperationChainUtil.validate(schema, validOperationChain);
// Then
assertTrue(validationResult.isValid());
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class SchemaOperationChainUtilTest method shouldValidateInvalidOperationChainAgainstSchema.
@Test
public void shouldValidateInvalidOperationChainAgainstSchema() {
// When
final ValidationResult validationResult = SchemaOperationChainUtil.validate(schema, invalidOperationChain);
// Then
assertFalse(validationResult.isValid());
assertThat(validationResult.getErrorString()).contains("elementGenerator is required for: AddElementsFromSocket").contains("hostname is required for: AddElementsFromSocket");
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class OperationChainHandlerTest method shouldHandleNestedOperationChain.
@Test
public void shouldHandleNestedOperationChain() throws OperationException {
// Given
final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
final OperationChainHandler opChainHandler = new OperationChainHandler(opChainValidator, opChainOptimisers);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final User user = mock(User.class);
final StoreProperties storeProperties = new StoreProperties();
final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
final GetElements op2 = mock(GetElements.class);
final Limit op3 = mock(Limit.class);
final OperationChain opChain1 = new OperationChain(Arrays.asList(op1, op2));
final OperationChain opChain2 = new OperationChain(Arrays.asList(opChain1, op3));
final Entity entityA = new Entity.Builder().group(TestGroups.ENTITY).vertex("A").build();
final Entity entityB = new Entity.Builder().group(TestGroups.ENTITY).vertex("B").build();
given(context.getUser()).willReturn(user);
given(store.getProperties()).willReturn(storeProperties);
given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
given(store.handleOperation(op1, context)).willReturn(new WrappedCloseableIterable<>(Lists.newArrayList(new EntitySeed("A"), new EntitySeed("B"))));
given(store.handleOperation(op2, context)).willReturn(new WrappedCloseableIterable<>(Lists.newArrayList(entityA, entityB)));
given(store.handleOperation(op3, context)).willReturn(entityA);
// When
final Object result = opChainHandler.doOperation(opChain2, context, store);
// Then
assertSame(entityA, result);
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class ValidateOperationChainHandlerTest method shouldReturnValidationResultWithErrorsIfOperationChainInvalid.
@Test
public void shouldReturnValidationResultWithErrorsIfOperationChainInvalid() throws OperationException {
// Given
final AddElementsFromSocket addElementsFromSocket = new AddElementsFromSocket();
OperationChain chain = new OperationChain.Builder().first(addElementsFromSocket).build();
ValidateOperationChain validateOperationChain = new ValidateOperationChain.Builder().operationChain(chain).build();
given(store.getOperationChainValidator()).willReturn(new OperationChainValidator(new ViewValidator()));
ValidateOperationChainHandler handler = new ValidateOperationChainHandler();
// When
ValidationResult result = handler.doOperation(validateOperationChain, context, store);
// Then
assertFalse(result.isValid());
assertTrue(result.getErrorString().contains("elementGenerator is required for: AddElementsFromSocket"));
assertTrue(result.getErrorString().contains("hostname is required for: AddElementsFromSocket"));
}
use of uk.gov.gchq.koryphe.ValidationResult in project Gaffer by gchq.
the class OperationChainValidatorTest method shouldInValidateNullElementDef.
@Test
public void shouldInValidateNullElementDef() {
// Given
final ViewValidator viewValidator = mock(ViewValidator.class);
final OperationChainValidator validator = new OperationChainValidator(viewValidator);
final Store store = mock(Store.class);
Schema schema = mock(Schema.class);
given(store.getSchema()).willReturn(schema);
given(schema.getElement(Mockito.anyString())).willReturn(null);
Max max = new Max();
max.setComparators(Lists.newArrayList(new ElementPropertyComparator.Builder().groups(TestGroups.ENTITY).property("property").build()));
ValidationResult validationResult = new ValidationResult();
// When
validator.validateComparables(max, null, store, validationResult);
// Then
assertEquals(false, validationResult.isValid());
Set<String> errors = validationResult.getErrors();
assertThat(errors).hasSize(1);
errors.contains(Max.class.getName() + " references BasicEntity group that does not exist in the schema");
}
Aggregations