use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method getAppServiceWithBundleInGivenState.
/**
* Returns an {@code ApplicationService} that contains one bundle in the
* received bundle state and the rest of the bundles in an {code
* Bundle#ACTIVE} state.
*
* @param repository The {@link Repository} from which to build the
* {@code ApplicationService}.
* @param bundleState The state, as defined in the {@link Bundle} interface, to set
* for one of the {@code Bundle}s in the
* {@code ApplicationService}
* @return An {@link ApplicationService} with one bundle set to the received
* bundle state and the rest of the {@code Bundle}s set to the
* {@link Bundle#ACTIVE} state
* @throws Exception
*/
private ApplicationService getAppServiceWithBundleInGivenState(Repository repository, int bundleState) throws Exception {
ApplicationService appService = null;
FeaturesService featuresService = createMockFeaturesService(repository, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
Bundle bundle = getAnyBundleFromFeaturesService(featuresService);
if (null != bundle) {
when(bundle.getState()).thenReturn(bundleState);
appService = createPermittedApplicationServiceImpl();
}
return appService;
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testGetAllFeatures.
/**
* Tests the {@link ApplicationServiceImpl#getAllFeatures()} method
*
* @throws Exception
*/
@Test
public void testGetAllFeatures() 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();
List<FeatureDetails> result = appService.getAllFeatures();
assertThat("Returned features should match features in mainFeatureRepo.", result.get(0).getName(), is(mainFeatureRepo.getFeatures()[0].getName()));
assertThat("Returned features should match features in mainFeatureRepo.", result.get(0).getId(), is(mainFeatureRepo.getFeatures()[0].getId()));
assertThat("Should return seven features.", result.size(), is(7));
}
use of org.apache.karaf.features.FeaturesService 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));
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testStopApplicationMainFeatureStringParam.
/**
* Tests the {@link ApplicationServiceImpl#stopApplication(String)} method
* for the case where a main feature exists
*
* @throws Exception
*/
@Test
public void testStopApplicationMainFeatureStringParam() 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 = mainFeatureRepo.getFeatures();
appService.stopApplication(TEST_APP);
verify(featuresService).uninstallFeature(featureList[0].getName(), featureList[0].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testRemoveApplicationASE.
/**
* Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
* for the case where an exception is thrown
*
* @throws Exception
*/
@Test(expected = ApplicationServiceException.class)
public void testRemoveApplicationASE() 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 = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
Repository[] repoList = { mainFeatureRepo };
URI testURL = mainFeatureRepo.getURI();
when(featuresService.listRepositories()).thenReturn(repoList);
doThrow(new Exception()).when(featuresService).removeRepository(Mockito.any(URI.class), eq(false));
appService.removeApplication(testURL);
}
Aggregations