Search in sources :

Example 46 with Appender

use of ch.qos.logback.core.Appender 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

Appender (ch.qos.logback.core.Appender)46 Test (org.junit.Test)36 Logger (org.slf4j.Logger)26 ArgumentMatcher (org.mockito.ArgumentMatcher)23 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)13 Logger (ch.qos.logback.classic.Logger)12 LoggerContext (ch.qos.logback.classic.LoggerContext)12 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)12 FileAppender (ch.qos.logback.core.FileAppender)11 FeaturesService (org.apache.karaf.features.FeaturesService)10 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)9 HashSet (java.util.HashSet)9 Repository (org.apache.karaf.features.Repository)9 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)8 File (java.io.File)6 ArrayList (java.util.ArrayList)6 Application (org.codice.ddf.admin.application.service.Application)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)2