diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/BoundRabbitChannelAdviceIntegrationTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/BoundRabbitChannelAdviceIntegrationTests.java index 4550cdb119..ef05439d75 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/BoundRabbitChannelAdviceIntegrationTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/BoundRabbitChannelAdviceIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2023 the original author or authors. + * Copyright 2018-2024 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. @@ -36,6 +36,7 @@ import org.springframework.integration.amqp.dsl.Amqp; import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.test.util.TestUtils; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -52,6 +53,7 @@ import static org.mockito.Mockito.spy; * */ @SpringJUnitConfig +@DirtiesContext @RabbitAvailable(queues = BoundRabbitChannelAdviceIntegrationTests.QUEUE) public class BoundRabbitChannelAdviceIntegrationTests { diff --git a/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests.java b/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests.java index d56cbf325b..49a64cfb01 100644 --- a/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests.java +++ b/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventInboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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,6 @@ import java.util.Set; import org.junit.jupiter.api.Test; -import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; @@ -36,7 +35,7 @@ import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; -import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; @@ -53,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 2.0 */ @SpringJUnitConfig -@ContextConfiguration +@DirtiesContext @TestExecutionListeners(DependencyInjectionTestExecutionListener.class) public class EventInboundChannelAdapterParserTests { @@ -73,44 +72,38 @@ public class EventInboundChannelAdapterParserTests { @Test public void validateEventParser() { Object adapter = context.getBean("eventAdapterSimple"); - assertThat(adapter).isNotNull(); - assertThat(adapter instanceof ApplicationEventListeningMessageProducer).isTrue(); - DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter); - assertThat(adapterAccessor.getPropertyValue("outputChannel")).isEqualTo(context.getBean("input")); - assertThat(adapterAccessor.getPropertyValue("errorChannel")).isSameAs(errorChannel); + assertThat(adapter).isInstanceOf(ApplicationEventListeningMessageProducer.class); + assertThat(TestUtils.getPropertyValue(adapter, "outputChannel")).isEqualTo(context.getBean("input")); + assertThat(TestUtils.getPropertyValue(adapter, "errorChannel")).isSameAs(errorChannel); } @Test @SuppressWarnings("unchecked") public void validateEventParserWithEventTypes() { Object adapter = context.getBean("eventAdapterFiltered"); - assertThat(adapter).isNotNull(); - assertThat(adapter instanceof ApplicationEventListeningMessageProducer).isTrue(); - DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter); - assertThat(adapterAccessor.getPropertyValue("outputChannel")).isEqualTo(context.getBean("inputFiltered")); - Set eventTypes = (Set) adapterAccessor.getPropertyValue("eventTypes"); - assertThat(eventTypes).isNotNull(); - assertThat(eventTypes.size() == 3).isTrue(); - assertThat(eventTypes.contains(ResolvableType.forClass(SampleEvent.class))).isTrue(); - assertThat(eventTypes.contains(ResolvableType.forClass(AnotherSampleEvent.class))).isTrue(); - assertThat(eventTypes.contains(ResolvableType.forClass(Date.class))).isTrue(); - assertThat(adapterAccessor.getPropertyValue("errorChannel")).isNull(); + assertThat(adapter).isInstanceOf(ApplicationEventListeningMessageProducer.class); + assertThat(TestUtils.getPropertyValue(adapter, "outputChannel")).isEqualTo(context.getBean("inputFiltered")); + Set eventTypes = TestUtils.getPropertyValue(adapter, "eventTypes", Set.class); + assertThat(eventTypes) + .hasSize(3) + .contains(ResolvableType.forClass(SampleEvent.class), + ResolvableType.forClass(AnotherSampleEvent.class), + ResolvableType.forClass(Date.class)); + assertThat(TestUtils.getPropertyValue(adapter, "errorChannel")).isNull(); } @Test @SuppressWarnings("unchecked") public void validateEventParserWithEventTypesAndPlaceholder() { Object adapter = context.getBean("eventAdapterFilteredPlaceHolder"); - assertThat(adapter).isNotNull(); - assertThat(adapter instanceof ApplicationEventListeningMessageProducer).isTrue(); - DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter); - assertThat(adapterAccessor.getPropertyValue("outputChannel")) + assertThat(adapter).isInstanceOf(ApplicationEventListeningMessageProducer.class); + assertThat(TestUtils.getPropertyValue(adapter, "outputChannel")) .isEqualTo(context.getBean("inputFilteredPlaceHolder")); - Set eventTypes = (Set) adapterAccessor.getPropertyValue("eventTypes"); - assertThat(eventTypes).isNotNull(); - assertThat(eventTypes.size() == 2).isTrue(); - assertThat(eventTypes.contains(ResolvableType.forClass(SampleEvent.class))).isTrue(); - assertThat(eventTypes.contains(ResolvableType.forClass(AnotherSampleEvent.class))).isTrue(); + Set eventTypes = TestUtils.getPropertyValue(adapter, "eventTypes", Set.class); + assertThat(eventTypes) + .hasSize(2) + .contains(ResolvableType.forClass(SampleEvent.class), ResolvableType.forClass(AnotherSampleEvent.class)); + } @Test @@ -132,9 +125,8 @@ public class EventInboundChannelAdapterParserTests { public void validatePayloadExpression() { Object adapter = context.getBean("eventAdapterSpel"); assertThat(adapter).isNotNull(); - assertThat(adapter instanceof ApplicationEventListeningMessageProducer).isTrue(); - DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter); - Expression expression = (Expression) adapterAccessor.getPropertyValue("payloadExpression"); + assertThat(adapter).isInstanceOf(ApplicationEventListeningMessageProducer.class); + Expression expression = TestUtils.getPropertyValue(adapter, "payloadExpression", Expression.class); assertThat(expression.getExpressionString()).isEqualTo("source + '-test'"); } diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyFilterTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyFilterTests.java index 9772408528..fecd81f156 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyFilterTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -38,6 +38,7 @@ import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessageHandlingException; import org.springframework.messaging.support.GenericMessage; import org.springframework.stereotype.Component; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -50,6 +51,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @since 2.0 */ @SpringJUnitConfig +@DirtiesContext public class GroovyFilterTests { @Autowired diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyHeaderEnricherTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyHeaderEnricherTests.java index b9efefb1b6..8e1e9f51dc 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyHeaderEnricherTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyHeaderEnricherTests.java @@ -18,8 +18,7 @@ package org.springframework.integration.groovy.config; import java.util.Map; -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.QueueChannel; @@ -29,8 +28,8 @@ import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.transformer.support.HeaderValueMessageProcessor; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -41,8 +40,8 @@ import static org.assertj.core.api.Assertions.assertThat; * * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class GroovyHeaderEnricherTests { @Autowired diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRefreshTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRefreshTests.java index 70564e63b5..729276f1ba 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRefreshTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRefreshTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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,16 +20,15 @@ import java.beans.PropertyEditorSupport; import java.io.ByteArrayInputStream; import java.io.InputStream; -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.core.io.AbstractResource; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.MessageChannel; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -39,8 +38,8 @@ import static org.assertj.core.api.Assertions.assertThat; * * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class GroovyRefreshTests { @Autowired @@ -70,7 +69,7 @@ public class GroovyRefreshTests { private int count = -1; - private String[] scripts = + private final String[] scripts = {"\"groovy-${binding.variables['payload']}-0\"", "\"groovy-${binding.variables['payload']}-1\""}; diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRouterTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRouterTests.java index 14d5ac4817..7fa5e91f62 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRouterTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyRouterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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.groovy.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; @@ -30,8 +29,8 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -41,8 +40,8 @@ import static org.assertj.core.api.Assertions.assertThat; * * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class GroovyRouterTests { @Autowired @@ -105,12 +104,12 @@ public class GroovyRouterTests { @Test public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() { - assertThat(this.groovyRouterMessageHandler instanceof MethodInvokingRouter).isTrue(); + assertThat(this.groovyRouterMessageHandler).isInstanceOf(MethodInvokingRouter.class); @SuppressWarnings("rawtypes") MessageProcessor messageProcessor = TestUtils.getPropertyValue(this.groovyRouterMessageHandler, "messageProcessor", MessageProcessor.class); //before it was MethodInvokingMessageProcessor - assertThat(messageProcessor instanceof GroovyScriptExecutingMessageProcessor).isTrue(); + assertThat(messageProcessor).isInstanceOf(GroovyScriptExecutingMessageProcessor.class); } } diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests.java index d821169c94..d6f81f0e96 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyServiceActivatorTests.java @@ -41,6 +41,7 @@ import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.ErrorMessage; import org.springframework.messaging.support.GenericMessage; import org.springframework.scripting.groovy.GroovyObjectCustomizer; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -55,6 +56,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @since 2.0 */ @SpringJUnitConfig +@DirtiesContext public class GroovyServiceActivatorTests { @Autowired diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovySplitterTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovySplitterTests.java index 7e2737d3d8..620bee6ea8 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovySplitterTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovySplitterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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,6 +29,7 @@ import org.springframework.integration.test.util.TestUtils; 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.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -39,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 2.0 */ @SpringJUnitConfig +@DirtiesContext public class GroovySplitterTests { @Autowired diff --git a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyTransformerTests.java b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyTransformerTests.java index 8ac0be6af1..7097e64693 100644 --- a/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyTransformerTests.java +++ b/spring-integration-groovy/src/test/java/org/springframework/integration/groovy/config/GroovyTransformerTests.java @@ -16,14 +16,12 @@ package org.springframework.integration.groovy.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; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor; -import org.springframework.integration.handler.MessageProcessor; import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.transformer.AbstractMessageProcessingTransformer; @@ -32,18 +30,19 @@ import org.springframework.integration.transformer.Transformer; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; /** * @author Mark Fisher * @author Artem Bilan + * * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class GroovyTransformerTests { @Autowired @@ -87,12 +86,12 @@ public class GroovyTransformerTests { @Test public void testInt2433VerifyRiddingOfMessageProcessorsWrapping() { assertThat(this.groovyTransformerMessageHandler instanceof MessageTransformingHandler).isTrue(); - Transformer transformer = TestUtils.getPropertyValue(this.groovyTransformerMessageHandler, "transformer", Transformer.class); - assertThat(transformer instanceof AbstractMessageProcessingTransformer).isTrue(); - @SuppressWarnings("rawtypes") - MessageProcessor messageProcessor = TestUtils.getPropertyValue(transformer, "messageProcessor", MessageProcessor.class); + Transformer transformer = + TestUtils.getPropertyValue(this.groovyTransformerMessageHandler, "transformer", Transformer.class); + assertThat(transformer).isInstanceOf(AbstractMessageProcessingTransformer.class); //before it was MethodInvokingMessageProcessor - assertThat(messageProcessor instanceof GroovyScriptExecutingMessageProcessor).isTrue(); + assertThat(TestUtils.getPropertyValue(transformer, "messageProcessor")) + .isInstanceOf(GroovyScriptExecutingMessageProcessor.class); } } diff --git a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Int3164Jsr223RefreshTests.java b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Int3164Jsr223RefreshTests.java index 20d5347b34..9cd23c43e9 100644 --- a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Int3164Jsr223RefreshTests.java +++ b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Int3164Jsr223RefreshTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2022 the original author or authors. + * Copyright 2013-2024 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,27 +19,27 @@ package org.springframework.integration.scripting.config.jsr223; import java.io.File; import java.io.IOException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.util.FileCopyUtils; import static org.assertj.core.api.Assertions.assertThat; /** * @author Artem Bilan + * * @since 3.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class Int3164Jsr223RefreshTests { private static File workDir; @@ -52,7 +52,7 @@ public class Int3164Jsr223RefreshTests { @Autowired private PollableChannel outputChannel; - @BeforeClass + @BeforeAll public static void start() throws IOException { String basePath = System.getProperty("java.io.tmpdir") + File.separator + "Int3164Jsr223RefreshTests"; workDir = new File(basePath); @@ -64,7 +64,7 @@ public class Int3164Jsr223RefreshTests { FileCopyUtils.copy("1".getBytes(), scriptFile); } - @AfterClass + @AfterAll public static void shutdown() { if (workDir != null && workDir.exists()) { for (File file : workDir.listFiles()) { diff --git a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223FilterTests.java b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223FilterTests.java index b35874fad6..14cab9f874 100644 --- a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223FilterTests.java +++ b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223FilterTests.java @@ -16,26 +16,27 @@ package org.springframework.integration.scripting.config.jsr223; -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.QueueChannel; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; /** * @author Mark Fisher * @author David Turanski + * @author Artem Bilan + * * @since 2.1 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class Jsr223FilterTests { @Autowired diff --git a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223HeaderEnricherTests.java b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223HeaderEnricherTests.java index 98540485e9..44a1064493 100644 --- a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223HeaderEnricherTests.java +++ b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223HeaderEnricherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.channel.QueueChannel; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.support.GenericMessage; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -35,6 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 2.1 */ @SpringJUnitConfig +@DirtiesContext public class Jsr223HeaderEnricherTests { @Autowired diff --git a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223RefreshTests.java b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223RefreshTests.java index 839ccb9912..e5f5c2470b 100644 --- a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223RefreshTests.java +++ b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223RefreshTests.java @@ -18,36 +18,36 @@ package org.springframework.integration.scripting.config.jsr223; import java.beans.PropertyEditorSupport; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; -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.core.io.AbstractResource; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.MessageChannel; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; /** * @author Mark Fisher * @author David Turanski + * @author Artem Bilan + * * @since 2.1 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class Jsr223RefreshTests { @Autowired private MessageChannel referencedScriptInput; @Test - public void referencedScript() throws Exception { + public void referencedScript() { QueueChannel replyChannel = new QueueChannel(); replyChannel.setBeanName("returnAddress"); this.referencedScriptInput.send(MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build()); @@ -87,12 +87,12 @@ public class Jsr223RefreshTests { } @Override - public long lastModified() throws IOException { + public long lastModified() { return -1; } @Override - public InputStream getInputStream() throws IOException { + public InputStream getInputStream() { if (++count > scripts.length - 1) { count = 0; } diff --git a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223ServiceActivatorTests.java b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223ServiceActivatorTests.java index bab6386472..acd19b2d6c 100644 --- a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223ServiceActivatorTests.java +++ b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223ServiceActivatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -30,6 +30,7 @@ import org.springframework.integration.scripting.ScriptVariableGenerator; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -45,6 +46,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @since 2.0 */ @SpringJUnitConfig +@DirtiesContext public class Jsr223ServiceActivatorTests { @Autowired diff --git a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223SplitterTests.java b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223SplitterTests.java index 177fc6c202..eb01848a1d 100644 --- a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223SplitterTests.java +++ b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223SplitterTests.java @@ -16,25 +16,26 @@ package org.springframework.integration.scripting.config.jsr223; -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.QueueChannel; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; /** * @author Mark Fisher + * @author Artem Bilan + * * @since 2.0 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class Jsr223SplitterTests { @Autowired diff --git a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223TransformerTests.java b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223TransformerTests.java index 2b7512404a..bc949bb39f 100644 --- a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223TransformerTests.java +++ b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/config/jsr223/Jsr223TransformerTests.java @@ -28,6 +28,7 @@ import org.springframework.messaging.Message; 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.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -39,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 2.0 */ @SpringJUnitConfig +@DirtiesContext public class Jsr223TransformerTests { @Autowired diff --git a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/jsr223/DeriveLanguageFromExtensionTests.java b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/jsr223/DeriveLanguageFromExtensionTests.java index a51b936431..079ed3dfcc 100644 --- a/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/jsr223/DeriveLanguageFromExtensionTests.java +++ b/spring-integration-scripting/src/test/java/org/springframework/integration/scripting/jsr223/DeriveLanguageFromExtensionTests.java @@ -31,6 +31,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.scripting.PolyglotScriptExecutor; import org.springframework.integration.scripting.ScriptExecutor; import org.springframework.integration.test.util.TestUtils; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -42,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * */ @SpringJUnitConfig +@DirtiesContext public class DeriveLanguageFromExtensionTests { @Autowired diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbParserInboundTests.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbParserInboundTests.java index 783d80fb39..5642a2b74f 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbParserInboundTests.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbParserInboundTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 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. @@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Markus Spann * @author Prafull Kumar Soni + * @author Artem Bilan * */ public class SmbParserInboundTests extends AbstractBaseTests { @@ -41,11 +42,13 @@ public class SmbParserInboundTests extends AbstractBaseTests { } @Test + @SuppressWarnings("try") public void testLocalFilesAutoCreationTrue() { assertFileNotExists(new File("test-temp/local-10")); - new ClassPathXmlApplicationContext(getApplicationContextXmlFile(), this.getClass()); - assertFileExists(new File("test-temp/local-10")); - assertFileNotExists(new File("test-temp/local-6")); + try (var ctx = new ClassPathXmlApplicationContext(getApplicationContextXmlFile(), getClass())) { + assertFileExists(new File("test-temp/local-10")); + assertFileNotExists(new File("test-temp/local-6")); + } } @Test diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParserTests.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParserTests.java index be03eb8e51..aac75bf530 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParserTests.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParserTests.java @@ -37,6 +37,7 @@ import org.springframework.integration.smb.inbound.SmbInboundFileSynchronizingMe import org.springframework.integration.smb.session.SmbSession; import org.springframework.integration.smb.session.SmbSessionFactory; import org.springframework.integration.test.util.TestUtils; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -51,12 +52,14 @@ import static org.mockito.Mockito.when; * @author Gregory Bragg */ @SpringJUnitConfig +@DirtiesContext public class SmbInboundChannelAdapterParserTests { @Autowired ApplicationContext applicationContext; @Test + @SuppressWarnings("unchecked") public void testSmbInboundChannelAdapterComplete() { final SourcePollingChannelAdapter adapter = @@ -76,7 +79,7 @@ public class SmbInboundChannelAdapterParserTests { assertThat(".working.tmp").isEqualTo(TestUtils.getPropertyValue(fisync, "temporaryFileSuffix", String.class)); String remoteFileSeparator = (String) TestUtils.getPropertyValue(fisync, "remoteFileSeparator"); assertThat(remoteFileSeparator).isNotNull(); - assertThat("").isEqualTo(remoteFileSeparator); + assertThat(remoteFileSeparator).isEqualTo(""); FileListFilter filter = TestUtils.getPropertyValue(fisync, "filter", FileListFilter.class); assertThat(filter).isNotNull(); assertThat(filter).isInstanceOf(CompositeFileListFilter.class); @@ -86,11 +89,12 @@ public class SmbInboundChannelAdapterParserTests { assertThat(filtersIterator.next()).isInstanceOf(SmbSimplePatternFileListFilter.class); assertThat(filtersIterator.next()).isInstanceOf(SmbPersistentAcceptOnceFileListFilter.class); Object sessionFactory = TestUtils.getPropertyValue(fisync, "remoteFileTemplate.sessionFactory"); - assertThat(SmbSessionFactory.class.isAssignableFrom(sessionFactory.getClass())).isTrue(); + assertThat(sessionFactory).isInstanceOf(SmbSessionFactory.class); FileListFilter acceptAllFilter = this.applicationContext.getBean("acceptAllFilter", FileListFilter.class); - assertThat(TestUtils.getPropertyValue(inbound, "fileSource.scanner.filter.fileFilters", Collection.class) - .contains(acceptAllFilter)).isTrue(); + + assertThat(TestUtils.getPropertyValue(inbound, "fileSource.scanner.filter.fileFilters", Collection.class)) + .contains(acceptAllFilter); } @Test @@ -104,7 +108,7 @@ public class SmbInboundChannelAdapterParserTests { TestUtils.getPropertyValue(adapter, "source.synchronizer", SmbInboundFileSynchronizer.class); String remoteFileSeparator = (String) TestUtils.getPropertyValue(fisync, "remoteFileSeparator"); assertThat(remoteFileSeparator).isNotNull(); - assertThat("/").isEqualTo(remoteFileSeparator); + assertThat(remoteFileSeparator).isEqualTo("/"); } @Test diff --git a/spring-integration-stream/src/test/java/org/springframework/integration/stream/config/ConsoleOutboundChannelAdapterParserTests.java b/spring-integration-stream/src/test/java/org/springframework/integration/stream/config/ConsoleOutboundChannelAdapterParserTests.java index 13cd4690e7..5549aff442 100644 --- a/spring-integration-stream/src/test/java/org/springframework/integration/stream/config/ConsoleOutboundChannelAdapterParserTests.java +++ b/spring-integration-stream/src/test/java/org/springframework/integration/stream/config/ConsoleOutboundChannelAdapterParserTests.java @@ -22,10 +22,10 @@ import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.io.Writer; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.beans.DirectFieldAccessor; @@ -39,10 +39,11 @@ import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -53,8 +54,8 @@ import static org.mockito.Mockito.verify; * @author Artem Bilan */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig +@DirtiesContext public class ConsoleOutboundChannelAdapterParserTests { @Autowired @@ -82,7 +83,8 @@ public class ConsoleOutboundChannelAdapterParserTests { @Test public void stdoutAdapterWithDefaultCharset() throws IOException { - BufferedWriter bufferedWriter = TestUtils.getPropertyValue(this.stdoutAdapterWithDefaultCharsetHandler, "writer", BufferedWriter.class); + BufferedWriter bufferedWriter = + TestUtils.getPropertyValue(this.stdoutAdapterWithDefaultCharsetHandler, "writer", BufferedWriter.class); Writer writer = TestUtils.getPropertyValue(bufferedWriter, "out", Writer.class); assertThat(writer.getClass()).isEqualTo(OutputStreamWriter.class); Charset writerCharset = Charset.forName(((OutputStreamWriter) writer).getEncoding()); @@ -96,7 +98,7 @@ public class ConsoleOutboundChannelAdapterParserTests { DirectFieldAccessor dfa = new DirectFieldAccessor(this.stdoutAdapterWithDefaultCharsetHandler); dfa.setPropertyValue("writer", bufferedWriter); - this.stdoutAdapterWithDefaultCharsetHandler.handleMessage(new GenericMessage("foo")); + this.stdoutAdapterWithDefaultCharsetHandler.handleMessage(new GenericMessage<>("foo")); verify(bufferedWriter, times(1)).write(eq("foo")); assertThat(TestUtils.getPropertyValue(this.stdoutAdapterWithDefaultCharsetHandler, "order")).isEqualTo(23); @@ -104,11 +106,12 @@ public class ConsoleOutboundChannelAdapterParserTests { @Test public void stdoutAdapterWithProvidedCharset() throws IOException { - BufferedWriter bufferedWriter = TestUtils.getPropertyValue(this.stdoutAdapterWithProvidedCharsetHandler, "writer", BufferedWriter.class); + BufferedWriter bufferedWriter = + TestUtils.getPropertyValue(this.stdoutAdapterWithProvidedCharsetHandler, "writer", BufferedWriter.class); Writer writer = TestUtils.getPropertyValue(bufferedWriter, "out", Writer.class); assertThat(writer.getClass()).isEqualTo(OutputStreamWriter.class); Charset writerCharset = Charset.forName(((OutputStreamWriter) writer).getEncoding()); - assertThat(writerCharset).isEqualTo(Charset.forName("UTF-8")); + assertThat(writerCharset).isEqualTo(StandardCharsets.UTF_8); Object lock = TestUtils.getPropertyValue(writer, "lock"); assertThat(lock).isEqualTo(System.out); @@ -118,28 +121,23 @@ public class ConsoleOutboundChannelAdapterParserTests { DirectFieldAccessor dfa = new DirectFieldAccessor(this.stdoutAdapterWithProvidedCharsetHandler); dfa.setPropertyValue("writer", bufferedWriter); - this.stdoutAdapterWithProvidedCharsetHandler.handleMessage(new GenericMessage("bar")); + this.stdoutAdapterWithProvidedCharsetHandler.handleMessage(new GenericMessage<>("bar")); verify(bufferedWriter, times(1)).write(eq("bar")); } @Test public void stdoutAdapterWithInvalidCharset() { - BeanCreationException beanCreationException = null; - try { - new ClassPathXmlApplicationContext("invalidConsoleOutboundChannelAdapterParserTests.xml", - ConsoleOutboundChannelAdapterParserTests.class).close(); - } - catch (BeanCreationException e) { - beanCreationException = e; - } - Throwable rootCause = beanCreationException.getRootCause(); - assertThat(rootCause.getClass()).isEqualTo(UnsupportedEncodingException.class); + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> new ClassPathXmlApplicationContext("invalidConsoleOutboundChannelAdapterParserTests.xml", + ConsoleOutboundChannelAdapterParserTests.class)) + .withRootCauseInstanceOf(UnsupportedEncodingException.class); } @Test public void stderrAdapter() throws IOException { - BufferedWriter bufferedWriter = TestUtils.getPropertyValue(this.stderrAdapterHandler, "writer", BufferedWriter.class); + BufferedWriter bufferedWriter = + TestUtils.getPropertyValue(this.stderrAdapterHandler, "writer", BufferedWriter.class); Writer writer = TestUtils.getPropertyValue(bufferedWriter, "out", Writer.class); assertThat(writer.getClass()).isEqualTo(OutputStreamWriter.class); Charset writerCharset = Charset.forName(((OutputStreamWriter) writer).getEncoding()); @@ -153,7 +151,7 @@ public class ConsoleOutboundChannelAdapterParserTests { DirectFieldAccessor dfa = new DirectFieldAccessor(this.stderrAdapterHandler); dfa.setPropertyValue("writer", bufferedWriter); - this.stderrAdapterHandler.handleMessage(new GenericMessage("bar")); + this.stderrAdapterHandler.handleMessage(new GenericMessage<>("bar")); verify(bufferedWriter, times(1)).write(eq("bar")); @@ -162,7 +160,8 @@ public class ConsoleOutboundChannelAdapterParserTests { @Test public void stdoutAdatperWithAppendNewLine() throws IOException { - BufferedWriter bufferedWriter = TestUtils.getPropertyValue(this.newlineAdapterHandler, "writer", BufferedWriter.class); + BufferedWriter bufferedWriter = + TestUtils.getPropertyValue(this.newlineAdapterHandler, "writer", BufferedWriter.class); Writer writer = TestUtils.getPropertyValue(bufferedWriter, "out", Writer.class); assertThat(writer.getClass()).isEqualTo(OutputStreamWriter.class); Charset writerCharset = Charset.forName(((OutputStreamWriter) writer).getEncoding()); @@ -176,7 +175,7 @@ public class ConsoleOutboundChannelAdapterParserTests { DirectFieldAccessor dfa = new DirectFieldAccessor(this.newlineAdapterHandler); dfa.setPropertyValue("writer", bufferedWriter); - this.newlineAdapterHandler.handleMessage(new GenericMessage("bar")); + this.newlineAdapterHandler.handleMessage(new GenericMessage<>("bar")); verify(bufferedWriter, times(1)).write(eq("bar")); verify(bufferedWriter, times(1)).newLine(); @@ -208,7 +207,7 @@ public class ConsoleOutboundChannelAdapterParserTests { DirectFieldAccessor dfa = new DirectFieldAccessor(stdoutHandler); dfa.setPropertyValue("writer", bufferedWriter); - this.stdoutInsideNestedChain.send(new GenericMessage("foo")); + this.stdoutInsideNestedChain.send(new GenericMessage<>("foo")); verify(bufferedWriter, times(1)).write(eq("foobar")); } diff --git a/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/config/SyslogReceivingChannelAdapterParserTests.java b/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/config/SyslogReceivingChannelAdapterParserTests.java index 08747605a3..f87a0f444a 100644 --- a/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/config/SyslogReceivingChannelAdapterParserTests.java +++ b/spring-integration-syslog/src/test/java/org/springframework/integration/syslog/config/SyslogReceivingChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +40,7 @@ import org.springframework.integration.syslog.inbound.UdpSyslogReceivingChannelA import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.PollableChannel; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.util.ReflectionUtils; @@ -54,6 +55,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * */ @SpringJUnitConfig +@DirtiesContext public class SyslogReceivingChannelAdapterParserTests { @Autowired diff --git a/spring-integration-test/src/test/java/org/springframework/integration/test/context/AbstractIntegrationTest.java b/spring-integration-test/src/test/java/org/springframework/integration/test/context/AbstractIntegrationTest.java index 466cef50b2..28ef93901e 100644 --- a/spring-integration-test/src/test/java/org/springframework/integration/test/context/AbstractIntegrationTest.java +++ b/spring-integration-test/src/test/java/org/springframework/integration/test/context/AbstractIntegrationTest.java @@ -22,6 +22,7 @@ import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.endpoint.AbstractEndpoint; import org.springframework.integration.endpoint.ReactiveMessageSourceProducer; import org.springframework.messaging.support.GenericMessage; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** @@ -29,11 +30,13 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; * to be inherited by concrete subclasses. * * @author Chris Bono + * @author Artem Bilan * * @since 6.2.10 */ @SpringJUnitConfig @SpringIntegrationTest(noAutoStartup = "*") +@DirtiesContext class AbstractIntegrationTest { @Configuration(proxyBeanMethods = false) diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/MarshallingWebServiceIntegrationTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/MarshallingWebServiceIntegrationTests.java index 5192abd3f4..fd905210f8 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/MarshallingWebServiceIntegrationTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/MarshallingWebServiceIntegrationTests.java @@ -38,6 +38,7 @@ import org.springframework.oxm.Marshaller; import org.springframework.oxm.MarshallingFailureException; import org.springframework.oxm.Unmarshaller; import org.springframework.oxm.XmlMappingException; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.ws.WebServiceMessage; import org.springframework.ws.context.MessageContext; @@ -54,6 +55,7 @@ import static org.mockito.Mockito.when; */ @SpringJUnitConfig +@DirtiesContext public class MarshallingWebServiceIntegrationTests { private static final String input = ""; diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests.java index 81c4eed34c..537ca0445d 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/UriVariableTests.java @@ -46,6 +46,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessageHandlingException; import org.springframework.messaging.MessagingException; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.ws.client.WebServiceClientException; import org.springframework.ws.client.WebServiceIOException; @@ -73,6 +74,7 @@ import static org.mockito.Mockito.doAnswer; * @since 2.1 */ @SpringJUnitConfig +@DirtiesContext public class UriVariableTests { @Autowired @@ -179,7 +181,6 @@ public class UriVariableTests { Mockito.verify(producer).setPriority(5); } - @Disabled("Until SF for for URL parser") @Test public void testInt2720EmailUriVariables() { final String testEmailTo = "user@example.com"; diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java index e7f12c8766..f9559e6410 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayParserTests.java @@ -42,6 +42,7 @@ import org.springframework.messaging.support.GenericMessage; import org.springframework.oxm.Marshaller; import org.springframework.oxm.Unmarshaller; import org.springframework.scheduling.support.PeriodicTrigger; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.web.util.DefaultUriBuilderFactory; import org.springframework.ws.WebServiceMessageFactory; @@ -70,6 +71,7 @@ import static org.mockito.Mockito.verify; * @author Artem Bilan */ @SpringJUnitConfig +@DirtiesContext public class WebServiceOutboundGatewayParserTests { private static volatile int adviceCalled; diff --git a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayWithHeaderMapperTests.java b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayWithHeaderMapperTests.java index c2e57fd2c5..260b3dfb76 100644 --- a/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayWithHeaderMapperTests.java +++ b/spring-integration-ws/src/test/java/org/springframework/integration/ws/config/WebServiceOutboundGatewayWithHeaderMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,7 @@ import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -48,7 +47,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.oxm.Unmarshaller; import org.springframework.oxm.XmlMappingException; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.util.xml.DomUtils; import org.springframework.ws.WebServiceMessage; import org.springframework.ws.WebServiceMessageFactory; @@ -69,26 +68,30 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gunnar Hillert * @author Artem Bilan */ -@RunWith(SpringRunner.class) +@SpringJUnitConfig @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public class WebServiceOutboundGatewayWithHeaderMapperTests { - private static String responseSoapMessage = " " + - " " + - " " + - " " + - " jane" + - " " + - ""; + private static final String responseSoapMessage = """ + + + + + jane + + + """; - private static String responseNonSoapMessage = " " + - "oleg"; + private static final String responseNonSoapMessage = """ + + oleg + """; @Autowired private ApplicationContext context; @Test - public void headerMapperParserTest() throws Exception { + public void headerMapperParserTest() { SimpleWebServiceOutboundGateway gateway = TestUtils.getPropertyValue(this.context.getBean("withHeaderMapper"), "handler", SimpleWebServiceOutboundGateway.class); @@ -152,7 +155,7 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests { Document document = docBuilder.parse(new ByteArrayInputStream("bill".getBytes())); DOMSource payload = new DOMSource(document); Message replyMessage = process(payload, "withHeaderMapper", "inputChannel", true); - assertThat(replyMessage.getPayload() instanceof DOMSource).isTrue(); + assertThat(replyMessage.getPayload()).isInstanceOf(DOMSource.class); assertThat(replyMessage.getHeaders().get("bar")).isEqualTo("bar"); assertThat(replyMessage.getHeaders().get("baz")).isNull(); } @@ -164,7 +167,7 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests { Document document = docBuilder.parse(new ByteArrayInputStream("bill".getBytes())); DOMSource payload = new DOMSource(document); Message replyMessage = process(payload, "withHeaderMapper", "inputChannel", false); - assertThat(replyMessage.getPayload() instanceof DOMSource).isTrue(); + assertThat(replyMessage.getPayload()).isInstanceOf(DOMSource.class); assertThat(this.extractStringResult(replyMessage).contains("oleg")).isTrue(); } @@ -174,7 +177,7 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests { DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document payload = docBuilder.parse(new ByteArrayInputStream("bill".getBytes())); Message replyMessage = process(payload, "withHeaderMapper", "inputChannel", true); - assertThat(replyMessage.getPayload() instanceof Document).isTrue(); + assertThat(replyMessage.getPayload()).isInstanceOf(Document.class); assertThat(replyMessage.getHeaders().get("bar")).isEqualTo("bar"); assertThat(replyMessage.getHeaders().get("baz")).isNull(); } @@ -185,7 +188,7 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests { DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); Document payload = docBuilder.parse(new ByteArrayInputStream("bill".getBytes())); Message replyMessage = process(payload, "withHeaderMapper", "inputChannel", false); - assertThat(replyMessage.getPayload() instanceof Document).isTrue(); + assertThat(replyMessage.getPayload()).isInstanceOf(Document.class); assertThat(this.extractStringResult(replyMessage).contains("oleg")).isTrue(); } @@ -198,13 +201,16 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests { assertThat(replyMessage.getHeaders().get("baz")).isNull(); } - private Message process(Object payload, String gatewayName, String channelName, final boolean soap) throws Exception { + private Message process(Object payload, String gatewayName, String channelName, final boolean soap) + throws Exception { + AbstractWebServiceOutboundGateway gateway = TestUtils.getPropertyValue(this.context.getBean(gatewayName), "handler", AbstractWebServiceOutboundGateway.class); if (!soap) { - WebServiceTemplate template = TestUtils.getPropertyValue(gateway, "webServiceTemplate", WebServiceTemplate.class); + WebServiceTemplate template = + TestUtils.getPropertyValue(gateway, "webServiceTemplate", WebServiceTemplate.class); template.setMessageFactory(new DomPoxMessageFactory()); } @@ -265,9 +271,13 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests { MessageChannel inputChannel = context.getBean(channelName, MessageChannel.class); Message message = - MessageBuilder.withPayload(payload). - setHeader("foo", "foo").setHeader("foobar", "foobar").setHeader("abaz", "abaz").setHeader("bar", "bar"). - setHeader(WebServiceHeaders.SOAP_ACTION, "someAction").build(); + MessageBuilder.withPayload(payload) + .setHeader("foo", "foo") + .setHeader("foobar", "foobar") + .setHeader("abaz", "abaz") + .setHeader("bar", "bar"). + setHeader(WebServiceHeaders.SOAP_ACTION, "someAction") + .build(); inputChannel.send(message); QueueChannel outputChannel = context.getBean("outputChannel", QueueChannel.class); return outputChannel.receive(0); diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/MarshallingTransformerParserTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/MarshallingTransformerParserTests.java index 6c5655bc91..6aedae3689 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/MarshallingTransformerParserTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/MarshallingTransformerParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -34,6 +34,7 @@ import org.springframework.messaging.Message; 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.junit.jupiter.SpringJUnitConfig; import org.springframework.util.MultiValueMap; import org.springframework.xml.transform.StringResult; @@ -47,6 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Artem Bilan */ @SpringJUnitConfig +@DirtiesContext public class MarshallingTransformerParserTests { @Autowired diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/UnmarshallingTransformerParserTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/UnmarshallingTransformerParserTests.java index 182320ef6b..fc013bc6e6 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/UnmarshallingTransformerParserTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/UnmarshallingTransformerParserTests.java @@ -34,6 +34,7 @@ import org.springframework.messaging.MessageChannel; 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.junit.jupiter.SpringJUnitConfig; import org.springframework.util.MultiValueMap; import org.springframework.xml.transform.StringSource; @@ -45,8 +46,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Jonas Partner * @author Mark Fisher * @author Gary Russell + * @author Artem Bilan */ @SpringJUnitConfig +@DirtiesContext public class UnmarshallingTransformerParserTests { @Autowired diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathMessageSplitterParserTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathMessageSplitterParserTests.java index 725961addd..ec35664dbc 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathMessageSplitterParserTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathMessageSplitterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.xml.util.XmlTestUtil; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.support.GenericMessage; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import static org.assertj.core.api.Assertions.assertThat; @@ -40,6 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Artem Bilan */ @ContextConfiguration +@DirtiesContext public class XPathMessageSplitterParserTests { private static final String channelDefinitions = """ @@ -89,6 +91,7 @@ public class XPathMessageSplitterParserTests { .autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); inputChannel.send(docMessage); assertThat(outputChannel.getQueueSize()).as("Wrong number of split messages ").isEqualTo(2); + ctx.close(); } @Test @@ -119,6 +122,7 @@ public class XPathMessageSplitterParserTests { .as("Splitter failed to create documents ").isInstanceOf(Document.class); assertThat(outputChannel.receive(1000).getPayload()) .as("Splitter failed to create documents ").isInstanceOf(Document.class); + ctx.close(); } @Test @@ -142,6 +146,7 @@ public class XPathMessageSplitterParserTests { fieldAccessor = new DirectFieldAccessor(handler); Object documentBuilderFactory = fieldAccessor.getPropertyValue("documentBuilderFactory"); assertThat(documentBuilderFactory).isInstanceOf(DocumentBuilderFactory.class); + ctx.close(); } @Test @@ -162,6 +167,7 @@ public class XPathMessageSplitterParserTests { fieldAccessor = new DirectFieldAccessor(handler); Object documentBuilderFactory = fieldAccessor.getPropertyValue("documentBuilderFactory"); assertThat(documentBuilderFactory).isInstanceOf(DocumentBuilderFactory.class); + ctx.close(); } } diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathRouterParserTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathRouterParserTests.java index e917119aba..7de6c07711 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathRouterParserTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XPathRouterParserTests.java @@ -41,6 +41,7 @@ import org.springframework.messaging.Message; 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.util.MultiValueMap; @@ -55,6 +56,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Artem Bilan */ @ContextConfiguration +@DirtiesContext public class XPathRouterParserTests { String channelConfig = """ diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XsltPayloadTransformerParserTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XsltPayloadTransformerParserTests.java index 37b130d7ef..00aff82167 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XsltPayloadTransformerParserTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/config/XsltPayloadTransformerParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -37,6 +37,7 @@ import org.springframework.messaging.Message; 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.junit.jupiter.SpringJUnitConfig; import org.springframework.util.MultiValueMap; import org.springframework.xml.transform.StringResult; @@ -51,6 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Artem Bilan */ @SpringJUnitConfig +@DirtiesContext public class XsltPayloadTransformerParserTests { private static final String doc = """ diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltTransformerTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltTransformerTests.java index 09a8906020..2d13bca6ee 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltTransformerTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/XsltTransformerTests.java @@ -31,6 +31,7 @@ import org.springframework.integration.support.MessageBuilder; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -42,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Artem Bilan */ @SpringJUnitConfig +@DirtiesContext public class XsltTransformerTests { private final String docAsString = """ @@ -73,9 +75,12 @@ public class XsltTransformerTests { TestUtils.locateComponentInHistory(history, "paramHeadersWithStartWildCharacter", 0); assertThat(componentHistoryRecord).isNotNull(); assertThat(componentHistoryRecord.get("type")).isEqualTo("xml:xslt-transformer"); - assertThat(resultMessage.getPayload().getClass()).as("Wrong payload type").isEqualTo(String.class); - assertThat(((String) resultMessage.getPayload()).contains("testParamValue")).isTrue(); - assertThat(((String) resultMessage.getPayload()).contains("FOO")).isFalse(); + assertThat(resultMessage.getPayload()) + .as("Wrong payload type") + .isInstanceOf(String.class) + .asString() + .contains("testParamValue") + .doesNotContain("FOO"); } @Test @@ -87,9 +92,11 @@ public class XsltTransformerTests { build(); input.send(message); Message resultMessage = output.receive(); - assertThat(resultMessage.getPayload().getClass()).as("Wrong payload type").isEqualTo(String.class); - assertThat(((String) resultMessage.getPayload()).contains("testParamValue")).isTrue(); - assertThat(((String) resultMessage.getPayload()).contains("FOO")).isTrue(); + assertThat(resultMessage.getPayload()) + .as("Wrong payload type") + .isInstanceOf(String.class) + .asString() + .contains("testParamValue", "FOO"); } @Test @@ -101,10 +108,11 @@ public class XsltTransformerTests { build(); input.send(message); Message resultMessage = output.receive(); - assertThat(resultMessage.getPayload().getClass()).as("Wrong payload type").isEqualTo(String.class); - assertThat(((String) resultMessage.getPayload()).contains("testParamValue")).isTrue(); - assertThat(((String) resultMessage.getPayload()).contains("FOO")).isTrue(); - assertThat(((String) resultMessage.getPayload()).contains("hello")).isTrue(); + assertThat(resultMessage.getPayload()) + .as("Wrong payload type") + .isInstanceOf(String.class) + .asString() + .contains("testParamValue", "FOO", "hello"); } @Test @@ -116,10 +124,11 @@ public class XsltTransformerTests { build(); input.send(message); Message resultMessage = output.receive(); - assertThat(resultMessage.getPayload().getClass()).as("Wrong payload type").isEqualTo(String.class); - assertThat(((String) resultMessage.getPayload()).contains("testParamValue")).isTrue(); - assertThat(((String) resultMessage.getPayload()).contains("FOO")).isTrue(); - assertThat(((String) resultMessage.getPayload()).contains("hello")).isTrue(); + assertThat(resultMessage.getPayload()) + .as("Wrong payload type") + .isInstanceOf(String.class) + .asString() + .contains("testParamValue", "FOO", "hello"); } @Test diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/jaxbmarshaling/JaxbMarshallingIntegrationTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/jaxbmarshaling/JaxbMarshallingIntegrationTests.java index 799d1a92f1..8c63c060d1 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/jaxbmarshaling/JaxbMarshallingIntegrationTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/transformer/jaxbmarshaling/JaxbMarshallingIntegrationTests.java @@ -35,6 +35,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.GenericMessage; import org.springframework.oxm.UnmarshallingFailureException; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.xml.transform.StringSource; @@ -46,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Artem Bilan */ @SpringJUnitConfig +@DirtiesContext public class JaxbMarshallingIntegrationTests { @Autowired diff --git a/spring-integration-xml/src/test/java/org/springframework/integration/xml/xpath/XPathTests.java b/spring-integration-xml/src/test/java/org/springframework/integration/xml/xpath/XPathTests.java index b5e05f506d..2d88d2debd 100644 --- a/spring-integration-xml/src/test/java/org/springframework/integration/xml/xpath/XPathTests.java +++ b/spring-integration-xml/src/test/java/org/springframework/integration/xml/xpath/XPathTests.java @@ -32,6 +32,7 @@ import org.springframework.messaging.MessageChannel; 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.junit.jupiter.SpringJUnitConfig; import org.springframework.xml.xpath.NodeMapper; @@ -46,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @since 3.0 */ @SpringJUnitConfig +@DirtiesContext public class XPathTests { private static final String XML = """ diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/ChatMessageOutboundChannelAdapterParserTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/ChatMessageOutboundChannelAdapterParserTests.java index 3b7fb098c9..fc6bbd4728 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/ChatMessageOutboundChannelAdapterParserTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/ChatMessageOutboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -39,6 +39,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.support.GenericMessage; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -54,6 +55,7 @@ import static org.mockito.Mockito.verify; * @author Florian Schmaus */ @SpringJUnitConfig +@DirtiesContext public class ChatMessageOutboundChannelAdapterParserTests { @Autowired @@ -72,20 +74,20 @@ public class ChatMessageOutboundChannelAdapterParserTests { Object pollingConsumer = context.getBean("withHeaderMapper"); QueueChannel channel = (QueueChannel) TestUtils.getPropertyValue(pollingConsumer, "inputChannel"); assertThat(channel.getComponentName()).isEqualTo("outboundPollingChannel"); - assertThat(pollingConsumer instanceof PollingConsumer).isTrue(); + assertThat(pollingConsumer).isInstanceOf(PollingConsumer.class); } @Test public void testEventConsumerWithNoChannel() { Object eventConsumer = context.getBean("outboundNoChannelAdapter"); - assertThat(eventConsumer instanceof SubscribableChannel).isTrue(); + assertThat(eventConsumer).isInstanceOf(SubscribableChannel.class); } @Test public void advised() { MessageHandler handler = TestUtils.getPropertyValue(context.getBean("advised"), "handler", MessageHandler.class); - handler.handleMessage(new GenericMessage("foo")); + handler.handleMessage(new GenericMessage<>("foo")); assertThat(adviceCalled).isEqualTo(1); } @@ -103,7 +105,7 @@ public class ChatMessageOutboundChannelAdapterParserTests { assertThat(requestHeaderMatcher.matchHeader("bar123")).isTrue(); assertThat(requestHeaderMatcher.matchHeader("biz")).isFalse(); assertThat(requestHeaderMatcher.matchHeader("else")).isFalse(); - assertThat(eventConsumer instanceof EventDrivenConsumer).isTrue(); + assertThat(eventConsumer).isInstanceOf(EventDrivenConsumer.class); MessageHandler outboundEventAdapterHandle = context.getBean("outboundEventAdapter.handler", MessageHandler.class); diff --git a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/PresenceOutboundChannelAdapterParserTests.java b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/PresenceOutboundChannelAdapterParserTests.java index 843ce6dea7..d1425dffcb 100644 --- a/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/PresenceOutboundChannelAdapterParserTests.java +++ b/spring-integration-xmpp/src/test/java/org/springframework/integration/xmpp/config/PresenceOutboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.support.GenericMessage; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -44,6 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Artem Bilan */ @SpringJUnitConfig +@DirtiesContext public class PresenceOutboundChannelAdapterParserTests { @Autowired @@ -74,7 +76,7 @@ public class PresenceOutboundChannelAdapterParserTests { Object eventConsumer = context.getBean("advised"); assertThat(eventConsumer instanceof EventDrivenConsumer).isTrue(); MessageHandler handler = TestUtils.getPropertyValue(eventConsumer, "handler", MessageHandler.class); - handler.handleMessage(new GenericMessage("foo")); + handler.handleMessage(new GenericMessage<>("foo")); assertThat(adviceCalled).isEqualTo(1); }