Search in sources :

Example 36 with Application

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

the class ApplicationServiceImplTest method testApplicationTree.

/**
     * Tests that an application tree is passed back correctly.
     *
     * @throws Exception
     */
@Test
public void testApplicationTree() throws Exception {
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, mainFeatureRepo2));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    Set<ApplicationNode> rootApps = appService.getApplicationTree();
    assertNotNull(rootApps);
    assertEquals(1, rootApps.size());
    ApplicationNode mainAppNode = rootApps.iterator().next();
    assertEquals(1, mainAppNode.getChildren().size());
    assertNull(mainAppNode.getParent());
    assertEquals("main-feature2", mainAppNode.getChildren().iterator().next().getApplication().getName());
    assertEquals(mainAppNode, mainAppNode.getChildren().iterator().next().getParent());
    Application mainApp = mainAppNode.getApplication();
    assertEquals("main-feature", mainApp.getName());
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) 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 37 with Application

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

the class ApplicationServiceImplTest method testStopApplicationGeneralASE.

/**
     * Tests the {@link ApplicationServiceImpl#stopApplication(Application)} method
     * for the case where an exception is caught
     *
     * @throws Exception
     */
@Test(expected = ApplicationServiceException.class)
public void testStopApplicationGeneralASE() 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 testApp1 = mock(ApplicationImpl.class);
    Feature testFeature1 = mock(Feature.class);
    when(testApp1.getFeatures()).thenReturn(new HashSet<>(Arrays.asList(testFeature1)));
    when(featuresService.isInstalled(any())).thenReturn(true);
    doThrow(new Exception()).when(featuresService).uninstallFeature(anyString(), anyString(), any());
    appService.stopApplication(testApp1);
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Application(org.codice.ddf.admin.application.service.Application) Feature(org.apache.karaf.features.Feature) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 38 with Application

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

the class TestApplicationService method dTestAppAddRemove.

@Test
public void dTestAppAddRemove() throws ApplicationServiceException {
    systemSubject.execute(() -> {
        ApplicationService applicationService = getServiceManager().getService(ApplicationService.class);
        Application sdkApp = applicationService.getApplication(SDK_APP);
        URI sdkUri = sdkApp.getURI();
        // Remove
        try {
            applicationService.removeApplication(sdkApp);
        } catch (ApplicationServiceException e) {
            LOGGER.error("Failed to remove {}: {}", sdkApp.getName(), e.getMessage());
            fail();
        }
        Set<Application> apps = applicationService.getApplications();
        assertThat(apps, not(hasItem(sdkApp)));
        // Add
        try {
            applicationService.addApplication(sdkUri);
        } catch (ApplicationServiceException e) {
            LOGGER.error("Failed to add {}: {}", sdkUri, e.getMessage());
            fail();
        }
        sdkApp = applicationService.getApplication(SDK_APP);
        assertThat(sdkApp.getName(), is(SDK_APP));
        assertThat(sdkApp.getURI(), is(sdkUri));
        ApplicationStatus status = applicationService.getApplicationStatus(sdkApp);
        assertThat(status.getState(), is(INACTIVE));
        apps = applicationService.getApplications();
        assertThat(apps, hasItem(sdkApp));
        // Test Commands
        // Remove
        String response = console.runCommand(REMOVE_COMMAND + SDK_APP);
        assertThat("Should be empty response after " + REMOVE_COMMAND, response, isEmptyString());
        response = console.runCommand(STATUS_COMMAND + SDK_APP);
        assertThat(SDK_APP + " should be not be found after " + REMOVE_COMMAND, response, containsString("No application found with name " + SDK_APP));
        // Add
        response = console.runCommand(ADD_COMMAND + sdkUri.toString());
        assertThat("Should be empty response after " + ADD_COMMAND, response, isEmptyString());
        response = console.runCommand(STATUS_COMMAND + SDK_APP);
        assertThat(SDK_APP + " should be INACTIVE after " + STATUS_COMMAND, response, containsString(INACTIVE_APP));
        try {
            applicationService.startApplication(SDK_APP);
        } catch (ApplicationServiceException e) {
            LOGGER.error("Failed to restart {}: {}", sdkUri, e.getMessage());
            fail();
        }
    });
}
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) URI(java.net.URI) 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 39 with Application

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

the class ApplicationNodeImplTest method testCompareTo.

/**
     * Tests the {@link ApplicationNodeImpl#compareTo(ApplicationNode)} method for the case
     * where the parameter node's application does not have the same name
     */
@Test
public void testCompareTo() {
    Application testApp = mock(Application.class);
    when(testApp.getName()).thenReturn(APP_NAME);
    Application testApp2 = mock(Application.class);
    when(testApp2.getName()).thenReturn(APP2_NAME);
    ApplicationNodeImpl testNode = new ApplicationNodeImpl(testApp);
    ApplicationNodeImpl testNode2 = new ApplicationNodeImpl(testApp2);
    assertEquals(-5, testNode.compareTo(testNode2));
}
Also used : Application(org.codice.ddf.admin.application.service.Application) Test(org.junit.Test)

Example 40 with Application

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

the class ApplicationServiceImplTest method testStopApplicationNoMainFeature.

/**
     * Tests the {@link ApplicationServiceImpl#stopApplication(Application)} method
     * for the case where there is no main feature, but other features exist
     *
     * @throws Exception
     */
@Test
public void testStopApplicationNoMainFeature() 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 = createPermittedApplicationServiceImpl();
    Application testApp = mock(ApplicationImpl.class);
    Feature testFeature1 = mock(Feature.class);
    Feature testFeature2 = mock(Feature.class);
    Set<Feature> featureSet = new HashSet<Feature>();
    featureSet.add(testFeature1);
    featureSet.add(testFeature2);
    when(testApp.getName()).thenReturn(TEST_APP_NAME);
    when(testApp.getMainFeature()).thenReturn(null);
    when(testApp.getFeatures()).thenReturn(featureSet);
    when(testFeature1.getName()).thenReturn(TEST_FEATURE_1_NAME);
    when(testFeature2.getName()).thenReturn(TEST_FEATURE_2_NAME);
    when(testFeature1.getInstall()).thenReturn(Feature.DEFAULT_INSTALL_MODE);
    when(testFeature2.getInstall()).thenReturn(Feature.DEFAULT_INSTALL_MODE);
    when(featuresService.isInstalled(testFeature1)).thenReturn(true);
    when(featuresService.isInstalled(testFeature2)).thenReturn(true);
    appService.stopApplication(testApp);
    verify(featuresService, atLeastOnce()).uninstallFeature(TEST_FEATURE_1_NAME, null, EnumSet.of(Option.NoAutoRefreshBundles));
    verify(featuresService, atLeastOnce()).uninstallFeature(TEST_FEATURE_2_NAME, null, EnumSet.of(Option.NoAutoRefreshBundles));
}
Also used : Repository(org.apache.karaf.features.Repository) 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)

Aggregations

Application (org.codice.ddf.admin.application.service.Application)55 Test (org.junit.Test)43 HashSet (java.util.HashSet)28 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)26 Repository (org.apache.karaf.features.Repository)21 FeaturesService (org.apache.karaf.features.FeaturesService)19 Feature (org.apache.karaf.features.Feature)14 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)13 ApplicationStatus (org.codice.ddf.admin.application.service.ApplicationStatus)13 ApplicationNode (org.codice.ddf.admin.application.service.ApplicationNode)11 ArrayList (java.util.ArrayList)9 RepositoryImpl (org.apache.karaf.features.internal.service.RepositoryImpl)7 HashMap (java.util.HashMap)5 Logger (org.slf4j.Logger)5 Appender (ch.qos.logback.core.Appender)4 URI (java.net.URI)4 TreeSet (java.util.TreeSet)4 ArgumentMatcher (org.mockito.ArgumentMatcher)4 Mockito.anyString (org.mockito.Mockito.anyString)4 SecurityServiceException (ddf.security.service.SecurityServiceException)3