use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testFindFeatureExceptions.
/**
* Tests the {@link ApplicationServiceImpl#findFeature(Feature)} method
* for the case where exceptions are thrown inside findFeature(Feature, Set<Application>)
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix and un-ignore
@Test
@Ignore
public void testFindFeatureExceptions() 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);
Application testApp = mock(ApplicationImpl.class);
final Set<Application> applicationSet = new HashSet<>();
applicationSet.add(testApp);
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
@Override
public Set<Application> getApplications() {
return applicationSet;
}
@Override
public boolean isPermittedToViewFeature(String featureName) {
return true;
}
};
Feature testFeature = mock(Feature.class);
doThrow(new NullPointerException()).when(testApp).getFeatures();
appService.findFeature(testFeature);
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(FIND_FEAT_EX);
}
}));
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(FIND_FEAT_EX2);
}
}));
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testApplicationTreeWithNoMainFeature.
/**
* Test that an application tree can be created even if there is an app that
* does not contain a main feature.
*
* @throws Exception
*/
@Test
public void testApplicationTreeWithNoMainFeature() throws Exception {
Repository mainFeaturesRepo2 = createRepo(TEST_MAIN_FEATURE_2_FILE_NAME);
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, mainFeaturesRepo2, noMainFeatureRepo1));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
Set<ApplicationNode> rootApps = appService.getApplicationTree();
assertNotNull(rootApps);
assertEquals(2, rootApps.size());
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testGetActiveApplicationStatus.
/**
* Tests receiving application status for an application in the ACTIVE
* state.
*/
@Test
public void testGetActiveApplicationStatus() throws Exception {
Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(noMainFeatureRepo1));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
Set<Application> applications = appService.getApplications();
assertEquals(1, applications.size());
for (Application curApp : applications) {
ApplicationStatus status = appService.getApplicationStatus(curApp);
assertEquals(curApp, status.getApplication());
assertEquals(ApplicationState.ACTIVE, status.getState());
assertTrue(status.getErrorBundles().isEmpty());
assertTrue(status.getErrorFeatures().isEmpty());
}
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationConfigInstallerTest method testFileEmpty.
/**
* Tests the use case that there is a file but it does not have any apps
* listed in it (they are commented out). The test should not call the
* features stop and start since no apps were loaded.
*
* @throws Exception
*/
@Test
public void testFileEmpty() throws Exception {
FeaturesService featuresService = mock(FeaturesService.class);
ApplicationService appService = mock(ApplicationService.class);
URL fileURL = this.getClass().getResource("/" + EMPTY_FILE);
ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(fileURL.getFile(), appService, featuresService, START_FEATURE, STOP_FEATURE);
configInstaller.run();
// verify that the app service was never called
verify(appService, never()).addApplication(any(URI.class));
verify(appService, never()).startApplication(anyString());
// verify the post start and post stop features were not called
verify(featuresService, never()).installFeature(anyString(), any(EnumSet.class));
verify(featuresService, never()).uninstallFeature(anyString());
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationConfigInstallerTest method testFileInstall.
/**
* Tests with a valid file that contains one non-local application that all of the
* services were called correctly.
*
* @throws Exception
*/
@Test
public void testFileInstall() throws Exception {
FeaturesService featuresService = mock(FeaturesService.class);
ApplicationService appService = mock(ApplicationService.class);
URL fileURL = this.getClass().getResource("/" + INSTALL_FILE);
ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(fileURL.getFile(), appService, featuresService, START_FEATURE, STOP_FEATURE);
configInstaller.run();
// verify that the correct application was added and then started
verify(appService).addApplication(new URI("file:/location/to/solr-app-1.0.0.kar"));
verify(appService).startApplication("solr-app");
// verify the post start and post stop features were called
verify(featuresService).installFeature(START_FEATURE, EnumSet.of(Option.NoAutoRefreshBundles));
verify(featuresService).uninstallFeature(STOP_FEATURE);
}
Aggregations