use of org.codice.ddf.admin.application.service.Application 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);
}
use of org.codice.ddf.admin.application.service.Application in project ddf by codice.
the class ApplicationServiceImplTest method testRemoveApplicationApplicationParam.
/**
* Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
*
* @throws Exception
*/
@Test
public void testRemoveApplicationApplicationParam() 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);
Feature testFeature1 = mock(Feature.class);
Feature testFeature2 = mock(Feature.class);
Set<Feature> featureSet = new HashSet<>();
featureSet.add(testFeature1);
featureSet.add(testFeature2);
featuresService.installFeature(testFeature1, EnumSet.noneOf(Option.class));
featuresService.installFeature(testFeature2, EnumSet.noneOf(Option.class));
when(testApp.getFeatures()).thenReturn(featureSet);
when(featuresService.isInstalled(testFeature1)).thenReturn(true);
when(featuresService.isInstalled(testFeature2)).thenReturn(true);
when(testFeature1.getName()).thenReturn(TEST_FEATURE_1_NAME);
when(testFeature1.getVersion()).thenReturn(TEST_FEATURE_VERSION);
when(testFeature2.getName()).thenReturn(TEST_FEATURE_1_NAME);
when(testFeature2.getVersion()).thenReturn(TEST_FEATURE_VERSION);
when(testApp.getURI()).thenReturn(null);
appService.removeApplication(testApp);
verify(testApp).getURI();
verify(featuresService, Mockito.times(2)).uninstallFeature(TEST_FEATURE_1_NAME, TEST_FEATURE_VERSION, EnumSet.of(Option.NoAutoRefreshBundles));
verify(featuresService).removeRepository(null, false);
}
use of org.codice.ddf.admin.application.service.Application in project ddf by codice.
the class ApplicationImplTest method testNoMainFeature.
/**
* Verifies if an app does NOT have a main feature that operations can still
* be performed.
*
* @throws Exception
*/
@Test
public void testNoMainFeature() throws Exception {
String mainFeatureVersion = "1.0.0";
String mainFeatureDescription = null;
String appToString = TEST_APP + " - " + mainFeatureVersion;
RepositoryImpl repo = new RepositoryImpl(getClass().getClassLoader().getResource(FILE_NO_MAIN_FEATURES).toURI());
repo.load();
Application testApp = new ApplicationImpl(repo);
assertEquals(TEST_APP, testApp.getName());
assertEquals(mainFeatureVersion, testApp.getVersion());
assertEquals(mainFeatureDescription, testApp.getDescription());
assertNotNull(testApp.toString());
assertEquals(appToString, testApp.toString());
assertNull(testApp.getMainFeature());
}
use of org.codice.ddf.admin.application.service.Application in project ddf by codice.
the class ApplicationImplTest method testGetURI.
/**
* Tests the {@link ApplicationImpl#getURI()} method
*
* @throws Exception
*/
@Test
public void testGetURI() throws Exception {
URI testURI = getClass().getClassLoader().getResource(FILE_MAIN_FEATURE).toURI();
RepositoryImpl repo1 = new RepositoryImpl(testURI);
repo1.load();
Application testApp1 = new ApplicationImpl(repo1);
assertEquals(testURI, testApp1.getURI());
}
use of org.codice.ddf.admin.application.service.Application in project ddf by codice.
the class ApplicationNodeImplTest method testGetters.
/**
* Tests the 'getters' to make sure that they return the correct values
* after initialization and after setting the child and parent.
*/
@Test
public void testGetters() {
Application testApp = mock(Application.class);
when(testApp.getName()).thenReturn(APP_NAME);
when(testApp.getVersion()).thenReturn(APP_VERSION);
when(testApp.getDescription()).thenReturn(APP_DESCRIPTION);
ApplicationNodeImpl testNode = new ApplicationNodeImpl(testApp);
// initialization test
assertTrue(testNode.getChildren().isEmpty());
assertNull(testNode.getParent());
assertEquals(testApp, testNode.getApplication());
// test after setting child and parent
Application testChildApp = mock(Application.class);
when(testChildApp.getName()).thenReturn(APP2_NAME);
when(testChildApp.getVersion()).thenReturn(APP2_VERSION);
when(testChildApp.getDescription()).thenReturn(APP2_DESCRIPTION);
ApplicationNodeImpl testChildNode = new ApplicationNodeImpl(testChildApp);
testChildNode.setParent(testNode);
testNode.getChildren().add(testChildNode);
assertEquals(1, testNode.getChildren().size());
assertEquals(testChildNode, testNode.getChildren().iterator().next());
assertNotNull(testChildNode.getParent());
assertEquals(testNode, testChildNode.getParent());
}
Aggregations