Search in sources :

Example 71 with Log

use of org.apache.commons.logging.Log in project spring-framework by spring-projects.

the class CustomizableTraceInterceptorTests method testExceptionPathLogsCorrectly.

@Test
public void testExceptionPathLogsCorrectly() throws Throwable {
    MethodInvocation methodInvocation = mock(MethodInvocation.class);
    IllegalArgumentException exception = new IllegalArgumentException();
    given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
    given(methodInvocation.getThis()).willReturn(this);
    given(methodInvocation.proceed()).willThrow(exception);
    Log log = mock(Log.class);
    given(log.isTraceEnabled()).willReturn(true);
    CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
    assertThatIllegalArgumentException().isThrownBy(() -> interceptor.invoke(methodInvocation));
    verify(log).trace(anyString());
    verify(log).trace(anyString(), eq(exception));
}
Also used : Log(org.apache.commons.logging.Log) MethodInvocation(org.aopalliance.intercept.MethodInvocation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Test(org.junit.jupiter.api.Test)

Example 72 with Log

use of org.apache.commons.logging.Log in project spring-framework by spring-projects.

the class CustomizableTraceInterceptorTests method testSunnyDayPathLogsCorrectly.

@Test
public void testSunnyDayPathLogsCorrectly() throws Throwable {
    MethodInvocation methodInvocation = mock(MethodInvocation.class);
    given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString"));
    given(methodInvocation.getThis()).willReturn(this);
    Log log = mock(Log.class);
    given(log.isTraceEnabled()).willReturn(true);
    CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
    interceptor.invoke(methodInvocation);
    verify(log, times(2)).trace(anyString());
}
Also used : Log(org.apache.commons.logging.Log) MethodInvocation(org.aopalliance.intercept.MethodInvocation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 73 with Log

use of org.apache.commons.logging.Log in project checkstyle by checkstyle.

the class Checker method process.

@Override
public int process(List<File> files) throws CheckstyleException {
    if (cacheFile != null) {
        cacheFile.putExternalResources(getExternalResourceLocations());
    }
    // Prepare to start
    fireAuditStarted();
    for (final FileSetCheck fsc : fileSetChecks) {
        fsc.beginProcessing(charset);
    }
    final List<File> targetFiles = files.stream().filter(file -> CommonUtil.matchesFileExtension(file, fileExtensions)).collect(Collectors.toList());
    processFiles(targetFiles);
    // Finish up
    // It may also log!!!
    fileSetChecks.forEach(FileSetCheck::finishProcessing);
    // It may also log!!!
    fileSetChecks.forEach(FileSetCheck::destroy);
    final int errorCount = counter.getCount();
    fireAuditFinished();
    return errorCount;
}
Also used : Context(com.puppycrawl.tools.checkstyle.api.Context) SortedSet(java.util.SortedSet) FilterSet(com.puppycrawl.tools.checkstyle.api.FilterSet) AuditListener(com.puppycrawl.tools.checkstyle.api.AuditListener) BeforeExecutionFileFilter(com.puppycrawl.tools.checkstyle.api.BeforeExecutionFileFilter) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Charset(java.nio.charset.Charset) FileSetCheck(com.puppycrawl.tools.checkstyle.api.FileSetCheck) Locale(java.util.Locale) MessageDispatcher(com.puppycrawl.tools.checkstyle.api.MessageDispatcher) Violation(com.puppycrawl.tools.checkstyle.api.Violation) PrintWriter(java.io.PrintWriter) Filter(com.puppycrawl.tools.checkstyle.api.Filter) BeforeExecutionFileFilterSet(com.puppycrawl.tools.checkstyle.api.BeforeExecutionFileFilterSet) CommonUtil(com.puppycrawl.tools.checkstyle.utils.CommonUtil) StringWriter(java.io.StringWriter) Set(java.util.Set) IOException(java.io.IOException) ExternalResourceHolder(com.puppycrawl.tools.checkstyle.api.ExternalResourceHolder) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) FileText(com.puppycrawl.tools.checkstyle.api.FileText) List(java.util.List) Stream(java.util.stream.Stream) AutomaticBean(com.puppycrawl.tools.checkstyle.api.AutomaticBean) Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) SeverityLevelCounter(com.puppycrawl.tools.checkstyle.api.SeverityLevelCounter) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RootModule(com.puppycrawl.tools.checkstyle.api.RootModule) AuditEvent(com.puppycrawl.tools.checkstyle.api.AuditEvent) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException) SeverityLevel(com.puppycrawl.tools.checkstyle.api.SeverityLevel) FileSetCheck(com.puppycrawl.tools.checkstyle.api.FileSetCheck) File(java.io.File)

Example 74 with Log

use of org.apache.commons.logging.Log in project spring-framework by spring-projects.

the class DebugInterceptorTests method testExceptionPathStillLogsCorrectly.

@Test
public void testExceptionPathStillLogsCorrectly() throws Throwable {
    MethodInvocation methodInvocation = mock(MethodInvocation.class);
    IllegalArgumentException exception = new IllegalArgumentException();
    given(methodInvocation.proceed()).willThrow(exception);
    Log log = mock(Log.class);
    given(log.isTraceEnabled()).willReturn(true);
    DebugInterceptor interceptor = new StubDebugInterceptor(log);
    assertThatIllegalArgumentException().isThrownBy(() -> interceptor.invoke(methodInvocation));
    checkCallCountTotal(interceptor);
    verify(log).trace(anyString());
    verify(log).trace(anyString(), eq(exception));
}
Also used : Log(org.apache.commons.logging.Log) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Test(org.junit.jupiter.api.Test)

Example 75 with Log

use of org.apache.commons.logging.Log in project spring-framework by spring-projects.

the class PerformanceMonitorInterceptorTests method testSunnyDayPathLogsPerformanceMetricsCorrectly.

@Test
public void testSunnyDayPathLogsPerformanceMetricsCorrectly() throws Throwable {
    MethodInvocation mi = mock(MethodInvocation.class);
    given(mi.getMethod()).willReturn(String.class.getMethod("toString", new Class[0]));
    Log log = mock(Log.class);
    PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true);
    interceptor.invokeUnderTrace(mi, log);
    verify(log).trace(anyString());
}
Also used : Log(org.apache.commons.logging.Log) MethodInvocation(org.aopalliance.intercept.MethodInvocation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Aggregations

Log (org.apache.commons.logging.Log)188 Test (org.junit.Test)51 Test (org.junit.jupiter.api.Test)40 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)35 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 BeanFactory (org.springframework.beans.factory.BeanFactory)17 CountDownLatch (java.util.concurrent.CountDownLatch)15 LogConfigurationException (org.apache.commons.logging.LogConfigurationException)15 ArrayList (java.util.ArrayList)12 File (java.io.File)11 QueueChannel (org.springframework.integration.channel.QueueChannel)11 MethodInvocation (org.aopalliance.intercept.MethodInvocation)10 IOException (java.io.IOException)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Log4JLogger (org.apache.commons.logging.impl.Log4JLogger)9 Message (org.springframework.messaging.Message)8 List (java.util.List)7 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)7 InputStream (java.io.InputStream)6 LogFactory (org.apache.commons.logging.LogFactory)6