use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusReturnsFailedWhenBundleStateServiceStatesIncludeActiveResolvedAndFailure.
/**
* Test method for
* {@link ApplicationServiceImpl#getApplicationStatus(Application)}
* <p>
* Verifies that {@link ApplicationState#FAILED} is returned when the
* extended bundle state reported by an injection framework states that one
* bundle is in an {@link BundleState#Resolved} state, one bundle is in an
* {@link BundleState#Installed} state and the rest of the bundles are in an
* {@link BundleState#Active} state. This simulates a condition wherein the
* {@code getApplicationStatus} method must discern between conditions that,
* independent of each other, would produce
* {@code ApplicationState#INACTIVE}, {@code ApplicationState#FAILED}, or
* {@code ApplicationState#ACTIVE} states, respectively, and determine which
* state to return for the overall Application.
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsFailedWhenBundleStateServiceStatesIncludeActiveResolvedAndFailure() throws Exception {
FeaturesService featuresService = createMockFeaturesService(noMainFeatureRepo1, null, null);
Set<Bundle> bundleSet = getXBundlesFromFeaturesService(featuresService, 2);
assertNotNull(noMainFeatureRepo1.getName() + " does not contain 2 bundles", bundleSet);
Bundle[] bundles = bundleSet.toArray(new Bundle[] {});
when(bundleStateServices.get(0).getState(bundles[0])).thenReturn(BundleState.Resolved);
when(bundleStateServices.get(0).getState(bundles[1])).thenReturn(BundleState.Failure);
ApplicationService appService = getAppServiceWithBundleStateServiceInGivenState(noMainFeatureRepo1, BundleState.Failure);
assertNotNull("Repository \"" + noMainFeatureRepo1.getName() + "\" does not contain any bundles", appService);
assertEquals(noMainFeatureRepo1.getName() + " returned unexpected state", ApplicationState.FAILED, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testRemoveApplicationStringParam.
/**
* Tests the {@link ApplicationServiceImpl#removeApplication(String)} method
*
* @throws Exception
*/
@Test
public void testRemoveApplicationStringParam() throws Exception {
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
Feature[] featureList = mainFeatureRepo.getFeatures();
appService.removeApplication(TEST_APP);
verify(featuresService).uninstallFeature(featureList[0].getName(), featureList[0].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
verify(featuresService).uninstallFeature(featureList[1].getName(), featureList[1].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testIsApplicationStartedReturnsFalseForInactiveApplicationState.
/**
* Test method for
* {@link ApplicationServiceImpl#isApplicationStarted(Application)}
* <p>
* Verifies that method returns false when application state is
* {@link ApplicationState#INACTIVE}
*
* @throws Exception
*/
@Test
public void testIsApplicationStartedReturnsFalseForInactiveApplicationState() throws Exception {
Set<String> notInstalledFeatures = new HashSet<String>();
notInstalledFeatures.add(TEST_MAIN_FEATURES_1_MAIN_FEATURE_NAME);
FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo, notInstalledFeatures, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
assertFalse(appService.isApplicationStarted(appService.getApplication(TEST_MAIN_FEATURES_1_MAIN_FEATURE_NAME)));
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusReturnsInactiveWhenMainFeatureNotInstalledAndAllBundlesActive.
/**
* Test method for
* {@link ApplicationServiceImpl#getApplicationStatus(Application)}
* <p>
* Verifies that {@link ApplicationState#INACTIVE} is returned when an
* {@code Application}'s main feature is not installed, but all of its
* {@code Bundle}s states and extended states are {@code Bundle#ACTIVE} and
* {@code BundleState#Active}, respectively.
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsInactiveWhenMainFeatureNotInstalledAndAllBundlesActive() throws Exception {
Set<String> notInstalledFeatures = new HashSet<String>();
notInstalledFeatures.add(TEST_MAIN_FEATURES_1_MAIN_FEATURE_NAME);
FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo, notInstalledFeatures, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
assertEquals("More than one application was returned from mainFeatureRepo", 1, appService.getApplications().size());
assertEquals("mainFeatureRepo returned unexpected state", ApplicationState.INACTIVE, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testIgnoreApplications.
/**
* Tests that the service properly ignores applications when checking for
* application status.
*
* @throws Exception
*/
@Test
public void testIgnoreApplications() throws Exception {
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(noMainFeatureRepo1, noMainFeatureRepo2));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationServiceImpl appService = createPermittedApplicationServiceImpl();
// just ignore the first application
List<String> ignoredApps1 = new ArrayList<>(1);
ignoredApps1.add(TEST_APP);
appService.setIgnoredApplications(ignoredApps1);
Set<Application> applications = appService.getApplications();
assertNotNull(applications);
assertEquals(1, applications.size());
assertEquals(TEST_APP2, applications.iterator().next().getName());
// now ignore both applications
List<String> ignoredApps2 = new ArrayList<>(2);
ignoredApps2.add(TEST_APP);
ignoredApps2.add(TEST_APP2);
appService.setIgnoredApplications(ignoredApps2);
applications = appService.getApplications();
assertNotNull(applications);
assertEquals(0, applications.size());
// ignore none
List<String> ignoredApps3 = new ArrayList<>(0);
appService.setIgnoredApplications(ignoredApps3);
applications = appService.getApplications();
assertNotNull(applications);
assertEquals(2, applications.size());
}
Aggregations