Search in sources :

Example 16 with ApplicationService

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

the class ApplicationServiceImplTest method testStopApplicationNoMainFeatureStringParam.

/**
     * Tests the {@link ApplicationServiceImpl#stopApplication(String)} method
     * for the case where there is no main feature, but other features exist
     *
     * @throws Exception
     */
@Test
public void testStopApplicationNoMainFeatureStringParam() 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();
    Feature[] featureList = noMainFeatureRepo1.getFeatures();
    appService.stopApplication(TEST_APP);
    verify(featuresService).uninstallFeature(featureList[0].getName(), featureList[0].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
    verify(featuresService).uninstallFeature(featureList[1].getName(), featureList[1].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
}
Also used : Repository(org.apache.karaf.features.Repository) 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)

Example 17 with ApplicationService

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

the class ApplicationServiceImplTest method testGetApplications.

/**
     * Tests that the {@link ApplicationServiceImpl#getApplications()} method
     * returns the correct number of applications.
     *
     * @throws Exception
     */
@Test
public void testGetApplications() throws Exception {
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(noMainFeatureRepo1, noMainFeatureRepo2));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    Set<Application> applications = appService.getApplications();
    assertNotNull(applications);
    assertEquals(2, applications.size());
}
Also used : Repository(org.apache.karaf.features.Repository) 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 18 with ApplicationService

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

the class ApplicationServiceImplTest method testFindFeatureExceptions.

/**
     * Tests the {@link ApplicationServiceImpl#findFeature(Feature)} method
     * for the case where exceptions are thrown inside findFeature(Feature, Set<Application>)
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix and un-ignore
@Test
@Ignore
public void testFindFeatureExceptions() 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);
    Application testApp = mock(ApplicationImpl.class);
    final Set<Application> applicationSet = new HashSet<>();
    applicationSet.add(testApp);
    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;
        }

        @Override
        public Set<Application> getApplications() {
            return applicationSet;
        }

        @Override
        public boolean isPermittedToViewFeature(String featureName) {
            return true;
        }
    };
    Feature testFeature = mock(Feature.class);
    doThrow(new NullPointerException()).when(testApp).getFeatures();
    appService.findFeature(testFeature);
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(FIND_FEAT_EX);
        }
    }));
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(FIND_FEAT_EX2);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) Mockito.anyString(org.mockito.Mockito.anyString) Logger(org.slf4j.Logger) Feature(org.apache.karaf.features.Feature) Repository(org.apache.karaf.features.Repository) ArgumentMatcher(org.mockito.ArgumentMatcher) 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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with ApplicationService

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

the class ApplicationServiceImplTest method testApplicationTreeWithNoMainFeature.

/**
     * Test that an application tree can be created even if there is an app that
     * does not contain a main feature.
     *
     * @throws Exception
     */
@Test
public void testApplicationTreeWithNoMainFeature() throws Exception {
    Repository mainFeaturesRepo2 = createRepo(TEST_MAIN_FEATURE_2_FILE_NAME);
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, mainFeaturesRepo2, noMainFeatureRepo1));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    Set<ApplicationNode> rootApps = appService.getApplicationTree();
    assertNotNull(rootApps);
    assertEquals(2, rootApps.size());
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) ApplicationNode(org.codice.ddf.admin.application.service.ApplicationNode) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 20 with ApplicationService

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

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