@Test public void basicFileFetch() throws IOException { FileSystem results = fakeFtpServer.getFileSystem(); FileEntry sampleFile = new FileEntry("c:\\data\\randombytes-2"); sampleFile.setContents("Just some random test test test chocolate"); results.add(sampleFile); // Check file exists Assert.assertTrue(results.exists("c:\\data\\randombytes-2")); TestRunner runner = TestRunners.newTestRunner(FetchFTP.class); runner.setProperty(FetchFTP.HOSTNAME, "${host}"); runner.setProperty(FetchFTP.USERNAME, "${username}"); runner.setProperty(FTPTransfer.PASSWORD, password); runner.setProperty(FTPTransfer.PORT, "${port}"); runner.setProperty(FetchFTP.REMOTE_FILENAME, "c:\\data\\randombytes-2"); runner.setProperty(FetchFTP.COMPLETION_STRATEGY, FetchFTP.COMPLETION_MOVE); runner.setProperty(FetchFTP.MOVE_DESTINATION_DIR, "data"); Map<String, String> attrs = new HashMap<String, String>(); attrs.put("host", "localhost"); attrs.put("username", username); attrs.put("port", Integer.toString(ftpPort)); runner.enqueue("", attrs); runner.run(); final MockFlowFile retrievedFile = runner.getFlowFilesForRelationship(FetchFTP.REL_SUCCESS).get(0); retrievedFile.assertContentEquals("Just some random test test test chocolate"); }
@Test public void basicFileGet() throws IOException { FileSystem results = fakeFtpServer.getFileSystem(); FileEntry sampleFile = new FileEntry("c:\\data\\randombytes-2"); sampleFile.setContents("Just some random test test test chocolate"); results.add(sampleFile); // Check file exists Assert.assertTrue(results.exists("c:\\data\\randombytes-2")); TestRunner runner = TestRunners.newTestRunner(GetFTP.class); runner.setProperty(FTPTransfer.HOSTNAME, "localhost"); runner.setProperty(FTPTransfer.USERNAME, username); runner.setProperty(FTPTransfer.PASSWORD, password); runner.setProperty(FTPTransfer.PORT, Integer.toString(ftpPort)); runner.setProperty(FTPTransfer.REMOTE_PATH, "/"); runner.run(); final MockFlowFile retrievedFile = runner.getFlowFilesForRelationship(GetFTP.REL_SUCCESS).get(0); retrievedFile.assertContentEquals("Just some random test test test chocolate"); }
sampleFile.setContents("Just some random test test test chocolate"); results.add(sampleFile);
/** * Construct a new instance with the specified path and file contents * * @param path - the value for path * @param contents - the contents of the file, as a String */ public FileEntry(String path, String contents) { super(path); setContents(contents); }
/** * Return a new FileSystemEntry that is a clone of this object, except having the specified path * * @param path - the new path value for the cloned file system entry * @return a new FileSystemEntry that has all the same values as this object except for its path */ public FileSystemEntry cloneWithNewPath(String path) { FileEntry clone = new FileEntry(path); clone.setLastModified(getLastModified()); clone.setOwner(getOwner()); clone.setGroup(getGroup()); clone.setPermissions(getPermissions()); clone.setContents(getCurrentBytes()); return clone; }