use of org.apache.karaf.features.Feature in project ddf by codice.
the class ApplicationServiceImplTest method testStopApplicationMainFeature.
/**
* Tests the {@link ApplicationServiceImpl#stopApplication(Application)} method
* for the case where a main feature exists
*
* @throws Exception
*/
@Test
public void testStopApplicationMainFeature() 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 testApp1 = mock(ApplicationImpl.class);
Feature testFeature1 = mock(Feature.class);
Dependency testDependency1 = mock(Dependency.class);
List<Dependency> dependencyList1 = new ArrayList<>();
Set<Feature> featureSet1 = new HashSet<>();
dependencyList1.add(testDependency1);
featureSet1.add(testFeature1);
when(testFeature1.getName()).thenReturn(TEST_FEATURE_1_NAME);
when(testApp1.getMainFeature()).thenReturn(testFeature1);
when(testApp1.getFeatures()).thenReturn(featureSet1);
when(featuresService.isInstalled(testFeature1)).thenReturn(true);
when(testFeature1.getDependencies()).thenReturn(dependencyList1);
when(testDependency1.getVersion()).thenReturn(TEST_FEATURE_VERSION);
when(testFeature1.getVersion()).thenReturn(TEST_FEATURE_VERSION);
appService.stopApplication(testApp1);
verify(featuresService, atLeastOnce()).uninstallFeature(TEST_FEATURE_1_NAME, TEST_FEATURE_VERSION, EnumSet.of(Option.NoAutoRefreshBundles));
}
use of org.apache.karaf.features.Feature in project ddf by codice.
the class ApplicationServiceImplTest method testFindFeature.
/**
* Tests the {@link ApplicationServiceImpl#findFeature(Feature)} method
*
* @throws Exception
*/
@Test
public void testFindFeature() 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 testFeature = mainFeatureRepo.getFeatures()[0];
Application result = appService.findFeature(testFeature);
assertTrue("Check that the returned application is the correct one.", result.getFeatures().contains(testFeature));
}
use of org.apache.karaf.features.Feature in project ddf by codice.
the class ApplicationServiceImplTest method testStartApplicationNoMainFeature.
/**
* Tests the {@link ApplicationServiceImpl#startApplication(Application)} method
* for the case where there is no main feature, but other features exist
*
* @throws Exception
*/
@Test
public void testStartApplicationNoMainFeature() 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 testFeature1 = mock(Feature.class);
Feature testFeature2 = mock(Feature.class);
Set<Feature> featureSet = new HashSet<Feature>();
featureSet.add(testFeature1);
featureSet.add(testFeature2);
when(testApp.getName()).thenReturn(TEST_APP_NAME);
when(testApp.getAutoInstallFeatures()).thenReturn(featureSet);
when(testFeature1.getName()).thenReturn(TEST_FEATURE_1_NAME);
when(testFeature2.getName()).thenReturn(TEST_FEATURE_2_NAME);
Set<String> featureNames = new HashSet<>(featureSet.size());
featureSet.forEach(f -> featureNames.add(f.getName()));
appService.startApplication(testApp);
verify(featuresService).installFeatures(featureNames, EnumSet.of(Option.NoAutoRefreshBundles));
}
use of org.apache.karaf.features.Feature in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusReturnsFailedStatusWhenFeatureDependencyContainsInactiveBundle.
/**
* 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>All dependency features are installed</li>
* <li>One dependency feature contains a Bundle that is in an inactive state
* </li>
* </ul>
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsFailedStatusWhenFeatureDependencyContainsInactiveBundle() throws Exception {
// Verify the pre-conditions
int bundleInclusionCount = 0;
for (Feature feature : mainFeatureRepo2.getFeatures()) {
for (BundleInfo bundleInfo : feature.getBundles()) {
if (bundleInfo.getLocation().equals(TEST_MAIN_FEATURES_2_UNIQUE_BUNDLE_LOCATION)) {
++bundleInclusionCount;
}
}
}
assertEquals("Bundle is not included in repository the expected number of times", 1, bundleInclusionCount);
// Execute test
Set<String> inactiveBundleNames = new HashSet<String>();
inactiveBundleNames.add(TEST_MAIN_FEATURES_2_UNIQUE_BUNDLE_LOCATION);
FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo2, null, inactiveBundleNames);
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());
}
use of org.apache.karaf.features.Feature in project ddf by codice.
the class ApplicationServiceImplTest method testRemoveApplicationURIParam.
/**
* Tests the {@link ApplicationServiceImpl#removeApplication(URI)} method
*
* @throws Exception
*/
@Test
public void testRemoveApplicationURIParam() throws Exception {
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo2));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
Repository[] repoList = { mainFeatureRepo };
URI testURL = mainFeatureRepo.getURI();
Feature[] featureList = mainFeatureRepo.getFeatures();
when(featuresService.listRepositories()).thenReturn(repoList);
appService.removeApplication(testURL);
verify(featuresService).removeRepository(testURL, false);
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));
}
Aggregations