use of org.codice.ddf.admin.application.service.ApplicationService 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.ApplicationService 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.ApplicationService in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusReturnsUnkownWhenBundleStateServiceStateIsStarting.
/**
* Test method for
* {@link ApplicationServiceImpl#getApplicationStatus(Application)}
* <p>
* Verifies that {@link ApplicationState#INACTIVE} is returned when the
* extended bundle state reported by an injection framework states that one
* bundle is in an {@link BundleState#Starting} state and the rest of the
* bundles are in an {@link BundleState#Active} state.
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsUnkownWhenBundleStateServiceStateIsStarting() throws Exception {
ApplicationService appService = getAppServiceWithBundleStateServiceInGivenState(mainFeatureRepo2, BundleState.Starting);
assertNotNull("Repository \"" + mainFeatureRepo.getName() + "\" does not contain any bundles", appService);
assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.UNKNOWN, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.
the class ApplicationServiceImplTest method testIsApplicationStartedReturnsFalseForFailedApplicationState.
/**
* Test method for
* {@link ApplicationServiceImpl#isApplicationStarted(Application)}
* <p>
* Verifies that method returns false when application state is
* {@link ApplicationState#FAILED}
*
* @throws Exception
*/
@Test
public void testIsApplicationStartedReturnsFalseForFailedApplicationState() throws Exception {
Set<String> inactiveBundles = new HashSet<String>();
inactiveBundles.add(TEST_MAIN_FEATURES_2_UNIQUE_BUNDLE_LOCATION);
FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo2, null, inactiveBundles);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
when(featuresService.isInstalled(mainFeatureRepo2.getFeatures()[0])).thenReturn(false);
ApplicationService appService = createPermittedApplicationServiceImpl();
assertFalse(appService.isApplicationStarted(appService.getApplication(TEST_MAIN_FEATURES_2_MAIN_FEATURE_NAME)));
}
use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusReturnsFailedStatusWhenOneFeatureConsistingOfInactiveBundlesIsNotInstalled.
/**
* Test method for
* {@link ApplicationService#getApplicationStatus(Application)}
* <p>
* Verifies method returns an {@link ApplicationState#FAILED } state for an
* {@code Application} under the following conditions:
* <p>
* <ul>
* <li>Main feature is installed</li>
* <li>One dependency feature is not installed</li>
* <li>Dependency feature that is not installed contains Bundle(s) whose
* states and extended states are inactive</li>
* </ul>
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsFailedStatusWhenOneFeatureConsistingOfInactiveBundlesIsNotInstalled() throws Exception {
Set<Repository> mainFeaturesRepoSet = new HashSet<Repository>();
Set<Feature> notInstalledFeatures = new HashSet<Feature>();
Set<BundleInfo> inactiveBundles = new HashSet<BundleInfo>();
for (Feature feature : mainFeatureRepo2.getFeatures()) {
if (feature.getName().equals(TEST_MAIN_FEATURES_2_MAIN_FEATURE_NAME)) {
notInstalledFeatures.add(feature);
inactiveBundles.addAll(feature.getBundles());
break;
}
}
assertEquals("Feature is not included in repository the expected number of times", 1, notInstalledFeatures.size());
assertTrue("No bundles included in Feature", inactiveBundles.size() > 0);
mainFeaturesRepoSet.add(mainFeatureRepo2);
FeaturesService featuresService = createMockFeaturesService(mainFeaturesRepoSet, notInstalledFeatures, inactiveBundles);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
assertEquals(ApplicationService.class.getName() + " does not contain the expected number of Applications", 1, appService.getApplications().size());
assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.FAILED, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Aggregations