Search in sources :

Example 21 with FeaturesService

use of org.apache.karaf.features.FeaturesService 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 22 with FeaturesService

use of org.apache.karaf.features.FeaturesService 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 23 with FeaturesService

use of org.apache.karaf.features.FeaturesService 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 24 with FeaturesService

use of org.apache.karaf.features.FeaturesService in project ddf by codice.

the class ApplicationConfigInstallerTest method testFileEmpty.

/**
     * Tests the use case that there is a file but it does not have any apps
     * listed in it (they are commented out). The test should not call the
     * features stop and start since no apps were loaded.
     *
     * @throws Exception
     */
@Test
public void testFileEmpty() throws Exception {
    FeaturesService featuresService = mock(FeaturesService.class);
    ApplicationService appService = mock(ApplicationService.class);
    URL fileURL = this.getClass().getResource("/" + EMPTY_FILE);
    ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(fileURL.getFile(), appService, featuresService, START_FEATURE, STOP_FEATURE);
    configInstaller.run();
    // verify that the app service was never called
    verify(appService, never()).addApplication(any(URI.class));
    verify(appService, never()).startApplication(anyString());
    // verify the post start and post stop features were not called
    verify(featuresService, never()).installFeature(anyString(), any(EnumSet.class));
    verify(featuresService, never()).uninstallFeature(anyString());
}
Also used : EnumSet(java.util.EnumSet) FeaturesService(org.apache.karaf.features.FeaturesService) URI(java.net.URI) URL(java.net.URL) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 25 with FeaturesService

use of org.apache.karaf.features.FeaturesService in project ddf by codice.

the class ApplicationConfigInstallerTest method testFileInstall.

/**
     * Tests with a valid file that contains one non-local application that all of the
     * services were called correctly.
     *
     * @throws Exception
     */
@Test
public void testFileInstall() throws Exception {
    FeaturesService featuresService = mock(FeaturesService.class);
    ApplicationService appService = mock(ApplicationService.class);
    URL fileURL = this.getClass().getResource("/" + INSTALL_FILE);
    ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(fileURL.getFile(), appService, featuresService, START_FEATURE, STOP_FEATURE);
    configInstaller.run();
    // verify that the correct application was added and then started
    verify(appService).addApplication(new URI("file:/location/to/solr-app-1.0.0.kar"));
    verify(appService).startApplication("solr-app");
    // verify the post start and post stop features were called
    verify(featuresService).installFeature(START_FEATURE, EnumSet.of(Option.NoAutoRefreshBundles));
    verify(featuresService).uninstallFeature(STOP_FEATURE);
}
Also used : FeaturesService(org.apache.karaf.features.FeaturesService) URI(java.net.URI) URL(java.net.URL) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Aggregations

FeaturesService (org.apache.karaf.features.FeaturesService)71 Test (org.junit.Test)61 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)51 HashSet (java.util.HashSet)48 Repository (org.apache.karaf.features.Repository)43 Feature (org.apache.karaf.features.Feature)29 Application (org.codice.ddf.admin.application.service.Application)19 Mockito.anyString (org.mockito.Mockito.anyString)13 Logger (org.slf4j.Logger)12 Appender (ch.qos.logback.core.Appender)10 URI (java.net.URI)10 ArgumentMatcher (org.mockito.ArgumentMatcher)10 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)9 EnumSet (java.util.EnumSet)6 Bundle (org.osgi.framework.Bundle)6 URL (java.net.URL)5 ArrayList (java.util.ArrayList)4 BundleInfo (org.apache.karaf.features.BundleInfo)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2