ValidateApplicationNotManagement implements UninstallApplicationValidator { @Override public void validate(final UninstallApplicationValidationContext validationContext) throws RestErrorException { logger.info("Validating that application is not management"); final String appName = validationContext.getApplicationName(); final Application app = validationContext.getAdmin().getApplications().waitFor( appName, 10, TimeUnit.SECONDS); if (app == null) { logger.log(Level.INFO, "Cannot uninstall application " + appName + " since it has not been discovered yet."); throw new RestErrorException(FAILED_TO_LOCATE_APP, appName); } if (app.getName().equals(CloudifyConstants.MANAGEMENT_APPLICATION_NAME)) { logger.log(Level.INFO, "Cannot uninstall the Management application."); throw new RestErrorException( ResponseConstants.CANNOT_UNINSTALL_MANAGEMENT_APP); } }  @Override void validate(final UninstallApplicationValidationContext validationContext);  }
@Test public void test() { UninstallApplicationValidationContext context = new UninstallApplicationValidationContext(); DefaultAdmin admin = Mockito.mock(DefaultAdmin.class); Applications applications = Mockito.mock(DefaultApplications.class); Mockito.when(applications.getAdmin()).thenReturn(admin); Application application = new DefaultApplication(admin, APP_NAME); Mockito.when(applications.waitFor(APP_NAME, TIMEOUT_SECONDS, TimeUnit.SECONDS)).thenReturn(application); Mockito.when(admin.getApplications()).thenReturn(applications); context.setAdmin(admin); context.setApplicationName(APP_NAME); ValidateApplicationNotManagement validator = new ValidateApplicationNotManagement(); try { validator.validate(context); Assert.fail("RestErrorException expected"); } catch (RestErrorException e) { Assert.assertEquals(ResponseConstants.CANNOT_UNINSTALL_MANAGEMENT_APP, e.getMessage()); } }