From dbdb7a519ca8e39408d5c0211c473c469cb91500 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 8 Jan 2018 16:20:22 -0500 Subject: [PATCH 1/2] INT-4376: Upgage to Log4J 2 JIRA: https://jira.spring.io/browse/INT-4376 * Deprecate Log4J 1.x components in favor of newly added a `Log4j2LevelAdjuster` JUnit `@Rule` * Update all the logging configuration to Log4J 2 --- build.gradle | 9 +- .../amqp/outbound/AsyncAmqpGatewayTests.java | 11 +- .../src/test/resources/log4j.properties | 10 - .../src/test/resources/log4j2-test.xml | 17 ++ .../endpoint/PollerAdviceTests.java | 9 +- .../src/test/resources/log4j.properties | 7 - .../src/test/resources/log4j2-test.xml | 14 ++ .../src/test/java/log4j.properties | 8 - .../src/test/resources/log4j2-test.xml | 15 ++ .../src/test/java/log4j.properties | 8 - .../src/test/resources/log4j2-test.xml | 15 ++ .../src/test/resources/log4j.properties | 8 - .../src/test/resources/log4j2-test.xml | 15 ++ .../src/test/resources/log4j.properties | 9 - .../src/test/resources/log4j2-test.xml | 17 ++ .../src/test/resources/log4j.xml | 28 --- .../src/test/resources/log4j2-test.xml | 16 ++ .../src/test/resources/log4j.properties | 7 - .../src/test/resources/log4j2-test.xml | 16 ++ .../src/test/resources/log4j.properties | 9 - .../src/test/resources/log4j2-test.xml | 18 ++ .../ip/tcp/TcpOutboundGatewayTests.java | 16 +- .../connection/ConnectionFactoryTests.java | 11 +- .../FailoverClientConnectionFactoryTests.java | 18 +- .../tcp/connection/TcpNioConnectionTests.java | 12 +- ...ramPacketMulticastSendingHandlerTests.java | 22 +- .../src/test/resources/log4j.properties | 7 - .../src/test/resources/log4j2-test.xml | 15 ++ .../JdbcLockRegistryLeaderInitiatorTests.java | 13 +- .../src/test/resources/log4j.properties | 11 - .../src/test/resources/log4j2-test.xml | 17 ++ .../jms/JmsOutboundGatewayTests.java | 15 +- .../jms/OutboundGatewayFunctionTests.java | 52 +++-- .../src/test/resources/log4j.properties | 11 - .../src/test/resources/log4j2-test.xml | 19 ++ .../src/test/resources/log4j.properties | 11 - .../src/test/resources/log4j2-test.xml | 17 ++ .../src/test/resources/log4j.properties | 8 - .../src/test/resources/log4j2-test.xml | 15 ++ .../src/test/java/log4j.properties | 8 - .../src/test/resources/.svnignore | 0 .../src/test/resources/log4j2-test.xml | 15 ++ .../src/test/resources/log4j.properties | 8 - .../src/test/resources/log4j2-test.xml | 15 ++ .../src/test/resources/log4j.properties | 8 - .../src/test/resources/log4j2-test.xml | 15 ++ spring-integration-redis/si-redis.conf | 5 - ...ayerHandlerRescheduleIntegrationTests.java | 11 +- .../redis/util/RedisLockRegistryTests.java | 7 +- .../src/test/resources/log4j.properties | 9 - .../src/test/resources/log4j2-test.xml | 16 ++ .../src/test/resources/log4j.properties | 8 - .../src/test/resources/log4j2-test.xml | 15 ++ .../src/test/resources/log4j.xml | 29 --- .../src/test/resources/log4j2-test.xml | 16 ++ .../src/test/resources/log4j.properties | 8 - .../src/test/resources/log4j2-test.xml | 15 ++ .../src/test/resources/log4j.properties | 9 - .../src/test/resources/log4j2-test.xml | 16 ++ .../client/StompServerIntegrationTests.java | 21 +- ...annelAdapterWebSocketIntegrationTests.java | 18 +- ...ssageHandlerWebSocketIntegrationTests.java | 19 +- .../src/test/resources/log4j.properties | 9 - .../src/test/resources/log4j2-test.xml | 16 ++ .../src/test/resources/log4j.properties | 7 - .../src/test/resources/log4j2-test.xml | 15 ++ .../src/test/resources/log4j.properties | 8 - .../src/test/resources/log4j2-test.xml | 15 ++ .../test/rule/Log4j2LevelAdjuster.java | 216 ++++++++++++++++++ .../test/rule/Log4jLevelAdjuster.java | 10 +- .../test/support/LogAdjustingTestSupport.java | 6 +- .../src/test/resources/log4j.properties | 7 - .../src/test/resources/log4j2-test.xml | 14 ++ .../src/test/resources/log4j.properties | 8 - .../src/test/resources/log4j2-test.xml | 15 ++ ...hReceivingMessageSourceWithRedisTests.java | 7 +- .../src/test/resources/log4j.properties | 8 - .../src/test/resources/log4j2-test.xml | 15 ++ .../src/test/resources/log4j.properties | 9 - .../src/test/resources/log4j2-test.xml | 16 ++ .../src/test/resources/log4j.properties | 8 - .../src/test/resources/log4j2-test.xml | 15 ++ .../src/test/resources/log4j.properties | 8 - .../src/test/resources/log4j2-test.xml | 15 ++ .../src/test/java/log4j.properties | 7 - .../src/test/resources/log4j2-test.xml | 15 ++ .../src/test/java/log4j.properties | 8 - .../xmpp/ignore/ConsoleChatTests-context.xml | 2 +- .../ignore/InboundPresenceTests-context.xml | 2 +- .../ignore/OutboundPresenceTests-context.xml | 2 +- .../src/test/resources/log4j2-test.xml | 15 ++ .../test/{java => resources}/test.properties | 0 .../src/test/resources/log4j.properties | 9 - .../src/test/resources/log4j2-test.xml | 16 ++ 94 files changed, 917 insertions(+), 453 deletions(-) delete mode 100644 spring-integration-amqp/src/test/resources/log4j.properties create mode 100644 spring-integration-amqp/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-core/src/test/resources/log4j.properties create mode 100644 spring-integration-core/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-event/src/test/java/log4j.properties create mode 100644 spring-integration-event/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-feed/src/test/java/log4j.properties create mode 100644 spring-integration-feed/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-file/src/test/resources/log4j.properties create mode 100644 spring-integration-file/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-ftp/src/test/resources/log4j.properties create mode 100644 spring-integration-ftp/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-gemfire/src/test/resources/log4j.xml create mode 100644 spring-integration-gemfire/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-groovy/src/test/resources/log4j.properties create mode 100644 spring-integration-groovy/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-http/src/test/resources/log4j.properties create mode 100644 spring-integration-http/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-ip/src/test/resources/log4j.properties create mode 100644 spring-integration-ip/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-jdbc/src/test/resources/log4j.properties create mode 100644 spring-integration-jdbc/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-jms/src/test/resources/log4j.properties create mode 100644 spring-integration-jms/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-jmx/src/test/resources/log4j.properties create mode 100644 spring-integration-jmx/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-jpa/src/test/resources/log4j.properties create mode 100644 spring-integration-jpa/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-mail/src/test/java/log4j.properties delete mode 100644 spring-integration-mail/src/test/resources/.svnignore create mode 100644 spring-integration-mail/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-mongodb/src/test/resources/log4j.properties create mode 100644 spring-integration-mongodb/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-mqtt/src/test/resources/log4j.properties create mode 100644 spring-integration-mqtt/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-redis/si-redis.conf delete mode 100644 spring-integration-redis/src/test/resources/log4j.properties create mode 100644 spring-integration-redis/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-rmi/src/test/resources/log4j.properties create mode 100644 spring-integration-rmi/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-scripting/src/test/resources/log4j.xml create mode 100644 spring-integration-scripting/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-security/src/test/resources/log4j.properties create mode 100644 spring-integration-security/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-sftp/src/test/resources/log4j.properties create mode 100644 spring-integration-sftp/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-stomp/src/test/resources/log4j.properties create mode 100644 spring-integration-stomp/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-stream/src/test/resources/log4j.properties create mode 100644 spring-integration-stream/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-syslog/src/test/resources/log4j.properties create mode 100644 spring-integration-syslog/src/test/resources/log4j2-test.xml create mode 100644 spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4j2LevelAdjuster.java delete mode 100644 spring-integration-test-support/src/test/resources/log4j.properties create mode 100644 spring-integration-test-support/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-test/src/test/resources/log4j.properties create mode 100644 spring-integration-test/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-twitter/src/test/resources/log4j.properties create mode 100644 spring-integration-twitter/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-webflux/src/test/resources/log4j.properties create mode 100644 spring-integration-webflux/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-websocket/src/test/resources/log4j.properties create mode 100644 spring-integration-websocket/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-ws/src/test/resources/log4j.properties create mode 100644 spring-integration-ws/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-xml/src/test/java/log4j.properties create mode 100644 spring-integration-xml/src/test/resources/log4j2-test.xml delete mode 100644 spring-integration-xmpp/src/test/java/log4j.properties create mode 100644 spring-integration-xmpp/src/test/resources/log4j2-test.xml rename spring-integration-xmpp/src/test/{java => resources}/test.properties (100%) delete mode 100644 spring-integration-zookeeper/src/test/resources/log4j.properties create mode 100644 spring-integration-zookeeper/src/test/resources/log4j2-test.xml diff --git a/build.gradle b/build.gradle index f0245690d5f..76fc5408000 100644 --- a/build.gradle +++ b/build.gradle @@ -118,7 +118,7 @@ subprojects { subproject -> junitVersion = '4.12' jythonVersion = '2.5.3' kryoShadedVersion = '3.0.3' - log4jVersion = '1.2.17' + log4jVersion = '2.10.0' mockitoVersion = '2.11.0' mysqlVersion = '6.0.6' pahoMqttClientVersion = '1.2.0' @@ -127,7 +127,6 @@ subprojects { subproject -> reactorVersion = '3.1.2.RELEASE' romeToolsVersion = '1.8.0' servletApiVersion = '4.0.0' - slf4jVersion = "1.7.25" smackVersion = '4.2.2' springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '2.0.1.RELEASE' springDataJpaVersion = '2.0.2.RELEASE' @@ -160,7 +159,8 @@ subprojects { subproject -> testCompile project(":spring-integration-test-support") } - testCompile "org.slf4j:slf4j-log4j12:$slf4jVersion" + testRuntime "org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion" + testRuntime "org.apache.logging.log4j:log4j-jcl:$log4jVersion" } // enable all compiler warnings; individual projects may customize further @@ -275,7 +275,8 @@ project('spring-integration-test-support') { compile "org.springframework:spring-context:$springVersion" compile "org.springframework:spring-messaging:$springVersion" compile "org.springframework:spring-test:$springVersion" - compile ("log4j:log4j:$log4jVersion", optional) + compile ("org.apache.logging.log4j:log4j-core:$log4jVersion" , optional) + compile ('log4j:log4j:1.2.17', optional) } } diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java index 99c03cbf97d..97601888c25 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 the original author or authors. + * Copyright 2016-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,6 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; -import org.apache.log4j.Level; import org.junit.AfterClass; import org.junit.ClassRule; import org.junit.Rule; @@ -59,7 +58,7 @@ import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.support.MessageBuilder; -import org.springframework.integration.test.rule.Log4jLevelAdjuster; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; import org.springframework.messaging.support.ErrorMessage; @@ -78,8 +77,10 @@ public class AsyncAmqpGatewayTests { public static BrokerRunning brokerRunning = BrokerRunning.isRunningWithEmptyQueues("asyncQ1", "asyncRQ1"); @Rule - public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.TRACE, "org.springframework.integration", - "org.springframework.amqp"); + public Log4j2LevelAdjuster adjuster = + Log4j2LevelAdjuster.trace() + .categories("org.springframework.integration", + "org.springframework.amqp"); @AfterClass public static void tearDown() { diff --git a/spring-integration-amqp/src/test/resources/log4j.properties b/spring-integration-amqp/src/test/resources/log4j.properties deleted file mode 100644 index cbcbba8150f..00000000000 --- a/spring-integration-amqp/src/test/resources/log4j.properties +++ /dev/null @@ -1,10 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d %p [%t] [%c] - %m%n - -log4j.category.test=DEBUG -log4j.category.org.springframework=WARN -log4j.category.org.springframework.amqp=WARN -log4j.category.org.springframework.integration.amqp=WARN diff --git a/spring-integration-amqp/src/test/resources/log4j2-test.xml b/spring-integration-amqp/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..6961531500e --- /dev/null +++ b/spring-integration-amqp/src/test/resources/log4j2-test.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollerAdviceTests.java b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollerAdviceTests.java index 275fff3f8c4..24dda6f495c 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollerAdviceTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/endpoint/PollerAdviceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,6 @@ import org.aopalliance.aop.Advice; import org.aopalliance.intercept.Joinpoint; import org.aopalliance.intercept.MethodInterceptor; -import org.apache.log4j.Level; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -67,7 +66,7 @@ import org.springframework.integration.core.MessageSource; import org.springframework.integration.scheduling.PollSkipAdvice; import org.springframework.integration.scheduling.SimplePollSkipStrategy; -import org.springframework.integration.test.rule.Log4jLevelAdjuster; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.integration.test.util.OnlyOnceTrigger; import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.util.CompoundTrigger; @@ -85,6 +84,8 @@ /** * @author Gary Russell + * @author Artem Bilan + * * @since 4.1 * */ @@ -94,7 +95,7 @@ public class PollerAdviceTests { @Rule - public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.TRACE, "org.springframework.integration"); + public Log4j2LevelAdjuster adjuster = Log4j2LevelAdjuster.trace(); @Autowired private MessageChannel control; diff --git a/spring-integration-core/src/test/resources/log4j.properties b/spring-integration-core/src/test/resources/log4j.properties deleted file mode 100644 index c87f9f5b945..00000000000 --- a/spring-integration-core/src/test/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d %p %c{1} [%t] : %m%n - -log4j.category.org.springframework.integration=WARN diff --git a/spring-integration-core/src/test/resources/log4j2-test.xml b/spring-integration-core/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..0e6b0198e3e --- /dev/null +++ b/spring-integration-core/src/test/resources/log4j2-test.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/spring-integration-event/src/test/java/log4j.properties b/spring-integration-event/src/test/java/log4j.properties deleted file mode 100644 index 34495a6fda0..00000000000 --- a/spring-integration-event/src/test/java/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%c{1}: (%t) %m%n - -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.event=INFO diff --git a/spring-integration-event/src/test/resources/log4j2-test.xml b/spring-integration-event/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..94419afcd9c --- /dev/null +++ b/spring-integration-event/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-feed/src/test/java/log4j.properties b/spring-integration-feed/src/test/java/log4j.properties deleted file mode 100644 index 54e2f03a720..00000000000 --- a/spring-integration-feed/src/test/java/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%c{1}: %m%n - -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.feed=WARN diff --git a/spring-integration-feed/src/test/resources/log4j2-test.xml b/spring-integration-feed/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..2802cef0d44 --- /dev/null +++ b/spring-integration-feed/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-file/src/test/resources/log4j.properties b/spring-integration-file/src/test/resources/log4j.properties deleted file mode 100644 index 941cbe4822e..00000000000 --- a/spring-integration-file/src/test/resources/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%c{1}: %m%n - -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.file=WARN diff --git a/spring-integration-file/src/test/resources/log4j2-test.xml b/spring-integration-file/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..3a7cc58bb23 --- /dev/null +++ b/spring-integration-file/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-ftp/src/test/resources/log4j.properties b/spring-integration-ftp/src/test/resources/log4j.properties deleted file mode 100644 index 5405a7cfd33..00000000000 --- a/spring-integration-ftp/src/test/resources/log4j.properties +++ /dev/null @@ -1,9 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n - -log4j.category.org.springframework=WARN -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.file=WARN diff --git a/spring-integration-ftp/src/test/resources/log4j2-test.xml b/spring-integration-ftp/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..7541cd10b70 --- /dev/null +++ b/spring-integration-ftp/src/test/resources/log4j2-test.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/spring-integration-gemfire/src/test/resources/log4j.xml b/spring-integration-gemfire/src/test/resources/log4j.xml deleted file mode 100644 index e871f822167..00000000000 --- a/spring-integration-gemfire/src/test/resources/log4j.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-gemfire/src/test/resources/log4j2-test.xml b/spring-integration-gemfire/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..d56e00716bf --- /dev/null +++ b/spring-integration-gemfire/src/test/resources/log4j2-test.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/spring-integration-groovy/src/test/resources/log4j.properties b/spring-integration-groovy/src/test/resources/log4j.properties deleted file mode 100644 index 538a5c4c9eb..00000000000 --- a/spring-integration-groovy/src/test/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%c{1}: %m%n - -log4j.category.org.springframework.integration=WARN diff --git a/spring-integration-groovy/src/test/resources/log4j2-test.xml b/spring-integration-groovy/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..d2a83887857 --- /dev/null +++ b/spring-integration-groovy/src/test/resources/log4j2-test.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/spring-integration-http/src/test/resources/log4j.properties b/spring-integration-http/src/test/resources/log4j.properties deleted file mode 100644 index 3cf693eac42..00000000000 --- a/spring-integration-http/src/test/resources/log4j.properties +++ /dev/null @@ -1,9 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n - -#log4j.category.org.springframework=DEBUG -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.http=WARN diff --git a/spring-integration-http/src/test/resources/log4j2-test.xml b/spring-integration-http/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..7340a5bb79b --- /dev/null +++ b/spring-integration-http/src/test/resources/log4j2-test.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpOutboundGatewayTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpOutboundGatewayTests.java index accbe3892db..ccbc647b2b5 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpOutboundGatewayTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpOutboundGatewayTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,7 +51,10 @@ import javax.net.ServerSocketFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mockito; @@ -70,7 +73,7 @@ import org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory; import org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory; import org.springframework.integration.support.MessageBuilder; -import org.springframework.integration.test.support.LogAdjustingTestSupport; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.integration.test.support.LongRunningIntegrationTest; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; @@ -80,13 +83,20 @@ /** * @author Gary Russell * @author Artem Bilan + * * @since 2.0 */ -public class TcpOutboundGatewayTests extends LogAdjustingTestSupport { +public class TcpOutboundGatewayTests { + + private static final Log logger = LogFactory.getLog(TcpOutboundGatewayTests.class); @ClassRule public static LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); + @Rule + public Log4j2LevelAdjuster adjuster = Log4j2LevelAdjuster.trace(); + + @Test public void testGoodNetSingle() throws Exception { final CountDownLatch latch = new CountDownLatch(1); diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java index cbc04dbc71b..db7ed2df466 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +44,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.junit.Rule; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -56,7 +57,7 @@ import org.springframework.integration.ip.config.TcpConnectionFactoryFactoryBean; import org.springframework.integration.ip.event.IpIntegrationEvent; import org.springframework.integration.ip.tcp.TcpReceivingChannelAdapter; -import org.springframework.integration.test.support.LogAdjustingTestSupport; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.integration.test.util.TestUtils; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; @@ -64,10 +65,14 @@ /** * @author Gary Russell * @author Artem Bilan + * * @since 3.0 * */ -public class ConnectionFactoryTests extends LogAdjustingTestSupport { +public class ConnectionFactoryTests { + + @Rule + public Log4j2LevelAdjuster adjuster = Log4j2LevelAdjuster.trace(); @Test public void factoryBeanTests() { diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/FailoverClientConnectionFactoryTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/FailoverClientConnectionFactoryTests.java index a7bce7bf53d..7858a52720a 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/FailoverClientConnectionFactoryTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/FailoverClientConnectionFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +41,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import org.apache.log4j.Level; import org.junit.Rule; import org.junit.Test; import org.mockito.Mockito; @@ -56,7 +55,7 @@ import org.springframework.integration.ip.tcp.TcpInboundGateway; import org.springframework.integration.ip.tcp.TcpOutboundGateway; import org.springframework.integration.ip.util.TestingUtilities; -import org.springframework.integration.test.rule.Log4jLevelAdjuster; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.util.SimplePool; import org.springframework.messaging.Message; @@ -66,6 +65,8 @@ /** * @author Gary Russell + * @author Artem Bilan + * * @since 2.2 * */ @@ -85,8 +86,10 @@ public void publishEvent(Object event) { }; @Rule - public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.TRACE, - "org.springframework.integration.ip.tcp", "org.springframework.integration.util.SimplePool"); + public Log4j2LevelAdjuster adjuster = + Log4j2LevelAdjuster.trace() + .classes(SimplePool.class) + .categories("org.springframework.integration.ip.tcp"); @Test public void testFailoverGood() throws Exception { @@ -227,7 +230,8 @@ public void testOkAgainAfterCompleteFailure() throws Exception { failoverFactory.getConnection().send(message); fail("ExpectedFailure"); } - catch (IOException e) { } + catch (IOException e) { + } failoverFactory.getConnection().send(message); Mockito.verify(conn2).send(message); Mockito.verify(conn1, times(3)).send(message); @@ -572,7 +576,7 @@ private Holder setupAndStartServers(AbstractServerConnectionFactory server1, gateway2.start(); TestingUtilities.waitListening(server1, null); TestingUtilities.waitListening(server2, null); - Holder holder = new Holder(); + Holder holder = new Holder(); holder.exec = exec; holder.connectionId = connectionId; holder.server1 = server1; diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java index 4240673df06..cbeffd04a2e 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,7 +64,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.log4j.Level; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; @@ -81,7 +80,7 @@ import org.springframework.integration.ip.util.TestingUtilities; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.support.converter.MapMessageConverter; -import org.springframework.integration.test.rule.Log4jLevelAdjuster; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.util.CompositeExecutor; import org.springframework.messaging.Message; @@ -93,6 +92,8 @@ /** * @author Gary Russell * @author John Anderson + * @author Artem Bilan + * * @since 2.0 * */ @@ -101,8 +102,9 @@ public class TcpNioConnectionTests { private final static Log logger = LogFactory.getLog(TcpNioConnectionTests.class); @Rule - public final Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.TRACE, - "org.springframework.integration.ip.tcp"); + public Log4j2LevelAdjuster adjuster = + Log4j2LevelAdjuster.trace() + .categories("org.springframework.integration.ip.tcp"); @Rule public TestName testName = new TestName(); diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/DatagramPacketMulticastSendingHandlerTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/DatagramPacketMulticastSendingHandlerTests.java index 2568b4a3def..ca80f104130 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/DatagramPacketMulticastSendingHandlerTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/DatagramPacketMulticastSendingHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,20 +31,19 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.commons.logging.LogFactory; -import org.apache.log4j.Level; import org.junit.Rule; import org.junit.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.integration.ip.IpHeaders; import org.springframework.integration.support.MessageBuilder; -import org.springframework.integration.test.rule.Log4jLevelAdjuster; import org.springframework.messaging.Message; /** * @author Mark Fisher * @author Gary Russell + * @author Artem Bilan + * * @since 2.0 */ public class DatagramPacketMulticastSendingHandlerTests { @@ -52,9 +51,6 @@ public class DatagramPacketMulticastSendingHandlerTests { @Rule public MulticastRule multicastRule = new MulticastRule(); - @Rule - public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.DEBUG, "org.springframework.integration"); - @Test public void verifySendMulticast() throws Exception { MulticastSocket socket; @@ -78,8 +74,6 @@ public void verifySendMulticast() throws Exception { InetAddress group = InetAddress.getByName(multicastAddress); socket1.joinGroup(group); listening.countDown(); - LogFactory.getLog(getClass()) - .debug(Thread.currentThread().getName() + " waiting for packet"); socket1.receive(receivedPacket); socket1.close(); byte[] src = receivedPacket.getData(); @@ -88,8 +82,6 @@ public void verifySendMulticast() throws Exception { byte[] dest = new byte[length]; System.arraycopy(src, offset, dest, 0, length); assertEquals(payload, new String(dest)); - LogFactory.getLog(getClass()) - .debug(Thread.currentThread().getName() + " received packet"); received.countDown(); } catch (Exception e) { @@ -140,7 +132,6 @@ public void verifySendMulticastWithAcks() throws Exception { socket1.joinGroup(group); listening.countDown(); assertTrue(ackListening.await(10, TimeUnit.SECONDS)); - LogFactory.getLog(getClass()).debug(Thread.currentThread().getName() + " waiting for packet"); socket1.receive(receivedPacket); socket1.close(); byte[] src = receivedPacket.getData(); @@ -149,7 +140,6 @@ public void verifySendMulticastWithAcks() throws Exception { byte[] dest = new byte[6]; System.arraycopy(src, offset + length - 6, dest, 0, 6); assertEquals(payload, new String(dest)); - LogFactory.getLog(getClass()).debug(Thread.currentThread().getName() + " received packet"); DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper(); mapper.setAcknowledge(true); mapper.setLengthCheck(true); @@ -157,11 +147,9 @@ public void verifySendMulticastWithAcks() throws Exception { Object id = message.getHeaders().get(IpHeaders.ACK_ID); byte[] ack = id.toString().getBytes(); DatagramPacket ackPack = new DatagramPacket(ack, ack.length, - new InetSocketAddress(multicastRule.getNic(), ackPort.get())); + new InetSocketAddress(multicastRule.getNic(), ackPort.get())); DatagramSocket out = new DatagramSocket(); out.send(ackPack); - LogFactory.getLog(getClass()).debug(Thread.currentThread().getName() + " sent ack to " - + ackPack.getSocketAddress()); out.close(); ackSent.countDown(); socket1.close(); @@ -176,7 +164,7 @@ public void verifySendMulticastWithAcks() throws Exception { executor.execute(catcher); assertTrue(listening.await(10000, TimeUnit.MILLISECONDS)); MulticastSendingMessageHandler handler = - new MulticastSendingMessageHandler(multicastAddress, testPort, true, true, "localhost", 0, 10000); + new MulticastSendingMessageHandler(multicastAddress, testPort, true, true, "localhost", 0, 10000); handler.setLocalAddress(this.multicastRule.getNic()); handler.setMinAcksForSuccess(2); handler.setBeanFactory(mock(BeanFactory.class)); diff --git a/spring-integration-ip/src/test/resources/log4j.properties b/spring-integration-ip/src/test/resources/log4j.properties deleted file mode 100644 index 31e0d7ed7ee..00000000000 --- a/spring-integration-ip/src/test/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d %5p %c{1} [%t] : %m%n - -log4j.category.org.springframework.integration=WARN diff --git a/spring-integration-ip/src/test/resources/log4j2-test.xml b/spring-integration-ip/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..13ed4369dc3 --- /dev/null +++ b/spring-integration-ip/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/leader/JdbcLockRegistryLeaderInitiatorTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/leader/JdbcLockRegistryLeaderInitiatorTests.java index 00c7de9c74f..5ef5a5604e0 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/leader/JdbcLockRegistryLeaderInitiatorTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/leader/JdbcLockRegistryLeaderInitiatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 the original author or authors. + * Copyright 2016-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.apache.log4j.Level; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Rule; @@ -37,7 +36,7 @@ import org.springframework.integration.leader.DefaultCandidate; import org.springframework.integration.leader.event.LeaderEventPublisher; import org.springframework.integration.support.leader.LockRegistryLeaderInitiator; -import org.springframework.integration.test.rule.Log4jLevelAdjuster; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; @@ -54,8 +53,12 @@ public class JdbcLockRegistryLeaderInitiatorTests { public static EmbeddedDatabase dataSource; @Rule - public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.DEBUG, "org.springframework.integration", - "org.springframework.integration.jdbc", "org.springframework.jdbc", "org.apache.derby"); + public Log4j2LevelAdjuster adjuster = + Log4j2LevelAdjuster.trace() + .categories("org.springframework.integration", + "org.springframework.integration.jdbc", + "org.springframework.jdbc", + "org.apache.derby"); @BeforeClass public static void init() { diff --git a/spring-integration-jdbc/src/test/resources/log4j.properties b/spring-integration-jdbc/src/test/resources/log4j.properties deleted file mode 100644 index badf30e5cbc..00000000000 --- a/spring-integration-jdbc/src/test/resources/log4j.properties +++ /dev/null @@ -1,11 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n - -log4j.category.org.springframework.integration=WARN -log4j.category.org.apache.derby=WARN - -log4j.category.org.springframework.jdbc=WARN -log4j.category.org.springframework.integration.jdbc=WARN diff --git a/spring-integration-jdbc/src/test/resources/log4j2-test.xml b/spring-integration-jdbc/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..c062dcc347f --- /dev/null +++ b/spring-integration-jdbc/src/test/resources/log4j2-test.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java index 38a19bbe805..83eace2cf94 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/JmsOutboundGatewayTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,13 +43,14 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.junit.Rule; import org.junit.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.jms.JmsOutboundGateway.ReplyContainerProperties; -import org.springframework.integration.test.support.LogAdjustingTestSupport; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.util.ErrorHandlingTaskExecutor; import org.springframework.jms.JmsException; @@ -63,15 +64,17 @@ /** * @author Gary Russell * @author Artem Bilan + * * @since 2.2.4 */ -public class JmsOutboundGatewayTests extends LogAdjustingTestSupport { +public class JmsOutboundGatewayTests { private final Log logger = LogFactory.getLog(this.getClass()); - public JmsOutboundGatewayTests() { - super("org.springframework.integration", "org.springframework.jms", "org.apache"); - } + @Rule + public Log4j2LevelAdjuster adjuster = + Log4j2LevelAdjuster.trace() + .categories("org.springframework.integration", "org.springframework.jms", "org.apache"); @Test public void testContainerBeanNameWhenNoGatewayBeanName() { diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/OutboundGatewayFunctionTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/OutboundGatewayFunctionTests.java index 85dc0421940..409fe6b7b2d 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/OutboundGatewayFunctionTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/OutboundGatewayFunctionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,11 +33,12 @@ import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.command.ActiveMQQueue; +import org.junit.Rule; import org.junit.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.integration.context.IntegrationContextUtils; -import org.springframework.integration.test.support.LogAdjustingTestSupport; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.integration.test.util.TestUtils; import org.springframework.jms.JmsException; import org.springframework.jms.connection.CachingConnectionFactory; @@ -50,10 +51,12 @@ /** * @author Gary Russell + * @author Artem Bilan + * * @since 2.2 * */ -public class OutboundGatewayFunctionTests extends LogAdjustingTestSupport { +public class OutboundGatewayFunctionTests { private static Destination requestQueue1 = new ActiveMQQueue("request1"); @@ -75,6 +78,9 @@ public class OutboundGatewayFunctionTests extends LogAdjustingTestSupport { private static Destination replyQueue7 = new ActiveMQQueue("reply7"); + @Rule + public Log4j2LevelAdjuster adjuster = Log4j2LevelAdjuster.trace(); + @Test public void testContainerWithDest() throws Exception { BeanFactory beanFactory = mock(BeanFactory.class); @@ -82,7 +88,7 @@ public void testContainerWithDest() throws Exception { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.initialize(); when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) - .thenReturn(scheduler); + .thenReturn(scheduler); final JmsOutboundGateway gateway = new JmsOutboundGateway(); gateway.setBeanFactory(beanFactory); ConnectionFactory connectionFactory = getConnectionFactory(); @@ -127,7 +133,7 @@ public void testContainerWithDestNoCorrelation() throws Exception { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.initialize(); when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) - .thenReturn(scheduler); + .thenReturn(scheduler); final JmsOutboundGateway gateway = new JmsOutboundGateway(); gateway.setBeanFactory(beanFactory); gateway.setConnectionFactory(getConnectionFactory()); @@ -173,7 +179,7 @@ public void testContainerWithDestName() throws Exception { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.initialize(); when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) - .thenReturn(scheduler); + .thenReturn(scheduler); final JmsOutboundGateway gateway = new JmsOutboundGateway(); gateway.setBeanFactory(beanFactory); gateway.setConnectionFactory(getConnectionFactory()); @@ -202,7 +208,7 @@ public void testContainerWithDestName() throws Exception { javax.jms.Message request = template.receive(requestQueue3); assertNotNull(request); final javax.jms.Message jmsReply = request; - template.send(request.getJMSReplyTo(), (MessageCreator) session -> jmsReply); + template.send(request.getJMSReplyTo(), session -> jmsReply); assertTrue(latch2.await(10, TimeUnit.SECONDS)); assertNotNull(reply.get()); @@ -217,7 +223,7 @@ public void testContainerWithDestNameNoCorrelation() throws Exception { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.initialize(); when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) - .thenReturn(scheduler); + .thenReturn(scheduler); final JmsOutboundGateway gateway = new JmsOutboundGateway(); gateway.setBeanFactory(beanFactory); gateway.setConnectionFactory(getConnectionFactory()); @@ -226,13 +232,13 @@ public void testContainerWithDestNameNoCorrelation() throws Exception { gateway.setUseReplyContainer(true); gateway.afterPropertiesSet(); gateway.start(); - final AtomicReference reply = new AtomicReference(); + final AtomicReference reply = new AtomicReference<>(); final CountDownLatch latch1 = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1); Executors.newSingleThreadExecutor().execute(() -> { latch1.countDown(); try { - reply.set(gateway.handleRequestMessage(new GenericMessage("foo"))); + reply.set(gateway.handleRequestMessage(new GenericMessage<>("foo"))); } finally { latch2.countDown(); @@ -245,7 +251,7 @@ public void testContainerWithDestNameNoCorrelation() throws Exception { javax.jms.Message request = template.receive(requestQueue4); assertNotNull(request); final javax.jms.Message jmsReply = request; - template.send(request.getJMSReplyTo(), (MessageCreator) session -> { + template.send(request.getJMSReplyTo(), session -> { jmsReply.setJMSCorrelationID(jmsReply.getJMSMessageID()); return jmsReply; }); @@ -263,7 +269,7 @@ public void testContainerWithTemporary() throws Exception { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.initialize(); when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) - .thenReturn(scheduler); + .thenReturn(scheduler); final JmsOutboundGateway gateway = new JmsOutboundGateway(); gateway.setBeanFactory(beanFactory); gateway.setConnectionFactory(getConnectionFactory()); @@ -273,13 +279,13 @@ public void testContainerWithTemporary() throws Exception { gateway.setComponentName("testContainerWithTemporary.gateway"); gateway.afterPropertiesSet(); gateway.start(); - final AtomicReference reply = new AtomicReference(); + final AtomicReference reply = new AtomicReference<>(); final CountDownLatch latch1 = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1); Executors.newSingleThreadExecutor().execute(() -> { latch1.countDown(); try { - reply.set(gateway.handleRequestMessage(new GenericMessage("foo"))); + reply.set(gateway.handleRequestMessage(new GenericMessage<>("foo"))); } finally { latch2.countDown(); @@ -292,7 +298,7 @@ public void testContainerWithTemporary() throws Exception { javax.jms.Message request = template.receive(requestQueue5); assertNotNull(request); final javax.jms.Message jmsReply = request; - template.send(request.getJMSReplyTo(), (MessageCreator) session -> jmsReply); + template.send(request.getJMSReplyTo(), session -> jmsReply); assertTrue(latch2.await(10, TimeUnit.SECONDS)); assertNotNull(reply.get()); @@ -307,7 +313,7 @@ public void testContainerWithTemporaryNoCorrelation() throws Exception { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.initialize(); when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) - .thenReturn(scheduler); + .thenReturn(scheduler); final JmsOutboundGateway gateway = new JmsOutboundGateway(); gateway.setBeanFactory(beanFactory); gateway.setConnectionFactory(getConnectionFactory()); @@ -315,13 +321,13 @@ public void testContainerWithTemporaryNoCorrelation() throws Exception { gateway.setUseReplyContainer(true); gateway.afterPropertiesSet(); gateway.start(); - final AtomicReference reply = new AtomicReference(); + final AtomicReference reply = new AtomicReference<>(); final CountDownLatch latch1 = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1); Executors.newSingleThreadExecutor().execute(() -> { latch1.countDown(); try { - reply.set(gateway.handleRequestMessage(new GenericMessage("foo"))); + reply.set(gateway.handleRequestMessage(new GenericMessage<>("foo"))); } finally { latch2.countDown(); @@ -334,7 +340,7 @@ public void testContainerWithTemporaryNoCorrelation() throws Exception { javax.jms.Message request = template.receive(requestQueue6); assertNotNull(request); final javax.jms.Message jmsReply = request; - template.send(request.getJMSReplyTo(), (MessageCreator) session -> { + template.send(request.getJMSReplyTo(), session -> { jmsReply.setJMSCorrelationID(jmsReply.getJMSMessageID()); return jmsReply; }); @@ -352,7 +358,7 @@ public void testLazyContainerWithDest() throws Exception { ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.initialize(); when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) - .thenReturn(scheduler); + .thenReturn(scheduler); final JmsOutboundGateway gateway = new JmsOutboundGateway(); gateway.setBeanFactory(beanFactory); gateway.setConnectionFactory(getConnectionFactory()); @@ -373,7 +379,7 @@ public void testLazyContainerWithDest() throws Exception { receiveAndSend(template); }); - assertNotNull(gateway.handleRequestMessage(new GenericMessage("foo"))); + assertNotNull(gateway.handleRequestMessage(new GenericMessage<>("foo"))); DefaultMessageListenerContainer container = TestUtils.getPropertyValue(gateway, "replyContainer", DefaultMessageListenerContainer.class); int n = 0; @@ -381,7 +387,7 @@ public void testLazyContainerWithDest() throws Exception { Thread.sleep(100); } assertFalse(container.isRunning()); - assertNotNull(gateway.handleRequestMessage(new GenericMessage("foo"))); + assertNotNull(gateway.handleRequestMessage(new GenericMessage<>("foo"))); assertTrue(container.isRunning()); gateway.stop(); @@ -393,7 +399,7 @@ private void receiveAndSend(JmsTemplate template) { javax.jms.Message request = template.receive(requestQueue7); final javax.jms.Message jmsReply = request; try { - template.send(request.getJMSReplyTo(), (MessageCreator) session -> jmsReply); + template.send(request.getJMSReplyTo(), session -> jmsReply); } catch (JmsException | JMSException e) { } diff --git a/spring-integration-jms/src/test/resources/log4j.properties b/spring-integration-jms/src/test/resources/log4j.properties deleted file mode 100644 index 4eb3e380a25..00000000000 --- a/spring-integration-jms/src/test/resources/log4j.properties +++ /dev/null @@ -1,11 +0,0 @@ -log4j.rootCategory=ERROR, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n - - -log4j.category.org.springframework=ERROR -log4j.category.org.springframework.integration=ERROR -log4j.category.org.springframework.integration.jms.request_reply=INFO -log4j.category.si.jmsgateway.debug=DEBUG diff --git a/spring-integration-jms/src/test/resources/log4j2-test.xml b/spring-integration-jms/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..c68405e4cb8 --- /dev/null +++ b/spring-integration-jms/src/test/resources/log4j2-test.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/spring-integration-jmx/src/test/resources/log4j.properties b/spring-integration-jmx/src/test/resources/log4j.properties deleted file mode 100644 index 71c73a07f2d..00000000000 --- a/spring-integration-jmx/src/test/resources/log4j.properties +++ /dev/null @@ -1,11 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n - - -log4j.category.org.springframework=WARN -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.jmx=WARN -log4j.category.org.springframework.integration.monitor=WARN diff --git a/spring-integration-jmx/src/test/resources/log4j2-test.xml b/spring-integration-jmx/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..52b8bd003e8 --- /dev/null +++ b/spring-integration-jmx/src/test/resources/log4j2-test.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/spring-integration-jpa/src/test/resources/log4j.properties b/spring-integration-jpa/src/test/resources/log4j.properties deleted file mode 100644 index 1fb66a84696..00000000000 --- a/spring-integration-jpa/src/test/resources/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n - -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.jpa=INFO \ No newline at end of file diff --git a/spring-integration-jpa/src/test/resources/log4j2-test.xml b/spring-integration-jpa/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..e164b537650 --- /dev/null +++ b/spring-integration-jpa/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-mail/src/test/java/log4j.properties b/spring-integration-mail/src/test/java/log4j.properties deleted file mode 100644 index e1274e6bd6b..00000000000 --- a/spring-integration-mail/src/test/java/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%c{1}: %m%n - -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.mail=WARN diff --git a/spring-integration-mail/src/test/resources/.svnignore b/spring-integration-mail/src/test/resources/.svnignore deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/spring-integration-mail/src/test/resources/log4j2-test.xml b/spring-integration-mail/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..c07e0edf611 --- /dev/null +++ b/spring-integration-mail/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-mongodb/src/test/resources/log4j.properties b/spring-integration-mongodb/src/test/resources/log4j.properties deleted file mode 100644 index 91e7970a403..00000000000 --- a/spring-integration-mongodb/src/test/resources/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n - -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.mongodb=INFO diff --git a/spring-integration-mongodb/src/test/resources/log4j2-test.xml b/spring-integration-mongodb/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..21d30a22915 --- /dev/null +++ b/spring-integration-mongodb/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-mqtt/src/test/resources/log4j.properties b/spring-integration-mqtt/src/test/resources/log4j.properties deleted file mode 100644 index 69750fc24e3..00000000000 --- a/spring-integration-mqtt/src/test/resources/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n - -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.mqtt=INFO diff --git a/spring-integration-mqtt/src/test/resources/log4j2-test.xml b/spring-integration-mqtt/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..f5fe82aa984 --- /dev/null +++ b/spring-integration-mqtt/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-redis/si-redis.conf b/spring-integration-redis/si-redis.conf deleted file mode 100644 index b2bd5a7d37b..00000000000 --- a/spring-integration-redis/si-redis.conf +++ /dev/null @@ -1,5 +0,0 @@ -# minimal config -#daemonize yes -bind 127.0.0.1 -loglevel debug -port 7379 \ No newline at end of file diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/store/DelayerHandlerRescheduleIntegrationTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/store/DelayerHandlerRescheduleIntegrationTests.java index f7f1cdc2338..59e8669fe98 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/store/DelayerHandlerRescheduleIntegrationTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/store/DelayerHandlerRescheduleIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; -import org.apache.log4j.Level; import org.junit.Rule; import org.junit.Test; @@ -38,7 +37,7 @@ import org.springframework.integration.store.MessageGroup; import org.springframework.integration.store.MessageGroupStore; import org.springframework.integration.support.MessageBuilder; -import org.springframework.integration.test.rule.Log4jLevelAdjuster; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.integration.test.support.LongRunningIntegrationTest; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; @@ -59,8 +58,10 @@ public class DelayerHandlerRescheduleIntegrationTests extends RedisAvailableTest public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); @Rule - public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.DEBUG, "org.springframework.integration", - "org.springframework.data.redis"); + public Log4j2LevelAdjuster adjuster = + Log4j2LevelAdjuster.trace() + .categories("org.springframework.integration", + "org.springframework.data.redis"); @Test @RedisAvailable diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/util/RedisLockRegistryTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/util/RedisLockRegistryTests.java index ef3df49eef3..6c79c523253 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/util/RedisLockRegistryTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/util/RedisLockRegistryTests.java @@ -37,7 +37,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.log4j.Level; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -48,7 +47,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.integration.redis.rules.RedisAvailable; import org.springframework.integration.redis.rules.RedisAvailableTests; -import org.springframework.integration.test.rule.Log4jLevelAdjuster; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.integration.test.util.TestUtils; /** @@ -68,7 +67,9 @@ public class RedisLockRegistryTests extends RedisAvailableTests { private final String registryKey2 = UUID.randomUUID().toString(); @Rule - public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.TRACE, "org.springframework.integration.redis"); + public Log4j2LevelAdjuster adjuster = + Log4j2LevelAdjuster.trace() + .categories("org.springframework.data.redis"); @Rule public ExpectedException thrown = ExpectedException.none(); diff --git a/spring-integration-redis/src/test/resources/log4j.properties b/spring-integration-redis/src/test/resources/log4j.properties deleted file mode 100644 index b29843860e2..00000000000 --- a/spring-integration-redis/src/test/resources/log4j.properties +++ /dev/null @@ -1,9 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d %5p %t [%c] - <%m>%n - -log4j.category.org.springframework.data.redis=WARN -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.redis=INFO diff --git a/spring-integration-redis/src/test/resources/log4j2-test.xml b/spring-integration-redis/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..6d8371fa2e4 --- /dev/null +++ b/spring-integration-redis/src/test/resources/log4j2-test.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/spring-integration-rmi/src/test/resources/log4j.properties b/spring-integration-rmi/src/test/resources/log4j.properties deleted file mode 100644 index b603c7d86ea..00000000000 --- a/spring-integration-rmi/src/test/resources/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n - -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.rmi=WARN diff --git a/spring-integration-rmi/src/test/resources/log4j2-test.xml b/spring-integration-rmi/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..842e2da2355 --- /dev/null +++ b/spring-integration-rmi/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-scripting/src/test/resources/log4j.xml b/spring-integration-scripting/src/test/resources/log4j.xml deleted file mode 100644 index 41d1078621b..00000000000 --- a/spring-integration-scripting/src/test/resources/log4j.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-integration-scripting/src/test/resources/log4j2-test.xml b/spring-integration-scripting/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..8481f076361 --- /dev/null +++ b/spring-integration-scripting/src/test/resources/log4j2-test.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/spring-integration-security/src/test/resources/log4j.properties b/spring-integration-security/src/test/resources/log4j.properties deleted file mode 100644 index 84f5f1959d3..00000000000 --- a/spring-integration-security/src/test/resources/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d %5p %c{1} [%t] : %m%n - -log4j.category.org.springframework.integration.security=WARN -log4j.category.org.springframework.integration=WARN diff --git a/spring-integration-security/src/test/resources/log4j2-test.xml b/spring-integration-security/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..1576469df44 --- /dev/null +++ b/spring-integration-security/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-sftp/src/test/resources/log4j.properties b/spring-integration-sftp/src/test/resources/log4j.properties deleted file mode 100644 index e3f87b00ee2..00000000000 --- a/spring-integration-sftp/src/test/resources/log4j.properties +++ /dev/null @@ -1,9 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n - -log4j.category.com.jcraft.jsch=WARN -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.sftp=WARN diff --git a/spring-integration-sftp/src/test/resources/log4j2-test.xml b/spring-integration-sftp/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..57ea6a43a36 --- /dev/null +++ b/spring-integration-sftp/src/test/resources/log4j2-test.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/client/StompServerIntegrationTests.java b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/client/StompServerIntegrationTests.java index d098a34a73e..768a8ec3a83 100644 --- a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/client/StompServerIntegrationTests.java +++ b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/client/StompServerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ import org.apache.activemq.broker.BrokerService; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; import org.springframework.context.ApplicationEvent; @@ -51,7 +52,7 @@ import org.springframework.integration.stomp.inbound.StompInboundChannelAdapter; import org.springframework.integration.stomp.outbound.StompMessageHandler; import org.springframework.integration.support.converter.PassThruMessageConverter; -import org.springframework.integration.test.support.LogAdjustingTestSupport; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageDeliveryException; @@ -66,19 +67,23 @@ /** * @author Artem Bilan * @author Gary Russell + * * @since 4.2 */ -public class StompServerIntegrationTests extends LogAdjustingTestSupport { +public class StompServerIntegrationTests { private static BrokerService activeMQBroker; private static ReactorNettyTcpStompClient stompClient; - - public StompServerIntegrationTests() { - super("org.springframework", "org.springframework.integration.stomp", - "org.apache.activemq.broker", "reactor.ipc", "io.netty"); - } + @Rule + public Log4j2LevelAdjuster adjuster = + Log4j2LevelAdjuster.trace() + .categories("org.springframework", + "org.springframework.integration.stomp", + "org.apache.activemq.broker", + "reactor.ipc", + "io.netty"); @BeforeClass public static void setup() throws Exception { diff --git a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java index 2d1c7c3e588..e7e5586442a 100644 --- a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java +++ b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapterWebSocketIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import java.util.Collections; import java.util.Map; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,7 +51,7 @@ import org.springframework.integration.stomp.event.StompIntegrationEvent; import org.springframework.integration.stomp.event.StompReceiptEvent; import org.springframework.integration.stomp.event.StompSessionConnectedEvent; -import org.springframework.integration.test.support.LogAdjustingTestSupport; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.integration.websocket.TomcatWebSocketTestServer; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandlingException; @@ -90,12 +91,18 @@ /** * @author Artem Bilan + * * @since 4.2 */ @ContextConfiguration(classes = StompInboundChannelAdapterWebSocketIntegrationTests.ContextConfiguration.class) @RunWith(SpringJUnit4ClassRunner.class) @DirtiesContext -public class StompInboundChannelAdapterWebSocketIntegrationTests extends LogAdjustingTestSupport { +public class StompInboundChannelAdapterWebSocketIntegrationTests { + + @Rule + public Log4j2LevelAdjuster adjuster = + Log4j2LevelAdjuster.trace() + .categories("org.springframework", "org.springframework.integration.stomp"); @Value("#{server.serverContext}") private ConfigurableApplicationContext serverContext; @@ -115,9 +122,6 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests extends LogAdju @Autowired private StompInboundChannelAdapter stompInboundChannelAdapter; - public StompInboundChannelAdapterWebSocketIntegrationTests() { - super("org.springframework", "org.springframework.integration.stomp"); - } @Test public void testWebSocketStompClient() throws Exception { @@ -274,7 +278,7 @@ public StompSessionManager stompSessionManager(WebSocketStompClient stompClient) handshakeHeaders.setOrigin("http://foo.com"); webSocketStompSessionManager.setHandshakeHeaders(handshakeHeaders); StompHeaders stompHeaders = new StompHeaders(); - stompHeaders.setHeartbeat(new long[] {10000, 10000}); + stompHeaders.setHeartbeat(new long[] { 10000, 10000 }); webSocketStompSessionManager.setConnectHeaders(stompHeaders); return webSocketStompSessionManager; } diff --git a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/outbound/StompMessageHandlerWebSocketIntegrationTests.java b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/outbound/StompMessageHandlerWebSocketIntegrationTests.java index bb293c869b1..674ac206d62 100644 --- a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/outbound/StompMessageHandlerWebSocketIntegrationTests.java +++ b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/outbound/StompMessageHandlerWebSocketIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2017 the original author or authors. + * Copyright 2015-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.junit.ClassRule; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -55,7 +56,7 @@ import org.springframework.integration.stomp.event.StompIntegrationEvent; import org.springframework.integration.stomp.event.StompReceiptEvent; import org.springframework.integration.stomp.event.StompSessionConnectedEvent; -import org.springframework.integration.test.support.LogAdjustingTestSupport; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.integration.test.support.LongRunningIntegrationTest; import org.springframework.integration.websocket.TomcatWebSocketTestServer; import org.springframework.messaging.Message; @@ -97,11 +98,16 @@ @ContextConfiguration(classes = StompMessageHandlerWebSocketIntegrationTests.ContextConfiguration.class) @RunWith(SpringJUnit4ClassRunner.class) @DirtiesContext -public class StompMessageHandlerWebSocketIntegrationTests extends LogAdjustingTestSupport { +public class StompMessageHandlerWebSocketIntegrationTests { @ClassRule public static LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); + @Rule + public Log4j2LevelAdjuster adjuster = + Log4j2LevelAdjuster.trace() + .categories("org.springframework", "org.springframework.integration.stomp"); + @Value("#{server.serverContext}") private ApplicationContext serverContext; @@ -113,10 +119,6 @@ public class StompMessageHandlerWebSocketIntegrationTests extends LogAdjustingTe @Qualifier("stompEvents") private PollableChannel stompEvents; - public StompMessageHandlerWebSocketIntegrationTests() { - super("org.springframework", "org.springframework.integration.stomp"); - } - @Test public void testStompMessageHandler() throws InterruptedException { StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND); @@ -225,10 +227,11 @@ public ApplicationListener stompEventListener() { // WebSocket Server part - @Target({ElementType.TYPE}) + @Target({ ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) @Controller private @interface IntegrationTestController { + } @IntegrationTestController diff --git a/spring-integration-stomp/src/test/resources/log4j.properties b/spring-integration-stomp/src/test/resources/log4j.properties deleted file mode 100644 index 87e6cad7728..00000000000 --- a/spring-integration-stomp/src/test/resources/log4j.properties +++ /dev/null @@ -1,9 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n - -#log4j.category.org.springframework=DEBUG -#log4j.category.org.springframework.integration=DEBUG -log4j.category.org.springframework.integration.stomp=WARN diff --git a/spring-integration-stomp/src/test/resources/log4j2-test.xml b/spring-integration-stomp/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..3418d5b02fc --- /dev/null +++ b/spring-integration-stomp/src/test/resources/log4j2-test.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/spring-integration-stream/src/test/resources/log4j.properties b/spring-integration-stream/src/test/resources/log4j.properties deleted file mode 100644 index f0a738122e0..00000000000 --- a/spring-integration-stream/src/test/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%c{1}: %m%n - -log4j.category.org.springframework.integration.stream=DEBUG diff --git a/spring-integration-stream/src/test/resources/log4j2-test.xml b/spring-integration-stream/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..2fc917117e8 --- /dev/null +++ b/spring-integration-stream/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-syslog/src/test/resources/log4j.properties b/spring-integration-syslog/src/test/resources/log4j.properties deleted file mode 100644 index 7eadf67086d..00000000000 --- a/spring-integration-syslog/src/test/resources/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n - -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.syslog=WARN diff --git a/spring-integration-syslog/src/test/resources/log4j2-test.xml b/spring-integration-syslog/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..c2bb0ecab10 --- /dev/null +++ b/spring-integration-syslog/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4j2LevelAdjuster.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4j2LevelAdjuster.java new file mode 100644 index 00000000000..06b84ca4d87 --- /dev/null +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4j2LevelAdjuster.java @@ -0,0 +1,216 @@ +/* + * Copyright 2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.test.rule; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.LoggerConfig; +import org.junit.rules.MethodRule; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.Statement; + +import org.springframework.util.Assert; +import org.springframework.util.ObjectUtils; + +/** + * A JUnit method {@link org.junit.Rule} that changes the Log4J 2 logger level for a set of classes + * or packages while a test method is running. Useful for performance or scalability tests + * where we don't want to generate a large log in a tight inner loop, or + * enabling debug logging for a test case. + * + * @author Artem Bilan + * + * @since 5.0.1 + * + */ +public class Log4j2LevelAdjuster implements MethodRule { + + private static final Log logger = LogFactory.getLog(Log4j2LevelAdjuster.class); + + private final Class[] classes; + + private final Level level; + + private final String[] categories; + + private Log4j2LevelAdjuster(Level level) { + this(level, null, new String[] { "org.springframework.integration" }); + } + + private Log4j2LevelAdjuster(Level level, Class[] classes, String[] categories) { + Assert.notNull(level, "'level' must be null"); + this.level = level; + this.classes = classes != null ? classes : new Class[0]; + + Stream categoryStream = Stream.of(getClass().getPackage().getName()); + + if (!ObjectUtils.isEmpty(categories)) { + categoryStream = Stream.concat(Arrays.stream(categories), categoryStream); + } + + this.categories = categoryStream.toArray(String[]::new); + } + + @Override + public Statement apply(final Statement base, final FrameworkMethod method, Object target) { + return new Statement() { + + @Override + public void evaluate() throws Throwable { + LoggerContext ctx = (LoggerContext) LogManager.getContext(false); + Configuration config = ctx.getConfiguration(); + + Map, Level> classLevels = new HashMap<>(); + for (Class cls : Log4j2LevelAdjuster.this.classes) { + String className = cls.getName(); + LoggerConfig loggerConfig = config.getLoggerConfig(className); + LoggerConfig specificConfig = loggerConfig; + + // We need a specific configuration for this logger, + // otherwise we would change the level of all other loggers + // having the original configuration as parent as well + + if (!loggerConfig.getName().equals(className)) { + specificConfig = new LoggerConfig(className, Log4j2LevelAdjuster.this.level, true); + specificConfig.setParent(loggerConfig); + config.addLogger(className, specificConfig); + } + + classLevels.put(cls, specificConfig.getLevel()); + specificConfig.setLevel(Log4j2LevelAdjuster.this.level); + } + + Map categoryLevels = new HashMap<>(); + for (String category : Log4j2LevelAdjuster.this.categories) { + LoggerConfig loggerConfig = config.getLoggerConfig(category); + LoggerConfig specificConfig = loggerConfig; + + // We need a specific configuration for this logger, + // otherwise we would change the level of all other loggers + // having the original configuration as parent as well + + if (!loggerConfig.getName().equals(category)) { + specificConfig = new LoggerConfig(category, Log4j2LevelAdjuster.this.level, true); + specificConfig.setParent(loggerConfig); + config.addLogger(category, specificConfig); + } + + categoryLevels.put(category, specificConfig.getLevel()); + specificConfig.setLevel(Log4j2LevelAdjuster.this.level); + } + + ctx.updateLoggers(); + + logger.debug("++++++++++++++++++++++++++++ " + + "Overridden log level setting for: " + Arrays.toString(Log4j2LevelAdjuster.this.classes) + + " and " + Arrays.toString(Log4j2LevelAdjuster.this.categories) + + " for test " + method.getName()); + + try { + base.evaluate(); + } + finally { + logger.debug("++++++++++++++++++++++++++++ " + + "Restoring log level setting for: " + Arrays.toString(Log4j2LevelAdjuster.this.classes) + + " and " + Arrays.toString(Log4j2LevelAdjuster.this.categories) + + " for test " + method.getName()); + + for (Class cls : Log4j2LevelAdjuster.this.classes) { + LoggerConfig loggerConfig = config.getLoggerConfig(cls.getName()); + loggerConfig.setLevel(classLevels.get(cls)); + } + + for (String category : Log4j2LevelAdjuster.this.categories) { + LoggerConfig loggerConfig = config.getLoggerConfig(category); + loggerConfig.setLevel(categoryLevels.get(category)); + } + + ctx.updateLoggers(); + } + } + + }; + } + + /** + * Specify the classes for logging level adjusting configured before. + * A new copy Log4j2LevelAdjuster instance is produced by this method. + * The provided classes parameter overrides existing value in the {@link #classes}. + * @param classes the classes to use for logging level adjusting + * @return a Log4j2LevelAdjuster copy with the provided classes + */ + public Log4j2LevelAdjuster classes(Class... classes) { + return new Log4j2LevelAdjuster(this.level, classes, this.categories); + } + + /** + * Specify the categories for logging level adjusting configured before. + * A new copy Log4j2LevelAdjuster instance is produced by this method. + * The provided categories parameter overrides existing value in the {@link #categories}. + * @param categories the categories to use for logging level adjusting + * @return a Log4j2LevelAdjuster copy with the provided categories + */ + public Log4j2LevelAdjuster categories(String... categories) { + return new Log4j2LevelAdjuster(this.level, this.classes, categories); + } + + /** + * The factory to produce Log4j2LevelAdjuster instances for {@link Level#TRACE} logging + * with the {@code org.springframework.integration} as default category. + * @return the Log4j2LevelAdjuster instance + */ + public static Log4j2LevelAdjuster trace() { + return level(Level.TRACE); + } + + /** + * The factory to produce Log4j2LevelAdjuster instances for {@link Level#DEBUG} logging + * with the {@code org.springframework.integration} as default category. + * @return the Log4j2LevelAdjuster instance + */ + public static Log4j2LevelAdjuster debug() { + return level(Level.DEBUG); + } + + /** + * The factory to produce Log4j2LevelAdjuster instances for {@link Level#INFO} logging + * with the {@code org.springframework.integration} as default category. + * @return the Log4j2LevelAdjuster instance + */ + public static Log4j2LevelAdjuster info() { + return level(Level.INFO); + } + + /** + * The factory to produce Log4j2LevelAdjuster instances for arbitrary logging {@link Level} + * with the {@code org.springframework.integration} as default category. + * @return the Log4j2LevelAdjuster instance + */ + public static Log4j2LevelAdjuster level(Level level) { + return new Log4j2LevelAdjuster(level); + } + +} diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4jLevelAdjuster.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4jLevelAdjuster.java index ac7f2b7eb8f..11c30ed8a47 100644 --- a/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4jLevelAdjuster.java +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4jLevelAdjuster.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 the original author or authors. + * Copyright 2015-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,10 +41,16 @@ * @author Dave Syer * @author Gary Russell * + * @deprecated since 5.0.1 in favor of {@link Log4j2LevelAdjuster}. + * Will be removed in 5.1. + * */ +@Deprecated +@SuppressWarnings("deprecation") public class Log4jLevelAdjuster implements MethodRule { - private static final Log logger = LogFactory.getLog(Log4jLevelAdjuster.class); + private static final Log logger = + LogFactory.getLog(org.springframework.integration.test.rule.Log4jLevelAdjuster.class); private final Class[] classes; diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/LogAdjustingTestSupport.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/LogAdjustingTestSupport.java index 151d754a8e0..9ba749a9cd0 100644 --- a/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/LogAdjustingTestSupport.java +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/LogAdjustingTestSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 the original author or authors. + * Copyright 2015-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +40,11 @@ * * @since 4.2.2 * + * @deprecated since 5.0.1 in favor of {@link org.springframework.integration.test.rule.Log4j2LevelAdjuster}. + * Will be removed in 5.1. + * */ +@Deprecated public class LogAdjustingTestSupport { /* diff --git a/spring-integration-test-support/src/test/resources/log4j.properties b/spring-integration-test-support/src/test/resources/log4j.properties deleted file mode 100644 index 538a5c4c9eb..00000000000 --- a/spring-integration-test-support/src/test/resources/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%c{1}: %m%n - -log4j.category.org.springframework.integration=WARN diff --git a/spring-integration-test-support/src/test/resources/log4j2-test.xml b/spring-integration-test-support/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..0e6b0198e3e --- /dev/null +++ b/spring-integration-test-support/src/test/resources/log4j2-test.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/spring-integration-test/src/test/resources/log4j.properties b/spring-integration-test/src/test/resources/log4j.properties deleted file mode 100644 index fbc5e406647..00000000000 --- a/spring-integration-test/src/test/resources/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n - -log4j.category.org.springframework.integration.test=INFO -log4j.category.org.springframework.integration=WARN diff --git a/spring-integration-test/src/test/resources/log4j2-test.xml b/spring-integration-test/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..9718b97801a --- /dev/null +++ b/spring-integration-test/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/inbound/SearchReceivingMessageSourceWithRedisTests.java b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/inbound/SearchReceivingMessageSourceWithRedisTests.java index 5a202d359ee..54c31848067 100644 --- a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/inbound/SearchReceivingMessageSourceWithRedisTests.java +++ b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/inbound/SearchReceivingMessageSourceWithRedisTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,6 @@ import java.util.GregorianCalendar; import java.util.List; -import org.apache.log4j.Level; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -46,7 +45,7 @@ import org.springframework.integration.redis.metadata.RedisMetadataStore; import org.springframework.integration.redis.rules.RedisAvailable; import org.springframework.integration.redis.rules.RedisAvailableTests; -import org.springframework.integration.test.rule.Log4jLevelAdjuster; +import org.springframework.integration.test.rule.Log4j2LevelAdjuster; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.PollableChannel; @@ -74,7 +73,7 @@ public class SearchReceivingMessageSourceWithRedisTests extends RedisAvailableTests { @Rule - public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.TRACE, "org.springframework.integration"); + public Log4j2LevelAdjuster adjuster = Log4j2LevelAdjuster.trace(); @Autowired private SourcePollingChannelAdapter twitterSearchAdapter; diff --git a/spring-integration-twitter/src/test/resources/log4j.properties b/spring-integration-twitter/src/test/resources/log4j.properties deleted file mode 100644 index 1ccf72feb15..00000000000 --- a/spring-integration-twitter/src/test/resources/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n - -# log4j.category.org.springframework.integration=DEBUG -log4j.category.org.springframework.integration.twitter=WARN diff --git a/spring-integration-twitter/src/test/resources/log4j2-test.xml b/spring-integration-twitter/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..ff3b0a5bbc2 --- /dev/null +++ b/spring-integration-twitter/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-webflux/src/test/resources/log4j.properties b/spring-integration-webflux/src/test/resources/log4j.properties deleted file mode 100644 index c65576b50fb..00000000000 --- a/spring-integration-webflux/src/test/resources/log4j.properties +++ /dev/null @@ -1,9 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n - -#log4j.category.org.springframework=DEBUG -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.webflux=WARN diff --git a/spring-integration-webflux/src/test/resources/log4j2-test.xml b/spring-integration-webflux/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..e387d0df9e2 --- /dev/null +++ b/spring-integration-webflux/src/test/resources/log4j2-test.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/spring-integration-websocket/src/test/resources/log4j.properties b/spring-integration-websocket/src/test/resources/log4j.properties deleted file mode 100644 index 7ab743934db..00000000000 --- a/spring-integration-websocket/src/test/resources/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n - -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.websocket=WARN diff --git a/spring-integration-websocket/src/test/resources/log4j2-test.xml b/spring-integration-websocket/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..3570db280ff --- /dev/null +++ b/spring-integration-websocket/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-ws/src/test/resources/log4j.properties b/spring-integration-ws/src/test/resources/log4j.properties deleted file mode 100644 index bc97250280e..00000000000 --- a/spring-integration-ws/src/test/resources/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n - -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.ws=WARN diff --git a/spring-integration-ws/src/test/resources/log4j2-test.xml b/spring-integration-ws/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..08c94f9e3eb --- /dev/null +++ b/spring-integration-ws/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-xml/src/test/java/log4j.properties b/spring-integration-xml/src/test/java/log4j.properties deleted file mode 100644 index 538a5c4c9eb..00000000000 --- a/spring-integration-xml/src/test/java/log4j.properties +++ /dev/null @@ -1,7 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%c{1}: %m%n - -log4j.category.org.springframework.integration=WARN diff --git a/spring-integration-xml/src/test/resources/log4j2-test.xml b/spring-integration-xml/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..c79b52d896c --- /dev/null +++ b/spring-integration-xml/src/test/resources/log4j2-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/spring-integration-xmpp/src/test/java/log4j.properties b/spring-integration-xmpp/src/test/java/log4j.properties deleted file mode 100644 index a2234480282..00000000000 --- a/spring-integration-xmpp/src/test/java/log4j.properties +++ /dev/null @@ -1,8 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n - -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.xmpp=INFO diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/ConsoleChatTests-context.xml b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/ConsoleChatTests-context.xml index 4a3c014ce95..a6c2489dbf5 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/ConsoleChatTests-context.xml +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/ignore/ConsoleChatTests-context.xml @@ -11,7 +11,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd"> - + - + - + + + + + + + + + + + + + + + diff --git a/spring-integration-xmpp/src/test/java/test.properties b/spring-integration-xmpp/src/test/resources/test.properties similarity index 100% rename from spring-integration-xmpp/src/test/java/test.properties rename to spring-integration-xmpp/src/test/resources/test.properties diff --git a/spring-integration-zookeeper/src/test/resources/log4j.properties b/spring-integration-zookeeper/src/test/resources/log4j.properties deleted file mode 100644 index 2be8933cd21..00000000000 --- a/spring-integration-zookeeper/src/test/resources/log4j.properties +++ /dev/null @@ -1,9 +0,0 @@ -log4j.rootCategory=WARN, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n - -log4j.category.org.springframework.integration=WARN -log4j.category.org.springframework.integration.zookeeper=INFO -log4j.category.org.springframework.integration.support.SmartLifecycleRoleController=DEBUG diff --git a/spring-integration-zookeeper/src/test/resources/log4j2-test.xml b/spring-integration-zookeeper/src/test/resources/log4j2-test.xml new file mode 100644 index 00000000000..f3c587543e1 --- /dev/null +++ b/spring-integration-zookeeper/src/test/resources/log4j2-test.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + From 6399f03f50d9f14cd566d746ab23e2fc74d92a59 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 8 Jan 2018 16:58:42 -0500 Subject: [PATCH 2/2] Polishing after testing --- ...regatorWithCustomReleaseStrategyTests.java | 45 ++------- .../xml/LoggingChannelAdapterParserTests.java | 9 +- ...essionEvaluatingMessageProcessorTests.java | 96 ++++++++++--------- .../test/rule/Log4j2LevelAdjuster.java | 2 +- 4 files changed, 65 insertions(+), 87 deletions(-) diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/AggregatorWithCustomReleaseStrategyTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/AggregatorWithCustomReleaseStrategyTests.java index 20859c1b2b2..a009c2bd99d 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/AggregatorWithCustomReleaseStrategyTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/scenarios/AggregatorWithCustomReleaseStrategyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,60 +25,27 @@ import java.util.concurrent.TimeUnit; import org.junit.AfterClass; -import org.junit.Assume; -import org.junit.Rule; +import org.junit.ClassRule; import org.junit.Test; -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.support.MessageBuilder; +import org.springframework.integration.test.support.LongRunningIntegrationTest; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; /** * @author Oleg Zhurakousky * @author Gary Russell + * @author Artem Bilan * */ public class AggregatorWithCustomReleaseStrategyTests { - @Rule - public TestWatcher longTests = new TestWatcher() { - - private static final String RUN_LONG_PROP = "RUN_LONG_INTEGRATION_TESTS"; - - private boolean shouldRun; - - { - for (String value: new String[]{System.getenv(RUN_LONG_PROP), System.getProperty(RUN_LONG_PROP)}) { - if ("true".equalsIgnoreCase(value)) { - this.shouldRun = true; - break; - } - } - } - - @Override - public Statement apply(Statement base, Description description) { - if (!this.shouldRun) { - return new Statement() { - - @Override - public void evaluate() throws Throwable { - Assume.assumeTrue(false); - } - }; - } - else { - return super.apply(base, description); - } - } - - }; + @ClassRule + public static LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); private static ExecutorService executor = Executors.newCachedThreadPool(); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/LoggingChannelAdapterParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/LoggingChannelAdapterParserTests.java index 372e59eed9b..4968db6acdf 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/LoggingChannelAdapterParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/LoggingChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +40,7 @@ * @author Mark Fisher * @author Artem Bilan * @author Gary Russell + * * @since 2.1 */ @ContextConfiguration @@ -56,7 +57,8 @@ public class LoggingChannelAdapterParserTests { @Test public void verifyConfig() { LoggingHandler loggingHandler = TestUtils.getPropertyValue(loggerConsumer, "handler", LoggingHandler.class); - assertEquals("org.springframework.integration.test.logger", TestUtils.getPropertyValue(loggingHandler, "messageLogger.name")); + assertEquals("org.springframework.integration.test.logger", + TestUtils.getPropertyValue(loggingHandler, "messageLogger.logger.name")); assertEquals(1, TestUtils.getPropertyValue(loggingHandler, "order")); assertEquals("WARN", TestUtils.getPropertyValue(loggingHandler, "level").toString()); assertEquals("#root", TestUtils.getPropertyValue(loggingHandler, "expression.expression")); @@ -65,7 +67,8 @@ public void verifyConfig() { @Test public void verifyExpressionAndOtherDefaultConfig() { LoggingHandler loggingHandler = TestUtils.getPropertyValue(loggerWithExpression, "handler", LoggingHandler.class); - assertEquals("org.springframework.integration.handler.LoggingHandler", TestUtils.getPropertyValue(loggingHandler, "messageLogger.name")); + assertEquals("org.springframework.integration.handler.LoggingHandler", + TestUtils.getPropertyValue(loggingHandler, "messageLogger.logger.name")); assertEquals(Ordered.LOWEST_PRECEDENCE, TestUtils.getPropertyValue(loggingHandler, "order")); assertEquals("INFO", TestUtils.getPropertyValue(loggingHandler, "level").toString()); assertEquals("payload.foo", TestUtils.getPropertyValue(loggingHandler, "expression.expression")); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/ExpressionEvaluatingMessageProcessorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/ExpressionEvaluatingMessageProcessorTests.java index cc5998d719e..30bdd368a47 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/ExpressionEvaluatingMessageProcessorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/ExpressionEvaluatingMessageProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import static org.mockito.Mockito.mock; import java.util.Arrays; +import java.util.UUID; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -41,7 +42,6 @@ import org.springframework.expression.EvaluationException; import org.springframework.expression.Expression; import org.springframework.expression.ExpressionParser; -import org.springframework.expression.spel.SpelParserConfiguration; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.integration.config.IntegrationEvaluationContextFactoryBean; import org.springframework.integration.context.IntegrationContextUtils; @@ -56,121 +56,122 @@ * @author Gunnar Hillert * @author Gary Russell * @author Artem Bilan + * * @since 2.0 */ public class ExpressionEvaluatingMessageProcessorTests { private static final Log logger = LogFactory.getLog(ExpressionEvaluatingMessageProcessorTests.class); - private static final ExpressionParser expressionParser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); + private static final ExpressionParser expressionParser = new SpelExpressionParser(); @Rule public ExpectedException expected = ExpectedException.none(); - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testProcessMessage() { Expression expression = expressionParser.parseExpression("payload"); - ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression); + ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(mock(BeanFactory.class)); - assertEquals("foo", processor.processMessage(new GenericMessage("foo"))); + assertEquals("foo", processor.processMessage(new GenericMessage<>("foo"))); } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testProcessMessageWithParameterCoercion() throws Exception { @SuppressWarnings("unused") class TestTarget { + public String stringify(int number) { return number + ""; } } Expression expression = expressionParser.parseExpression("#target.stringify(payload)"); - ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression); + ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(mock(BeanFactory.class)); processor.afterPropertiesSet(); - EvaluationContext evaluationContext = TestUtils.getPropertyValue(processor, "evaluationContext", EvaluationContext.class); + EvaluationContext evaluationContext = + TestUtils.getPropertyValue(processor, "evaluationContext", EvaluationContext.class); evaluationContext.setVariable("target", new TestTarget()); - assertEquals("2", processor.processMessage(new GenericMessage("2"))); + assertEquals("2", processor.processMessage(new GenericMessage<>("2"))); } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testProcessMessageWithVoidResult() throws Exception { @SuppressWarnings("unused") class TestTarget { + public void ping(String input) { } } + Expression expression = expressionParser.parseExpression("#target.ping(payload)"); - ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression); + ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(mock(BeanFactory.class)); processor.afterPropertiesSet(); - EvaluationContext evaluationContext = TestUtils.getPropertyValue(processor, "evaluationContext", EvaluationContext.class); + EvaluationContext evaluationContext = + TestUtils.getPropertyValue(processor, "evaluationContext", EvaluationContext.class); evaluationContext.setVariable("target", new TestTarget()); - assertEquals(null, processor.processMessage(new GenericMessage("2"))); + assertEquals(null, processor.processMessage(new GenericMessage<>("2"))); } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testProcessMessageWithParameterCoercionToNonPrimitive() throws Exception { class TestTarget { + @SuppressWarnings("unused") public String find(Resource[] resources) { - return Arrays.asList(resources).toString(); + return Arrays.toString(resources); } } Expression expression = expressionParser.parseExpression("#target.find(payload)"); - ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression); + ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor<>(expression); AbstractApplicationContext applicationContext = new GenericApplicationContext(); processor.setBeanFactory(applicationContext); IntegrationEvaluationContextFactoryBean factoryBean = new IntegrationEvaluationContextFactoryBean(); factoryBean.setApplicationContext(applicationContext); - applicationContext.getBeanFactory().registerSingleton(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME, - factoryBean.getObject()); + applicationContext.getBeanFactory() + .registerSingleton(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME, + factoryBean.getObject()); applicationContext.refresh(); processor.afterPropertiesSet(); - EvaluationContext evaluationContext = TestUtils.getPropertyValue(processor, "evaluationContext", EvaluationContext.class); + EvaluationContext evaluationContext = + TestUtils.getPropertyValue(processor, "evaluationContext", EvaluationContext.class); evaluationContext.setVariable("target", new TestTarget()); - String result = (String) processor.processMessage(new GenericMessage("classpath*:*.properties")); - assertTrue("Wrong result: " + result, result.contains("log4j.properties")); + String result = processor.processMessage(new GenericMessage<>("classpath*:*-test.xml")); + assertTrue("Wrong result: " + result, result.contains("log4j2-test.xml")); } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testProcessMessageWithDollarInBrackets() { Expression expression = expressionParser.parseExpression("headers['$foo_id']"); - ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression); + ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(mock(BeanFactory.class)); Message message = MessageBuilder.withPayload("foo").setHeader("$foo_id", "abc").build(); assertEquals("abc", processor.processMessage(message)); } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testProcessMessageWithDollarPropertyAccess() { Expression expression = expressionParser.parseExpression("headers.$foo_id"); - ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression); + ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(mock(BeanFactory.class)); Message message = MessageBuilder.withPayload("foo").setHeader("$foo_id", "xyz").build(); assertEquals("xyz", processor.processMessage(message)); } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testProcessMessageWithStaticKey() { Expression expression = expressionParser.parseExpression("headers[headers.ID]"); - ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression); + ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(mock(BeanFactory.class)); - GenericMessage message = new GenericMessage("foo"); + GenericMessage message = new GenericMessage<>("foo"); assertEquals(message.getHeaders().getId(), processor.processMessage(message)); } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testProcessMessageWithBeanAsMethodArgument() throws Exception { StaticApplicationContext context = new StaticApplicationContext(); @@ -182,14 +183,13 @@ public void testProcessMessageWithBeanAsMethodArgument() throws Exception { context.refresh(); Expression expression = expressionParser.parseExpression("payload.concat(@testString)"); - ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression); + ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(context); processor.afterPropertiesSet(); - GenericMessage message = new GenericMessage("foo"); + GenericMessage message = new GenericMessage<>("foo"); assertEquals("foobar", processor.processMessage(message)); } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testProcessMessageWithMethodCallOnBean() throws Exception { StaticApplicationContext context = new StaticApplicationContext(); @@ -201,76 +201,83 @@ public void testProcessMessageWithMethodCallOnBean() throws Exception { context.refresh(); Expression expression = expressionParser.parseExpression("@testString.concat(payload)"); - ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression); + ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(context); processor.afterPropertiesSet(); - GenericMessage message = new GenericMessage("foo"); + GenericMessage message = new GenericMessage<>("foo"); assertEquals("barfoo", processor.processMessage(message)); } - @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test public void testProcessMessageBadExpression() { expected.expect(new TypeSafeMatcher(Exception.class) { + private Throwable cause; + @Override public boolean matchesSafely(Exception item) { logger.debug(item); cause = item.getCause(); return cause instanceof EvaluationException; } + @Override public void describeTo(Description description) { description.appendText("cause to be EvaluationException but was ").appendValue(cause); } }); Expression expression = expressionParser.parseExpression("payload.fixMe()"); - ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression); + ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(mock(BeanFactory.class)); - assertEquals("foo", processor.processMessage(new GenericMessage("foo"))); + assertEquals("foo", processor.processMessage(new GenericMessage<>("foo"))); } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testProcessMessageExpressionThrowsRuntimeException() { expected.expect(new TypeSafeMatcher(Exception.class) { + private Throwable cause; + @Override public boolean matchesSafely(Exception item) { logger.debug(item); cause = item.getCause(); return cause instanceof UnsupportedOperationException; } + @Override public void describeTo(Description description) { description.appendText("cause to be UnsupportedOperationException but was ").appendValue(cause); } }); Expression expression = expressionParser.parseExpression("payload.throwRuntimeException()"); - ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression); + ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(mock(BeanFactory.class)); - assertEquals("foo", processor.processMessage(new GenericMessage(new TestPayload()))); + assertEquals("foo", processor.processMessage(new GenericMessage<>(new TestPayload()))); } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testProcessMessageExpressionThrowsCheckedException() { expected.expect(new TypeSafeMatcher(Exception.class) { + private Throwable cause; + @Override public boolean matchesSafely(Exception item) { logger.debug(item); cause = item.getCause(); return cause instanceof CheckedException; } + @Override public void describeTo(Description description) { description.appendText("cause to be CheckedException but was ").appendValue(cause); } }); Expression expression = expressionParser.parseExpression("payload.throwCheckedException()"); - ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression); + ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor<>(expression); processor.setBeanFactory(mock(BeanFactory.class)); - assertEquals("foo", processor.processMessage(new GenericMessage(new TestPayload()))); + assertEquals("foo", processor.processMessage(new GenericMessage<>(new TestPayload()))); } @@ -288,6 +295,7 @@ public String throwRuntimeException() { public String throwCheckedException() throws Exception { throw new CheckedException("Expected test exception"); } + } @SuppressWarnings("serial") diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4j2LevelAdjuster.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4j2LevelAdjuster.java index 06b84ca4d87..e272132c234 100644 --- a/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4j2LevelAdjuster.java +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/rule/Log4j2LevelAdjuster.java @@ -63,7 +63,7 @@ private Log4j2LevelAdjuster(Level level) { private Log4j2LevelAdjuster(Level level, Class[] classes, String[] categories) { Assert.notNull(level, "'level' must be null"); this.level = level; - this.classes = classes != null ? classes : new Class[0]; + this.classes = classes != null ? classes : new Class[0]; Stream categoryStream = Stream.of(getClass().getPackage().getName());