use of org.apache.karaf.features.Repository 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.Repository 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.Repository 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);
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testStartApplicationMainFeature.
/**
* Tests the {@link ApplicationServiceImpl#startApplication(Application)} method
* for the case where there a main feature exists
*
* @throws Exception
*/
@Test
public void testStartApplicationMainFeature() 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);
Set<Feature> features = new HashSet<>(Arrays.asList(testFeature));
Set<String> featureNames = new HashSet<>(features.size());
features.forEach(f -> featureNames.add(f.getName()));
when(testApp.getAutoInstallFeatures()).thenReturn(features);
appService.startApplication(testApp);
verify(featuresService, atLeastOnce()).installFeatures(featureNames, EnumSet.of(Option.NoAutoRefreshBundles));
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testStopApplicationException.
/**
* Tests the {@link ApplicationServiceImpl#stopApplication(Application)} method
* for the case where an Exception is thrown
*
* @throws Exception
*/
@Test(expected = ApplicationServiceException.class)
public void testStopApplicationException() 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);
when(testApp.getMainFeature()).thenReturn(mainFeatureRepo.getFeatures()[1]);
doThrow(new NullPointerException()).when(testApp).getFeatures();
appService.stopApplication(testApp);
}
Aggregations