Search in sources :

Example 81 with ApplicationService

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

the class NotActiveApplicationsCompleterTest method testNotActiveApplicationsCompleter.

/**
     * Tests the {@link NotActiveApplicationsCompleter#complete(String, int, List)} method
     */
@Test
public void testNotActiveApplicationsCompleter() {
    Application testApp = mock(ApplicationImpl.class);
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    Set<Application> appSet = new HashSet<>();
    appSet.add(testApp);
    ApplicationStatus testStatus = mock(ApplicationStatusImpl.class);
    ApplicationStatus.ApplicationState testState = ApplicationStatus.ApplicationState.INACTIVE;
    when(testAppService.getApplications()).thenReturn(appSet);
    when(testAppService.getApplicationStatus(testApp)).thenReturn(testStatus);
    when(testStatus.getState()).thenReturn(testState);
    when(testApp.getName()).thenReturn("TestApp");
    NotActiveApplicationsCompleter activeApplicationsCompleter = new NotActiveApplicationsCompleter();
    activeApplicationsCompleter.setApplicationService(testAppService);
    assertThat("If the return value is -1, then the expected match was not found.", activeApplicationsCompleter.complete(null, commandLine, new ArrayList<>()), is(not(-1)));
}
Also used : ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) ArrayList(java.util.ArrayList) Application(org.codice.ddf.admin.application.service.Application) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 82 with ApplicationService

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

the class AddApplicationCommandTest method testAddApplicationCommandASE.

/**
     * Tests the {@link AddApplicationCommand} class and its contained methods
     * for the case where the ApplicationService throws an ApplicationServiceException
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testAddApplicationCommandASE() 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);
    root.setLevel(Level.ALL);
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    AddApplicationCommand addApplicationCommand = new AddApplicationCommand();
    addApplicationCommand.appName = "TestApp";
    addApplicationCommand.setApplicationService(testAppService);
    doThrow(new ApplicationServiceException()).when(testAppService).addApplication(any(URI.class));
    addApplicationCommand.execute();
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(CMD_ERROR_STRING);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(org.slf4j.Logger) URI(java.net.URI) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) ArgumentMatcher(org.mockito.ArgumentMatcher) 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 Logger (org.slf4j.Logger)14 Appender (ch.qos.logback.core.Appender)13 URI (java.net.URI)13 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)13 ArgumentMatcher (org.mockito.ArgumentMatcher)13 Mockito.anyString (org.mockito.Mockito.anyString)10 ApplicationStatus (org.codice.ddf.admin.application.service.ApplicationStatus)9 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 EnumSet (java.util.EnumSet)3 ApplicationNode (org.codice.ddf.admin.application.service.ApplicationNode)3 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)3 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)3