use of org.codice.ddf.admin.application.service.Application 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.codice.ddf.admin.application.service.Application in project ddf by codice.
the class ApplicationServiceImplTest method testRemoveApplicationApplicationParamASE.
/**
* Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
* for the case where an exception is thrown
*
* @throws Exception
*/
@Test(expected = ApplicationServiceException.class)
public void testRemoveApplicationApplicationParamASE() 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();
Application testApp = mock(ApplicationImpl.class);
doThrow(new Exception()).when(featuresService).removeRepository(Mockito.any(URI.class), eq(false));
appService.removeApplication(testApp);
}
use of org.codice.ddf.admin.application.service.Application 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.codice.ddf.admin.application.service.Application 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.codice.ddf.admin.application.service.Application 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));
}
Aggregations