Search in sources :

Example 1 with ApplicationService

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

the class TestApplicationService method bTestAppStatus.

@Test
public void bTestAppStatus() throws ApplicationServiceException, InterruptedException {
    systemSubject.execute(() -> {
        // Test AppService
        ApplicationService applicationService = getServiceManager().getService(ApplicationService.class);
        Set<Application> apps = applicationService.getApplications();
        List<Application> catalogList = apps.stream().filter(a -> CATALOG_APP.equals(a.getName())).collect(Collectors.toList());
        if (catalogList.size() != 1) {
            fail("Expected to find 1 " + CATALOG_APP + " in Application list.");
        }
        Application catalog = catalogList.get(0);
        try {
            applicationService.startApplication(catalog);
            getServiceManager().waitForAllBundles();
        } catch (ApplicationServiceException e) {
            LOGGER.error("Failed to start the {}: {}", CATALOG_APP, e.getMessage());
            fail();
        } catch (InterruptedException e) {
            LOGGER.error("Failed to start start all bundles {}", e.getMessage());
            fail();
        }
        assertNotNull("Application [" + CATALOG_APP + "] must not be null", catalog);
        ApplicationStatus status = applicationService.getApplicationStatus(catalog);
        assertThat("Application [" + CATALOG_APP + "] should be ACTIVE", status.getState(), is(ACTIVE));
        List<Application> registryList = apps.stream().filter(a -> REGISTRY_APP.equals(a.getName())).collect(Collectors.toList());
        if (catalogList.size() != 1) {
            fail("Expected to find 1 " + REGISTRY_APP + " in Application list.");
        }
        Application registry = registryList.get(0);
        assertNotNull("Application [" + REGISTRY_APP + "] must not be null", registry);
        status = applicationService.getApplicationStatus(registry);
        assertThat("Application [" + REGISTRY_APP + "] should be INACTIVE", status.getState(), is(INACTIVE));
        // Test Commands
        String response = console.runCommand(STATUS_COMMAND + CATALOG_APP);
        assertThat(CATALOG_APP + " should be ACTIVE", response, containsString(ACTIVE_APP));
        response = console.runCommand(STATUS_COMMAND + REGISTRY_APP);
        assertThat(REGISTRY_APP + " should be INACTIVE", response, containsString(INACTIVE_APP));
    });
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) MethodSorters(org.junit.runners.MethodSorters) PaxExam(org.ops4j.pax.exam.junit.PaxExam) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) INACTIVE(org.codice.ddf.admin.application.service.ApplicationStatus.ApplicationState.INACTIVE) CoreMatchers.not(org.hamcrest.CoreMatchers.not) RunWith(org.junit.runner.RunWith) LoggerFactory(org.slf4j.LoggerFactory) Application(org.codice.ddf.admin.application.service.Application) Assert.assertThat(org.junit.Assert.assertThat) Subject(org.apache.shiro.subject.Subject) BeforeExam(org.codice.ddf.itests.common.annotations.BeforeExam) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) LoggingUtils(org.codice.ddf.itests.common.utils.LoggingUtils) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Logger(org.slf4j.Logger) Security(org.codice.ddf.security.common.Security) Assert.assertNotNull(org.junit.Assert.assertNotNull) Set(java.util.Set) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest) ExamReactorStrategy(org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy) PerSuite(org.ops4j.pax.exam.spi.reactors.PerSuite) List(java.util.List) Rule(org.junit.Rule) ACTIVE(org.codice.ddf.admin.application.service.ApplicationStatus.ApplicationState.ACTIVE) FixMethodOrder(org.junit.FixMethodOrder) ConditionalIgnoreRule(org.codice.ddf.itests.common.annotations.ConditionalIgnoreRule) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Application(org.codice.ddf.admin.application.service.Application) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest)

Example 2 with ApplicationService

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

the class TestApplicationService method cTestAppStartStop.

@Test
// DDF-2954
@ConditionalIgnoreRule.ConditionalIgnore(condition = SkipUnstableTest.class)
public void cTestAppStartStop() throws ApplicationServiceException {
    systemSubject.execute(() -> {
        // Test AppService
        ApplicationService applicationService = getServiceManager().getService(ApplicationService.class);
        Application registry = applicationService.getApplication(REGISTRY_APP);
        assertNotNull("Application [" + REGISTRY_APP + "] must not be null", registry);
        ApplicationStatus status = applicationService.getApplicationStatus(registry);
        assertThat(REGISTRY_APP + " should be INACTIVE", status.getState(), is(INACTIVE));
        try {
            applicationService.startApplication(registry);
        } catch (ApplicationServiceException e) {
            LOGGER.error("Failed to start the {}: {}", REGISTRY_APP, e.getMessage());
            fail();
        }
        status = applicationService.getApplicationStatus(registry);
        assertThat(REGISTRY_APP + " should be ACTIVE after start, but was [" + status.getState() + "]", status.getState(), is(ACTIVE));
        try {
            applicationService.stopApplication(registry);
        } catch (ApplicationServiceException e) {
            LOGGER.error("Failed to stop the {}: {}", REGISTRY_APP, e.getMessage());
            fail();
        }
        status = applicationService.getApplicationStatus(registry);
        assertThat(REGISTRY_APP + " should be INACTIVE after stop", status.getState(), is(INACTIVE));
        // Test Commands
        String response = console.runCommand(STATUS_COMMAND + REGISTRY_APP);
        assertThat(REGISTRY_APP + " should be INACTIVE", response, containsString(INACTIVE_APP));
        response = console.runCommand(START_COMMAND + REGISTRY_APP);
        assertThat(REGISTRY_APP + " should be empty response after " + START_COMMAND, response, isEmptyString());
        response = console.runCommand(STATUS_COMMAND + REGISTRY_APP);
        assertThat(REGISTRY_APP + " should be ACTIVE after " + START_COMMAND, response, containsString(ACTIVE_APP));
        response = console.runCommand(STOP_COMMAND + REGISTRY_APP);
        assertThat(REGISTRY_APP + " should be empty response after " + START_COMMAND, response, isEmptyString());
        response = console.runCommand(STATUS_COMMAND + REGISTRY_APP);
        assertThat(REGISTRY_APP + " should be INACTIVE after " + STOP_COMMAND, response, containsString(INACTIVE_APP));
    });
}
Also used : ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Application(org.codice.ddf.admin.application.service.Application) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest)

Example 3 with ApplicationService

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

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsUnkownWhenBundleStateServiceStateIsStarting.

/**
     * Test method for
     * {@link ApplicationServiceImpl#getApplicationStatus(Application)}
     * <p>
     * Verifies that {@link ApplicationState#INACTIVE} is returned when the
     * extended bundle state reported by an injection framework states that one
     * bundle is in an {@link BundleState#Starting} state and the rest of the
     * bundles are in an {@link BundleState#Active} state.
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsUnkownWhenBundleStateServiceStateIsStarting() throws Exception {
    ApplicationService appService = getAppServiceWithBundleStateServiceInGivenState(mainFeatureRepo2, BundleState.Starting);
    assertNotNull("Repository \"" + mainFeatureRepo.getName() + "\" does not contain any bundles", appService);
    assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.UNKNOWN, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Also used : ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 4 with ApplicationService

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

the class ApplicationServiceImplTest method testIsApplicationStartedReturnsFalseForFailedApplicationState.

/**
     * Test method for
     * {@link ApplicationServiceImpl#isApplicationStarted(Application)}
     * <p>
     * Verifies that method returns false when application state is
     * {@link ApplicationState#FAILED}
     *
     * @throws Exception
     */
@Test
public void testIsApplicationStartedReturnsFalseForFailedApplicationState() throws Exception {
    Set<String> inactiveBundles = new HashSet<String>();
    inactiveBundles.add(TEST_MAIN_FEATURES_2_UNIQUE_BUNDLE_LOCATION);
    FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo2, null, inactiveBundles);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    when(featuresService.isInstalled(mainFeatureRepo2.getFeatures()[0])).thenReturn(false);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    assertFalse(appService.isApplicationStarted(appService.getApplication(TEST_MAIN_FEATURES_2_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 5 with ApplicationService

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

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsFailedStatusWhenOneFeatureConsistingOfInactiveBundlesIsNotInstalled.

/**
     * Test method for
     * {@link ApplicationService#getApplicationStatus(Application)}
     * <p>
     * Verifies method returns an {@link ApplicationState#FAILED } 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 Bundle(s) whose
     * states and extended states are inactive</li>
     * </ul>
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsFailedStatusWhenOneFeatureConsistingOfInactiveBundlesIsNotInstalled() throws Exception {
    Set<Repository> mainFeaturesRepoSet = new HashSet<Repository>();
    Set<Feature> notInstalledFeatures = new HashSet<Feature>();
    Set<BundleInfo> inactiveBundles = new HashSet<BundleInfo>();
    for (Feature feature : mainFeatureRepo2.getFeatures()) {
        if (feature.getName().equals(TEST_MAIN_FEATURES_2_MAIN_FEATURE_NAME)) {
            notInstalledFeatures.add(feature);
            inactiveBundles.addAll(feature.getBundles());
            break;
        }
    }
    assertEquals("Feature is not included in repository the expected number of times", 1, notInstalledFeatures.size());
    assertTrue("No bundles included in Feature", inactiveBundles.size() > 0);
    mainFeaturesRepoSet.add(mainFeatureRepo2);
    FeaturesService featuresService = createMockFeaturesService(mainFeaturesRepoSet, notInstalledFeatures, inactiveBundles);
    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(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.FAILED, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Also used : Repository(org.apache.karaf.features.Repository) BundleInfo(org.apache.karaf.features.BundleInfo) FeaturesService(org.apache.karaf.features.FeaturesService) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) 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