diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests.java index 03b7c8cd91..b7cb53d1c4 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/OutboundGatewayTests.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. @@ -35,6 +35,7 @@ import org.springframework.integration.handler.MessageProcessor; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.util.ReflectionTestUtils; @@ -55,6 +56,7 @@ import static org.mockito.Mockito.when; * @since 2.1 */ @SpringJUnitConfig +@DirtiesContext public class OutboundGatewayTests { private static final ExpressionParser PARSER = new SpelExpressionParser(); diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/BoundRabbitChannelAdviceTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/BoundRabbitChannelAdviceTests.java index d179dff371..ff733a2032 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/BoundRabbitChannelAdviceTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/support/BoundRabbitChannelAdviceTests.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. @@ -33,6 +33,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.integration.amqp.dsl.Amqp; import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.dsl.IntegrationFlow; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; @@ -55,6 +56,7 @@ import static org.mockito.Mockito.verify; * */ @SpringJUnitConfig +@DirtiesContext public class BoundRabbitChannelAdviceTests { @Autowired diff --git a/spring-integration-cassandra/src/test/java/org/springframework/integration/cassandra/config/CassandraOutboundAdapterParserTests.java b/spring-integration-cassandra/src/test/java/org/springframework/integration/cassandra/config/CassandraOutboundAdapterParserTests.java index a0322565f0..78d6de09bd 100644 --- a/spring-integration-cassandra/src/test/java/org/springframework/integration/cassandra/config/CassandraOutboundAdapterParserTests.java +++ b/spring-integration-cassandra/src/test/java/org/springframework/integration/cassandra/config/CassandraOutboundAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 the original author or authors. + * Copyright 2022-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.context.ApplicationContext; import org.springframework.integration.cassandra.outbound.CassandraMessageHandler; 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; @@ -33,6 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 6.0 */ @SpringJUnitConfig +@DirtiesContext class CassandraOutboundAdapterParserTests { @Autowired diff --git a/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventOutboundChannelAdapterParserTests.java b/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventOutboundChannelAdapterParserTests.java index 629193b6d7..75c7e7d1e4 100644 --- a/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventOutboundChannelAdapterParserTests.java +++ b/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventOutboundChannelAdapterParserTests.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,7 +38,7 @@ import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.support.GenericMessage; -import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.event.ApplicationEvents; import org.springframework.test.context.event.RecordApplicationEvents; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; @@ -55,7 +55,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @SpringJUnitConfig @RecordApplicationEvents -@ContextConfiguration +@DirtiesContext public class EventOutboundChannelAdapterParserTests { @Autowired diff --git a/spring-integration-event/src/test/java/org/springframework/integration/event/inbound/ApplicationEventListeningMessageProducerTests.java b/spring-integration-event/src/test/java/org/springframework/integration/event/inbound/ApplicationEventListeningMessageProducerTests.java index 9baba507cb..93d09a75cb 100644 --- a/spring-integration-event/src/test/java/org/springframework/integration/event/inbound/ApplicationEventListeningMessageProducerTests.java +++ b/spring-integration-event/src/test/java/org/springframework/integration/event/inbound/ApplicationEventListeningMessageProducerTests.java @@ -76,6 +76,7 @@ public class ApplicationEventListeningMessageProducerTests { Message message3 = channel.receive(20); assertThat(message3).isNotNull(); assertThat(((ApplicationEvent) message3.getPayload()).getSource()).isEqualTo("event2"); + adapter.stop(); } @Test @@ -106,6 +107,7 @@ public class ApplicationEventListeningMessageProducerTests { adapter.setEventTypes(null, null); assertThat(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent1.class))).isTrue(); assertThat(adapter.supportsEventType(ResolvableType.forClass(TestApplicationEvent2.class))).isTrue(); + adapter.stop(); } @Test @@ -178,6 +180,7 @@ public class ApplicationEventListeningMessageProducerTests { Message message2 = channel.receive(20); assertThat(message2).isNotNull(); assertThat(message2.getPayload()).isEqualTo("test"); + adapter.stop(); } @Test @@ -192,6 +195,7 @@ public class ApplicationEventListeningMessageProducerTests { Message message2 = channel.receive(20); assertThat(message2).isNotNull(); assertThat(message2.getPayload()).isEqualTo("test"); + adapter.stop(); } @Test @@ -216,6 +220,7 @@ public class ApplicationEventListeningMessageProducerTests { adapter.setErrorChannel(null); assertThatExceptionOfType(MessageHandlingException.class) .isThrownBy(() -> adapter.onApplicationEvent(new TestApplicationEvent1())); + adapter.stop(); } @Test diff --git a/spring-integration-feed/src/test/java/org/springframework/integration/feed/inbound/FeedEntryMessageSourceTests.java b/spring-integration-feed/src/test/java/org/springframework/integration/feed/inbound/FeedEntryMessageSourceTests.java index 1727f1ae0e..75e1d3dd97 100644 --- a/spring-integration-feed/src/test/java/org/springframework/integration/feed/inbound/FeedEntryMessageSourceTests.java +++ b/spring-integration-feed/src/test/java/org/springframework/integration/feed/inbound/FeedEntryMessageSourceTests.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,6 +22,7 @@ import java.net.HttpURLConnection; import java.net.URL; import com.rometools.rome.feed.synd.SyndEntry; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -46,15 +47,24 @@ import static org.mockito.Mockito.mock; */ public class FeedEntryMessageSourceTests { + static File metadataStoreFile; + @BeforeEach public void prepare() { - File metadataStoreFile = new File(System.getProperty("java.io.tmpdir") + "/spring-integration/", + metadataStoreFile = new File(System.getProperty("java.io.tmpdir") + "/spring-integration/", "metadata-store.properties"); if (metadataStoreFile.exists()) { metadataStoreFile.delete(); } } + @AfterAll + static void tearDown() { + if (metadataStoreFile.exists()) { + metadataStoreFile.delete(); + } + } + @Test public void testFailureWhenNotInitialized() throws Exception { URL url = new ClassPathResource("org/springframework/integration/feed/sample.rss").getURL(); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundChannelAdapterInsideChainTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundChannelAdapterInsideChainTests.java index 413703e017..4a54c8cf23 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundChannelAdapterInsideChainTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundChannelAdapterInsideChainTests.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. @@ -28,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired; 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 org.springframework.util.FileCopyUtils; @@ -38,6 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell */ @SpringJUnitConfig +@DirtiesContext public class FileOutboundChannelAdapterInsideChainTests { static final String TEST_FILE_NAME = FileOutboundChannelAdapterInsideChainTests.class.getSimpleName(); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundGatewayIntegrationTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundGatewayIntegrationTests.java index 5054336009..d93dd154a9 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundGatewayIntegrationTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileOutboundGatewayIntegrationTests.java @@ -20,12 +20,10 @@ import java.io.File; import java.io.FileOutputStream; import java.util.List; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,8 +32,8 @@ 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 org.springframework.util.FileCopyUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -45,8 +43,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Mark Fisher * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class FileOutboundGatewayIntegrationTests { @Qualifier("copyInput") @@ -76,26 +74,10 @@ public class FileOutboundGatewayIntegrationTests { File sourceFile; + @TempDir static File workDir; - @BeforeClass - public static void setupClass() { - workDir = new File(System.getProperty("java.io.tmpdir"), "anyDir"); - workDir.mkdir(); - workDir.deleteOnExit(); - } - - @AfterClass - public static void cleanUp() { - if (workDir != null && workDir.exists()) { - for (File file : workDir.listFiles()) { - file.delete(); - } - } - workDir.delete(); - } - - @Before + @BeforeEach public void setUp() throws Exception { sourceFile = File.createTempFile("anyFile", ".txt"); sourceFile.deleteOnExit(); @@ -104,7 +86,7 @@ public class FileOutboundGatewayIntegrationTests { message = MessageBuilder.withPayload(sourceFile).build(); } - @After + @AfterEach public void tearDown() { sourceFile.delete(); } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceIntegrationTests-context.xml b/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceIntegrationTests-context.xml index 12380c2dad..4c7645eeb9 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceIntegrationTests-context.xml +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceIntegrationTests-context.xml @@ -7,7 +7,7 @@ diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceIntegrationTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceIntegrationTests.java index 58640fedc7..024b1527cf 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceIntegrationTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceIntegrationTests.java @@ -17,21 +17,20 @@ package org.springframework.integration.file; import java.io.File; +import java.io.IOException; import java.util.concurrent.CountDownLatch; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +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; import org.springframework.messaging.Message; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.Repeat; -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; @@ -40,71 +39,39 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * @author Artem Bilan */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig +@DirtiesContext public class FileReadingMessageSourceIntegrationTests { @Autowired FileReadingMessageSource pollableFileSource; - private static File inputDir; + @TempDir + public static File inputDir; - @AfterClass - public static void cleanUp() throws Throwable { - if (inputDir.exists()) { - inputDir.delete(); - } - } - - @BeforeClass - public static void setupInputDir() { - inputDir = new File(System.getProperty("java.io.tmpdir") + "/" - + FileReadingMessageSourceIntegrationTests.class.getSimpleName()); - inputDir.mkdir(); - clean(); - } - - @AfterClass - public static void tearDown() { - clean(); - inputDir.delete(); - } - - private static void clean() { - File[] files = inputDir.listFiles(); - for (File file : files) { - file.delete(); - } - } - - @Before - public void generateTestFiles() throws Exception { + @BeforeEach + public void generateTestFiles() throws IOException { File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000); File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000); File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000); } - @After - public void cleanupInputDir() throws Exception { + @AfterEach + public void cleanupInputDir() { File[] listFiles = inputDir.listFiles(); - for (int i = 0; i < listFiles.length; i++) { - listFiles[i].delete(); + for (File listFile : listFiles) { + listFile.delete(); } } - @AfterClass - public static void removeInputDir() throws Exception { - inputDir.delete(); - } - @Test - public void configured() throws Exception { + public void configured() { DirectFieldAccessor accessor = new DirectFieldAccessor(pollableFileSource); assertThat(accessor.getPropertyValue("directory")).isEqualTo(inputDir); } @Test - public void getFiles() throws Exception { + public void getFiles() { Message received1 = pollableFileSource.receive(); assertThat(received1).as("This should return the first message").isNotNull(); Message received2 = pollableFileSource.receive(); @@ -117,7 +84,7 @@ public class FileReadingMessageSourceIntegrationTests { } @Test - public void parallelRetrieval() throws Exception { + public void parallelRetrieval() { Message received1 = pollableFileSource.receive(); Message received2 = pollableFileSource.receive(); Message received3 = pollableFileSource.receive(); @@ -127,7 +94,7 @@ public class FileReadingMessageSourceIntegrationTests { } @Test - public void inputDirExhausted() throws Exception { + public void inputDirExhausted() { assertThat(pollableFileSource.receive()).isNotNull(); assertThat(pollableFileSource.receive()).isNotNull(); Message receive = pollableFileSource.receive(); @@ -141,7 +108,7 @@ public class FileReadingMessageSourceIntegrationTests { @Test @Repeat(5) - public void concurrentProcessing() throws Exception { + public void concurrentProcessing() { CountDownLatch go = new CountDownLatch(1); Runnable successfulConsumer = () -> { Message received = pollableFileSource.receive(); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourcePersistentFilterIntegrationTests-context.xml b/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourcePersistentFilterIntegrationTests-context.xml index c5acba44a7..a33feb87b7 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourcePersistentFilterIntegrationTests-context.xml +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourcePersistentFilterIntegrationTests-context.xml @@ -7,7 +7,7 @@ @@ -18,7 +18,7 @@ + value="#{T(org.springframework.integration.file.FileReadingMessageSourcePersistentFilterIntegrationTests).inputDir.path}"/> diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourcePersistentFilterIntegrationTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourcePersistentFilterIntegrationTests.java index 22f35e1b3a..9cc0bcff86 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourcePersistentFilterIntegrationTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/FileReadingMessageSourcePersistentFilterIntegrationTests.java @@ -18,86 +18,57 @@ package org.springframework.integration.file; import java.io.File; -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.AfterEach; +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.context.support.AbstractApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.Message; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; /** * @author Iwein Fuld * @author Gary Russell + * @author Artem Bilan */ +@SpringJUnitConfig +@DirtiesContext public class FileReadingMessageSourcePersistentFilterIntegrationTests { - AbstractApplicationContext context; - + @Autowired FileReadingMessageSource pollableFileSource; - private static File inputDir; + @TempDir + public static File inputDir; - @AfterClass - public static void cleanUp() throws Throwable { - if (inputDir.exists()) { - inputDir.delete(); - } - } - - @BeforeClass - public static void setupInputDir() { - inputDir = new File(System.getProperty("java.io.tmpdir") + "/" - + FileReadingMessageSourcePersistentFilterIntegrationTests.class.getSimpleName()); - inputDir.mkdir(); - } - - @Before + @BeforeEach public void generateTestFiles() throws Exception { File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000); File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000); File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000); - this.loadContextAndGetMessageSource(); } - private void loadContextAndGetMessageSource() { - this.context = new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-context.xml", - this.getClass()); - this.pollableFileSource = context.getBean(FileReadingMessageSource.class); - } - - @After - public void cleanoutInputDir() throws Exception { + @AfterEach + public void cleanupInputDir() { File[] listFiles = inputDir.listFiles(); - for (int i = 0; i < listFiles.length; i++) { - listFiles[i].delete(); + for (File listFile : listFiles) { + listFile.delete(); } } - @AfterClass - public static void removeInputDir() throws Exception { - inputDir.delete(); - File persistDir = new File(System.getProperty("java.io.tmpdir") + "/" - + FileReadingMessageSourcePersistentFilterIntegrationTests.class.getSimpleName() - + ".meta"); - File persist = new File(persistDir, "metadata-store.properties"); - persist.delete(); - persistDir.delete(); - } - @Test - public void configured() throws Exception { + public void configured() { DirectFieldAccessor accessor = new DirectFieldAccessor(this.pollableFileSource); assertThat(accessor.getPropertyValue("directory")).isEqualTo(inputDir); } @Test - public void getFiles() throws Exception { + public void getFiles() { Message received1 = this.pollableFileSource.receive(); assertThat(received1).as("This should return the first message").isNotNull(); Message received2 = this.pollableFileSource.receive(); @@ -107,12 +78,9 @@ public class FileReadingMessageSourcePersistentFilterIntegrationTests { assertThat(received2.getPayload()).as(received1 + " == " + received2).isNotSameAs(received1.getPayload()); assertThat(received3.getPayload()).as(received1 + " == " + received3).isNotSameAs(received1.getPayload()); assertThat(received3.getPayload()).as(received2 + " == " + received3).isNotSameAs(received2.getPayload()); - this.context.close(); - loadContextAndGetMessageSource(); Message received4 = this.pollableFileSource.receive(); assertThat(received4).isNull(); - this.context.close(); } } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithClasspathInPropertiesTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithClasspathInPropertiesTests.java index 85d218b109..aed07ba126 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithClasspathInPropertiesTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithClasspathInPropertiesTests.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,9 +20,8 @@ import java.io.File; import java.util.Iterator; import java.util.Set; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.BeanFactory; @@ -33,8 +32,8 @@ import org.springframework.integration.file.filters.CompositeFileListFilter; import org.springframework.integration.file.filters.ExpressionFileListFilter; import org.springframework.integration.file.filters.FileListFilter; import org.springframework.integration.test.util.TestUtils; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; @@ -42,8 +41,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Iwein Fuld * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringRunner.class) +@SpringJUnitConfig +@DirtiesContext public class FileInboundChannelAdapterWithClasspathInPropertiesTests { @Autowired @@ -54,7 +53,7 @@ public class FileInboundChannelAdapterWithClasspathInPropertiesTests { private DirectFieldAccessor accessor; - @Before + @BeforeEach public void init() { accessor = new DirectFieldAccessor(source); } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPatternParserTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPatternParserTests.java index 5872d2964f..4efd924ff3 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPatternParserTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPatternParserTests.java @@ -19,8 +19,7 @@ package org.springframework.integration.file.config; import java.io.File; import java.util.Set; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; @@ -33,17 +32,19 @@ import org.springframework.integration.file.filters.AcceptOnceFileListFilter; import org.springframework.integration.file.filters.CompositeFileListFilter; import org.springframework.integration.file.filters.FileListFilter; import org.springframework.integration.file.filters.SimplePatternFileListFilter; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +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; /** * @author Mark Fisher * @author Iwein Fuld + * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class FileInboundChannelAdapterWithPatternParserTests { @Autowired @@ -53,12 +54,8 @@ public class FileInboundChannelAdapterWithPatternParserTests { @Qualifier("adapterWithPattern.adapter") private AbstractEndpoint endpoint; - private DirectFieldAccessor accessor; - @Autowired - public void setSource(FileReadingMessageSource source) { - this.accessor = new DirectFieldAccessor(source); - } + FileReadingMessageSource source; @Test public void channelName() { @@ -75,35 +72,30 @@ public class FileInboundChannelAdapterWithPatternParserTests { @Test public void inputDirectory() { File expected = new File(System.getProperty("java.io.tmpdir")); - File actual = (File) accessor.getPropertyValue("directory"); + File actual = TestUtils.getPropertyValue(this.source, "directory", File.class); assertThat(actual).isEqualTo(expected); } @Test public void compositeFilterType() { - DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner")); - assertThat(scannerAccessor.getPropertyValue("filter") instanceof CompositeFileListFilter).isTrue(); + FileListFilter filter = TestUtils.getPropertyValue(this.source, "scanner.filter", FileListFilter.class); + assertThat(filter).isInstanceOf(CompositeFileListFilter.class); } @Test - @SuppressWarnings("unchecked") public void compositeFilterSetSize() { - DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner")); - Set> filters = (Set>) new DirectFieldAccessor( - scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters"); - assertThat(filters.size()).isEqualTo(2); + assertThat((Set) TestUtils.getPropertyValue(this.source, "scanner.filter.fileFilters")).hasSize(2); } @Test @SuppressWarnings("unchecked") public void acceptOnceFilter() { - DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner")); - Set> filters = (Set>) new DirectFieldAccessor( - scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters"); + var filters = (Set>) TestUtils.getPropertyValue(this.source, "scanner.filter.fileFilters"); boolean hasAcceptOnceFilter = false; for (FileListFilter filter : filters) { if (filter instanceof AcceptOnceFileListFilter) { hasAcceptOnceFilter = true; + break; } } assertThat(hasAcceptOnceFilter).as("expected AcceptOnceFileListFilter").isTrue(); @@ -112,9 +104,7 @@ public class FileInboundChannelAdapterWithPatternParserTests { @Test @SuppressWarnings("unchecked") public void patternFilter() { - DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner")); - Set> filters = (Set>) new DirectFieldAccessor( - scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters"); + var filters = (Set>) TestUtils.getPropertyValue(this.source, "scanner.filter.fileFilters"); String pattern = null; for (FileListFilter filter : filters) { if (filter instanceof SimplePatternFileListFilter) { @@ -122,7 +112,7 @@ public class FileInboundChannelAdapterWithPatternParserTests { } } assertThat(pattern).as("expected SimplePatternFileListFilterTest").isNotNull(); - assertThat(pattern.toString()).isEqualTo("*.txt"); + assertThat(pattern).isEqualTo("*.txt"); } } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPreventDuplicatesFlagTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPreventDuplicatesFlagTests.java index f8f4c54d76..a294e13a66 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPreventDuplicatesFlagTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithPreventDuplicatesFlagTests.java @@ -21,8 +21,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; @@ -33,8 +32,9 @@ import org.springframework.integration.file.filters.AcceptOnceFileListFilter; import org.springframework.integration.file.filters.CompositeFileListFilter; import org.springframework.integration.file.filters.FileListFilter; import org.springframework.integration.file.filters.SimplePatternFileListFilter; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +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,8 +42,8 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Mark Fisher * @author Gunnar Hillert */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class FileInboundChannelAdapterWithPreventDuplicatesFlagTests { @Autowired @@ -70,7 +70,7 @@ public class FileInboundChannelAdapterWithPreventDuplicatesFlagTests { } @Test - public void filterAndFalse() throws Exception { + public void filterAndFalse() { FileListFilter filter = this.extractFilter("filterAndFalse"); assertThat(filter instanceof CompositeFileListFilter).isFalse(); assertThat(filter).isSameAs(testFilter); @@ -78,7 +78,7 @@ public class FileInboundChannelAdapterWithPreventDuplicatesFlagTests { @Test @SuppressWarnings("unchecked") - public void patternAndNull() throws Exception { + public void patternAndNull() { FileListFilter filter = this.extractFilter("patternAndNull"); assertThat(filter instanceof CompositeFileListFilter).isTrue(); Collection> filters = (Collection>) @@ -90,7 +90,7 @@ public class FileInboundChannelAdapterWithPreventDuplicatesFlagTests { @Test @SuppressWarnings("unchecked") - public void patternAndTrue() throws Exception { + public void patternAndTrue() { FileListFilter filter = this.extractFilter("patternAndTrue"); assertThat(filter instanceof CompositeFileListFilter).isTrue(); Collection> filters = (Collection>) @@ -101,14 +101,14 @@ public class FileInboundChannelAdapterWithPreventDuplicatesFlagTests { } @Test - public void patternAndFalse() throws Exception { + public void patternAndFalse() { FileListFilter filter = this.extractFilter("patternAndFalse"); assertThat(filter instanceof CompositeFileListFilter).isFalse(); assertThat(filter).isInstanceOf(SimplePatternFileListFilter.class); } @Test - public void defaultAndNull() throws Exception { + public void defaultAndNull() { FileListFilter filter = this.extractFilter("defaultAndNull"); assertThat(filter).isNotNull(); assertThat(filter instanceof CompositeFileListFilter).isFalse(); @@ -121,7 +121,7 @@ public class FileInboundChannelAdapterWithPreventDuplicatesFlagTests { } @Test - public void defaultAndTrue() throws Exception { + public void defaultAndTrue() { FileListFilter filter = this.extractFilter("defaultAndTrue"); assertThat(filter instanceof CompositeFileListFilter).isFalse(); assertThat(filter instanceof AcceptOnceFileListFilter).isTrue(); @@ -132,7 +132,7 @@ public class FileInboundChannelAdapterWithPreventDuplicatesFlagTests { } @Test - public void defaultAndFalse() throws Exception { + public void defaultAndFalse() { FileListFilter filter = this.extractFilter("defaultAndFalse"); assertThat(filter).isNotNull(); assertThat(filter instanceof CompositeFileListFilter).isFalse(); @@ -145,13 +145,7 @@ public class FileInboundChannelAdapterWithPreventDuplicatesFlagTests { @SuppressWarnings("unchecked") private FileListFilter extractFilter(String beanName) { - return (FileListFilter) - new DirectFieldAccessor( - new DirectFieldAccessor( - new DirectFieldAccessor(context.getBean(beanName)) - .getPropertyValue("source")) - .getPropertyValue("scanner")) - .getPropertyValue("filter"); + return (FileListFilter) TestUtils.getPropertyValue(context.getBean(beanName), "source.scanner.filter"); } } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithQueueSizeTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithQueueSizeTests.java index 1649bd7e1e..78ada972c1 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithQueueSizeTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithQueueSizeTests.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. @@ -19,33 +19,30 @@ package org.springframework.integration.file.config; import java.io.File; import java.util.List; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.integration.file.FileReadingMessageSource; import org.springframework.integration.file.HeadDirectoryScanner; import org.springframework.integration.test.util.TestUtils; -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 Gunnar Hillert * @author Gary Russell + * @author Artem Bilan */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig +@DirtiesContext public class FileInboundChannelAdapterWithQueueSizeTests { - private static final String PATHNAME = System.getProperty("java.io.tmpdir") + "/" - + FileInboundChannelAdapterWithQueueSizeTests.class.getSimpleName(); - + @TempDir private static File inputDir; @Autowired @@ -56,27 +53,7 @@ public class FileInboundChannelAdapterWithQueueSizeTests { @Qualifier("inputDirPollerSimpleFilter.adapter.source") FileReadingMessageSource source2; - @BeforeClass - public static void setupInputDir() { - inputDir = new File(PATHNAME); - inputDir.mkdir(); - clean(); - } - - @AfterClass - public static void tearDown() { - clean(); - inputDir.delete(); - } - - private static void clean() { - File[] files = inputDir.listFiles(); - for (File file : files) { - file.delete(); - } - } - - @Before + @BeforeEach public void generateTestFiles() throws Exception { File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000); File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000); @@ -87,15 +64,15 @@ public class FileInboundChannelAdapterWithQueueSizeTests { public void queueSize() { HeadDirectoryScanner scanner1 = TestUtils.getPropertyValue(source1, "scanner", HeadDirectoryScanner.class); HeadDirectoryScanner scanner2 = TestUtils.getPropertyValue(source2, "scanner", HeadDirectoryScanner.class); - List files = scanner1.listFiles(new File(PATHNAME)); + List files = scanner1.listFiles(inputDir); assertThat(files.size()).isEqualTo(2); - files = scanner2.listFiles(new File(PATHNAME)); + files = scanner2.listFiles(inputDir); assertThat(files.size()).isEqualTo(2); files.get(0).delete(); files.get(1).delete(); - files = scanner1.listFiles(new File(PATHNAME)); + files = scanner1.listFiles(inputDir); assertThat(files.size()).isEqualTo(1); - files = scanner2.listFiles(new File(PATHNAME)); + files = scanner2.listFiles(inputDir); assertThat(files.size()).isEqualTo(1); } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithRegexPatternParserTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithRegexPatternParserTests.java index 2f77d46099..841cfaf2d9 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithRegexPatternParserTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterWithRegexPatternParserTests.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. @@ -19,17 +19,15 @@ package org.springframework.integration.file.config; import java.util.Set; import java.util.regex.Pattern; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; -import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.file.FileReadingMessageSource; -import org.springframework.integration.file.filters.CompositeFileListFilter; import org.springframework.integration.file.filters.FileListFilter; import org.springframework.integration.file.filters.RegexPatternFileListFilter; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +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; @@ -37,32 +35,26 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Mark Fisher * @author Iwein Fuld * @author Gunnar Hillert + * @author Artem Bilan * * @see org.springframework.integration.file.config.FileInboundChannelAdapterWithPatternParserTests */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class FileInboundChannelAdapterWithRegexPatternParserTests { - private DirectFieldAccessor accessor; - - @Autowired(required = true) - public void setSource(FileReadingMessageSource source) { - this.accessor = new DirectFieldAccessor(source); - } + @Autowired + FileReadingMessageSource source; @Test @SuppressWarnings("unchecked") public void regexFilter() { - DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner")); - Object extractedFilter = scannerAccessor.getPropertyValue("filter"); - assertThat(extractedFilter).isInstanceOf(CompositeFileListFilter.class); - Set> filters = (Set>) new DirectFieldAccessor( - extractedFilter).getPropertyValue("fileFilters"); + var filters = (Set>) TestUtils.getPropertyValue(this.source, "scanner.filter.fileFilters"); Pattern pattern = null; for (FileListFilter filter : filters) { if (filter instanceof RegexPatternFileListFilter) { - pattern = (Pattern) new DirectFieldAccessor(filter).getPropertyValue("pattern"); + pattern = TestUtils.getPropertyValue(filter, "pattern", Pattern.class); + break; } } assertThat(pattern).as("expected PatternMatchingFileListFilter").isNotNull(); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundAdaptersWithClasspathInPropertiesTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundAdaptersWithClasspathInPropertiesTests.java index 64a2b74dec..e41d8f3f9d 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundAdaptersWithClasspathInPropertiesTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileOutboundAdaptersWithClasspathInPropertiesTests.java @@ -18,17 +18,17 @@ package org.springframework.integration.file.config; import java.io.File; -import org.junit.Test; -import org.junit.runner.RunWith; +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.core.io.ClassPathResource; import org.springframework.expression.Expression; import org.springframework.integration.endpoint.EventDrivenConsumer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.integration.test.util.TestUtils; +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; @@ -36,11 +36,12 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Iwein Fuld * @author Mark Fisher * @author Gunnar Hillert + * @author Artem Bilan * * @since 1.0.3 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig +@DirtiesContext public class FileOutboundAdaptersWithClasspathInPropertiesTests { @Autowired @@ -53,11 +54,11 @@ public class FileOutboundAdaptersWithClasspathInPropertiesTests { @Test public void outboundChannelAdapter() throws Exception { - DirectFieldAccessor accessor = new DirectFieldAccessor( - new DirectFieldAccessor(adapter).getPropertyValue("handler")); + MessageHandler handler = adapter.getHandler(); File expected = new ClassPathResource("").getFile(); - Expression destinationDirectoryExpression = (Expression) accessor.getPropertyValue("destinationDirectoryExpression"); + var destinationDirectoryExpression = + TestUtils.getPropertyValue(handler, "destinationDirectoryExpression", Expression.class); File actual = new File(destinationDirectoryExpression.getExpressionString()); assertThat(actual).as("'destinationDirectory' should be set").isEqualTo(expected); @@ -65,11 +66,11 @@ public class FileOutboundAdaptersWithClasspathInPropertiesTests { @Test public void outboundGateway() throws Exception { - DirectFieldAccessor accessor = new DirectFieldAccessor( - new DirectFieldAccessor(gateway).getPropertyValue("handler")); + MessageHandler handler = gateway.getHandler(); File expected = new ClassPathResource("").getFile(); - Expression destinationDirectoryExpression = (Expression) accessor.getPropertyValue("destinationDirectoryExpression"); + var destinationDirectoryExpression = + TestUtils.getPropertyValue(handler, "destinationDirectoryExpression", Expression.class); File actual = new File(destinationDirectoryExpression.getExpressionString()); assertThat(actual).as("'destinationDirectory' should be set").isEqualTo(expected); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileSplitterParserTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileSplitterParserTests.java index ddc8912919..25d1b9ff67 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileSplitterParserTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileSplitterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-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,10 +16,9 @@ package org.springframework.integration.file.config; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; -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.endpoint.EventDrivenConsumer; @@ -27,8 +26,7 @@ import org.springframework.integration.file.splitter.FileSplitter; 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; @@ -39,8 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 4.2 * */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class FileSplitterParserTests { @@ -63,7 +60,7 @@ public class FileSplitterParserTests { assertThat(TestUtils.getPropertyValue(this.splitter, "markersJson", Boolean.class)).isTrue(); assertThat(TestUtils.getPropertyValue(this.splitter, "requiresReply", Boolean.class)).isTrue(); assertThat(TestUtils.getPropertyValue(this.splitter, "applySequence", Boolean.class)).isTrue(); - assertThat(TestUtils.getPropertyValue(this.splitter, "charset")).isEqualTo(Charset.forName("UTF-8")); + assertThat(TestUtils.getPropertyValue(this.splitter, "charset")).isEqualTo(StandardCharsets.UTF_8); assertThat(TestUtils.getPropertyValue(this.splitter, "messagingTemplate.sendTimeout")).isEqualTo(5L); assertThat(TestUtils.getPropertyValue(this.splitter, "firstLineHeaderName")).isEqualTo("foo"); assertThat(TestUtils.getPropertyValue(this.splitter, "discardChannelName")).isEqualTo("nullChannel"); diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java index eb342beb6f..bab92ed104 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.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,18 +16,14 @@ package org.springframework.integration.file.config; -import org.junit.Test; -import org.junit.runner.RunWith; +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.integration.endpoint.PollingConsumer; -import org.springframework.integration.file.transformer.FileToStringTransformer; -import org.springframework.integration.transformer.MessageTransformingHandler; +import org.springframework.integration.test.util.TestUtils; 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 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Gary Russell * @author Artem Bilan */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig @DirtiesContext public class FileToStringTransformerParserTests { @@ -47,14 +42,7 @@ public class FileToStringTransformerParserTests { @Test public void checkDeleteFilesValue() { - DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(endpoint); - MessageTransformingHandler handler = (MessageTransformingHandler) - endpointAccessor.getPropertyValue("handler"); - DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler); - FileToStringTransformer transformer = (FileToStringTransformer) - handlerAccessor.getPropertyValue("transformer"); - DirectFieldAccessor transformerAccessor = new DirectFieldAccessor(transformer); - assertThat(transformerAccessor.getPropertyValue("deleteFiles")).isEqualTo(Boolean.TRUE); + assertThat(TestUtils.getPropertyValue(this.endpoint, "handler.transformer.deleteFiles", Boolean.class)).isTrue(); } } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/InboundAdapterWithLockersTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/InboundAdapterWithLockersTests.java index 23ea4468bd..7dab9a62ba 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/InboundAdapterWithLockersTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/InboundAdapterWithLockersTests.java @@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.integration.file.locking.NioFileLocker; 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; @@ -33,6 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat; * */ @SpringJUnitConfig +@DirtiesContext public class InboundAdapterWithLockersTests { @Autowired diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/session/DelegatingSessionFactoryTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/session/DelegatingSessionFactoryTests.java index 4d4e902bc5..e6301bb8ad 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/session/DelegatingSessionFactoryTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/session/DelegatingSessionFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2022 the original author or authors. + * Copyright 2015-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.MessageChannel; import org.springframework.messaging.MessageHandler; 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; @@ -54,6 +55,7 @@ import static org.mockito.Mockito.verify; * */ @SpringJUnitConfig +@DirtiesContext public class DelegatingSessionFactoryTests { @Autowired