Search in sources :

Example 1 with Logger

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

the class FailFastProblemReporterTests method testWarn.

@Test
public void testWarn() throws Exception {
    Problem problem = new Problem("VGER", new Location(new DescriptiveResource("here")), null, new IllegalArgumentException());
    Logger log = mock(Logger.class);
    FailFastProblemReporter reporter = new FailFastProblemReporter();
    reporter.setLogger(log);
    reporter.warning(problem);
    verify(log).warn(any(), isA(IllegalArgumentException.class));
}
Also used : DescriptiveResource(cn.taketoday.core.io.DescriptiveResource) Logger(cn.taketoday.logging.Logger) Test(org.junit.jupiter.api.Test)

Example 2 with Logger

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

the class LoggingCacheErrorHandlerTests method handleCacheErrorWithStacktrace.

@Test
void handleCacheErrorWithStacktrace() {
    Logger logger = mock(Logger.class);
    LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, true);
    RuntimeException exception = new RuntimeException();
    handler.handleCacheGetError(exception, new NoOpCache("NOOP"), "key");
    verify(logger).warn("Cache 'NOOP' failed to get entry with key 'key'", exception);
}
Also used : NoOpCache(cn.taketoday.cache.support.NoOpCache) Logger(cn.taketoday.logging.Logger) Test(org.junit.jupiter.api.Test)

Example 3 with Logger

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

the class LoggingCacheErrorHandlerTests method handleClearErrorLogsAppropriateMessage.

@Test
void handleClearErrorLogsAppropriateMessage() {
    Logger logger = mock(Logger.class);
    LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, false);
    handler.handleCacheClearError(new RuntimeException(), new NoOpCache("NOOP"));
    verify(logger).warn("Cache 'NOOP' failed to clear entries");
}
Also used : NoOpCache(cn.taketoday.cache.support.NoOpCache) Logger(cn.taketoday.logging.Logger) Test(org.junit.jupiter.api.Test)

Example 4 with Logger

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

the class LoggingCacheErrorHandlerTests method handleEvictCacheErrorLogsAppropriateMessage.

@Test
void handleEvictCacheErrorLogsAppropriateMessage() {
    Logger logger = mock(Logger.class);
    LoggingCacheErrorHandler handler = new LoggingCacheErrorHandler(logger, false);
    handler.handleCacheEvictError(new RuntimeException(), new NoOpCache("NOOP"), "key");
    verify(logger).warn("Cache 'NOOP' failed to evict entry with key 'key'");
}
Also used : NoOpCache(cn.taketoday.cache.support.NoOpCache) Logger(cn.taketoday.logging.Logger) Test(org.junit.jupiter.api.Test)

Example 5 with Logger

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

the class CustomizableTraceInterceptorTests method testSunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching.

@Test
public void testSunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching() throws Throwable {
    MethodInvocation methodInvocation = mock(MethodInvocation.class);
    given(methodInvocation.getMethod()).willReturn(String.class.getMethod("toString", new Class[0]));
    given(methodInvocation.getThis()).willReturn(this);
    given(methodInvocation.getArguments()).willReturn(new Object[] { "$ One \\$", 2L });
    given(methodInvocation.proceed()).willReturn("Hello!");
    Logger log = mock(Logger.class);
    given(log.isTraceEnabled()).willReturn(true);
    CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
    interceptor.setEnterMessage(new StringBuilder().append("Entering the '").append(CustomizableTraceInterceptor.PLACEHOLDER_METHOD_NAME).append("' method of the [").append(CustomizableTraceInterceptor.PLACEHOLDER_TARGET_CLASS_NAME).append("] class with the following args (").append(CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENTS).append(") and arg types (").append(CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENT_TYPES).append(").").toString());
    interceptor.setExitMessage(new StringBuilder().append("Exiting the '").append(CustomizableTraceInterceptor.PLACEHOLDER_METHOD_NAME).append("' method of the [").append(CustomizableTraceInterceptor.PLACEHOLDER_TARGET_CLASS_SHORT_NAME).append("] class with the following args (").append(CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENTS).append(") and arg types (").append(CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENT_TYPES).append("), returning '").append(CustomizableTraceInterceptor.PLACEHOLDER_RETURN_VALUE).append("' and taking '").append(CustomizableTraceInterceptor.PLACEHOLDER_INVOCATION_TIME).append("' this long.").toString());
    interceptor.invoke(methodInvocation);
    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