use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testGetAllFeaturesFTRException.
/**
* Tests the {@link ApplicationServiceImpl#getAllFeatures()} method
* for the case where an exception is thrown in getFeatureToRepository(..)
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testGetAllFeaturesFTRException() 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, noMainFeatureRepo2));
FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
doThrow(new NullPointerException()).when(featuresService).listRepositories();
appService.getAllFeatures();
verify(mockAppender, times(7)).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(MAP_FAIL_STRING);
}
}));
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testGetInstallProfilesException.
/**
* Tests the {@link ApplicationServiceImpl#getInstallationProfiles()} method
* for the case where featuresService.listFeatures() throws an exception
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testGetInstallProfilesException() 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);
ApplicationService appService = new ApplicationServiceImpl(bundleStateServices) {
@Override
protected BundleContext getContext() {
return bundleContext;
}
};
doThrow(new NullPointerException()).when(featuresService).listFeatures();
appService.getInstallationProfiles();
verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(PROF_INST_EX);
}
}));
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testGetApplicationStatusReturnsActiveStatusForNotInstalledFeatureDependencyThatContainsActiveBundle.
/**
* Test method for
* {@link ApplicationService#getApplicationStatus(Application)}
* <p>
* Verifies method returns an {@link ApplicationState#ACTIVE} state for an
* {@code Application} under the following conditions:
* <p>
* <ul>
* <li>Main feature is installed</li>
* <li>One dependency feature is NOT installed</li>
* <li>Dependency feature that is not installed contains a {@code Bundle}
* with a state of {@link Bundle#ACTIVE} and extended state of
* {@link BundleState#Active}</li>
* </ul>
* <p>
* This effectively emulates the circumstance in which there is a
* {@code Feature} in another {@code Application} that includes and starts
* the same {@code Bundle} that is contained in a {@code Feature} of the
* current {@code Application} that is not installed.
*
* @throws Exception
*/
@Test
public void testGetApplicationStatusReturnsActiveStatusForNotInstalledFeatureDependencyThatContainsActiveBundle() throws Exception {
Set<String> notInstalledFeatureNames = new HashSet<String>();
notInstalledFeatureNames.add(TEST_MAIN_FEATURES_1_FEATURE_1_NAME);
FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo, notInstalledFeatureNames, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
assertNotNull("Features repo is missing feature with the name of \"" + TEST_MAIN_FEATURES_1_FEATURE_1_NAME + "\"", featuresService.getFeature(TEST_MAIN_FEATURES_1_FEATURE_1_NAME));
ApplicationService appService = createPermittedApplicationServiceImpl();
assertEquals(ApplicationService.class.getName() + " does not contain the expected number of Applications", 1, appService.getApplications().size());
assertEquals(mainFeatureRepo.getName() + " returned unexpected state", ApplicationState.ACTIVE, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method setUp.
/**
* Creates default {@link BundleContext}, {@code List} of
* {@code BundleStateService}s, and {@link Repository} objects for use in
* the tests.
* <p>
* NOTE: These must be in {@code setUp()} method rather than a
* {@code beforeClass()} method because they are modified by individual
* tests as part of the setup for individual test conditions. @see
* {@link #createMockFeaturesService(Set, Set, Set)}
*
* @throws Exception
*/
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
// Recreate the repos and BundleContext prior to each test in order to
// ensure modifications made in one test do not effect another test.
noMainFeatureRepo1 = createRepo(TEST_NO_MAIN_FEATURE_1_FILE_NAME);
noMainFeatureRepo2 = createRepo(TEST_NO_MAIN_FEATURE_2_FILE_NAME);
mainFeatureRepo = createRepo(TEST_MAIN_FEATURE_1_FILE_NAME);
mainFeatureRepo2 = createRepo(TEST_MAIN_FEATURE_2_FILE_NAME);
bundleContext = mock(BundleContext.class);
mockFeatureRef = (ServiceReference<FeaturesService>) mock(ServiceReference.class);
when(bundleContext.getServiceReference(FeaturesService.class)).thenReturn(mockFeatureRef);
bundleStateServices = new ArrayList<BundleStateService>();
// Create a BundleStateService for Blueprint
BundleStateService mockBundleStateService = mock(BundleStateService.class);
when(mockBundleStateService.getName()).thenReturn(BundleStateService.NAME_BLUEPRINT);
bundleStateServices.add(mockBundleStateService);
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testIsApplicationStartedReturnsTrueForActiveApplicationState.
/**
* Test method for
* {@link ApplicationServiceImpl#isApplicationStarted(Application)}
* <p>
* Verifies that method returns true when application state is
* {@link ApplicationState#ACTIVE}
*
* @throws Exception
*/
@Test
public void testIsApplicationStartedReturnsTrueForActiveApplicationState() throws Exception {
FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo, null, null);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
ApplicationService appService = createPermittedApplicationServiceImpl();
assertTrue(appService.isApplicationStarted(appService.getApplication(TEST_MAIN_FEATURES_1_MAIN_FEATURE_NAME)));
}
Aggregations