@Before public void setUp() throws Exception { fakeFtpServer.setServerControlPort(0); fakeFtpServer.addUserAccount(new UserAccount(username, password, "c:\\data")); FileSystem fileSystem = new WindowsFakeFileSystem(); fileSystem.add(new DirectoryEntry("c:\\data")); fakeFtpServer.setFileSystem(fileSystem); fakeFtpServer.start(); ftpPort = fakeFtpServer.getServerControlPort(); }
fileSystem.add(directoryEntry); fakeFtpServer.setFileSystem(fileSystem); UserAccount userAccount = new UserAccount(user, password, this.baseDir); fakeFtpServer.addUserAccount(userAccount);
@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(); } }