Search in sources :

Example 26 with Logger

use of cn.taketoday.logging.Logger in project today-infrastructure by TAKETODAY.

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]));
    Logger log = mock(Logger.class);
    PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true);
    interceptor.invokeUnderTrace(mi, log);
    verify(log).trace(anyString());
}
Also used : MethodInvocation(org.aopalliance.intercept.MethodInvocation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Logger(cn.taketoday.logging.Logger) Test(org.junit.jupiter.api.Test)

Example 27 with Logger

use of cn.taketoday.logging.Logger in project today-infrastructure by TAKETODAY.

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);
    Logger log = mock(Logger.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 : MethodInvocation(org.aopalliance.intercept.MethodInvocation) Logger(cn.taketoday.logging.Logger) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Test(org.junit.jupiter.api.Test)

Example 28 with Logger

use of cn.taketoday.logging.Logger in project today-infrastructure by TAKETODAY.

the class DebugInterceptorTests method testSunnyDayPathLogsCorrectly.

@Test
public void testSunnyDayPathLogsCorrectly() throws Throwable {
    MethodInvocation methodInvocation = mock(MethodInvocation.class);
    Logger log = mock(Logger.class);
    given(log.isTraceEnabled()).willReturn(true);
    DebugInterceptor interceptor = new StubDebugInterceptor(log);
    interceptor.invoke(methodInvocation);
    checkCallCountTotal(interceptor);
    verify(log, times(2)).trace(anyString());
}
Also used : MethodInvocation(org.aopalliance.intercept.MethodInvocation) Logger(cn.taketoday.logging.Logger) Test(org.junit.jupiter.api.Test)

Example 29 with Logger

use of cn.taketoday.logging.Logger in project today-infrastructure by TAKETODAY.

the class SimpleTraceInterceptorTests method testExceptionPathStillLogsCorrectly.

@Test
public void testExceptionPathStillLogsCorrectly() throws Throwable {
    MethodInvocation mi = mock(MethodInvocation.class);
    given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
    given(mi.getThis()).willReturn(this);
    IllegalArgumentException exception = new IllegalArgumentException();
    given(mi.proceed()).willThrow(exception);
    Logger log = mock(Logger.class);
    final SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);
    assertThatIllegalArgumentException().isThrownBy(() -> interceptor.invokeUnderTrace(mi, log));
    verify(log).trace(anyString());
    verify(log).trace(anyString(), eq(exception));
}
Also used : MethodInvocation(org.aopalliance.intercept.MethodInvocation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Logger(cn.taketoday.logging.Logger) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Test(org.junit.jupiter.api.Test)

Example 30 with Logger

use of cn.taketoday.logging.Logger in project today-infrastructure by TAKETODAY.

the class SimpleTraceInterceptorTests method testSunnyDayPathLogsCorrectly.

@Test
public void testSunnyDayPathLogsCorrectly() throws Throwable {
    MethodInvocation mi = mock(MethodInvocation.class);
    given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
    given(mi.getThis()).willReturn(this);
    Logger log = mock(Logger.class);
    SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);
    interceptor.invokeUnderTrace(mi, log);
    verify(log, times(2)).trace(anyString());
}
Also used : MethodInvocation(org.aopalliance.intercept.MethodInvocation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Logger(cn.taketoday.logging.Logger) Test(org.junit.jupiter.api.Test)

Aggregations

Logger (cn.taketoday.logging.Logger)34 Test (org.junit.jupiter.api.Test)32 MethodInvocation (org.aopalliance.intercept.MethodInvocation)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14 NoOpCache (cn.taketoday.cache.support.NoOpCache)10 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)10 List (java.util.List)4 ResolvableType (cn.taketoday.core.ResolvableType)2 Hints (cn.taketoday.core.codec.Hints)2 ResourceDecoder (cn.taketoday.core.codec.ResourceDecoder)2 ResourceEncoder (cn.taketoday.core.codec.ResourceEncoder)2 ResourceRegionEncoder (cn.taketoday.core.codec.ResourceRegionEncoder)2 DescriptiveResource (cn.taketoday.core.io.DescriptiveResource)2 InputStreamResource (cn.taketoday.core.io.InputStreamResource)2 Resource (cn.taketoday.core.io.Resource)2 ResourceRegion (cn.taketoday.core.io.ResourceRegion)2 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)2 DataBufferFactory (cn.taketoday.core.io.buffer.DataBufferFactory)2 HttpHeaders (cn.taketoday.http.HttpHeaders)2 HttpLogging (cn.taketoday.http.HttpLogging)2