ValidateAddTemplate extends ValidateTemplateOperation implements AddTemplatesValidator { @Override public void validate(final AddTemplatesValidationContext validationContext) throws RestErrorException { validationContext.setOperationName("add-templates"); super.validate(validationContext); if (validationContext.getRequest().getUploadKey() == null) { throw new RestErrorException(CloudifyErrorMessages.UPLOAD_KEY_PARAMETER_MISSING.getName()); } }  @Override void validate(final AddTemplatesValidationContext validationContext);  }
@Test public void testMissingUploadKey() { AddTemplatesValidationContext validationContext = new AddTemplatesValidationContext(); validationContext.setCloud(new Cloud()); validationContext.setOperationName("add-templates"); AddTemplatesRequest request = new AddTemplatesRequest(); request.setUploadKey(null); validationContext.setRequest(request); ValidateAddTemplate validator = new ValidateAddTemplate(); try { validator.validate(validationContext); Assert.fail("RestErrorException expected"); } catch (RestErrorException e) { Assert.assertEquals(CloudifyErrorMessages.UPLOAD_KEY_PARAMETER_MISSING.getName(), e.getMessage()); } }