Search in sources :

Example 36 with FeaturesService

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

the class ProfileInstallCommandTest method testNullFeature.

@Test(expected = IllegalArgumentException.class)
public void testNullFeature() throws Exception {
    FeaturesService badFeatureService = mock(FeaturesService.class);
    when(badFeatureService.getFeature(any())).thenReturn(null);
    profileInstallCommand.profileName = "invalidFeatureUninstall";
    profileInstallCommand.doExecute(applicationService, badFeatureService, bundleService);
}
Also used : FeaturesService(org.apache.karaf.features.FeaturesService) Test(org.junit.Test)

Example 37 with FeaturesService

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

the class ProfileInstallCommandTest method testPostInstallerAndInstaller.

@Test
public void testPostInstallerAndInstaller() throws Exception {
    Feature postInstallFeature = createMockFeature("admin-post-install-modules");
    Feature installerFeature = createMockFeature("admin-modules-installer");
    this.featuresService = mock(FeaturesService.class);
    when(featuresService.getFeature("admin-post-install-modules")).thenReturn(postInstallFeature);
    when(featuresService.getFeature("admin-modules-installer")).thenReturn(installerFeature);
    when(featuresService.isInstalled(postInstallFeature)).thenReturn(false);
    when(featuresService.isInstalled(installerFeature)).thenReturn(true);
    profileInstallCommand.profileName = "invalidStopBundles";
    profileInstallCommand.doExecute(applicationService, featuresService, bundleService);
    verify(featuresService).installFeature(eq("admin-post-install-modules"), eq(NO_AUTO_REFRESH));
    verify(featuresService).uninstallFeature(eq("admin-modules-installer"), eq(NO_AUTO_REFRESH));
}
Also used : FeaturesService(org.apache.karaf.features.FeaturesService) Feature(org.apache.karaf.features.Feature) Test(org.junit.Test)

Example 38 with FeaturesService

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

the class ApplicationConfigInstallerTest method testRunASE.

/**
     * Tests the {@link ApplicationConfigInstaller#run()} method for the case
     * where an ApplicationServiceException is thrown by appService.addApplication(..)
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRunASE() 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);
    FeaturesService featuresService = mock(FeaturesService.class);
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    doThrow(new ApplicationServiceException()).when(testAppService).startApplication(anyString());
    URL fileURL = this.getClass().getResource("/" + GOOD_FILE);
    ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(fileURL.getFile(), testAppService, featuresService, START_FEATURE, STOP_FEATURE);
    configInstaller.run();
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(RUN_ASE_EX);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(org.slf4j.Logger) URL(java.net.URL) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) ArgumentMatcher(org.mockito.ArgumentMatcher) FeaturesService(org.apache.karaf.features.FeaturesService) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 39 with FeaturesService

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

the class ApplicationConfigInstallerTest method testFileValid.

/**
     * Tests with a valid file that contains one application that all of the
     * services were called correctly.
     *
     * @throws Exception
     */
@Test
public void testFileValid() throws Exception {
    FeaturesService featuresService = mock(FeaturesService.class);
    ApplicationService appService = mock(ApplicationService.class);
    URL fileURL = this.getClass().getResource("/" + GOOD_FILE);
    ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(fileURL.getFile(), appService, featuresService, START_FEATURE, STOP_FEATURE);
    configInstaller.run();
    // verify that the correct application was started
    verify(appService, never()).addApplication(any(URI.class));
    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 40 with FeaturesService

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

the class ApplicationConfigInstallerTest method testFileNotValid.

/**
     * Tests that when a file is not found, the post install start and post
     * install stop features are NOT called.
     */
@Test
public void testFileNotValid() throws Exception {
    FeaturesService featuresService = mock(FeaturesService.class);
    ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(BAD_FILE, null, featuresService, START_FEATURE, STOP_FEATURE);
    configInstaller.run();
    // 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) 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