ValidateCustomCommandName implements InstallServiceValidator { @Override public void validate(final InstallServiceValidationContext validationContext) throws RestErrorException { logger.info("Validating custom command name"); ExecutableEntriesMap customCommands = validationContext.getService().getCustomCommands(); for (String key : customCommands.keySet()) { if (key.startsWith(reservedPrefix)) { throw new RestErrorException(CloudifyErrorMessages.ILLEGAL_CUSTOM_COMMAND_PREFIX.getName(), key, reservedPrefix); } } }  @Override void validate(final InstallServiceValidationContext validationContext);  }
@Test public void invalidCustomCommandNameInInstallService1() { Service service = new Service(); ExecutableEntriesMap customCommands = new ExecutableEntriesMap(); customCommands.put("key1", null); customCommands.put(RESERVED_PREFIX + " key2", null); service.setCustomCommands(customCommands); InstallServiceValidationContext context = new InstallServiceValidationContext(); context.setService(service); ValidatorsTestsUtils.validate(validateCustomCommandName, context, ERR_MSG); }
@Test public void invalidCustomCommandNameInInstallService2() { Service service = new Service(); ExecutableEntriesMap customCommands = new ExecutableEntriesMap(); customCommands.put(RESERVED_PREFIX, null); service.setCustomCommands(customCommands); InstallServiceValidationContext context = new InstallServiceValidationContext(); context.setService(service); ValidatorsTestsUtils.validate(validateCustomCommandName, context, ERR_MSG); }
@Test public void invalidCustomCommandNameInInstallService3() { Service service = new Service(); service.setCustomCommands(new ExecutableEntriesMap()); InstallServiceValidationContext context = new InstallServiceValidationContext(); context.setService(service); ValidatorsTestsUtils.validate(validateCustomCommandName, context, null); }
@Test public void invalidCustomCommandNameInInstallApplication1() { Service service = new Service(); ExecutableEntriesMap customCommands = new ExecutableEntriesMap(); customCommands.put("key1", null); customCommands.put(RESERVED_PREFIX + " key2", null); service.setCustomCommands(customCommands); InstallApplicationValidationContext context = new InstallApplicationValidationContext(); Application application = new Application(); List<Service> services = new LinkedList<Service>(); services.add(service); application.setServices(services); context.setApplication(application); ValidatorsTestsUtils.validate(validateApplicationServices, context, ERR_MSG); }
@Test public void invalidCustomCommandNameInInstallApplication2() { Service service = new Service(); ExecutableEntriesMap customCommands = new ExecutableEntriesMap(); customCommands.put(RESERVED_PREFIX, null); service.setCustomCommands(customCommands); InstallApplicationValidationContext context = new InstallApplicationValidationContext(); Application application = new Application(); List<Service> services = new LinkedList<Service>(); services.add(service); application.setServices(services); context.setApplication(application); ValidatorsTestsUtils.validate(validateApplicationServices, context, ERR_MSG); }
@Test public void invalidCustomCommandNameInInstallApplication3() { Service service = new Service(); service.setCustomCommands(new ExecutableEntriesMap()); InstallApplicationValidationContext context = new InstallApplicationValidationContext(); Application application = new Application(); List<Service> services = new LinkedList<Service>(); services.add(service); application.setServices(services); context.setApplication(application); ValidatorsTestsUtils.validate(validateApplicationServices, context, null); }