Search in sources :

Example 36 with ApplicationService

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

the class AddApplicationCommandTest method testAddApplicationCommandInvalidURIParam.

/**
     * Tests the {@link AddApplicationCommand} class and its contained methods
     * for the case where it is given an invalid URI as a parameter
     *
     * @throws Exception
     */
@Test
public void testAddApplicationCommandInvalidURIParam() throws Exception {
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    AddApplicationCommand addApplicationCommand = new AddApplicationCommand();
    addApplicationCommand.appName = ">BadURI<";
    //Should have a graceful recovery, if an exception is thrown, this test fails.
    addApplicationCommand.doExecute(testAppService);
}
Also used : ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 37 with ApplicationService

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

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

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

the class RemoveApplicationCommandTest method testRemoveApplicationCommand.

/**
     * Tests the {@link RemoveApplicationCommand} class
     *
     * @throws Exception
     */
@Test
public void testRemoveApplicationCommand() throws Exception {
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    RemoveApplicationCommand removeApplicationCommand = new RemoveApplicationCommand();
    removeApplicationCommand.appName = APP_NAME;
    removeApplicationCommand.doExecute(testAppService);
    verify(testAppService).removeApplication(APP_NAME);
}
Also used : ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 40 with ApplicationService

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

the class StopApplicationCommandTest method testStopApplicationCommandTest.

/**
     * Tests the {@link StopApplicationCommand} class and its associated methods
     *
     * @throws Exception
     */
@Test
public void testStopApplicationCommandTest() throws Exception {
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    Application testApp = mock(ApplicationImpl.class);
    ApplicationStatus testStatus = mock(ApplicationStatus.class);
    StopApplicationCommand stopApplicationCommand = new StopApplicationCommand();
    stopApplicationCommand.appName = APP_NAME;
    when(testStatus.getState()).thenReturn(ApplicationState.ACTIVE);
    when(testAppService.getApplicationStatus(testApp)).thenReturn(testStatus);
    when(testAppService.getApplication(APP_NAME)).thenReturn(testApp);
    stopApplicationCommand.doExecute(testAppService);
    verify(testAppService).stopApplication(APP_NAME);
}
Also used : ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) Application(org.codice.ddf.admin.application.service.Application) 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