diff --git a/build.gradle b/build.gradle index 4d8c25679b..950550585c 100644 --- a/build.gradle +++ b/build.gradle @@ -299,9 +299,6 @@ configure(javaProjects) { subproject -> testImplementation("org.awaitility:awaitility:$awaitilityVersion") { exclude group: 'org.hamcrest' } - testImplementation("junit:junit:$junit4Version") { - exclude group: 'org.hamcrest' - } testImplementation 'org.junit.jupiter:junit-jupiter-api' testImplementation 'org.junit.jupiter:junit-jupiter-params' testImplementation("com.willowtreeapps.assertk:assertk-jvm:$assertkVersion") { @@ -314,8 +311,6 @@ configure(javaProjects) { subproject -> testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' - // To support JUnit 4 tests - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine' testRuntimeOnly 'org.apache.logging.log4j:log4j-core' testRuntimeOnly 'org.apache.logging.log4j:log4j-jcl' diff --git a/spring-integration-core/src/test/java/org/springframework/integration/support/MessageScenariosTests.java b/spring-integration-core/src/test/java/org/springframework/integration/support/MessageScenariosTests.java index d5120e4960..4e4a049402 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/support/MessageScenariosTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/support/MessageScenariosTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -20,7 +20,7 @@ import java.util.ArrayList; import java.util.List; import org.springframework.integration.test.predicate.MessagePredicate; -import org.springframework.integration.test.support.AbstractRequestResponseScenarioTests; +import org.springframework.integration.test.support.AbstractRequestResponseScenarioTest; import org.springframework.integration.test.support.MessageValidator; import org.springframework.integration.test.support.PayloadValidator; import org.springframework.integration.test.support.RequestResponseScenario; @@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @ContextConfiguration @DirtiesContext -public class MessageScenariosTests extends AbstractRequestResponseScenarioTests { +public class MessageScenariosTests extends AbstractRequestResponseScenarioTest { @Override protected List defineRequestResponseScenarios() { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/support/SingleScenarioTests.java b/spring-integration-core/src/test/java/org/springframework/integration/support/SingleScenarioTests.java index 840e66dfcd..feac834fd3 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/support/SingleScenarioTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/support/SingleScenarioTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -18,7 +18,7 @@ package org.springframework.integration.support; import org.springframework.integration.test.support.PayloadValidator; import org.springframework.integration.test.support.RequestResponseScenario; -import org.springframework.integration.test.support.SingleRequestResponseScenarioTests; +import org.springframework.integration.test.support.SingleRequestResponseScenarioTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; @@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @ContextConfiguration("MessageScenariosTests-context.xml") @DirtiesContext -public class SingleScenarioTests extends SingleRequestResponseScenarioTests { +public class SingleScenarioTests extends SingleRequestResponseScenarioTest { @Override protected RequestResponseScenario defineRequestResponseScenario() { diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests-context.xml b/spring-integration-file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests-context.xml index 91d7ba5c40..507e2211f6 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests-context.xml +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests-context.xml @@ -19,11 +19,8 @@ directory="#{inputDirectory.path}" channel="fileMessages" filter="compositeFilter"/> - - - + diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests.java index 469f38d628..7f6acd5ba1 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests.java @@ -19,6 +19,7 @@ package org.springframework.integration.file; import java.io.File; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.Message; @@ -37,6 +38,9 @@ import static org.assertj.core.api.Assertions.assertThat; @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public class FileToChannelIntegrationTests { + @TempDir + public static File tempDir; + @Autowired File inputDirectory; diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingNamespaceTests-context.xml b/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingNamespaceTests-context.xml index 50d0178327..4264c578aa 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingNamespaceTests-context.xml +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingNamespaceTests-context.xml @@ -11,17 +11,19 @@ https://www.springframework.org/schema/integration/file/spring-integration-file.xsd"> - + - + - + + + diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingNamespaceTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingNamespaceTests.java index edc983e034..f7fd02b57f 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingNamespaceTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/locking/FileLockingNamespaceTests.java @@ -20,6 +20,7 @@ import java.io.File; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; @@ -41,6 +42,9 @@ import static org.assertj.core.api.Assertions.assertThat; @DirtiesContext public class FileLockingNamespaceTests { + @TempDir + public static File tempDir; + @Autowired @Qualifier("nioLockingAdapter.adapter") SourcePollingChannelAdapter nioAdapter; diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/AttributePollingMessageSourceTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/AttributePollingMessageSourceTests.java index c86c4295e2..a2da477f98 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/AttributePollingMessageSourceTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/AttributePollingMessageSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -20,7 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger; import javax.management.MBeanServer; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.jmx.support.MBeanServerFactoryBean; import org.springframework.jmx.support.ObjectNameManager; diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/MBeanTreePollingMessageSourceTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/MBeanTreePollingMessageSourceTests.java index b2328ca013..4ff2438325 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/MBeanTreePollingMessageSourceTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/MBeanTreePollingMessageSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2022 the original author or authors. + * Copyright 2013-2025 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,9 @@ import java.util.Map; import javax.management.MBeanServer; -import org.junit.AfterClass; -import org.junit.BeforeClass; -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.jmx.support.MBeanServerFactoryBean; @@ -40,7 +40,7 @@ public class MBeanTreePollingMessageSourceTests { private static MBeanServer server; - @BeforeClass + @BeforeAll public static void setup() { factoryBean = new MBeanServerFactoryBean(); factoryBean.setLocateExistingServerIfPossible(true); @@ -48,7 +48,7 @@ public class MBeanTreePollingMessageSourceTests { server = factoryBean.getObject(); } - @AfterClass + @AfterAll public static void tearDown() { factoryBean.destroy(); } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/NotificationListeningMessageProducerTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/NotificationListeningMessageProducerTests.java index 54c3c6ab38..66345d8b9e 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/NotificationListeningMessageProducerTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/NotificationListeningMessageProducerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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,11 +22,11 @@ import javax.management.MBeanServer; import javax.management.Notification; import javax.management.ObjectName; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.factory.BeanFactory; @@ -59,13 +59,13 @@ public class NotificationListeningMessageProducerTests { private ObjectName objectName; - @BeforeClass + @BeforeAll public static void setupClass() { serverFactoryBean = new MBeanServerFactoryBean(); serverFactoryBean.afterPropertiesSet(); } - @Before + @BeforeEach public void setup() throws Exception { this.server = serverFactoryBean.getObject(); MBeanExporter exporter = new MBeanExporter(); @@ -75,12 +75,12 @@ public class NotificationListeningMessageProducerTests { exporter.registerManagedResource(this.numberHolder, this.objectName); } - @After + @AfterEach public void cleanup() throws Exception { this.server.unregisterMBean(this.objectName); } - @AfterClass + @AfterAll public static void tearDown() { serverFactoryBean.destroy(); } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/NotificationPublishingMessageHandlerTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/NotificationPublishingMessageHandlerTests.java index 62b6f4e1fc..f0c9b3602e 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/NotificationPublishingMessageHandlerTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/NotificationPublishingMessageHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -23,9 +23,9 @@ import javax.management.Notification; import javax.management.NotificationListener; import javax.management.ObjectName; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.config.RuntimeBeanReference; @@ -54,7 +54,7 @@ public class NotificationPublishingMessageHandlerTests { private volatile ObjectName publisherObjectName; - @Before + @BeforeEach public void setup() throws Exception { this.publisherObjectName = ObjectNameManager.getInstance("test:type=publisher"); this.context.registerBean("mbeanServer", MBeanServerFactoryBean.class, MBeanServerFactoryBean::new); @@ -72,7 +72,7 @@ public class NotificationPublishingMessageHandlerTests { exporter.getServer().addNotificationListener(publisherObjectName, this.listener, null, null); } - @After + @AfterEach public void cleanup() { this.listener.clearNotifications(); context.close(); diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/OperationInvokingMessageHandlerTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/OperationInvokingMessageHandlerTests.java index 946a99f28b..52ea64aca9 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/OperationInvokingMessageHandlerTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/OperationInvokingMessageHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -23,11 +23,11 @@ import java.util.Map; import javax.management.MBeanServer; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.integration.channel.QueueChannel; @@ -39,6 +39,7 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.Mockito.mock; /** @@ -61,24 +62,24 @@ public class OperationInvokingMessageHandlerTests { private final String objectName = "si:name=test"; - @BeforeClass + @BeforeAll public static void setupClass() { factoryBean = new MBeanServerFactoryBean(); factoryBean.afterPropertiesSet(); server = factoryBean.getObject(); } - @AfterClass + @AfterAll public static void tearDown() { factoryBean.destroy(); } - @Before + @BeforeEach public void setup() throws Exception { server.registerMBean(new TestOps(), ObjectNameManager.getInstance(this.objectName)); } - @After + @AfterEach public void cleanup() throws Exception { server.unregisterMBean(ObjectNameManager.getInstance(this.objectName)); } @@ -115,7 +116,7 @@ public class OperationInvokingMessageHandlerTests { handler.handleMessage(message); } - @Test(expected = MessagingException.class) + @Test public void invocationWithMapPayloadNotEnoughParameters() { QueueChannel outputChannel = new QueueChannel(); OperationInvokingMessageHandler handler = new OperationInvokingMessageHandler(server); @@ -127,10 +128,8 @@ public class OperationInvokingMessageHandlerTests { Map params = new HashMap<>(); params.put("p1", "foo"); Message message = MessageBuilder.withPayload(params).build(); - handler.handleMessage(message); - Message reply = outputChannel.receive(0); - assertThat(reply).isNotNull(); - assertThat(reply.getPayload()).isEqualTo("foobar"); + assertThatExceptionOfType(MessagingException.class) + .isThrownBy(() -> handler.handleMessage(message)); } @Test diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests.java index 2ca8bc9ec8..2b566adc6a 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/AttributePollingChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -16,8 +16,7 @@ package org.springframework.integration.jmx.config; -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; @@ -27,8 +26,7 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; 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 static org.assertj.core.api.Assertions.assertThat; @@ -38,8 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class AttributePollingChannelAdapterParserTests { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java index a1648074bd..93524be751 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/ControlBusParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -16,15 +16,14 @@ package org.springframework.integration.jmx.config; -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.context.ApplicationContext; import org.springframework.integration.core.MessagingTemplate; import org.springframework.messaging.MessageChannel; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -35,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @since 2.0 */ -@RunWith(SpringRunner.class) +@SpringJUnitConfig @DirtiesContext public class ControlBusParserTests { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/CustomObjectNameTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/CustomObjectNameTests.java index ddaf589f3e..be1ad37d9a 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/CustomObjectNameTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/CustomObjectNameTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2025 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,8 +25,7 @@ import javax.management.MBeanInfo; import javax.management.MBeanServer; import javax.management.ObjectName; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -39,8 +38,7 @@ import org.springframework.integration.support.management.IntegrationManagedReso import org.springframework.messaging.Message; 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.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Transactional; @@ -51,8 +49,7 @@ import static org.mockito.Mockito.mock; * @author Gary Russell * @since 4.2.1 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class CustomObjectNameTests { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/DynamicRouterTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/DynamicRouterTests.java index 19834444da..eb23cc7c51 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/DynamicRouterTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/DynamicRouterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -19,9 +19,8 @@ package org.springframework.integration.jmx.config; import java.util.HashMap; import java.util.Map; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -31,8 +30,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; 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 static org.assertj.core.api.Assertions.assertThat; @@ -41,8 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class DynamicRouterTests { @@ -119,7 +116,7 @@ public class DynamicRouterTests { @Test @DirtiesContext - @Ignore + @Disabled public void testPerf() throws Exception { // this.nullChannel.enableStats(false); for (int i = 0; i < 1000000000; i++) { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanAutoDetectTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanAutoDetectTests.java index 1d42cac627..c7708be597 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanAutoDetectTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanAutoDetectTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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,8 @@ import java.util.Set; import javax.management.MBeanServer; import javax.management.ObjectName; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -40,7 +40,7 @@ public class MBeanAutoDetectTests { private ClassPathXmlApplicationContext context; - @After + @AfterEach public void close() { if (context != null) { context.close(); diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanExporterNameTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanExporterNameTests.java index 7ae997eeac..40843c8fd9 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanExporterNameTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanExporterNameTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -16,7 +16,8 @@ package org.springframework.integration.jmx.config; -import org.junit.Test; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -27,9 +28,10 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; */ public class MBeanExporterNameTests { - @Test(expected = BeanDefinitionParsingException.class) - public void testHandlerMBeanRegistration() throws Exception { - new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass()).close(); + @Test + public void testHandlerMBeanRegistration() { + Assertions.assertThatExceptionOfType(BeanDefinitionParsingException.class) + .isThrownBy(() -> new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass())); } public static class Source { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanRegistrationCustomNamingTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanRegistrationCustomNamingTests.java index b03858d3c9..708fdb74de 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanRegistrationCustomNamingTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanRegistrationCustomNamingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2024 the original author or authors. + * Copyright 2013-2025 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,15 +22,13 @@ import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; -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.jmx.export.naming.KeyNamingStrategy; import org.springframework.jmx.export.naming.ObjectNamingStrategy; 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 static org.assertj.core.api.Assertions.assertThat; @@ -39,8 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * @since 3.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class MBeanRegistrationCustomNamingTests { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanRegistrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanRegistrationTests.java index d5b143a85f..6ab99862c6 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanRegistrationTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MBeanRegistrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -24,15 +24,13 @@ import javax.management.MBeanOperationInfo; import javax.management.MBeanServer; import javax.management.ObjectName; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.gateway.MessagingGatewaySupport; 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 static org.assertj.core.api.Assertions.assertThat; @@ -41,8 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class MBeanRegistrationTests { @@ -78,7 +75,7 @@ public class MBeanRegistrationTests { } @Test - @Ignore // re-instate this if Spring decides to look for @ManagedResource on super classes + @Disabled // re-instate this if Spring decides to look for @ManagedResource on super classes public void testServiceActivatorMBeanHasTrackableComponent() throws Exception { Set names = server.queryNames(new ObjectName("test.MBeanRegistration:type=ServiceActivatingHandler,name=service,*"), null); Map infos = new HashMap(); diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MessageStoreTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MessageStoreTests.java index 95adc91ab5..fe2cb2a5a5 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MessageStoreTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MessageStoreTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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,13 +21,11 @@ import java.util.Set; import javax.management.MBeanServer; import javax.management.ObjectName; -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.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 static org.assertj.core.api.Assertions.assertThat; @@ -36,8 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class MessageStoreTests { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MethodInvokerTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MethodInvokerTests.java index 1205946848..5e1b74b19f 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MethodInvokerTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/MethodInvokerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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,16 +21,14 @@ import java.util.Set; import javax.management.MBeanServer; import javax.management.ObjectName; -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.integration.support.MessageBuilder; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.SubscribableChannel; 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 static org.assertj.core.api.Assertions.assertThat; @@ -39,8 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class MethodInvokerTests { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests.java index 54ef908e26..cf6b8ab8ab 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationListeningChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -18,8 +18,7 @@ package org.springframework.integration.jmx.config; import javax.management.Notification; -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; @@ -29,8 +28,7 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; 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 static org.assertj.core.api.Assertions.assertThat; @@ -39,8 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class NotificationListeningChannelAdapterParserTests { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationPublishingChannelAdapterParserTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationPublishingChannelAdapterParserTests.java index 54309d3845..ccb5013316 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationPublishingChannelAdapterParserTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/NotificationPublishingChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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,9 +25,8 @@ import javax.management.Notification; import javax.management.ObjectInstance; import javax.management.ObjectName; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -38,8 +37,7 @@ import org.springframework.messaging.Message; 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 static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -50,8 +48,7 @@ import static org.assertj.core.api.Assertions.fail; * @author Gary Russell * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class NotificationPublishingChannelAdapterParserTests { @@ -72,7 +69,7 @@ public class NotificationPublishingChannelAdapterParserTests { private static volatile int adviceCalled; - @After + @AfterEach public void clearListener() { listener.lastNotification = null; } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/OperationInvokingOutboundGatewayTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/OperationInvokingOutboundGatewayTests.java index 1d36ccf691..3eab92afe1 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/OperationInvokingOutboundGatewayTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/OperationInvokingOutboundGatewayTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -38,8 +37,7 @@ import org.springframework.messaging.MessagingException; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; 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 static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -50,8 +48,7 @@ import static org.assertj.core.api.Assertions.fail; * @author Gary Russell * */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class OperationInvokingOutboundGatewayTests { @@ -79,7 +76,7 @@ public class OperationInvokingOutboundGatewayTests { private static volatile int adviceCalled; - @After + @AfterEach public void resetLists() { testBean.messages.clear(); } diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PollingAdapterMBeanTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PollingAdapterMBeanTests.java index a042fa87c3..ef671cd299 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PollingAdapterMBeanTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PollingAdapterMBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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,13 +21,11 @@ import java.util.Set; import javax.management.MBeanServer; import javax.management.ObjectName; -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.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 static org.assertj.core.api.Assertions.assertThat; @@ -36,8 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class PollingAdapterMBeanTests { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PriorityChannelTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PriorityChannelTests.java index 56e3cd72f5..b48f2d29a3 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PriorityChannelTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/PriorityChannelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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,15 +21,13 @@ import java.util.Set; import javax.management.MBeanServer; import javax.management.ObjectName; -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.integration.channel.QueueChannelOperations; import org.springframework.messaging.PollableChannel; 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 static org.assertj.core.api.Assertions.assertThat; @@ -38,8 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class PriorityChannelTests { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/RouterMBeanTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/RouterMBeanTests.java index 5a191e93a4..2506f0b565 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/RouterMBeanTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/RouterMBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -23,11 +23,9 @@ import java.util.Set; import javax.management.MBeanServer; import javax.management.ObjectName; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -37,59 +35,65 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Dave Syer * @since 2.0 */ -@RunWith(Parameterized.class) public class RouterMBeanTests { - private final MBeanServer server; + private MBeanServer server; - private final ClassPathXmlApplicationContext context; + private ClassPathXmlApplicationContext context; - public RouterMBeanTests(String configLocation) { + public void initContext(String configLocation) { context = new ClassPathXmlApplicationContext(configLocation, getClass()); server = context.getBean(MBeanServer.class); } - @Parameters - public static List getParameters() { + public static List contexts() { return Arrays.asList( - new Object[] {"RouterMBeanTests-context.xml"}, - new Object[] {"RouterMBeanGatewayTests-context.xml"}, - new Object[] {"RouterMBeanNoneTests-context.xml"}, - new Object[] {"RouterMBeanSwitchTests-context.xml"}); + "RouterMBeanTests-context.xml", + "RouterMBeanGatewayTests-context.xml", + "RouterMBeanNoneTests-context.xml", + "RouterMBeanSwitchTests-context.xml"); } - @After + @AfterEach public void close() { if (context != null) { context.close(); } } - @Test - public void testRouterMBeanExists() throws Exception { + @ParameterizedTest + @MethodSource("contexts") + public void testRouterMBeanExists(String context) throws Exception { + initContext(context); // System . err.println(server.queryNames(new ObjectName("test.RouterMBean:*"), null)); Set names = server.queryNames( new ObjectName("test.RouterMBean:type=MessageHandler,name=ptRouter,*"), null); assertThat(names.size()).isEqualTo(1); } - @Test - public void testInputChannelMBeanExists() throws Exception { + @ParameterizedTest + @MethodSource("contexts") + public void testInputChannelMBeanExists(String context) throws Exception { + initContext(context); // System . err.println(server.queryNames(new ObjectName("test.RouterMBean:type=MessageChannel,*"), null)); Set names = server.queryNames( new ObjectName("test.RouterMBean:type=MessageChannel,name=testChannel,*"), null); assertThat(names.size()).isEqualTo(1); } - @Test - public void testErrorChannelMBeanExists() throws Exception { + @ParameterizedTest + @MethodSource("contexts") + public void testErrorChannelMBeanExists(String context) throws Exception { + initContext(context); Set names = server.queryNames( new ObjectName("test.RouterMBean:type=MessageChannel,name=errorChannel,*"), null); assertThat(names.size()).isEqualTo(1); } - @Test - public void testRouterMBeanOnlyRegisteredOnce() throws Exception { + @ParameterizedTest + @MethodSource("contexts") + public void testRouterMBeanOnlyRegisteredOnce(String context) throws Exception { + initContext(context); // System . err.println(server.queryNames(new ObjectName("*:type=MessageHandler,*"), null)); Set names = server.queryNames(new ObjectName("test.RouterMBean:type=MessageHandler,name=ptRouter,*"), null); assertThat(names.size()).isEqualTo(1); diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/RouterMBeanVanillaTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/RouterMBeanVanillaTests.java index ea38bddbe0..658315e7d6 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/RouterMBeanVanillaTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/RouterMBeanVanillaTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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,13 +21,11 @@ import java.util.Set; import javax.management.MBeanServer; import javax.management.ObjectName; -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.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 static org.assertj.core.api.Assertions.assertThat; @@ -36,8 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class RouterMBeanVanillaTests { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChainWithMessageProducingHandlersTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChainWithMessageProducingHandlersTests.java index e3eb35bbce..d6188f8afb 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChainWithMessageProducingHandlersTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/ChainWithMessageProducingHandlersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -16,14 +16,12 @@ package org.springframework.integration.monitor; -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.context.ApplicationContext; 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 static org.assertj.core.api.Assertions.assertThat; @@ -33,8 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class ChainWithMessageProducingHandlersTests { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java index c813f55537..502e24e054 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/HandlerMonitoringIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2022 the original author or authors. + * Copyright 2009-2025 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 org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.context.support.ClassPathXmlApplicationContext; diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MBeanExporterIntegrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MBeanExporterIntegrationTests.java index 69d6aa7719..eafa30ce31 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MBeanExporterIntegrationTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MBeanExporterIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2022 the original author or authors. + * Copyright 2009-2025 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. @@ -24,8 +24,8 @@ import javax.management.MBeanOperationInfo; import javax.management.MBeanServer; import javax.management.ObjectName; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.aop.framework.Advised; import org.springframework.beans.factory.FactoryBean; @@ -66,7 +66,7 @@ public class MBeanExporterIntegrationTests { private GenericXmlApplicationContext context; - @After + @AfterEach public void close() { if (context != null) { context.close(); diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessagingGatewaySupportRegistrationTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessagingGatewaySupportRegistrationTests.java index c5a222dcf9..c692f3fa5c 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessagingGatewaySupportRegistrationTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/MessagingGatewaySupportRegistrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-2025 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 java.util.Set; import javax.management.MBeanServer; import javax.management.ObjectName; -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.context.annotation.Bean; @@ -34,8 +33,7 @@ import org.springframework.integration.jmx.config.EnableIntegrationMBeanExport; import org.springframework.jmx.support.MBeanServerFactoryBean; import org.springframework.messaging.MessageChannel; 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 static org.assertj.core.api.Assertions.assertThat; @@ -44,8 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * @since 4.2.1 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class MessagingGatewaySupportRegistrationTests { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/RemoteMBeanServerTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/RemoteMBeanServerTests.java index afa198616e..429f91651b 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/RemoteMBeanServerTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/RemoteMBeanServerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -18,8 +18,7 @@ package org.springframework.integration.monitor; import javax.management.Notification; -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.messaging.Message; @@ -27,8 +26,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; 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 static org.assertj.core.api.Assertions.assertThat; @@ -44,8 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 2.2 * */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class RemoteMBeanServerTests { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/TransformerContextTests.java b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/TransformerContextTests.java index a8f97e9309..cf8ac1043a 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/TransformerContextTests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration/monitor/TransformerContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -16,8 +16,7 @@ package org.springframework.integration.monitor; -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.context.ApplicationContext; @@ -29,7 +28,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -38,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * @author Artem Bilan */ -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class TransformerContextTests { diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/INT_2626Tests.java b/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/INT_2626Tests.java index 4f4c9f47a8..1928f1b282 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/INT_2626Tests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/INT_2626Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -16,7 +16,7 @@ package org.springframework.integration_.mbeanexporterhelper; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java b/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java index faf20418c6..f61e49a811 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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 java.util.Set; import javax.management.MBeanServer; import javax.management.ObjectInstance; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.test.util.TestUtils; diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaMessageHandlerParserTests.java b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaMessageHandlerParserTests.java index a83962a231..218bde5e20 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaMessageHandlerParserTests.java +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/config/xml/JpaMessageHandlerParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -18,8 +18,8 @@ package org.springframework.integration.jpa.config.xml; import java.util.List; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.aop.support.AopUtils; import org.springframework.context.ConfigurableApplicationContext; @@ -210,7 +210,7 @@ public class JpaMessageHandlerParserTests { } - @After + @AfterEach public void tearDown() { if (context != null) { context.close(); diff --git a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/inbound/JpaPollingChannelAdapterUnitTests.java b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/inbound/JpaPollingChannelAdapterUnitTests.java index ef977f3ca0..88f614e2a7 100644 --- a/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/inbound/JpaPollingChannelAdapterUnitTests.java +++ b/spring-integration-jpa/src/test/java/org/springframework/integration/jpa/inbound/JpaPollingChannelAdapterUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -16,7 +16,7 @@ package org.springframework.integration.jpa.inbound; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.integration.jpa.core.JpaExecutor; diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueOutboundGatewayParserTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueOutboundGatewayParserTests.java index 6b27b488f7..30023f8c59 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueOutboundGatewayParserTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueOutboundGatewayParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 the original author or authors. + * Copyright 2014-2025 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. @@ -16,8 +16,7 @@ package org.springframework.integration.redis.config; -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; @@ -27,8 +26,7 @@ import org.springframework.integration.redis.outbound.RedisQueueOutboundGateway; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.MessageChannel; 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 static org.assertj.core.api.Assertions.assertThat; @@ -37,8 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * since 4.1 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class RedisQueueOutboundGatewayParserTests { diff --git a/spring-integration-stream/src/test/java/org/springframework/integration/stream/ByteStreamSourceTests.java b/spring-integration-stream/src/test/java/org/springframework/integration/stream/ByteStreamSourceTests.java index 26ddbce716..bf915cb24e 100644 --- a/spring-integration-stream/src/test/java/org/springframework/integration/stream/ByteStreamSourceTests.java +++ b/spring-integration-stream/src/test/java/org/springframework/integration/stream/ByteStreamSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -18,7 +18,7 @@ package org.springframework.integration.stream; import java.io.ByteArrayInputStream; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.messaging.Message; diff --git a/spring-integration-stream/src/test/java/org/springframework/integration/stream/ByteStreamWritingMessageHandlerTests.java b/spring-integration-stream/src/test/java/org/springframework/integration/stream/ByteStreamWritingMessageHandlerTests.java index 0fe69f93cd..9a981e7db5 100644 --- a/spring-integration-stream/src/test/java/org/springframework/integration/stream/ByteStreamWritingMessageHandlerTests.java +++ b/spring-integration-stream/src/test/java/org/springframework/integration/stream/ByteStreamWritingMessageHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -19,9 +19,9 @@ package org.springframework.integration.stream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.integration.channel.QueueChannel; @@ -51,7 +51,7 @@ public class ByteStreamWritingMessageHandlerTests { private ThreadPoolTaskScheduler scheduler; - @Before + @BeforeEach public void initialize() { stream = new ByteArrayOutputStream(); handler = new ByteStreamWritingMessageHandler(stream); @@ -65,7 +65,7 @@ public class ByteStreamWritingMessageHandlerTests { endpoint.setBeanFactory(mock(BeanFactory.class)); } - @After + @AfterEach public void stop() throws Exception { scheduler.destroy(); } diff --git a/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/inbound/SyslogDeserializerTests.java b/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/inbound/SyslogDeserializerTests.java index 8c848b5b23..ce1d0a0ce9 100644 --- a/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/inbound/SyslogDeserializerTests.java +++ b/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/inbound/SyslogDeserializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 the original author or authors. + * Copyright 2014-2025 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. @@ -20,7 +20,7 @@ import java.io.ByteArrayInputStream; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.integration.syslog.SyslogHeaders; 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 83c3e925c1..44bc04ea6d 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 @@ -1,5 +1,5 @@ /* - * Copyright 2018-2024 the original author or authors. + * Copyright 2018-2025 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. @@ -24,6 +24,7 @@ import org.junit.rules.MethodRule; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.Statement; +import org.springframework.integration.test.condition.LogLevels; import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.test.util.TestUtils.LevelsContainer; import org.springframework.util.Assert; @@ -37,10 +38,13 @@ import org.springframework.util.ObjectUtils; * * @author Artem Bilan * @author Gary Russell + * @author Jiandong Ma * * @since 5.0.1 * + * @deprecated since 7.0 in favor of {@link LogLevels} */ +@Deprecated(since = "7.0", forRemoval = true) public final class Log4j2LevelAdjuster implements MethodRule { private final Class[] classes; diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/AbstractRequestResponseScenarioTest.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/AbstractRequestResponseScenarioTest.java new file mode 100644 index 0000000000..ebc595af13 --- /dev/null +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/AbstractRequestResponseScenarioTest.java @@ -0,0 +1,108 @@ +/* + * Copyright 2002-2025 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 + * + * https://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.support; + +import java.util.List; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.PollableChannel; +import org.springframework.messaging.SubscribableChannel; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Convenience class for testing Spring Integration request-response message scenarios. + * Users create subclasses to execute on or more {@link RequestResponseScenario} tests. + * each scenario defines: + *
    + *
  • An inputChannelName
  • + *
  • An outputChannelName
  • + *
  • A payload or message to send as a request message on the inputChannel
  • + *
  • A handler to validate the response received on the outputChannel
  • + *
+ * + * @author David Turanski + * @author Gary Russell + * @author Artem Bilan + * @author Jiandong Ma + */ +@SpringJUnitConfig +@DirtiesContext +public abstract class AbstractRequestResponseScenarioTest { + + private List scenarios = null; + + @Autowired + private ApplicationContext applicationContext; + + @BeforeEach + public void setUp() { + scenarios = defineRequestResponseScenarios(); + } + + /** + * Execute each scenario. Instantiate the message channels, send the request message + * on the input channel and invoke the validator on the response received on the + * output channel. This can handle subscribable or pollable output channels. + */ + @Test + public void testRequestResponseScenarios() { + int i = 1; + for (RequestResponseScenario scenario : scenarios) { + String name = scenario.getName() == null ? "scenario-" + (i++) : scenario.getName(); + scenario.init(); + MessageChannel inputChannel = applicationContext.getBean(scenario.getInputChannelName(), + MessageChannel.class); + MessageChannel outputChannel = applicationContext.getBean(scenario.getOutputChannelName(), + MessageChannel.class); + if (outputChannel instanceof SubscribableChannel) { + ((SubscribableChannel) outputChannel).subscribe(scenario.getResponseValidator()); + } + + assertThat(inputChannel.send(scenario.getMessage())) + .as(name + ": message not sent on " + scenario.getInputChannelName()).isTrue(); + + if (outputChannel instanceof PollableChannel) { + Message response = ((PollableChannel) outputChannel).receive(10000); // NOSONAR magic number + assertThat(response).as(name + ": receive timeout on " + scenario.getOutputChannelName()).isNotNull(); + scenario.getResponseValidator().handleMessage(response); + } + + assertThat(scenario.getResponseValidator().getLastMessage()) + .as("message was not handled on " + outputChannel + " for scenario '" + name + "'.").isNotNull(); + + if (outputChannel instanceof SubscribableChannel) { + ((SubscribableChannel) outputChannel).unsubscribe(scenario.getResponseValidator()); + } + } + } + + /** + * Implement this method to define RequestResponse scenarios + * @return - A List of {@link RequestResponseScenario} + */ + protected abstract List defineRequestResponseScenarios(); + +} diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/AbstractRequestResponseScenarioTests.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/AbstractRequestResponseScenarioTests.java index c777d4c976..343bbf8ac9 100644 --- a/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/AbstractRequestResponseScenarioTests.java +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/AbstractRequestResponseScenarioTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -47,9 +47,13 @@ import static org.assertj.core.api.Assertions.assertThat; * @author David Turanski * @author Gary Russell * @author Artem Bilan + * @author Jiandong Ma + * + * @deprecated since 7.0 in favor of {@link AbstractRequestResponseScenarioTest} */ @RunWith(SpringJUnit4ClassRunner.class) @DirtiesContext +@Deprecated(since = "7.0", forRemoval = true) public abstract class AbstractRequestResponseScenarioTests { private List scenarios = null; diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/LongRunningIntegrationTest.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/LongRunningIntegrationTest.java index 5577e9f1ee..ebcbd186ca 100644 --- a/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/LongRunningIntegrationTest.java +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/LongRunningIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2022 the original author or authors. + * Copyright 2013-2025 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. @@ -23,16 +23,21 @@ import org.junit.rules.TestWatcher; import org.junit.runner.Description; import org.junit.runners.model.Statement; +import org.springframework.integration.test.condition.LongRunningTest; + /** * Rule to prevent long running tests from running on every build; set environment * variable RUN_LONG_INTEGRATION_TESTS on a CI nightly build to ensure coverage. * * @author Gary Russell * @author Artem Bilan + * @author Jiandong Ma * * @since 3.0 * + * @deprecated since 7.0 in favor of {@link LongRunningTest}. */ +@Deprecated(since = "7.0", forRemoval = true) public class LongRunningIntegrationTest extends TestWatcher { private static final Log LOGGER = LogFactory.getLog(LongRunningIntegrationTest.class); diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/SingleRequestResponseScenarioTest.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/SingleRequestResponseScenarioTest.java new file mode 100644 index 0000000000..a14cf36c0e --- /dev/null +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/SingleRequestResponseScenarioTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2002-2025 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 + * + * https://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.support; + +import java.util.Collections; +import java.util.List; + +/** + * Convenience class for a single {@link RequestResponseScenario} test + * + * @author David Turanski + * @author Jiandong Ma + * + */ +public abstract class SingleRequestResponseScenarioTest extends AbstractRequestResponseScenarioTest { + + @Override + protected List defineRequestResponseScenarios() { + return Collections.singletonList(defineRequestResponseScenario()); + } + + protected abstract RequestResponseScenario defineRequestResponseScenario(); + +} diff --git a/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/SingleRequestResponseScenarioTests.java b/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/SingleRequestResponseScenarioTests.java index 1cafdc3377..0e53de83c7 100644 --- a/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/SingleRequestResponseScenarioTests.java +++ b/spring-integration-test-support/src/main/java/org/springframework/integration/test/support/SingleRequestResponseScenarioTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2025 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. @@ -23,7 +23,11 @@ import java.util.List; * Convenience class for a single {@link RequestResponseScenario} test * * @author David Turanski + * @author Jiandong Ma + * + * @deprecated since 7.0 in favor of {@link SingleRequestResponseScenarioTest} */ +@Deprecated(since = "7.0", forRemoval = true) public abstract class SingleRequestResponseScenarioTests extends AbstractRequestResponseScenarioTests { @Override diff --git a/spring-integration-test-support/src/test/java/org/springframework/integration/test/matcher/MockitoMessageMatchersTests.java b/spring-integration-test-support/src/test/java/org/springframework/integration/test/matcher/MockitoMessageMatchersTests.java index a74a47bf53..4d99c68b8f 100644 --- a/spring-integration-test-support/src/test/java/org/springframework/integration/test/matcher/MockitoMessageMatchersTests.java +++ b/spring-integration-test-support/src/test/java/org/springframework/integration/test/matcher/MockitoMessageMatchersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2025 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. @@ -19,12 +19,9 @@ package org.springframework.integration.test.matcher; import java.util.Date; import org.hamcrest.Matchers; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.exceptions.verification.opentest4j.ArgumentsAreDifferent; -import org.mockito.junit.MockitoJUnitRunner; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; @@ -33,6 +30,7 @@ import org.springframework.messaging.support.MessageBuilder; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -43,7 +41,6 @@ import static org.mockito.Mockito.when; * @author Artem Bilan * */ -@RunWith(MockitoJUnitRunner.Silent.class) public class MockitoMessageMatchersTests { static final Date SOME_PAYLOAD = new Date(); @@ -52,15 +49,13 @@ public class MockitoMessageMatchersTests { static final String SOME_HEADER_KEY = "test.foo"; - @Mock - MessageHandler handler; + MessageHandler handler = mock(); - @Mock - MessageChannel channel; + MessageChannel channel = mock(); Message message; - @Before + @BeforeEach public void setUp() { this.message = MessageBuilder.withPayload(SOME_PAYLOAD) diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/DefaultSoapHeaderMapperTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/DefaultSoapHeaderMapperTests.java index 956a9322f8..933af38af5 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/DefaultSoapHeaderMapperTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/DefaultSoapHeaderMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2024 the original author or authors. + * Copyright 2002-2025 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. @@ -29,7 +29,7 @@ import jakarta.xml.soap.MessageFactory; import jakarta.xml.soap.MimeHeaders; import jakarta.xml.soap.SOAPException; import jakarta.xml.soap.SOAPMessage; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.w3c.dom.NodeList; import org.springframework.messaging.MessageHeaders; diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/WebServiceInboundGatewayJavaConfigTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/WebServiceInboundGatewayJavaConfigTests.java index 21680776a8..daab6a4d1c 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/WebServiceInboundGatewayJavaConfigTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/WebServiceInboundGatewayJavaConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2024 the original author or authors. + * Copyright 2016-2025 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. @@ -23,8 +23,7 @@ import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamResult; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.w3c.dom.Element; import org.springframework.beans.factory.annotation.Autowired; @@ -43,8 +42,7 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; 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.ws.config.annotation.EnableWs; import org.springframework.ws.context.MessageContext; import org.springframework.ws.server.EndpointMapping; @@ -70,8 +68,7 @@ import static org.mockito.Mockito.when; * @author Artem Bilan * @since 4.3 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class WebServiceInboundGatewayJavaConfigTests { diff --git a/src/reference/antora/modules/ROOT/pages/testing.adoc b/src/reference/antora/modules/ROOT/pages/testing.adoc index 74017affd6..8ea5df57e9 100644 --- a/src/reference/antora/modules/ROOT/pages/testing.adoc +++ b/src/reference/antora/modules/ROOT/pages/testing.adoc @@ -114,20 +114,18 @@ public void testWithEntityClass() throws Exception { The `org.springframework.integration.test.support` package contains various abstract classes that you should implement in target tests -* https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/AbstractRequestResponseScenarioTests.html[`AbstractRequestResponseScenarioTests`] +* https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/AbstractRequestResponseScenarioTest.html[`AbstractRequestResponseScenarioTest`] * https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/AbstractResponseValidator.html[`AbstractResponseValidator`] -* https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/LogAdjustingTestSupport.html[`LogAdjustingTestSupport`] (Deprecated) * https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/MessageValidator.html[`MessageValidator`] * https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/PayloadValidator.html[`PayloadValidator`] * https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/RequestResponseScenario.html[`RequestResponseScenario`] -* https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/SingleRequestResponseScenarioTests.html[`SingleRequestResponseScenarioTests`] +* https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/SingleRequestResponseScenarioTest.html[`SingleRequestResponseScenarioTest`] -[[test-junit-rules]] -=== JUnit Rules and Conditions +[[test-junit-conditions]] +=== JUnit Conditions -The `LongRunningIntegrationTest` JUnit 4 test rule is present to indicate if test should be run if `RUN_LONG_INTEGRATION_TESTS` environment or system property is set to `true`. +The `@LongRunningTest` conditional annotation is present to indicate if test should be run if `RUN_LONG_INTEGRATION_TESTS` environment or system property is set to `true`. Otherwise, it is skipped. -For the same reason since version 5.1, a `@LongRunningTest` conditional annotation is provided for JUnit 5 tests. [[hamcrest-and-mockito-matchers]] === Hamcrest and Mockito Matchers @@ -231,7 +229,7 @@ After test is performed you can restore the state of endpoint beans to the real [source,java] ---- -@After +@AfterEach public void tearDown() { this.mockIntegrationContext.resetBeans(); } diff --git a/src/reference/antora/modules/ROOT/pages/whats-new.adoc b/src/reference/antora/modules/ROOT/pages/whats-new.adoc index 8c646414e7..01ac532be5 100644 --- a/src/reference/antora/modules/ROOT/pages/whats-new.adoc +++ b/src/reference/antora/modules/ROOT/pages/whats-new.adoc @@ -17,6 +17,8 @@ Java 17 is still baseline, but Java 24 is supported. [[x7.0-general]] == General Changes +Junit 4 Based Support Components are deprecated. + [[x7.0-new-components]] == New Components