use of org.apache.karaf.features.Feature in project ddf by codice.
the class ApplicationServiceImplTest method testRemoveApplicationUninstallAllFeaturesException.
/**
* Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
* for the case where an exception is thrown within uninstallAllFeatures(Application)
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRemoveApplicationUninstallAllFeaturesException() throws Exception {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
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();
Application testApp = mock(ApplicationImpl.class);
Feature testFeature1 = mock(Feature.class);
Feature testFeature2 = mock(Feature.class);
Set<Feature> featureSet = new HashSet<>();
featureSet.add(testFeature1);
featureSet.add(testFeature2);
when(featuresService.isInstalled(any(Feature.class))).thenReturn(true);
when(testApp.getFeatures()).thenReturn(featureSet);
doThrow(new Exception()).when(featuresService).uninstallFeature(anyString(), anyString(), any(EnumSet.class));
appService.removeApplication(testApp);
verify(mockAppender, times(2)).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(UNINSTALL_FAIL);
}
}));
}
use of org.apache.karaf.features.Feature 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.Feature in project ddf by codice.
the class ApplicationServiceImplTest method createMockFeaturesService.
/**
* Creates a mock {@code FeaturesService} object consisting of all of the
* features contained in a {@code Repository} object.
*
* @param repo
* @param notInstalledFeatureNames
* @param inactiveBundleLocations
* @return
* @throws Exception
* @see #createMockFeaturesService(Set, Set, Set) for additional details
*/
private FeaturesService createMockFeaturesService(Repository repo, Set<String> notInstalledFeatureNames, Set<String> inactiveBundleLocations) throws Exception {
Set<Feature> notInstalledFeatures = new HashSet<Feature>();
Set<BundleInfo> inactiveBundles = new HashSet<BundleInfo>();
for (Feature feature : repo.getFeatures()) {
if (null != notInstalledFeatureNames && notInstalledFeatureNames.contains(feature.getName())) {
notInstalledFeatures.add(feature);
}
if (null != inactiveBundleLocations) {
for (BundleInfo bundleInfo : feature.getBundles()) {
if (inactiveBundleLocations.contains(bundleInfo.getLocation())) {
inactiveBundles.add(bundleInfo);
}
}
}
}
Set<Repository> repoSet = new HashSet<Repository>();
repoSet.add(repo);
return createMockFeaturesService(repoSet, notInstalledFeatures, inactiveBundles);
}
use of org.apache.karaf.features.Feature 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.Feature in project ddf by codice.
the class ApplicationServiceImplTest method getXBundlesFromFeaturesService.
/**
* Retrieves a given number of {@code Bundle}s from the received
* {@code FeaturesService}
*
* @param featuresService The {@link FeaturesService} from which to obtain a
* {@code Bundle}
* @param numBundles The number of bundles to be retrieved from the
* {@code FeaturesService}
* @return A {@code Set} containing the requested number of {@link Bundle}s
* from the received {@code FeaturesService} or <code>null</code> if
* the {@code FeaturesService} does not contain the requested number
* of {@code Bundle}s
* @throws Exception
*/
private Set<Bundle> getXBundlesFromFeaturesService(FeaturesService featuresService, int numBundles) throws Exception {
Set<Bundle> bundles = new HashSet<Bundle>();
// BundleInfo bundleInfo = null;
Bundle bundle = null;
Feature[] features = featuresService.listFeatures();
List<BundleInfo> bundleInfos = null;
int ii = 0;
while (bundles.size() < numBundles && ii < features.length) {
bundleInfos = features[ii].getBundles();
int jj = 0;
while (bundles.size() < numBundles && jj < bundleInfos.size()) {
bundle = bundleContext.getBundle(bundleInfos.get(ii).getLocation());
if (null != bundle) {
bundles.add(bundle);
}
++jj;
}
++ii;
}
if (bundles.size() < numBundles) {
bundles = null;
}
return bundles;
}
Aggregations