Search in sources :

Example 71 with Appender

use of ch.qos.logback.core.Appender in project ddf by codice.

the class ApplicationServiceImplTest method testFindApplicationFeaturesException.

/**
     * Tests the {@link ApplicationServiceImpl#findApplicationFeatures(String)} method
     * for the case where an exception is thrown by the featuresService
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testFindApplicationFeaturesException() 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);
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1, noMainFeatureRepo2));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = new ApplicationServiceImpl(bundleStateServices) {

        @Override
        protected BundleContext getContext() {
            return bundleContext;
        }
    };
    doThrow(new NullPointerException()).when(featuresService).listRepositories();
    appService.findApplicationFeatures(TEST_APP_NAME);
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

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

Example 72 with Appender

use of ch.qos.logback.core.Appender in project ddf by codice.

the class ApplicationServiceImplTest method testGetApplicationStatusException.

/**
     * Tests the {@link ApplicationServiceImpl#getApplicationStatus(Application)} method
     * for the case where an exception is thrown in the main block
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testGetApplicationStatusException() 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);
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationServiceImpl appService = new ApplicationServiceImpl(bundleStateServices) {

        @Override
        protected BundleContext getContext() {
            return bundleContext;
        }
    };
    Application testApp = mock(ApplicationImpl.class);
    doThrow(new NullPointerException()).when(testApp).getFeatures();
    ApplicationStatus result = appService.getApplicationStatus(testApp);
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(APP_STATUS_EX);
        }
    }));
    assertThat("State of resulting ApplicationStatus should be UNKNOWN.", result.getState(), is(ApplicationState.UNKNOWN));
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(org.slf4j.Logger) Repository(org.apache.karaf.features.Repository) ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) ArgumentMatcher(org.mockito.ArgumentMatcher) FeaturesService(org.apache.karaf.features.FeaturesService) Application(org.codice.ddf.admin.application.service.Application) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 73 with Appender

use of ch.qos.logback.core.Appender in project ddf by codice.

the class ApplicationServiceBeanTest method testRemoveApplicationASE.

/**
     * Tests the {@link ApplicationServiceBean#removeApplication(String)} method
     * for the case where an ApplicationServiceException is thrown by the AppService
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRemoveApplicationASE() 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);
    ApplicationServiceBean serviceBean = new ApplicationServiceBean(testAppService, testConfigAdminExt, mBeanServer);
    doThrow(new ApplicationServiceException()).when(testAppService).removeApplication(any(String.class));
    serviceBean.removeApplication(TEST_APP_NAME);
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

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

Example 74 with Appender

use of ch.qos.logback.core.Appender in project ddf by codice.

the class ApplicationServiceImplTest method testFindApplicationFeaturesGetRepoFeatException.

/**
     * Tests the {@link ApplicationServiceImpl#findApplicationFeatures(String)} method
     * for the case where an exception is thrown in getRepositoryFeatures
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testFindApplicationFeaturesGetRepoFeatException() 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);
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1, noMainFeatureRepo2));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = new ApplicationServiceImpl(bundleStateServices) {

        @Override
        protected BundleContext getContext() {
            return bundleContext;
        }
    };
    Repository testRepo = mock(Repository.class);
    Repository[] repoList = { testRepo };
    when(featuresService.listRepositories()).thenReturn(repoList);
    when(testRepo.getName()).thenReturn(TEST_APP_NAME);
    doThrow(new Exception()).when(testRepo).getFeatures();
    appService.findApplicationFeatures(TEST_APP_NAME);
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

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

Example 75 with Appender

use of ch.qos.logback.core.Appender in project sling by apache.

the class LogTailerWebConsolePlugin method getOptions.

private String getOptions() {
    Set<String> logFiles = new HashSet<String>();
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
        for (Iterator<Appender<ILoggingEvent>> index = logger.iteratorForAppenders(); index.hasNext(); ) {
            Appender<ILoggingEvent> appender = index.next();
            if (appender instanceof FileAppender) {
                FileAppender fileAppender = (FileAppender) appender;
                String logfilePath = fileAppender.getFile();
                logFiles.add(logfilePath);
            }
        }
    }
    String logFilesHtml = "<option value=\"\"> - Select file - </option>";
    for (String logFile : logFiles) {
        File file = new File(logFile);
        logFilesHtml += "<option value=\"" + getKey(file) + "\">" + file.getName() + "</option>";
    }
    return logFilesHtml;
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) FileAppender(ch.qos.logback.core.FileAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Aggregations

Appender (ch.qos.logback.core.Appender)118 Test (org.junit.Test)62 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)51 Logger (ch.qos.logback.classic.Logger)32 LoggerContext (ch.qos.logback.classic.LoggerContext)32 FileAppender (ch.qos.logback.core.FileAppender)27 Logger (org.slf4j.Logger)25 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)21 ArgumentMatcher (org.mockito.ArgumentMatcher)19 AsyncAppender (ch.qos.logback.classic.AsyncAppender)18 File (java.io.File)14 OnMarkerEvaluator (ch.qos.logback.classic.boolex.OnMarkerEvaluator)13 EvaluatorFilter (ch.qos.logback.core.filter.EvaluatorFilter)13 LogstashTcpSocketAppender (net.logstash.logback.appender.LogstashTcpSocketAppender)13 ArrayList (java.util.ArrayList)11 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)11 OutputStreamAppender (ch.qos.logback.core.OutputStreamAppender)10 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)9 DBAppender (ch.qos.logback.classic.db.DBAppender)8 Test (org.junit.jupiter.api.Test)7