Search in sources :

Example 11 with ApplicationService

use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.

the class ApplicationServiceImplTest method testIsApplicationStartedReturnsFalseForInactiveApplicationState.

/**
     * Test method for
     * {@link ApplicationServiceImpl#isApplicationStarted(Application)}
     * <p>
     * Verifies that method returns false when application state is
     * {@link ApplicationState#INACTIVE}
     *
     * @throws Exception
     */
@Test
public void testIsApplicationStartedReturnsFalseForInactiveApplicationState() throws Exception {
    Set<String> notInstalledFeatures = new HashSet<String>();
    notInstalledFeatures.add(TEST_MAIN_FEATURES_1_MAIN_FEATURE_NAME);
    FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo, notInstalledFeatures, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    assertFalse(appService.isApplicationStarted(appService.getApplication(TEST_MAIN_FEATURES_1_MAIN_FEATURE_NAME)));
}
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 12 with ApplicationService

use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsInactiveWhenMainFeatureNotInstalledAndAllBundlesActive.

/**
     * Test method for
     * {@link ApplicationServiceImpl#getApplicationStatus(Application)}
     * <p>
     * Verifies that {@link ApplicationState#INACTIVE} is returned when an
     * {@code Application}'s main feature is not installed, but all of its
     * {@code Bundle}s states and extended states are {@code Bundle#ACTIVE} and
     * {@code BundleState#Active}, respectively.
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsInactiveWhenMainFeatureNotInstalledAndAllBundlesActive() throws Exception {
    Set<String> notInstalledFeatures = new HashSet<String>();
    notInstalledFeatures.add(TEST_MAIN_FEATURES_1_MAIN_FEATURE_NAME);
    FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo, notInstalledFeatures, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    assertEquals("More than one application was returned from mainFeatureRepo", 1, appService.getApplications().size());
    assertEquals("mainFeatureRepo returned unexpected state", ApplicationState.INACTIVE, 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 13 with ApplicationService

use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.

the class ApplicationServiceImplTest method testStartApplicationASE.

/**
     * Tests the {@link ApplicationServiceImpl#startApplication(Application)} method
     * for the case where an exception is thrown
     *
     * @throws Exception
     */
@Test(expected = ApplicationServiceException.class)
public void testStartApplicationASE() 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);
    Feature testFeature = mock(Feature.class);
    when(testFeature.getName()).thenReturn(TEST_FEATURE_1_NAME);
    when(testApp.getAutoInstallFeatures()).thenReturn(new HashSet<>(Arrays.asList(testFeature)));
    doThrow(new ApplicationServiceException()).when(featuresService).installFeatures(anySet(), any(EnumSet.class));
    appService.startApplication(testApp);
}
Also used : ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) Repository(org.apache.karaf.features.Repository) EnumSet(java.util.EnumSet) FeaturesService(org.apache.karaf.features.FeaturesService) Application(org.codice.ddf.admin.application.service.Application) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 14 with ApplicationService

use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsActiveStatusWhenAllFeaturesInstalledAndAllBundlesActive.

/**
     * Test method for
     * {@link ApplicationService#getApplicationStatus(Application)}
     * <p>
     * Verifies method returns an {@link ApplicationState#ACTIVE} state for an
     * Application under the following conditions:
     * <p>
     * <ul>
     * <li>Main feature is installed</li>
     * <li>All dependency features are installed</li>
     * <li>The bundle state and extended bundle state of each bundle specified
     * in each dependency feature is {@link Bundle#ACTIVE} and
     * {@link BundleState#Active}, respectively</li>
     * </ul>
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsActiveStatusWhenAllFeaturesInstalledAndAllBundlesActive() throws Exception {
    FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    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) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 15 with ApplicationService

use of org.codice.ddf.admin.application.service.ApplicationService in project ddf by codice.

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsInactiveWhenBundleStateIsStarting.

/**
     * Test method for
     * {@link ApplicationServiceImpl#getApplicationStatus(Application)}
     * <p>
     * Verifies that {@link ApplicationState#INACTIVE} is returned when
     * {@code Bundle} state is {@link Bundle#STARTING}
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsInactiveWhenBundleStateIsStarting() throws Exception {
    ApplicationService appService = getAppServiceWithBundleInGivenState(mainFeatureRepo2, Bundle.STARTING);
    assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.INACTIVE, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Also used : ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Aggregations

ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)82 Test (org.junit.Test)79 FeaturesService (org.apache.karaf.features.FeaturesService)51 HashSet (java.util.HashSet)45 Repository (org.apache.karaf.features.Repository)37 Application (org.codice.ddf.admin.application.service.Application)26 Feature (org.apache.karaf.features.Feature)19 URI (java.net.URI)13 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)13 Logger (org.slf4j.Logger)11 Appender (ch.qos.logback.core.Appender)10 ArgumentMatcher (org.mockito.ArgumentMatcher)10 ApplicationStatus (org.codice.ddf.admin.application.service.ApplicationStatus)9 Mockito.anyString (org.mockito.Mockito.anyString)9 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 EnumSet (java.util.EnumSet)3 FeatureDetails (org.codice.ddf.admin.application.rest.model.FeatureDetails)3 ApplicationNode (org.codice.ddf.admin.application.service.ApplicationNode)3 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)3