use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testStartApplicationASE.
/**
* Tests the {@link ApplicationServiceImpl#startApplication(Application)} method
* for the case where an exception is thrown
*
* @throws Exception
*/
@Test(expected = ApplicationServiceException.class)
public void testStartApplicationASE() throws Exception {
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 = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
Application testApp = mock(ApplicationImpl.class);
Feature testFeature = mock(Feature.class);
when(testFeature.getName()).thenReturn(TEST_FEATURE_1_NAME);
when(testApp.getAutoInstallFeatures()).thenReturn(new HashSet<>(Arrays.asList(testFeature)));
doThrow(new ApplicationServiceException()).when(featuresService).installFeatures(anySet(), any(EnumSet.class));
appService.startApplication(testApp);
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusReturnsActiveStatusWhenAllFeaturesInstalledAndAllBundlesActive.
/**
* Test method for
* {@link ApplicationService#getApplicationStatus(Application)}
* <p>
* Verifies method returns an {@link ApplicationState#ACTIVE} state for an
* Application under the following conditions:
* <p>
* <ul>
* <li>Main feature is installed</li>
* <li>All dependency features are installed</li>
* <li>The bundle state and extended bundle state of each bundle specified
* in each dependency feature is {@link Bundle#ACTIVE} and
* {@link BundleState#Active}, respectively</li>
* </ul>
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsActiveStatusWhenAllFeaturesInstalledAndAllBundlesActive() throws Exception {
FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo, null, null);
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(mainFeatureRepo.getName() + " returned unexpected state", ApplicationState.ACTIVE, 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 testServiceChanged.
/**
* Tests the {@link ApplicationServiceImpl#setConfigFileName(String)} method
*
* @throws Exception
*/
@Test
public void testServiceChanged() throws Exception {
Set<Repository> activeRepos = new HashSet<>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationServiceImpl appService = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
appService.setConfigFileName("foo");
ServiceReference<ConfigurationAdmin> testConfigAdminRef = mock(ServiceReference.class);
ConfigurationAdmin testConfigAdmin = mock(ConfigurationAdmin.class);
Configuration testConfig = mock(Configuration.class);
when(bundleContext.getServiceReference(ConfigurationAdmin.class)).thenReturn(testConfigAdminRef);
when(bundleContext.getService(testConfigAdminRef)).thenReturn(testConfigAdmin);
when(testConfigAdmin.getConfiguration(ApplicationServiceImpl.class.getName())).thenReturn(testConfig);
Dictionary<String, Object> testProperties = new Hashtable<>();
testProperties.put("test1", "foo");
testProperties.put("test2", "bar");
when(testConfig.getProperties()).thenReturn(testProperties);
ServiceEvent serviceEvent = mock(ServiceEvent.class);
when(serviceEvent.getType()).thenReturn(ServiceEvent.REGISTERED);
appService.serviceChanged(serviceEvent);
assertThat(testConfig.getProperties().size(), is(testProperties.size()));
assertThat(testConfig.getProperties().get("test1"), is("foo"));
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testStopApplicationNoMainFeatureStringParam.
/**
* Tests the {@link ApplicationServiceImpl#stopApplication(String)} method
* for the case where there is no main feature, but other features exist
*
* @throws Exception
*/
@Test
public void testStopApplicationNoMainFeatureStringParam() throws Exception {
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();
Feature[] featureList = noMainFeatureRepo1.getFeatures();
appService.stopApplication(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 testGetApplications.
/**
* Tests that the {@link ApplicationServiceImpl#getApplications()} method
* returns the correct number of applications.
*
* @throws Exception
*/
@Test
public void testGetApplications() throws Exception {
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(noMainFeatureRepo1, noMainFeatureRepo2));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
Set<Application> applications = appService.getApplications();
assertNotNull(applications);
assertEquals(2, applications.size());
}
Aggregations