use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusException.
/**
* Tests the {@link ApplicationServiceImpl#getApplicationStatus(Application)} method
* for the case where an exception is thrown in the main block
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testGetApplicationStatusException() 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));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationServiceImpl appService = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
Application testApp = mock(ApplicationImpl.class);
doThrow(new NullPointerException()).when(testApp).getFeatures();
ApplicationStatus result = appService.getApplicationStatus(testApp);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(APP_STATUS_EX);
}
}));
assertThat("State of resulting ApplicationStatus should be UNKNOWN.", result.getState(), is(ApplicationState.UNKNOWN));
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testApplicationTree.
/**
* Tests that an application tree is passed back correctly.
*
* @throws Exception
*/
@Test
public void testApplicationTree() throws Exception {
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, mainFeatureRepo2));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
Set<ApplicationNode> rootApps = appService.getApplicationTree();
assertNotNull(rootApps);
assertEquals(1, rootApps.size());
ApplicationNode mainAppNode = rootApps.iterator().next();
assertEquals(1, mainAppNode.getChildren().size());
assertNull(mainAppNode.getParent());
assertEquals("main-feature2", mainAppNode.getChildren().iterator().next().getApplication().getName());
assertEquals(mainAppNode, mainAppNode.getChildren().iterator().next().getParent());
Application mainApp = mainAppNode.getApplication();
assertEquals("main-feature", mainApp.getName());
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testStopApplicationGeneralASE.
/**
* Tests the {@link ApplicationServiceImpl#stopApplication(Application)} method
* for the case where an exception is caught
*
* @throws Exception
*/
@Test(expected = ApplicationServiceException.class)
public void testStopApplicationGeneralASE() 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);
when(testApp1.getFeatures()).thenReturn(new HashSet<>(Arrays.asList(testFeature1)));
when(featuresService.isInstalled(any())).thenReturn(true);
doThrow(new Exception()).when(featuresService).uninstallFeature(anyString(), anyString(), any());
appService.stopApplication(testApp1);
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testStopApplicationNoMainFeature.
/**
* Tests the {@link ApplicationServiceImpl#stopApplication(Application)} method
* for the case where there is no main feature, but other features exist
*
* @throws Exception
*/
@Test
public void testStopApplicationNoMainFeature() 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<Feature>();
featureSet.add(testFeature1);
featureSet.add(testFeature2);
when(testApp.getName()).thenReturn(TEST_APP_NAME);
when(testApp.getMainFeature()).thenReturn(null);
when(testApp.getFeatures()).thenReturn(featureSet);
when(testFeature1.getName()).thenReturn(TEST_FEATURE_1_NAME);
when(testFeature2.getName()).thenReturn(TEST_FEATURE_2_NAME);
when(testFeature1.getInstall()).thenReturn(Feature.DEFAULT_INSTALL_MODE);
when(testFeature2.getInstall()).thenReturn(Feature.DEFAULT_INSTALL_MODE);
when(featuresService.isInstalled(testFeature1)).thenReturn(true);
when(featuresService.isInstalled(testFeature2)).thenReturn(true);
appService.stopApplication(testApp);
verify(featuresService, atLeastOnce()).uninstallFeature(TEST_FEATURE_1_NAME, null, EnumSet.of(Option.NoAutoRefreshBundles));
verify(featuresService, atLeastOnce()).uninstallFeature(TEST_FEATURE_2_NAME, null, EnumSet.of(Option.NoAutoRefreshBundles));
}
use of org.apache.karaf.features.Repository in project ddf by codice.
the class ApplicationServiceImplTest method testStartApplicationStringParam.
/**
* Tests the {@link ApplicationServiceImpl#startApplication(String)} method
*
* @throws Exception
*/
@Test
public void testStartApplicationStringParam() 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);
when(featuresService.isInstalled(any(Feature.class))).thenReturn(false);
ApplicationService appService = createPermittedApplicationServiceImpl();
appService.startApplication(TEST_APP);
Set<String> names = new HashSet<>();
names.add(mainFeatureRepo.getFeatures()[0].getName());
names.add(mainFeatureRepo.getFeatures()[1].getName());
verify(featuresService).installFeatures(names, EnumSet.of(Option.NoAutoRefreshBundles));
}
Aggregations