Search in sources :

Example 1 with FileSystem

use of org.mockftpserver.fake.filesystem.FileSystem in project cdap by caskdata.

the class LocalizationUtilsTest method testRemoteFile.

@Test
public void testRemoteFile() throws IOException {
    File directory = TEMP_FOLDER.newFolder("ftp");
    File ftpFile = new File(directory, "ftp_file");
    String ftpFileContents = "Contents of ftp_file";
    FileSystem fileSystem = new UnixFakeFileSystem();
    fileSystem.add(new FileEntry(ftpFile.getAbsolutePath(), ftpFileContents));
    String user = "user";
    String password = "password";
    FakeFtpServer ftpServer = new FakeFtpServer();
    // Use any available port
    ftpServer.setServerControlPort(0);
    ftpServer.addUserAccount(new UserAccount(user, password, directory.getAbsolutePath()));
    ftpServer.setFileSystem(fileSystem);
    ftpServer.start();
    try {
        URI uri = URI.create(String.format("ftp://%s:%s@localhost:%d/%s", user, password, ftpServer.getServerControlPort(), ftpFile.getName()));
        File localizationDir = TEMP_FOLDER.newFolder("localRemote");
        File localizedResource = LocalizationUtils.localizeResource("file1", new LocalizeResource(uri, false), localizationDir);
        Assert.assertTrue(localizedResource.exists());
        Assert.assertTrue(localizedResource.isFile());
        Assert.assertEquals(ftpFileContents, com.google.common.io.Files.toString(localizedResource, Charsets.UTF_8));
    } finally {
        ftpServer.stop();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) LocalizeResource(co.cask.cdap.internal.app.runtime.distributed.LocalizeResource) FileEntry(org.mockftpserver.fake.filesystem.FileEntry) File(java.io.File) UserAccount(org.mockftpserver.fake.UserAccount) URI(java.net.URI) Test(org.junit.Test)

Aggregations

LocalizeResource (co.cask.cdap.internal.app.runtime.distributed.LocalizeResource)1 File (java.io.File)1 URI (java.net.URI)1 Test (org.junit.Test)1 FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)1 UserAccount (org.mockftpserver.fake.UserAccount)1 FileEntry (org.mockftpserver.fake.filesystem.FileEntry)1 FileSystem (org.mockftpserver.fake.filesystem.FileSystem)1 UnixFakeFileSystem (org.mockftpserver.fake.filesystem.UnixFakeFileSystem)1