Search in sources :

Example 1 with ApplicationStatus

use of org.codice.ddf.admin.application.service.ApplicationStatus 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 ApplicationStatus

use of org.codice.ddf.admin.application.service.ApplicationStatus 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 ApplicationStatus

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

Example 4 with ApplicationStatus

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

the class StopApplicationCommandTest method testStopApplicationCommandTest.

/**
     * Tests the {@link StopApplicationCommand} class and its associated methods
     *
     * @throws Exception
     */
@Test
public void testStopApplicationCommandTest() throws Exception {
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    Application testApp = mock(ApplicationImpl.class);
    ApplicationStatus testStatus = mock(ApplicationStatus.class);
    StopApplicationCommand stopApplicationCommand = new StopApplicationCommand();
    stopApplicationCommand.appName = APP_NAME;
    when(testStatus.getState()).thenReturn(ApplicationState.ACTIVE);
    when(testAppService.getApplicationStatus(testApp)).thenReturn(testStatus);
    when(testAppService.getApplication(APP_NAME)).thenReturn(testApp);
    stopApplicationCommand.doExecute(testAppService);
    verify(testAppService).stopApplication(APP_NAME);
}
Also used : ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) Application(org.codice.ddf.admin.application.service.Application) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 5 with ApplicationStatus

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

the class StopApplicationCommandTest method testStopApplicationCommandAlreadyStopped.

/**
     * Tests the {@link StopApplicationCommand} class and its associated methods
     * for the case where the application parameter has already been stopped
     *
     * @throws Exception
     */
@Test
public void testStopApplicationCommandAlreadyStopped() throws Exception {
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    Application testApp = mock(ApplicationImpl.class);
    ApplicationStatus testStatus = mock(ApplicationStatus.class);
    StopApplicationCommand stopApplicationCommand = new StopApplicationCommand();
    stopApplicationCommand.appName = APP_NAME;
    when(testStatus.getState()).thenReturn(ApplicationState.INACTIVE);
    when(testAppService.getApplicationStatus(testApp)).thenReturn(testStatus);
    when(testAppService.getApplication(APP_NAME)).thenReturn(testApp);
    // Should handle this condition gracefully without throwing an exception
    // If an exception is thrown, this test fails...
    stopApplicationCommand.doExecute(testAppService);
}
Also used : ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) Application(org.codice.ddf.admin.application.service.Application) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Aggregations

Application (org.codice.ddf.admin.application.service.Application)13 ApplicationStatus (org.codice.ddf.admin.application.service.ApplicationStatus)13 Test (org.junit.Test)11 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)9 HashSet (java.util.HashSet)6 ArrayList (java.util.ArrayList)3 FeaturesService (org.apache.karaf.features.FeaturesService)3 Repository (org.apache.karaf.features.Repository)3 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)3 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)3 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)3 URI (java.net.URI)2 Feature (org.apache.karaf.features.Feature)2 ApplicationState (org.codice.ddf.admin.application.service.ApplicationStatus.ApplicationState)2 Bundle (org.osgi.framework.Bundle)2 Logger (org.slf4j.Logger)2 Appender (ch.qos.logback.core.Appender)1 List (java.util.List)1