Skip to content

Commit 42845f0

Browse files
authored
Convert (S)FTP Tests to JUnit5
* Fix SftpTestServer for latest RemoteFileTestSupport changes.
1 parent bc84d47 commit 42845f0

File tree

42 files changed

+265
-275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+265
-275
lines changed

spring-integration-file/src/test/java/org/springframework/integration/file/remote/RemoteFileTestSupport.java

Lines changed: 67 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,15 +19,14 @@
1919
import java.io.File;
2020
import java.io.FileOutputStream;
2121
import java.io.IOException;
22+
import java.nio.file.Path;
2223
import java.util.Arrays;
2324

2425
import org.apache.commons.logging.Log;
2526
import org.apache.commons.logging.LogFactory;
26-
import org.junit.Before;
27-
import org.junit.ClassRule;
28-
import org.junit.Rule;
29-
import org.junit.rules.TemporaryFolder;
30-
import org.junit.rules.TestName;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.TestInfo;
29+
import org.junit.jupiter.api.io.TempDir;
3130

3231
/**
3332
* Abstract base class for tests requiring remote file servers, e.g. (S)FTP.
@@ -42,14 +41,12 @@ public abstract class RemoteFileTestSupport {
4241

4342
protected static int port;
4443

45-
@ClassRule
46-
public static final TemporaryFolder remoteTemporaryFolder = new TemporaryFolder();
44+
@TempDir
45+
public static Path temporaryFolder;
4746

48-
@ClassRule
49-
public static final TemporaryFolder localTemporaryFolder = new TemporaryFolder();
47+
protected static File remoteTemporaryFolder;
5048

51-
@Rule
52-
public final TestName testName = new TestName();
49+
protected static File localTemporaryFolder;
5350

5451
protected volatile File sourceRemoteDirectory;
5552

@@ -89,42 +86,53 @@ public String getTargetLocalDirectoryName() {
8986
* <pre class="code">
9087
* $ tree remoteSource/
9188
* remoteSource/
92-
* ??? remoteSource1.txt - contains 'source1'
93-
* ??? remoteSource2.txt - contains 'source2'
94-
* ??? subRemoteSource
95-
* ??? subRemoteSource1.txt - contains 'subSource1'
89+
* |-- remoteSource1.txt - contains 'source1'
90+
* |-- remoteSource2.txt - contains 'source2'
91+
* |-- subRemoteSource
92+
* |-- subRemoteSource1.txt - contains 'subSource1'
9693
* remoteTarget/
9794
* $ tree localSource/
9895
* localSource/
99-
* ??? localSource1.txt - contains 'local1'
100-
* ??? localSource2.txt - contains 'local2'
101-
* ??? subLocalSource
102-
* ??? subLocalSource1.txt - contains 'subLocal1'
96+
* |-- localSource1.txt - contains 'local1'
97+
* |-- localSource2.txt - contains 'local2'
98+
* |-- subLocalSource
99+
* |-- subLocalSource1.txt - contains 'subLocal1'
103100
* localTarget/
104101
* </pre>
105102
*
106-
* The intent is tests retrieve from remoteSource and verify arrival in localTarget or send from localSource and verify
107-
* arrival in remoteTarget.
103+
* The intent is tests retrieve from remoteSource and verify arrival in localTarget or
104+
* send from localSource and verify arrival in remoteTarget.
108105
* <p>
109-
* Subclasses can change 'remote' in these names by overriding {@link #prefix()} or override this method completely to
110-
* create a different structure.
106+
* Subclasses can change 'remote' in these names by overriding {@link #prefix()} or
107+
* override this method completely to create a different structure.
111108
* <p>
112-
* While a single server exists for all tests, the directory structure is rebuilt for each test.
109+
* While a single server exists for all tests, the directory structure is rebuilt for
110+
* each test.
113111
* @throws IOException IO Exception.
114112
*/
115-
@Before
116-
public void setupFolders() throws IOException {
113+
@BeforeEach
114+
public void setupFolders(TestInfo info) throws IOException {
117115
String prefix = prefix();
118-
recursiveDelete(new File(remoteTemporaryFolder.getRoot(), prefix + "Source"));
119-
this.sourceRemoteDirectory = remoteTemporaryFolder.newFolder(prefix + "Source");
120-
recursiveDelete(new File(remoteTemporaryFolder.getRoot(), prefix + "Target"));
121-
this.targetRemoteDirectory = remoteTemporaryFolder.newFolder(prefix + "Target");
122-
recursiveDelete(new File(localTemporaryFolder.getRoot(), "localSource"));
123-
this.sourceLocalDirectory = localTemporaryFolder.newFolder("localSource");
124-
recursiveDelete(new File(localTemporaryFolder.getRoot(), "localTarget"));
125-
this.targetLocalDirectory = localTemporaryFolder.newFolder("localTarget");
126-
127-
File file = new File(this.sourceRemoteDirectory, " " + prefix + "Source1.txt");
116+
getRemoteTempFolder();
117+
getLocalTempFolder();
118+
File file = new File(remoteTemporaryFolder, prefix + "Source");
119+
recursiveDelete(file, info);
120+
this.sourceRemoteDirectory = new File(file.getAbsolutePath());
121+
this.sourceRemoteDirectory.mkdirs();
122+
file = new File(remoteTemporaryFolder, prefix + "Target");
123+
recursiveDelete(file, info);
124+
this.targetRemoteDirectory = new File(file.getAbsolutePath());
125+
this.targetRemoteDirectory.mkdirs();
126+
file = new File(localTemporaryFolder, "localSource");
127+
recursiveDelete(file, info);
128+
this.sourceLocalDirectory = new File(file.getAbsolutePath());
129+
this.sourceLocalDirectory.mkdirs();
130+
file = new File(localTemporaryFolder, "localTarget");
131+
recursiveDelete(file, info);
132+
this.targetLocalDirectory = new File(file.getAbsolutePath());
133+
this.targetLocalDirectory.mkdirs();
134+
135+
file = new File(this.sourceRemoteDirectory, " " + prefix + "Source1.txt");
128136
file.createNewFile();
129137
FileOutputStream fos = new FileOutputStream(file);
130138
fos.write("source1".getBytes());
@@ -161,31 +169,47 @@ public void setupFolders() throws IOException {
161169
fos.close();
162170
}
163171

172+
protected static File getRemoteTempFolder() {
173+
if (remoteTemporaryFolder == null) {
174+
remoteTemporaryFolder = new File(temporaryFolder.toFile().getAbsolutePath() + File.separator + "source");
175+
remoteTemporaryFolder.mkdirs();
176+
}
177+
return remoteTemporaryFolder;
178+
}
179+
180+
protected static File getLocalTempFolder() {
181+
if (localTemporaryFolder == null) {
182+
localTemporaryFolder = new File(temporaryFolder.toFile().getAbsolutePath() + File.separator + "local");
183+
localTemporaryFolder.mkdirs();
184+
}
185+
return localTemporaryFolder;
186+
}
187+
164188
private String camelCase(String prefix) {
165189
char[] chars = prefix.toCharArray();
166190
chars[0] &= 0xdf;
167191
return new String(chars);
168192
}
169193

170-
public void recursiveDelete(File file) {
194+
public void recursiveDelete(File file, TestInfo info) {
171195
if (file != null && file.exists()) {
172196
File[] files = file.listFiles();
173197
if (files != null) {
174198
for (File fyle : files) {
175-
logger.info("Deleting: " + fyle + " in " + testName.getMethodName());
199+
logger.info("Deleting: " + fyle + " in " + info.getDisplayName());
176200
if (fyle.isDirectory()) {
177-
recursiveDelete(fyle);
201+
recursiveDelete(fyle, info);
178202
}
179203
else {
180204
if (!fyle.delete()) {
181-
logger.error("Couldn't delete: " + fyle + " in " + testName.getMethodName());
205+
logger.error("Couldn't delete: " + fyle + " in " + info.getDisplayName());
182206
}
183207
}
184208
}
185209
}
186-
logger.info("Deleting: " + file + " in " + testName.getMethodName());
210+
logger.info("Deleting: " + file + " in " + info.getDisplayName());
187211
if (!file.delete()) {
188-
logger.error("Couldn't delete: " + file + " in " + testName.getMethodName());
212+
logger.error("Couldn't delete: " + file + " in " + info.getDisplayName());
189213
if (file.isDirectory()) {
190214
logger.error("Contents: " + Arrays.toString(file.listFiles()));
191215
}

spring-integration-ftp/src/test/java/org/springframework/integration/ftp/FtpMessageHistoryTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
import org.springframework.context.support.ClassPathXmlApplicationContext;
2424
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
@@ -30,6 +30,7 @@
3030
*
3131
*/
3232
public class FtpMessageHistoryTests {
33+
3334
@Test
3435
public void testMessageHistory() throws Exception {
3536
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("ftp-message-history-context.xml",
@@ -39,4 +40,5 @@ public void testMessageHistory() throws Exception {
3940
assertThat(adapter.getComponentType()).isEqualTo("ftp:inbound-channel-adapter");
4041
ac.close();
4142
}
43+
4244
}

spring-integration-ftp/src/test/java/org/springframework/integration/ftp/FtpParserInboundTests.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,9 +22,9 @@
2222
import java.io.File;
2323
import java.io.FileNotFoundException;
2424

25-
import org.junit.After;
26-
import org.junit.Before;
27-
import org.junit.Test;
25+
import org.junit.jupiter.api.AfterEach;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
2828

2929
import org.springframework.beans.BeansException;
3030
import org.springframework.beans.factory.BeanCreationException;
@@ -38,7 +38,8 @@
3838
*
3939
*/
4040
public class FtpParserInboundTests {
41-
@Before
41+
42+
@BeforeEach
4243
public void prepare() {
4344
new File("target/foo").delete();
4445
}
@@ -67,7 +68,7 @@ public void testLocalFilesAutoCreationFalse() throws Exception {
6768
}
6869
}
6970

70-
@After
71+
@AfterEach
7172
public void cleanUp() throws Exception {
7273
new File("target/foo").delete();
7374
}

spring-integration-ftp/src/test/java/org/springframework/integration/ftp/FtpTestSupport.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2019 the original author or authors.
2+
* Copyright 2015-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,8 +35,8 @@
3535
import org.apache.ftpserver.usermanager.impl.ConcurrentLoginPermission;
3636
import org.apache.ftpserver.usermanager.impl.TransferRatePermission;
3737
import org.apache.ftpserver.usermanager.impl.WritePermission;
38-
import org.junit.AfterClass;
39-
import org.junit.BeforeClass;
38+
import org.junit.jupiter.api.AfterAll;
39+
import org.junit.jupiter.api.BeforeAll;
4040

4141
import org.springframework.integration.file.remote.RemoteFileTestSupport;
4242
import org.springframework.integration.file.remote.session.CachingSessionFactory;
@@ -58,10 +58,10 @@ public class FtpTestSupport extends RemoteFileTestSupport {
5858

5959
private static volatile FtpServer server;
6060

61-
@BeforeClass
61+
@BeforeAll
6262
public static void createServer() throws Exception {
6363
FtpServerFactory serverFactory = new FtpServerFactory();
64-
serverFactory.setUserManager(new TestUserManager(remoteTemporaryFolder.getRoot().getAbsolutePath()));
64+
serverFactory.setUserManager(new TestUserManager(getRemoteTempFolder().getAbsolutePath()));
6565

6666
ListenerFactory factory = new ListenerFactory();
6767
factory.setPort(0);
@@ -78,7 +78,7 @@ public static void createServer() throws Exception {
7878
}
7979

8080

81-
@AfterClass
81+
@AfterAll
8282
public static void stopServer() throws Exception {
8383
server.stop();
8484
}

spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundChannelAdapterParserTests.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,8 +28,7 @@
2828
import java.util.concurrent.PriorityBlockingQueue;
2929
import java.util.concurrent.atomic.AtomicReference;
3030

31-
import org.junit.Test;
32-
import org.junit.runner.RunWith;
31+
import org.junit.jupiter.api.Test;
3332

3433
import org.springframework.beans.factory.FactoryBean;
3534
import org.springframework.beans.factory.annotation.Autowired;
@@ -52,8 +51,7 @@
5251
import org.springframework.integration.test.util.TestUtils;
5352
import org.springframework.messaging.MessageChannel;
5453
import org.springframework.test.annotation.DirtiesContext;
55-
import org.springframework.test.context.ContextConfiguration;
56-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
54+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
5755
import org.springframework.util.ReflectionUtils;
5856

5957
/**
@@ -64,8 +62,7 @@
6462
* @author Artem Bilan
6563
* @author Venil Noronha
6664
*/
67-
@ContextConfiguration
68-
@RunWith(SpringJUnit4ClassRunner.class)
65+
@SpringJUnitConfig
6966
@DirtiesContext
7067
public class FtpInboundChannelAdapterParserTests {
7168

spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpInboundOutboundSanitySample.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,8 +20,8 @@
2020

2121
import java.io.File;
2222

23-
import org.junit.Ignore;
24-
import org.junit.Test;
23+
import org.junit.jupiter.api.Disabled;
24+
import org.junit.jupiter.api.Test;
2525

2626
import org.springframework.context.support.ClassPathXmlApplicationContext;
2727
import org.springframework.messaging.MessageChannel;
@@ -36,7 +36,7 @@ public class FtpInboundOutboundSanitySample {
3636

3737

3838
@Test
39-
@Ignore
39+
@Disabled
4040
public void testFtpInboundChannelAdapter() throws Exception {
4141
File fileA = new File("local-test-dir/a.test");
4242
if (fileA.exists()) {
@@ -66,7 +66,7 @@ public void testFtpInboundChannelAdapter() throws Exception {
6666
}
6767

6868
@Test
69-
@Ignore
69+
@Disabled
7070
public void testFtpOutboundChannelAdapter() throws Exception {
7171
ClassPathXmlApplicationContext ac =
7272
new ClassPathXmlApplicationContext("FtpOutboundChannelAdapterSample-context.xml", this.getClass());

spring-integration-ftp/src/test/java/org/springframework/integration/ftp/config/FtpOutboundGatewayParserTests.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,8 +22,7 @@
2222
import java.util.Set;
2323
import java.util.concurrent.atomic.AtomicReference;
2424

25-
import org.junit.Test;
26-
import org.junit.runner.RunWith;
25+
import org.junit.jupiter.api.Test;
2726

2827
import org.springframework.beans.factory.annotation.Autowired;
2928
import org.springframework.expression.Expression;
@@ -45,8 +44,7 @@
4544
import org.springframework.messaging.Message;
4645
import org.springframework.messaging.support.GenericMessage;
4746
import org.springframework.test.annotation.DirtiesContext;
48-
import org.springframework.test.context.ContextConfiguration;
49-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
47+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
5048
import org.springframework.util.ReflectionUtils;
5149

5250
/**
@@ -57,8 +55,7 @@
5755
* @since 2.1
5856
*
5957
*/
60-
@ContextConfiguration
61-
@RunWith(SpringJUnit4ClassRunner.class)
58+
@SpringJUnitConfig
6259
@DirtiesContext
6360
public class FtpOutboundGatewayParserTests {
6461

0 commit comments

Comments
 (0)