use of org.codice.ddf.admin.application.service.ApplicationStatus in project ddf by codice.
the class TestApplicationService method bTestAppStatus.
@Test
public void bTestAppStatus() throws ApplicationServiceException, InterruptedException {
systemSubject.execute(() -> {
// Test AppService
ApplicationService applicationService = getServiceManager().getService(ApplicationService.class);
Set<Application> apps = applicationService.getApplications();
List<Application> catalogList = apps.stream().filter(a -> CATALOG_APP.equals(a.getName())).collect(Collectors.toList());
if (catalogList.size() != 1) {
fail("Expected to find 1 " + CATALOG_APP + " in Application list.");
}
Application catalog = catalogList.get(0);
try {
applicationService.startApplication(catalog);
getServiceManager().waitForAllBundles();
} catch (ApplicationServiceException e) {
LOGGER.error("Failed to start the {}: {}", CATALOG_APP, e.getMessage());
fail();
} catch (InterruptedException e) {
LOGGER.error("Failed to start start all bundles {}", e.getMessage());
fail();
}
assertNotNull("Application [" + CATALOG_APP + "] must not be null", catalog);
ApplicationStatus status = applicationService.getApplicationStatus(catalog);
assertThat("Application [" + CATALOG_APP + "] should be ACTIVE", status.getState(), is(ACTIVE));
List<Application> registryList = apps.stream().filter(a -> REGISTRY_APP.equals(a.getName())).collect(Collectors.toList());
if (catalogList.size() != 1) {
fail("Expected to find 1 " + REGISTRY_APP + " in Application list.");
}
Application registry = registryList.get(0);
assertNotNull("Application [" + REGISTRY_APP + "] must not be null", registry);
status = applicationService.getApplicationStatus(registry);
assertThat("Application [" + REGISTRY_APP + "] should be INACTIVE", status.getState(), is(INACTIVE));
// Test Commands
String response = console.runCommand(STATUS_COMMAND + CATALOG_APP);
assertThat(CATALOG_APP + " should be ACTIVE", response, containsString(ACTIVE_APP));
response = console.runCommand(STATUS_COMMAND + REGISTRY_APP);
assertThat(REGISTRY_APP + " should be INACTIVE", response, containsString(INACTIVE_APP));
});
}
use of org.codice.ddf.admin.application.service.ApplicationStatus in project ddf by codice.
the class TestApplicationService method cTestAppStartStop.
@Test
// DDF-2954
@ConditionalIgnoreRule.ConditionalIgnore(condition = SkipUnstableTest.class)
public void cTestAppStartStop() throws ApplicationServiceException {
systemSubject.execute(() -> {
// Test AppService
ApplicationService applicationService = getServiceManager().getService(ApplicationService.class);
Application registry = applicationService.getApplication(REGISTRY_APP);
assertNotNull("Application [" + REGISTRY_APP + "] must not be null", registry);
ApplicationStatus status = applicationService.getApplicationStatus(registry);
assertThat(REGISTRY_APP + " should be INACTIVE", status.getState(), is(INACTIVE));
try {
applicationService.startApplication(registry);
} catch (ApplicationServiceException e) {
LOGGER.error("Failed to start the {}: {}", REGISTRY_APP, e.getMessage());
fail();
}
status = applicationService.getApplicationStatus(registry);
assertThat(REGISTRY_APP + " should be ACTIVE after start, but was [" + status.getState() + "]", status.getState(), is(ACTIVE));
try {
applicationService.stopApplication(registry);
} catch (ApplicationServiceException e) {
LOGGER.error("Failed to stop the {}: {}", REGISTRY_APP, e.getMessage());
fail();
}
status = applicationService.getApplicationStatus(registry);
assertThat(REGISTRY_APP + " should be INACTIVE after stop", status.getState(), is(INACTIVE));
// Test Commands
String response = console.runCommand(STATUS_COMMAND + REGISTRY_APP);
assertThat(REGISTRY_APP + " should be INACTIVE", response, containsString(INACTIVE_APP));
response = console.runCommand(START_COMMAND + REGISTRY_APP);
assertThat(REGISTRY_APP + " should be empty response after " + START_COMMAND, response, isEmptyString());
response = console.runCommand(STATUS_COMMAND + REGISTRY_APP);
assertThat(REGISTRY_APP + " should be ACTIVE after " + START_COMMAND, response, containsString(ACTIVE_APP));
response = console.runCommand(STOP_COMMAND + REGISTRY_APP);
assertThat(REGISTRY_APP + " should be empty response after " + START_COMMAND, response, isEmptyString());
response = console.runCommand(STATUS_COMMAND + REGISTRY_APP);
assertThat(REGISTRY_APP + " should be INACTIVE after " + STOP_COMMAND, response, containsString(INACTIVE_APP));
});
}
use of org.codice.ddf.admin.application.service.ApplicationStatus in project ddf by codice.
the class ApplicationServiceImplTest method testGetActiveApplicationStatus.
/**
* Tests receiving application status for an application in the ACTIVE
* state.
*/
@Test
public void testGetActiveApplicationStatus() throws Exception {
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(noMainFeatureRepo1));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
Set<Application> applications = appService.getApplications();
assertEquals(1, applications.size());
for (Application curApp : applications) {
ApplicationStatus status = appService.getApplicationStatus(curApp);
assertEquals(curApp, status.getApplication());
assertEquals(ApplicationState.ACTIVE, status.getState());
assertTrue(status.getErrorBundles().isEmpty());
assertTrue(status.getErrorFeatures().isEmpty());
}
}
use of org.codice.ddf.admin.application.service.ApplicationStatus in project ddf by codice.
the class StopApplicationCommandTest method testStopApplicationCommandTest.
/**
* Tests the {@link StopApplicationCommand} class and its associated methods
*
* @throws Exception
*/
@Test
public void testStopApplicationCommandTest() throws Exception {
ApplicationService testAppService = mock(ApplicationServiceImpl.class);
Application testApp = mock(ApplicationImpl.class);
ApplicationStatus testStatus = mock(ApplicationStatus.class);
StopApplicationCommand stopApplicationCommand = new StopApplicationCommand();
stopApplicationCommand.appName = APP_NAME;
when(testStatus.getState()).thenReturn(ApplicationState.ACTIVE);
when(testAppService.getApplicationStatus(testApp)).thenReturn(testStatus);
when(testAppService.getApplication(APP_NAME)).thenReturn(testApp);
stopApplicationCommand.doExecute(testAppService);
verify(testAppService).stopApplication(APP_NAME);
}
use of org.codice.ddf.admin.application.service.ApplicationStatus in project ddf by codice.
the class StopApplicationCommandTest method testStopApplicationCommandAlreadyStopped.
/**
* Tests the {@link StopApplicationCommand} class and its associated methods
* for the case where the application parameter has already been stopped
*
* @throws Exception
*/
@Test
public void testStopApplicationCommandAlreadyStopped() throws Exception {
ApplicationService testAppService = mock(ApplicationServiceImpl.class);
Application testApp = mock(ApplicationImpl.class);
ApplicationStatus testStatus = mock(ApplicationStatus.class);
StopApplicationCommand stopApplicationCommand = new StopApplicationCommand();
stopApplicationCommand.appName = APP_NAME;
when(testStatus.getState()).thenReturn(ApplicationState.INACTIVE);
when(testAppService.getApplicationStatus(testApp)).thenReturn(testStatus);
when(testAppService.getApplication(APP_NAME)).thenReturn(testApp);
// Should handle this condition gracefully without throwing an exception
// If an exception is thrown, this test fails...
stopApplicationCommand.doExecute(testAppService);
}
Aggregations