ValidateOperationChainHandler implements OutputOperationHandler<ValidateOperationChain, ValidationResult> { @Override public ValidationResult doOperation(final ValidateOperationChain operation, final Context context, final Store store) throws OperationException { return validateOperationChain(operation.getOperationChain(), context.getUser(), store); }  @Override ValidationResult doOperation(final ValidateOperationChain operation, final Context context, final Store store);  }
@Test public void shouldValidateOperationChain() throws OperationException { final AddElements addElements = new AddElements(); final GetAdjacentIds getAdj = new GetAdjacentIds(); final GetElements getElements = new GetElements(); final DiscardOutput discardOutput = new DiscardOutput(); OperationChain chain = new OperationChain.Builder().first(addElements).then(getAdj).then(getElements).then(discardOutput).build(); ValidateOperationChain validateOperationChain = new ValidateOperationChain.Builder().operationChain(chain).build(); given(store.getOperationChainValidator()).willReturn(new OperationChainValidator(new ViewValidator())); ValidateOperationChainHandler handler = new ValidateOperationChainHandler(); ValidationResult result = handler.doOperation(validateOperationChain, context, store); assertTrue(result.isValid()); }
@Test public void shouldReturnValidationResultWithErrorsIfOperationChainInvalid() throws OperationException { 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(); ValidationResult result = handler.doOperation(validateOperationChain, context, store); assertFalse(result.isValid()); assertTrue(result.getErrorString().contains("elementGenerator is required for: AddElementsFromSocket")); assertTrue(result.getErrorString().contains("hostname is required for: AddElementsFromSocket")); }