diff --git a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/StompSessionManagerTests.java b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/StompSessionManagerTests.java index 11083379fb..59df502980 100644 --- a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/StompSessionManagerTests.java +++ b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/StompSessionManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 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. @@ -22,7 +22,7 @@ import static org.mockito.Mockito.mock; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.messaging.simp.stomp.StompClientSupport; import org.springframework.messaging.simp.stomp.StompHeaders; @@ -35,6 +35,7 @@ import org.springframework.util.concurrent.SettableListenableFuture; /** * @author Artem Bilan + * * @since 4.2.9 */ public class StompSessionManagerTests { 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 baec89feb1..a775c84788 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-2019 the original author or authors. + * Copyright 2015-2020 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. @@ -17,13 +17,12 @@ package org.springframework.integration.stomp.client; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import org.apache.activemq.broker.BrokerService; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; @@ -46,7 +45,6 @@ import org.springframework.integration.stomp.event.StompSessionConnectedEvent; 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.rule.Log4j2LevelAdjuster; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageDeliveryException; @@ -70,15 +68,7 @@ public class StompServerIntegrationTests { private static ReactorNettyTcpStompClient stompClient; - @Rule - public Log4j2LevelAdjuster adjuster = - Log4j2LevelAdjuster.trace() - .categories(true, "org.springframework", - "org.apache.activemq.broker", - "reactor.ipc", - "io.netty"); - - @BeforeClass + @BeforeAll public static void setup() throws Exception { int port = SocketUtils.findAvailableTcpPort(61613); activeMQBroker = new BrokerService(); @@ -97,8 +87,9 @@ public class StompServerIntegrationTests { stompClient.setReceiptTimeLimit(5000); } - @AfterClass + @AfterAll public static void teardown() throws Exception { + stompClient.shutdown(); activeMQBroker.stop(); } @@ -142,7 +133,7 @@ public class StompServerIntegrationTests { assertThat(stompReceiptEvent.getStompCommand()).isEqualTo(StompCommand.SUBSCRIBE); assertThat(stompReceiptEvent.getDestination()).isEqualTo("/topic/myTopic"); - stompOutputChannel1.send(new GenericMessage("Hello, Client#2!".getBytes())); + stompOutputChannel1.send(new GenericMessage<>("Hello, Client#2!".getBytes())); Message receive11 = stompInputChannel1.receive(10000); Message receive21 = stompInputChannel2.receive(10000); @@ -153,7 +144,7 @@ public class StompServerIntegrationTests { assertThat((byte[]) receive11.getPayload()).isEqualTo("Hello, Client#2!".getBytes()); assertThat((byte[]) receive21.getPayload()).isEqualTo("Hello, Client#2!".getBytes()); - stompOutputChannel2.send(new GenericMessage("Hello, Client#1!".getBytes())); + stompOutputChannel2.send(new GenericMessage<>("Hello, Client#1!".getBytes())); Message receive12 = stompInputChannel1.receive(10000); Message receive22 = stompInputChannel2.receive(10000); @@ -175,7 +166,7 @@ public class StompServerIntegrationTests { Lifecycle stompInboundChannelAdapter2 = context2.getBean("stompInboundChannelAdapter", Lifecycle.class); stompInboundChannelAdapter2.stop(); - stompOutputChannel1.send(new GenericMessage("How do you do?".getBytes())); + stompOutputChannel1.send(new GenericMessage<>("How do you do?".getBytes())); Message receive13 = stompInputChannel1.receive(10000); assertThat(receive13).isNotNull(); @@ -192,7 +183,7 @@ public class StompServerIntegrationTests { assertThat(stompReceiptEvent.getStompCommand()).isEqualTo(StompCommand.SUBSCRIBE); assertThat(stompReceiptEvent.getDestination()).isEqualTo("/topic/myTopic"); - stompOutputChannel1.send(new GenericMessage("???".getBytes())); + stompOutputChannel1.send(new GenericMessage<>("???".getBytes())); Message receive24 = stompInputChannel2.receive(10000); assertThat(receive24).isNotNull(); @@ -206,14 +197,10 @@ public class StompServerIntegrationTests { } while (!(eventMessage.getPayload() instanceof StompConnectionFailedEvent)); - try { - stompOutputChannel1.send(new GenericMessage("foo".getBytes())); - fail("MessageDeliveryException is expected"); - } - catch (Exception e) { - assertThat(e).isInstanceOf(MessageDeliveryException.class); - assertThat(e.getMessage()).contains("could not deliver message"); - } + + assertThatExceptionOfType(MessageDeliveryException.class) + .isThrownBy(() -> stompOutputChannel1.send(new GenericMessage<>("foo".getBytes()))) + .withMessageContaining("could not deliver message"); activeMQBroker.start(false); @@ -229,7 +216,7 @@ public class StompServerIntegrationTests { } while (!(eventMessage.getPayload() instanceof StompReceiptEvent)); - stompOutputChannel1.send(new GenericMessage("foo".getBytes())); + stompOutputChannel1.send(new GenericMessage<>("foo".getBytes())); Message receive25 = stompInputChannel2.receive(10000); assertThat(receive25).isNotNull(); assertThat((byte[]) receive25.getPayload()).isEqualTo("foo".getBytes()); @@ -278,7 +265,6 @@ public class StompServerIntegrationTests { } @Bean - @SuppressWarnings("unchecked") public ApplicationListener stompEventListener() { ApplicationEventListeningMessageProducer producer = new ApplicationEventListeningMessageProducer(); producer.setEventTypes(StompIntegrationEvent.class); diff --git a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/config/StompAdaptersParserTests.java b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/config/StompAdaptersParserTests.java index 88b1b494ba..322f1c5685 100644 --- a/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/config/StompAdaptersParserTests.java +++ b/spring-integration-stomp/src/test/java/org/springframework/integration/stomp/config/StompAdaptersParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2020 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,8 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Collections; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -36,16 +35,15 @@ import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.util.MultiValueMap; /** * @author Artem Bilan + * * @since 4.2 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class StompAdaptersParserTests { @@ -64,6 +62,7 @@ public class StompAdaptersParserTests { @Autowired private MessageChannel inboundChannel; + @Autowired @Qualifier("defaultInboundAdapter.adapter") private StompInboundChannelAdapter defaultInboundAdapter; @@ -122,7 +121,7 @@ public class StompAdaptersParserTests { assertThat(headerMapper).isNotNull(); assertThat(headerMapper).isNotSameAs(this.headerMapper); assertThat(TestUtils.getPropertyValue(headerMapper, "inboundHeaderNames", String[].class)) - .isEqualTo(new String[] { "bar", "foo" }); + .isEqualTo(new String[]{"bar", "foo"}); assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "payloadType", Class.class)) .isEqualTo(Integer.class); assertThat(TestUtils.getPropertyValue(this.customInboundAdapter, "autoStartup", Boolean.class)).isFalse(); 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 02e524af89..d77e3ee4e5 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-2019 the original author or authors. + * Copyright 2015-2020 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,9 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Collections; import java.util.Map; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -45,7 +43,6 @@ import org.springframework.integration.stomp.event.StompConnectionFailedEvent; 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.rule.Log4j2LevelAdjuster; import org.springframework.integration.websocket.TomcatWebSocketTestServer; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandlingException; @@ -65,7 +62,7 @@ import org.springframework.messaging.support.MessageBuilder; import org.springframework.scheduling.TaskScheduler; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.util.MultiValueMap; import org.springframework.web.socket.WebSocketHandler; import org.springframework.web.socket.WebSocketHttpHeaders; @@ -80,7 +77,6 @@ import org.springframework.web.socket.server.HandshakeInterceptor; import org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy; import org.springframework.web.socket.server.support.DefaultHandshakeHandler; import org.springframework.web.socket.sockjs.client.SockJsClient; -import org.springframework.web.socket.sockjs.client.Transport; import org.springframework.web.socket.sockjs.client.WebSocketTransport; /** @@ -89,15 +85,10 @@ import org.springframework.web.socket.sockjs.client.WebSocketTransport; * @since 4.2 */ @ContextConfiguration(classes = StompInboundChannelAdapterWebSocketIntegrationTests.ContextConfiguration.class) -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class StompInboundChannelAdapterWebSocketIntegrationTests { - @Rule - public Log4j2LevelAdjuster adjuster = - Log4j2LevelAdjuster.trace() - .categories("org.springframework", "org.springframework.integration.stomp"); - @Value("#{server.serverContext}") private ConfigurableApplicationContext serverContext; @@ -252,7 +243,7 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests { @Bean public WebSocketClient webSocketClient() { - return new SockJsClient(Collections.singletonList(new WebSocketTransport(new StandardWebSocketClient()))); + return new SockJsClient(Collections.singletonList(new WebSocketTransport(new StandardWebSocketClient()))); } @Bean @@ -273,7 +264,7 @@ public class StompInboundChannelAdapterWebSocketIntegrationTests { handshakeHeaders.setOrigin("https://www.example.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 a8c64b22ca..0283545c06 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-2019 the original author or authors. + * Copyright 2015-2020 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. @@ -77,7 +77,6 @@ import org.springframework.web.socket.messaging.WebSocketStompClient; import org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy; import org.springframework.web.socket.server.support.DefaultHandshakeHandler; import org.springframework.web.socket.sockjs.client.SockJsClient; -import org.springframework.web.socket.sockjs.client.Transport; import org.springframework.web.socket.sockjs.client.WebSocketTransport; /** @@ -171,7 +170,7 @@ public class StompMessageHandlerWebSocketIntegrationTests { @Bean public WebSocketClient webSocketClient() { - return new SockJsClient(Collections.singletonList(new WebSocketTransport(new StandardWebSocketClient()))); + return new SockJsClient(Collections.singletonList(new WebSocketTransport(new StandardWebSocketClient()))); } @Bean @@ -217,7 +216,7 @@ public class StompMessageHandlerWebSocketIntegrationTests { // WebSocket Server part - @Target({ ElementType.TYPE }) + @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Controller private @interface IntegrationTestController {