use of org.codice.ddf.admin.application.service.ApplicationServiceException in project ddf by codice.
the class ApplicationServiceImplTest method testRemoveApplicationApplicationServiceException.
/**
* Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
* for the case where an ApplicationServiceException is thrown within uninstallAllFeatures(..)
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRemoveApplicationApplicationServiceException() throws Exception {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1, noMainFeatureRepo2));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
Application testApp = mock(ApplicationImpl.class);
doThrow(new ApplicationServiceException()).when(testApp).getFeatures();
appService.removeApplication(testApp);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(UNINSTALL_ASE);
}
}));
}
use of org.codice.ddf.admin.application.service.ApplicationServiceException in project ddf by codice.
the class TestApplicationService method dTestAppAddRemove.
@Test
public void dTestAppAddRemove() throws ApplicationServiceException {
systemSubject.execute(() -> {
ApplicationService applicationService = getServiceManager().getService(ApplicationService.class);
Application sdkApp = applicationService.getApplication(SDK_APP);
URI sdkUri = sdkApp.getURI();
// Remove
try {
applicationService.removeApplication(sdkApp);
} catch (ApplicationServiceException e) {
LOGGER.error("Failed to remove {}: {}", sdkApp.getName(), e.getMessage());
fail();
}
Set<Application> apps = applicationService.getApplications();
assertThat(apps, not(hasItem(sdkApp)));
// Add
try {
applicationService.addApplication(sdkUri);
} catch (ApplicationServiceException e) {
LOGGER.error("Failed to add {}: {}", sdkUri, e.getMessage());
fail();
}
sdkApp = applicationService.getApplication(SDK_APP);
assertThat(sdkApp.getName(), is(SDK_APP));
assertThat(sdkApp.getURI(), is(sdkUri));
ApplicationStatus status = applicationService.getApplicationStatus(sdkApp);
assertThat(status.getState(), is(INACTIVE));
apps = applicationService.getApplications();
assertThat(apps, hasItem(sdkApp));
// Test Commands
// Remove
String response = console.runCommand(REMOVE_COMMAND + SDK_APP);
assertThat("Should be empty response after " + REMOVE_COMMAND, response, isEmptyString());
response = console.runCommand(STATUS_COMMAND + SDK_APP);
assertThat(SDK_APP + " should be not be found after " + REMOVE_COMMAND, response, containsString("No application found with name " + SDK_APP));
// Add
response = console.runCommand(ADD_COMMAND + sdkUri.toString());
assertThat("Should be empty response after " + ADD_COMMAND, response, isEmptyString());
response = console.runCommand(STATUS_COMMAND + SDK_APP);
assertThat(SDK_APP + " should be INACTIVE after " + STATUS_COMMAND, response, containsString(INACTIVE_APP));
try {
applicationService.startApplication(SDK_APP);
} catch (ApplicationServiceException e) {
LOGGER.error("Failed to restart {}: {}", sdkUri, e.getMessage());
fail();
}
});
}
use of org.codice.ddf.admin.application.service.ApplicationServiceException in project ddf by codice.
the class ApplicationServiceBeanTest method testRemoveApplicationASE.
/**
* Tests the {@link ApplicationServiceBean#removeApplication(String)} method
* for the case where an ApplicationServiceException is thrown by the AppService
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRemoveApplicationASE() throws Exception {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
root.setLevel(Level.ALL);
ApplicationServiceBean serviceBean = new ApplicationServiceBean(testAppService, testConfigAdminExt, mBeanServer);
doThrow(new ApplicationServiceException()).when(testAppService).removeApplication(any(String.class));
serviceBean.removeApplication(TEST_APP_NAME);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(REMOVE_APP_ASE);
}
}));
}
use of org.codice.ddf.admin.application.service.ApplicationServiceException in project ddf by codice.
the class ApplicationServiceBeanTest method testStartApplicationException.
/**
* Tests the {@link ApplicationServiceBean#startApplication(String)} method for the case where
* an exception is thrown
*
* @throws Exception
*/
@Test
public void testStartApplicationException() throws Exception {
ApplicationServiceBean serviceBean = new ApplicationServiceBean(testAppService, testConfigAdminExt, mBeanServer);
doThrow(new ApplicationServiceException()).when(testAppService).startApplication(TEST_APP_NAME);
assertFalse(serviceBean.startApplication(TEST_APP_NAME));
verify(testAppService).startApplication(TEST_APP_NAME);
}
use of org.codice.ddf.admin.application.service.ApplicationServiceException in project ddf by codice.
the class ApplicationFileInstaller method install.
/**
* Installs the given application file to the system repository.
*
* @param application
* Application file to install.
* @return A string URI that points to the main feature file for the
* application that was just installed.
* @throws ApplicationServiceException
* If any errors occur while trying to install the application.
*/
public static URI install(File application) throws ApplicationServiceException {
// Extract files to local repo
ZipFile appZip = null;
try {
appZip = new ZipFile(application);
if (isFileValid(appZip)) {
LOGGER.debug("Installing {} to the system repository.", application.getAbsolutePath());
String featureLocation = installToRepo(appZip);
String uri = new File("").getAbsolutePath() + File.separator + REPO_LOCATION + featureLocation;
// It fails on windows if we do not use.
return Paths.get(uri).toUri();
}
} catch (ZipException ze) {
LOGGER.warn("Got an error when trying to read the application as a zip file.", ze);
} catch (IOException ioe) {
LOGGER.warn("Got an error when trying to read the incoming application.", ioe);
} finally {
IOUtils.closeQuietly(appZip);
}
throw new ApplicationServiceException("Could not install application.");
}
Aggregations