Search in sources :

Example 21 with ApplicationService

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

the class NotActiveApplicationsCompleterTest method testNotActiveApplicationsCompleterNullAppService.

/**
     * Tests the {@link NotActiveApplicationsCompleter#complete(String, int, List)} method
     * for the case where the ApplicationService given to it is null
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testNotActiveApplicationsCompleterNullAppService() {
    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);
    root.setLevel(Level.ALL);
    ApplicationService testAppService = null;
    NotActiveApplicationsCompleter notActiveApplicationsCompleter = new NotActiveApplicationsCompleter();
    notActiveApplicationsCompleter.setApplicationService(testAppService);
    notActiveApplicationsCompleter.complete(null, commandLine, new ArrayList<>());
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(NO_APP_SERV);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) ArgumentMatcher(org.mockito.ArgumentMatcher) Logger(org.slf4j.Logger) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 22 with ApplicationService

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

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

Example 24 with ApplicationService

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

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsActiveStatusForNotInstalledFeatureDependencyThatContainsActiveBundle.

/**
     * Test method for
     * {@link ApplicationService#getApplicationStatus(Application)}
     * <p>
     * Verifies method returns an {@link ApplicationState#ACTIVE} 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 a {@code Bundle}
     * with a state of {@link Bundle#ACTIVE} and extended state of
     * {@link BundleState#Active}</li>
     * </ul>
     * <p>
     * This effectively emulates the circumstance in which there is a
     * {@code Feature} in another {@code Application} that includes and starts
     * the same {@code Bundle} that is contained in a {@code Feature} of the
     * current {@code Application} that is not installed.
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsActiveStatusForNotInstalledFeatureDependencyThatContainsActiveBundle() throws Exception {
    Set<String> notInstalledFeatureNames = new HashSet<String>();
    notInstalledFeatureNames.add(TEST_MAIN_FEATURES_1_FEATURE_1_NAME);
    FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo, notInstalledFeatureNames, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    assertNotNull("Features repo is missing feature with the name of \"" + TEST_MAIN_FEATURES_1_FEATURE_1_NAME + "\"", featuresService.getFeature(TEST_MAIN_FEATURES_1_FEATURE_1_NAME));
    ApplicationService appService = createPermittedApplicationServiceImpl();
    assertEquals(ApplicationService.class.getName() + " does not contain the expected number of Applications", 1, appService.getApplications().size());
    assertEquals(mainFeatureRepo.getName() + " returned unexpected state", ApplicationState.ACTIVE, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
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 25 with ApplicationService

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

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsInactiveWhenBundleStateServiceStateIsStopping.

/**
     * 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#Stopping} state and the rest of the
     * bundles are in an {@link BundleState#Active} state.
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsInactiveWhenBundleStateServiceStateIsStopping() throws Exception {
    ApplicationService appService = getAppServiceWithBundleStateServiceInGivenState(mainFeatureRepo2, BundleState.Stopping);
    assertNotNull("Repository \"" + mainFeatureRepo.getName() + "\" does not contain any bundles", appService);
    assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.INACTIVE, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Also used : 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