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();
}
}
Aggregations