|
1 | 1 | /* |
2 | | - * Copyright 2013-2020 the original author or authors. |
| 2 | + * Copyright 2013-2021 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
35 | 35 | import java.util.concurrent.Executors; |
36 | 36 | import java.util.concurrent.TimeUnit; |
37 | 37 | import java.util.regex.Matcher; |
| 38 | +import java.util.stream.Collectors; |
38 | 39 |
|
39 | 40 | import org.apache.commons.io.FileUtils; |
40 | 41 | import org.junit.jupiter.api.BeforeEach; |
|
60 | 61 | import org.springframework.integration.sftp.server.SessionClosedEvent; |
61 | 62 | import org.springframework.integration.sftp.server.SessionOpenedEvent; |
62 | 63 | import org.springframework.integration.sftp.session.DefaultSftpSessionFactory; |
| 64 | +import org.springframework.integration.sftp.session.SftpFileInfo; |
63 | 65 | import org.springframework.integration.sftp.session.SftpRemoteFileTemplate; |
64 | 66 | import org.springframework.integration.support.MessageBuilder; |
65 | 67 | import org.springframework.integration.test.util.TestUtils; |
@@ -100,6 +102,15 @@ public class SftpServerOutboundTests extends SftpTestSupport { |
100 | 102 | @Autowired |
101 | 103 | private DirectChannel inboundMGetRecursive; |
102 | 104 |
|
| 105 | + @Autowired |
| 106 | + private DirectChannel inboundLSRecursive; |
| 107 | + |
| 108 | + @Autowired |
| 109 | + private DirectChannel inboundLSRecursiveALL; |
| 110 | + |
| 111 | + @Autowired |
| 112 | + private DirectChannel inboundLSRecursiveNoDirs; |
| 113 | + |
103 | 114 | @Autowired |
104 | 115 | private DirectChannel inboundMGetRecursiveFiltered; |
105 | 116 |
|
@@ -254,6 +265,63 @@ public void testInt3172LocalDirectoryExpressionMGETRecursive() throws IOExceptio |
254 | 265 | FileUtils.copyInputStreamToFile(new ByteArrayInputStream(localAsString.getBytes()), secondRemote); |
255 | 266 | } |
256 | 267 |
|
| 268 | + @Test |
| 269 | + @SuppressWarnings("unchecked") |
| 270 | + void testLSRecursive() throws IOException { |
| 271 | + String dir = "sftpSource/"; |
| 272 | + this.inboundLSRecursive.send(new GenericMessage<Object>(dir)); |
| 273 | + Message<?> result = this.output.receive(1000); |
| 274 | + assertThat(result).isNotNull(); |
| 275 | + List<SftpFileInfo> files = (List<SftpFileInfo>) result.getPayload(); |
| 276 | + assertThat(files).hasSize(4); |
| 277 | + assertThat(files.stream() |
| 278 | + .map(fi -> fi.getFilename()) |
| 279 | + .collect(Collectors.toList())).contains( |
| 280 | + " sftpSource1.txt", |
| 281 | + "sftpSource2.txt", |
| 282 | + "subSftpSource", |
| 283 | + "subSftpSource/subSftpSource1.txt"); |
| 284 | + } |
| 285 | + |
| 286 | + @Test |
| 287 | + @SuppressWarnings("unchecked") |
| 288 | + void testLSRecursiveALL() throws IOException { |
| 289 | + String dir = "sftpSource/"; |
| 290 | + this.inboundLSRecursiveALL.send(new GenericMessage<Object>(dir)); |
| 291 | + Message<?> result = this.output.receive(1000); |
| 292 | + assertThat(result).isNotNull(); |
| 293 | + List<SftpFileInfo> files = (List<SftpFileInfo>) result.getPayload(); |
| 294 | + assertThat(files).hasSize(8); |
| 295 | + assertThat(files.stream() |
| 296 | + .map(fi -> fi.getFilename()) |
| 297 | + .collect(Collectors.toList())).contains( |
| 298 | + " sftpSource1.txt", |
| 299 | + "sftpSource2.txt", |
| 300 | + "subSftpSource", |
| 301 | + "subSftpSource/subSftpSource1.txt", |
| 302 | + ".", |
| 303 | + "..", |
| 304 | + "subSftpSource/.", |
| 305 | + "subSftpSource/.."); |
| 306 | + } |
| 307 | + |
| 308 | + @Test |
| 309 | + @SuppressWarnings("unchecked") |
| 310 | + void testLSRecursiveNoDirs() throws IOException { |
| 311 | + String dir = "sftpSource/"; |
| 312 | + this.inboundLSRecursiveNoDirs.send(new GenericMessage<Object>(dir)); |
| 313 | + Message<?> result = this.output.receive(1000); |
| 314 | + assertThat(result).isNotNull(); |
| 315 | + List<SftpFileInfo> files = (List<SftpFileInfo>) result.getPayload(); |
| 316 | + assertThat(files).hasSize(3); |
| 317 | + assertThat(files.stream() |
| 318 | + .map(fi -> fi.getFilename()) |
| 319 | + .collect(Collectors.toList())).contains( |
| 320 | + " sftpSource1.txt", |
| 321 | + "sftpSource2.txt", |
| 322 | + "subSftpSource/subSftpSource1.txt"); |
| 323 | + } |
| 324 | + |
257 | 325 | private long setModifiedOnSource1() { |
258 | 326 | File firstRemote = new File(getSourceRemoteDirectory(), " sftpSource1.txt"); |
259 | 327 | firstRemote.setLastModified(System.currentTimeMillis() - 1_000_000); |
|
0 commit comments