This JUnit 5 libary provides a way to create a sftp server that can be used for integration testing.
Add the dependency to gradle
testImplementation 'io.github.ricall.junit5-sftp:junit5-sftp:2.0.1'
Add the dependency to mvn pom.xml
<dependency>
<groupId>io.github.ricall.junit5-sftp</groupId>
<artifactId>junit5-sftp</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
public class TestEmbeddedSftpServer {
@RegisterExtension
public final EmbeddedSftpServer sftpServer = SftpServer.defaultSftpServer()
.withPort(3022)
.withUser("user", "pass")
.withResources(resourceAt("/tmp/data").fromClasspathResource("/data"))
.build();
@Test
public void verifySftpFilesCanBeDownloaded() {
// sftp server is running on sftp://user:pass@localhost:3022
// the files and directories from the data package are copied into the /tmp/data folder
// on the sftp server
}
}
The FTP server uses an in-memory FileSystem to manage files, between tests the file system is recreated so that tests do not impact each other.
@SftpEmbeddableServerExtension
provides a powerful FileSystemResource
abstraction that allows you to populate the
in-memory FileSystem with files/folders in a simple easy to use fashion.
Return a FileSystemResource
that will populate the /tmp/file1.txt
file with File Contents
FileSystemResource.resourceAt("/tmp/file1.txt").withText("File Contents")
Return a FileSystemResource
that will populate the /tmp/file2.txt
file with the data returned from
createFileInputStream()
FileSystemResource.resourceAt("/tmp/file2.txt").withContent(this::createFileInputStream)
Return a list of FileSystemResource
's that will populate the /tmp/test-data
folder with all files/directories under
the test.data
package.
FileSystemResource.resourceAt("/tmp/test-data").fromClasspathResource("/test/data")
Return a list of FileSystemResource
's that will populate the /tmp/folder
folder with all the files/directories
under path
(path can be files/folders on your hard drive, files/folders in a ZIP/TAR container or event files/folders
in another in-memory filesystem)
FileSystemResource.resourceAt("/tmp/folder").fromPath(path)
This software is licensed using MIT