Search in sources :

Example 26 with FeaturesService

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);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(org.slf4j.Logger) Repository(org.apache.karaf.features.Repository) ArgumentMatcher(org.mockito.ArgumentMatcher) FeaturesService(org.apache.karaf.features.FeaturesService) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 27 with FeaturesService

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);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(org.slf4j.Logger) Repository(org.apache.karaf.features.Repository) ArgumentMatcher(org.mockito.ArgumentMatcher) FeaturesService(org.apache.karaf.features.FeaturesService) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 28 with FeaturesService

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());
}
Also used : FeaturesService(org.apache.karaf.features.FeaturesService) Mockito.anyString(org.mockito.Mockito.anyString) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 29 with FeaturesService

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);
}
Also used : BundleStateService(org.apache.karaf.bundle.core.BundleStateService) FeaturesService(org.apache.karaf.features.FeaturesService) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 30 with FeaturesService

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)));
}
Also used : FeaturesService(org.apache.karaf.features.FeaturesService) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Aggregations

FeaturesService (org.apache.karaf.features.FeaturesService)71 Test (org.junit.Test)61 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)51 HashSet (java.util.HashSet)48 Repository (org.apache.karaf.features.Repository)43 Feature (org.apache.karaf.features.Feature)29 Application (org.codice.ddf.admin.application.service.Application)19 Mockito.anyString (org.mockito.Mockito.anyString)13 Logger (org.slf4j.Logger)12 Appender (ch.qos.logback.core.Appender)10 URI (java.net.URI)10 ArgumentMatcher (org.mockito.ArgumentMatcher)10 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)9 EnumSet (java.util.EnumSet)6 Bundle (org.osgi.framework.Bundle)6 URL (java.net.URL)5 ArrayList (java.util.ArrayList)4 BundleInfo (org.apache.karaf.features.BundleInfo)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2