Migrate few modules to Junit Jupiter
including: `spring-integration-amqp`, `spring-integration-file`, 'spring-integration-groovy' Signed-off-by: Jiandong Ma <jiandong.ma.cn@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,9 +18,9 @@ package org.springframework.integration.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
|
||||
@@ -44,8 +44,8 @@ public class AutoCreateDirectoryTests {
|
||||
|
||||
private static final String OUTBOUND_PATH = BASE_PATH + File.separator + "outbound";
|
||||
|
||||
@Before
|
||||
@After
|
||||
@BeforeEach
|
||||
@AfterEach
|
||||
public void clearDirectories() {
|
||||
File baseDir = new File(BASE_PATH);
|
||||
File inboundDir = new File(INBOUND_PATH);
|
||||
@@ -92,13 +92,14 @@ public class AutoCreateDirectoryTests {
|
||||
assertThat(new File(OUTBOUND_PATH).exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void autoCreateForOutboundDisabled() {
|
||||
FileWritingMessageHandler handler = new FileWritingMessageHandler(
|
||||
new File(OUTBOUND_PATH));
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.setAutoCreateDirectory(false);
|
||||
handler.afterPropertiesSet();
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(handler::afterPropertiesSet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
<int-file:inbound-channel-adapter id="pseudoTx"
|
||||
channel="input" auto-startup="false"
|
||||
directory="#{T (org.springframework.integration.file.FileInboundTransactionTests).tmpDir.root}/si-test1"
|
||||
directory="#{T (org.springframework.integration.file.FileInboundTransactionTests).tmpDir}/si-test1"
|
||||
use-watch-service="true"
|
||||
watch-events="CREATE,DELETE">
|
||||
<int:poller fixed-rate="500">
|
||||
@@ -34,7 +34,7 @@
|
||||
<int:channel id="txInput" />
|
||||
|
||||
<int-file:inbound-channel-adapter id="realTx" channel="txInput" auto-startup="false"
|
||||
directory="#{T (org.springframework.integration.file.FileInboundTransactionTests).tmpDir.root}/si-test2">
|
||||
directory="#{T (org.springframework.integration.file.FileInboundTransactionTests).tmpDir}/si-test2">
|
||||
<int:poller fixed-rate="500">
|
||||
<int:transactional transaction-manager="txManager" synchronization-factory="syncFactoryB"/>
|
||||
</int:poller>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,10 +20,8 @@ import java.io.File;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
@@ -35,8 +33,7 @@ import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
|
||||
@@ -52,13 +49,12 @@ import static org.mockito.Mockito.verify;
|
||||
* @since 2.2
|
||||
*
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class FileInboundTransactionTests {
|
||||
|
||||
@ClassRule
|
||||
public static TemporaryFolder tmpDir = new TemporaryFolder();
|
||||
@TempDir
|
||||
public static File tmpDir;
|
||||
|
||||
@Autowired
|
||||
private SourcePollingChannelAdapter pseudoTx;
|
||||
@@ -102,14 +98,14 @@ public class FileInboundTransactionTests {
|
||||
latch.countDown();
|
||||
});
|
||||
pseudoTx.start();
|
||||
File file = new File(tmpDir.getRoot(), "si-test1/foo");
|
||||
File file = new File(tmpDir, "si-test1/foo");
|
||||
file.createNewFile();
|
||||
Message<?> result = successChannel.receive(60000);
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getPayload()).isEqualTo(Boolean.TRUE);
|
||||
assertThat(file.delete()).isFalse();
|
||||
crash.set(true);
|
||||
file = new File(tmpDir.getRoot(), "si-test1/bar");
|
||||
file = new File(tmpDir, "si-test1/bar");
|
||||
file.createNewFile();
|
||||
result = failureChannel.receive(60000);
|
||||
assertThat(result).isNotNull();
|
||||
@@ -119,7 +115,7 @@ public class FileInboundTransactionTests {
|
||||
assertThat(transactionManager.getCommitted()).isFalse();
|
||||
assertThat(transactionManager.getRolledBack()).isFalse();
|
||||
|
||||
verify(fileListFilter).remove(new File(tmpDir.getRoot(), "si-test1/foo"));
|
||||
verify(fileListFilter).remove(new File(tmpDir, "si-test1/foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,7 +129,7 @@ public class FileInboundTransactionTests {
|
||||
latch.countDown();
|
||||
});
|
||||
realTx.start();
|
||||
File file = new File(tmpDir.getRoot(), "si-test2/baz");
|
||||
File file = new File(tmpDir, "si-test2/baz");
|
||||
file.createNewFile();
|
||||
Message<?> result = successChannel.receive(60000);
|
||||
assertThat(result).isNotNull();
|
||||
@@ -141,7 +137,7 @@ public class FileInboundTransactionTests {
|
||||
assertThat(file.delete()).isTrue();
|
||||
assertThat(transactionManager.getCommitted()).isTrue();
|
||||
crash.set(true);
|
||||
file = new File(tmpDir.getRoot(), "si-test2/qux");
|
||||
file = new File(tmpDir, "si-test2/qux");
|
||||
file.createNewFile();
|
||||
result = failureChannel.receive(60000);
|
||||
assertThat(result).isNotNull();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,16 +18,14 @@ package org.springframework.integration.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
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;
|
||||
|
||||
@@ -35,8 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Iwein Fuld
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class FileToChannelIntegrationTests {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,7 @@ import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@@ -28,6 +28,7 @@ import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.filters.RegexPatternFileListFilter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -80,9 +81,10 @@ public class PatternMatchingFileListFilterTests {
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
@Test
|
||||
public void invalidPatternSyntax() throws Throwable {
|
||||
new ClassPathXmlApplicationContext("invalidPatternMatchingFileListFilterTests.xml", this.getClass()).close();
|
||||
assertThatExceptionOfType(BeanCreationException.class)
|
||||
.isThrownBy(() -> new ClassPathXmlApplicationContext("invalidPatternMatchingFileListFilterTests.xml", this.getClass()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2022 the original author or authors.
|
||||
* Copyright 2017-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,10 +20,9 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.integration.file.filters.AcceptOnceFileListFilter;
|
||||
|
||||
@@ -49,15 +48,16 @@ public class RecursiveDirectoryScannerTests {
|
||||
|
||||
private File subSubLevelFile;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder recursivePath = new TemporaryFolder();
|
||||
@TempDir
|
||||
public File recursivePath;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws IOException {
|
||||
this.subFolder = this.recursivePath.newFolder("subFolder");
|
||||
this.subFolder = new File(this.recursivePath, "subFolder");
|
||||
this.subSubFolder = new File(this.subFolder, "subSubFolder");
|
||||
this.subSubFolder.mkdir();
|
||||
this.topLevelFile = this.recursivePath.newFile("file1");
|
||||
this.subSubFolder.mkdirs();
|
||||
this.topLevelFile = new File(this.recursivePath, "file1");
|
||||
this.topLevelFile.createNewFile();
|
||||
this.subLevelFile = new File(this.subFolder, "file2");
|
||||
this.subLevelFile.createNewFile();
|
||||
this.subSubLevelFile = new File(this.subSubFolder, "file3");
|
||||
@@ -68,7 +68,7 @@ public class RecursiveDirectoryScannerTests {
|
||||
public void shouldReturnAllFilesIncludingDirs() throws IOException {
|
||||
RecursiveDirectoryScanner scanner = new RecursiveDirectoryScanner();
|
||||
scanner.setFilter(new AcceptOnceFileListFilter<>());
|
||||
List<File> files = scanner.listFiles(this.recursivePath.getRoot());
|
||||
List<File> files = scanner.listFiles(this.recursivePath);
|
||||
assertThat(files.size()).isEqualTo(5);
|
||||
assertThat(files).contains(this.topLevelFile);
|
||||
assertThat(files).contains(this.subLevelFile);
|
||||
@@ -77,7 +77,7 @@ public class RecursiveDirectoryScannerTests {
|
||||
assertThat(files).contains(this.subSubFolder);
|
||||
File file = new File(this.subSubFolder, "file4");
|
||||
file.createNewFile();
|
||||
files = scanner.listFiles(this.recursivePath.getRoot());
|
||||
files = scanner.listFiles(this.recursivePath);
|
||||
assertThat(files.size()).isEqualTo(1);
|
||||
assertThat(files).contains(file);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,10 +18,9 @@ package org.springframework.integration.file.config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
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.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -29,7 +28,7 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.integration.file.FileWritingMessageHandler;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -37,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class AutoCreateDirectoryIntegrationTests {
|
||||
|
||||
@@ -48,7 +47,7 @@ public class AutoCreateDirectoryIntegrationTests {
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setupNonAutoCreatedDirectories() {
|
||||
new File(BASE_PATH).delete();
|
||||
new File(BASE_PATH + File.separator + "customInbound").mkdirs();
|
||||
@@ -56,7 +55,7 @@ public class AutoCreateDirectoryIntegrationTests {
|
||||
new File(BASE_PATH + File.separator + "customOutboundGateway").mkdirs();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void deleteBaseDirectory() {
|
||||
new File(BASE_PATH).delete();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,9 +20,9 @@ import java.io.ByteArrayInputStream;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.config.PropertiesFactoryBean;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
@@ -46,13 +46,13 @@ public class ChainElementsTests {
|
||||
|
||||
private Locale localeBeforeTest;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
localeBeforeTest = Locale.getDefault();
|
||||
Locale.setDefault(new Locale("en", "US"));
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
Locale.setDefault(localeBeforeTest);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,7 @@ import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.integration.file.filters.AbstractFileListFilter;
|
||||
@@ -31,6 +31,7 @@ import org.springframework.integration.file.filters.SimplePatternFileListFilter;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -39,13 +40,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class FileListFilterFactoryBeanTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void customFilterAndFilenamePatternAreMutuallyExclusive() throws Exception {
|
||||
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
|
||||
factory.setIgnoreHidden(false);
|
||||
factory.setFilter(new TestFilter());
|
||||
factory.setFilenamePattern("foo");
|
||||
factory.getObject();
|
||||
assertThatIllegalArgumentException().isThrownBy(factory::getObject);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -10,9 +10,7 @@
|
||||
|
||||
<int:message-history/>
|
||||
|
||||
<bean id="input" class="org.junit.rules.TemporaryFolder" init-method="create" destroy-method="delete"/>
|
||||
|
||||
<int-file:inbound-channel-adapter id="fileAdapter" directory="#{input.root}"
|
||||
<int-file:inbound-channel-adapter id="fileAdapter" directory="#{T (org.springframework.integration.file.config.FileMessageHistoryTests).tempFolder}"
|
||||
auto-startup="true"
|
||||
channel="outChannel"
|
||||
auto-create-directory="true">
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,14 +21,15 @@ import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -38,20 +39,22 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Gunnar Hillert
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
public class FileMessageHistoryTests {
|
||||
|
||||
@TempDir
|
||||
public static File tempFolder;
|
||||
|
||||
@Autowired
|
||||
PollableChannel outChannel;
|
||||
|
||||
@Test
|
||||
public void testMessageHistory() throws Exception {
|
||||
ClassPathXmlApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("file-message-history-context.xml", getClass());
|
||||
|
||||
TemporaryFolder input = context.getBean(TemporaryFolder.class);
|
||||
File file = input.newFile("FileMessageHistoryTest.txt");
|
||||
File file = new File(tempFolder, "FileMessageHistoryTest.txt");
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(file));
|
||||
out.write("hello");
|
||||
out.close();
|
||||
|
||||
PollableChannel outChannel = context.getBean("outChannel", PollableChannel.class);
|
||||
Message<?> message = outChannel.receive(10000);
|
||||
assertThat(message).isNotNull();
|
||||
MessageHistory history = MessageHistory.read(message);
|
||||
@@ -60,7 +63,6 @@ public class FileMessageHistoryTests {
|
||||
assertThat(componentHistoryRecord).isNotNull();
|
||||
assertThat(componentHistoryRecord.get("type")).isEqualTo("file:inbound-channel-adapter");
|
||||
|
||||
context.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,8 +23,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
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;
|
||||
@@ -42,8 +41,7 @@ import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
@@ -61,8 +59,7 @@ import static org.assertj.core.api.Assertions.fail;
|
||||
* @author Artem Bilan
|
||||
*
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class FileOutboundChannelAdapterParserTests {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
static-field="org.springframework.integration.file.config.FileOutboundGatewayParserTests.tempFolder"/>
|
||||
|
||||
<int-file:outbound-gateway id="ordered"
|
||||
request-channel="someChannel" reply-timeout="777" directory="#{temporaryFolder.root}"
|
||||
request-channel="someChannel" reply-timeout="777" directory="#{temporaryFolder}"
|
||||
auto-startup="false" order="777" filename-generator-expression="'foo.txt'"/>
|
||||
|
||||
<int-file:outbound-gateway id="gatewayWithDirectoryExpression"
|
||||
request-channel="someChannel" directory-expression="temporaryFolder.root"
|
||||
request-channel="someChannel" directory-expression="temporaryFolder"
|
||||
auto-startup="false" order="777" filename-generator-expression="'foo.txt'"
|
||||
requires-reply="false">
|
||||
<int-file:request-handler-advice-chain>
|
||||
@@ -33,32 +33,32 @@
|
||||
<int-file:outbound-gateway id="gatewayWithReplaceMode"
|
||||
request-channel="gatewayWithReplaceModeChannel"
|
||||
filename-generator-expression="'fileToAppend.txt'" mode="REPLACE"
|
||||
directory="#{temporaryFolder.root}" requires-reply="false"/>
|
||||
directory="#{temporaryFolder}" requires-reply="false"/>
|
||||
|
||||
<int-file:outbound-gateway id="gatewayWithAppendMode"
|
||||
request-channel="gatewayWithAppendModeChannel"
|
||||
filename-generator-expression="'fileToAppend.txt'" mode="APPEND"
|
||||
directory="#{temporaryFolder.root}"/>
|
||||
directory="#{temporaryFolder}"/>
|
||||
|
||||
<int-file:outbound-gateway id="gatewayWithFailMode"
|
||||
request-channel="gatewayWithFailModeChannel"
|
||||
filename-generator-expression="'fileToAppend.txt'" mode="FAIL"
|
||||
directory="#{temporaryFolder.root}"/>
|
||||
directory="#{temporaryFolder}"/>
|
||||
|
||||
<int-file:outbound-gateway id="gatewayWithIgnoreMode"
|
||||
request-channel="gatewayWithIgnoreModeChannel"
|
||||
filename-generator-expression="'fileToAppend.txt'" mode="IGNORE"
|
||||
directory="#{temporaryFolder.root}"/>
|
||||
directory="#{temporaryFolder}"/>
|
||||
|
||||
<int-file:outbound-gateway id="gatewayWithFailModeLowercase"
|
||||
request-channel="gatewayWithFailModeLowercaseChannel"
|
||||
filename-generator-expression="'fileToAppend.txt'" mode="fail"
|
||||
directory="#{temporaryFolder.root}"/>
|
||||
directory="#{temporaryFolder}"/>
|
||||
|
||||
<int-file:outbound-gateway id="gatewayWithAppendNewLine"
|
||||
request-channel="gatewayWithAppendNewLineChannel"
|
||||
filename-generator-expression="'fileToAppend.txt'"
|
||||
append-new-line="true"
|
||||
directory="#{temporaryFolder.root}"/>
|
||||
directory="#{temporaryFolder}"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,11 +18,9 @@ package org.springframework.integration.file.config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
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.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -40,7 +38,7 @@ import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
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.FileCopyUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -52,12 +50,12 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Artem Bilan
|
||||
* @author Tony Falabella
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class FileOutboundGatewayParserTests {
|
||||
|
||||
@ClassRule
|
||||
public static final TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
@TempDir
|
||||
public static File tempFolder;
|
||||
|
||||
@Autowired
|
||||
private EventDrivenConsumer ordered;
|
||||
@@ -89,9 +87,12 @@ public class FileOutboundGatewayParserTests {
|
||||
|
||||
private static volatile int adviceCalled;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
tempFolder.delete();
|
||||
File[] files = tempFolder.listFiles();
|
||||
for (File file : files) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,7 +121,7 @@ public class FileOutboundGatewayParserTests {
|
||||
FileWritingMessageHandler handler =
|
||||
TestUtils.getPropertyValue(gatewayWithDirectoryExpression, "handler", FileWritingMessageHandler.class);
|
||||
assertThat(TestUtils.getPropertyValue(handler, "destinationDirectoryExpression", Expression.class)
|
||||
.getExpressionString()).isEqualTo("temporaryFolder.root");
|
||||
.getExpressionString()).isEqualTo("temporaryFolder");
|
||||
handler.handleMessage(new GenericMessage<>("foo"));
|
||||
assertThat(adviceCalled).isEqualTo(1);
|
||||
}
|
||||
@@ -140,7 +141,7 @@ public class FileOutboundGatewayParserTests {
|
||||
messagingTemplate.setDefaultDestination(this.gatewayWithIgnoreModeChannel);
|
||||
|
||||
final String expectedFileContent = "Initial File Content:";
|
||||
final File testFile = new File(tempFolder.getRoot(), "fileToAppend.txt");
|
||||
final File testFile = new File(tempFolder, "fileToAppend.txt");
|
||||
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:"));
|
||||
|
||||
@@ -172,7 +173,7 @@ public class FileOutboundGatewayParserTests {
|
||||
|
||||
String expectedFileContent = "Initial File Content:";
|
||||
|
||||
File testFile = new File(tempFolder.getRoot(), "fileToAppend.txt");
|
||||
File testFile = new File(tempFolder, "fileToAppend.txt");
|
||||
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:"));
|
||||
|
||||
@@ -199,7 +200,7 @@ public class FileOutboundGatewayParserTests {
|
||||
|
||||
String expectedFileContent = "Initial File Content:";
|
||||
|
||||
File testFile = new File(tempFolder.getRoot(), "fileToAppend.txt");
|
||||
File testFile = new File(tempFolder, "fileToAppend.txt");
|
||||
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:"));
|
||||
|
||||
@@ -228,7 +229,7 @@ public class FileOutboundGatewayParserTests {
|
||||
|
||||
String expectedFileContent = "Initial File Content:String content:";
|
||||
|
||||
File testFile = new File(tempFolder.getRoot(), "fileToAppend.txt");
|
||||
File testFile = new File(tempFolder, "fileToAppend.txt");
|
||||
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:"));
|
||||
Message<?> m = messagingTemplate.sendAndReceive(new GenericMessage<>("String content:"));
|
||||
@@ -263,7 +264,7 @@ public class FileOutboundGatewayParserTests {
|
||||
|
||||
String expectedFileContent = "String content:";
|
||||
|
||||
File testFile = new File(tempFolder.getRoot(), "fileToAppend.txt");
|
||||
File testFile = new File(tempFolder, "fileToAppend.txt");
|
||||
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:"));
|
||||
Message<?> m = messagingTemplate.sendAndReceive(new GenericMessage<>("String content:"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2022 the original author or authors.
|
||||
* Copyright 2017-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,7 +22,7 @@ import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2022 the original author or authors.
|
||||
* Copyright 2017-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,7 @@ import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2022 the original author or authors.
|
||||
* Copyright 2017-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,9 +19,8 @@ package org.springframework.integration.file.filters;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -32,17 +31,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class FileSystemMarkerFilePresentFileListFilterTests {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
@TempDir
|
||||
public File folder;
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
FileSystemMarkerFilePresentFileListFilter filter = new FileSystemMarkerFilePresentFileListFilter(
|
||||
new SimplePatternFileListFilter("*.txt"));
|
||||
File foo = this.folder.newFile("foo.txt");
|
||||
File foo = new File(folder, "foo.txt");
|
||||
foo.createNewFile();
|
||||
assertThat(filter.filterFiles(new File[] {foo}).size()).isEqualTo(0);
|
||||
File complete = this.folder.newFile("foo.txt.complete");
|
||||
File complete = new File(folder, "foo.txt.complete");
|
||||
complete.createNewFile();
|
||||
List<File> filtered = filter.filterFiles(new File[] {foo, complete});
|
||||
assertThat(filtered.size()).isEqualTo(1);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,7 @@ package org.springframework.integration.file.filters;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2022 the original author or authors.
|
||||
* Copyright 2019-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,9 +19,8 @@ package org.springframework.integration.file.locking;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -31,12 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class FileChannelCacheTests {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temp = new TemporaryFolder();
|
||||
@TempDir
|
||||
public File temp;
|
||||
|
||||
@Test
|
||||
public void throwsExceptionWhenFileNotExists() throws IOException {
|
||||
File testFile = new File(temp.getRoot(), "test0");
|
||||
File testFile = new File(temp, "test0");
|
||||
assertThat(testFile.exists()).isFalse();
|
||||
assertThat(FileChannelCache.tryLockFor(testFile)).isNull();
|
||||
assertThat(testFile.exists()).isFalse();
|
||||
@@ -44,7 +43,7 @@ public class FileChannelCacheTests {
|
||||
|
||||
@Test
|
||||
public void fileLocked() throws IOException {
|
||||
File testFile = temp.newFile("test1");
|
||||
File testFile = new File(temp, "test1");
|
||||
testFile.createNewFile();
|
||||
assertThat(testFile.exists()).isTrue();
|
||||
assertThat(FileChannelCache.tryLockFor(testFile)).isNotNull();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,9 +18,8 @@ package org.springframework.integration.file.locking;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
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.annotation.Autowired;
|
||||
@@ -29,7 +28,7 @@ import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
|
||||
import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.integration.file.filters.CompositeFileListFilter;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -38,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Gunnar Hillert
|
||||
* @author Artme Bilan
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class FileLockingNamespaceTests {
|
||||
|
||||
@@ -54,7 +53,7 @@ public class FileLockingNamespaceTests {
|
||||
|
||||
FileReadingMessageSource customLockingSource;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void extractSources() {
|
||||
nioLockingSource = (FileReadingMessageSource) new DirectFieldAccessor(nioAdapter).getPropertyValue("source");
|
||||
customLockingSource =
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,17 +19,16 @@ package org.springframework.integration.file.locking;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.file.FileReadingMessageSource;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -37,13 +36,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Iwein Fuld
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class FileLockingWithMultipleSourcesIntegrationTests {
|
||||
|
||||
private static File workdir;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setupWorkDirectory() {
|
||||
workdir = new File(new File(System.getProperty("java.io.tmpdir")),
|
||||
FileLockingWithMultipleSourcesIntegrationTests.class.getSimpleName());
|
||||
@@ -62,7 +61,7 @@ public class FileLockingWithMultipleSourcesIntegrationTests {
|
||||
@Qualifier("fileSource2")
|
||||
private FileReadingMessageSource fileSource3;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void cleanoutWorkDir() {
|
||||
for (File file : workdir.listFiles()) {
|
||||
file.delete();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,9 +22,8 @@ import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
@@ -38,18 +37,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class NioFileLockerTests {
|
||||
|
||||
@TempDir
|
||||
private File workdir;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temp = new TemporaryFolder() {
|
||||
|
||||
@Override
|
||||
public void create() throws IOException {
|
||||
super.create();
|
||||
workdir = temp.newFolder(NioFileLockerTests.class.getSimpleName());
|
||||
}
|
||||
};
|
||||
|
||||
@Test
|
||||
public void fileListedByFirstFilter() throws Exception {
|
||||
NioFileLocker filter = new NioFileLocker();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,7 @@ import java.io.InputStream;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
@@ -38,6 +38,7 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
@@ -124,7 +125,7 @@ public class FileTransferringMessageHandlerTests {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public <F> void testEmptyTemporaryFileSuffixCannotBeNull() throws Exception {
|
||||
SessionFactory<F> sf = mock(SessionFactory.class);
|
||||
Session<F> session = mock(Session.class);
|
||||
@@ -132,8 +133,8 @@ public class FileTransferringMessageHandlerTests {
|
||||
FileTransferringMessageHandler<F> handler = new FileTransferringMessageHandler<F>(sf);
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.setRemoteDirectoryExpressionString("headers['path']");
|
||||
handler.setTemporaryFileSuffix(null);
|
||||
handler.onInit();
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> handler.setTemporaryFileSuffix(null));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -25,10 +25,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
@@ -57,9 +56,6 @@ public class FileTailingMessageProducerTests {
|
||||
|
||||
private static final String TAIL_OPTIONS_FOLLOW_NAME_ALL_LINES = "-F -n +0";
|
||||
|
||||
@Rule
|
||||
public TailRule tailRule = new TailRule(TAIL_OPTIONS_FOLLOW_NAME_ALL_LINES);
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private final String tmpDir = System.getProperty("java.io.tmpdir");
|
||||
@@ -68,14 +64,14 @@ public class FileTailingMessageProducerTests {
|
||||
|
||||
private FileTailingMessageProducerSupport adapter;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
File f = new File(tmpDir, "FileTailingMessageProducerTests");
|
||||
f.mkdir();
|
||||
this.testDir = f;
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
if (this.adapter != null) {
|
||||
adapter.stop();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,13 +21,23 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
* @since 3.0
|
||||
*
|
||||
*/
|
||||
@ExtendWith(TailCondition.class)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD})
|
||||
public @interface TailAvailable {
|
||||
|
||||
/**
|
||||
* The options for the 'tail' command.
|
||||
* @return the options.
|
||||
* @author Jiandong Ma
|
||||
* @since 6.5
|
||||
*/
|
||||
String options() default "";
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,8 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -30,12 +32,11 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestWatcher;
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runners.model.Statement;
|
||||
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
||||
import org.junit.jupiter.api.extension.ExecutionCondition;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.springframework.core.annotation.MergedAnnotations;
|
||||
|
||||
/**
|
||||
* Ignores tests annotated with {@link TailAvailable} if 'tail' with the requested options
|
||||
@@ -43,36 +44,40 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @author Jiandong Ma
|
||||
*
|
||||
* @since 3.0
|
||||
* @since 6.5
|
||||
*
|
||||
*/
|
||||
public class TailRule extends TestWatcher {
|
||||
public class TailCondition implements ExecutionCondition {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TailRule.class);
|
||||
private static final Log logger = LogFactory.getLog(TailCondition.class);
|
||||
|
||||
private static final String tmpDir = System.getProperty("java.io.tmpdir");
|
||||
|
||||
private final String commandToTest;
|
||||
private String commandToTest;
|
||||
|
||||
public TailRule(String optionsToTest) {
|
||||
private static final ConditionEvaluationResult ENABLED = ConditionEvaluationResult.enabled(
|
||||
"@TailAvailable is not present");
|
||||
|
||||
public void setOptionsToTest(String optionsToTest) {
|
||||
this.commandToTest = "tail " + optionsToTest + " ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Statement apply(Statement base, Description description) {
|
||||
if (description.getAnnotation(TailAvailable.class) != null) {
|
||||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
|
||||
Optional<AnnotatedElement> element = context.getElement();
|
||||
MergedAnnotations annotations = MergedAnnotations.from(element.get(),
|
||||
MergedAnnotations.SearchStrategy.TYPE_HIERARCHY);
|
||||
if (annotations.get(TailAvailable.class).isPresent()) {
|
||||
TailAvailable tail = annotations.get(TailAvailable.class).synthesize();
|
||||
setOptionsToTest(tail.options());
|
||||
if (!tailWorksOnThisMachine()) {
|
||||
return new Statement() {
|
||||
|
||||
@Override
|
||||
public void evaluate() {
|
||||
// skip
|
||||
}
|
||||
};
|
||||
return ConditionEvaluationResult.disabled(
|
||||
"Tests Ignored: 'Tail' command does not work on this platform");
|
||||
}
|
||||
}
|
||||
return super.apply(base, description);
|
||||
return ENABLED;
|
||||
}
|
||||
|
||||
private boolean tailWorksOnThisMachine() {
|
||||
@@ -127,15 +132,4 @@ public class TailRule extends TestWatcher {
|
||||
}
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
public static class TestRule {
|
||||
|
||||
@Test
|
||||
public void test1() {
|
||||
TailRule rule = new TailRule("-BLAH");
|
||||
assertThat(rule.tailWorksOnThisMachine()).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,9 +19,9 @@ package org.springframework.integration.file.transformer;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.integration.file.FileHeaders;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
@@ -46,7 +46,7 @@ public abstract class AbstractFilePayloadTransformerTests<T extends AbstractFile
|
||||
|
||||
File sourceFile;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUpCommonTestData() throws Exception {
|
||||
sourceFile = File.createTempFile("anyFile", ".txt");
|
||||
sourceFile.deleteOnExit();
|
||||
@@ -55,7 +55,7 @@ public abstract class AbstractFilePayloadTransformerTests<T extends AbstractFile
|
||||
message = MessageBuilder.withPayload(sourceFile).build();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDownCommonTestData() {
|
||||
if (sourceFile.exists()) {
|
||||
sourceFile.delete();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file.transformer;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
@@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class FileToByteArrayTransformerTests extends
|
||||
AbstractFilePayloadTransformerTests<FileToByteArrayTransformer> {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
transformer = new FileToByteArrayTransformer();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.integration.file.transformer;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
@@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class FileToStringTransformerTests extends
|
||||
AbstractFilePayloadTransformerTests<FileToStringTransformer> {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
transformer = new FileToStringTransformer();
|
||||
transformer.setCharset(DEFAULT_ENCODING);
|
||||
|
||||
Reference in New Issue
Block a user