Java Code Examples for org.mockftpserver.fake.filesystem.FileEntry#setContents()
The following examples show how to use
org.mockftpserver.fake.filesystem.FileEntry#setContents() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestFTP.java From localization_nifi with Apache License 2.0 | 6 votes |
@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"); }
Example 2
Source File: TestFTP.java From nifi with Apache License 2.0 | 6 votes |
@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"); }
Example 3
Source File: TestFTP.java From nifi with Apache License 2.0 | 5 votes |
@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"); }
Example 4
Source File: TestFTP.java From nifi with Apache License 2.0 | 5 votes |
@Test public void basicFileList() throws IOException, InterruptedException { 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(ListFTP.class); runner.setProperty(ListFTP.HOSTNAME, "localhost"); runner.setProperty(ListFTP.USERNAME, username); runner.setProperty(FTPTransfer.PASSWORD, password); runner.setProperty(FTPTransfer.PORT, Integer.toString(ftpPort)); runner.setProperty(ListFTP.REMOTE_PATH, "/"); // FakeFTPServer has timestamp precision in minutes. // Specify milliseconds precision so that test does not need to wait for minutes. runner.setProperty(ListFile.TARGET_SYSTEM_TIMESTAMP_PRECISION, ListFile.PRECISION_MILLIS); runner.assertValid(); // Ensure wait for enough lag time. Thread.sleep(AbstractListProcessor.LISTING_LAG_MILLIS.get(TimeUnit.MILLISECONDS) * 2); runner.run(); runner.assertTransferCount(FetchFTP.REL_SUCCESS, 1); final MockFlowFile retrievedFile = runner.getFlowFilesForRelationship(FetchFTP.REL_SUCCESS).get(0); runner.assertAllFlowFilesContainAttribute("ftp.remote.host"); runner.assertAllFlowFilesContainAttribute("ftp.remote.port"); runner.assertAllFlowFilesContainAttribute("ftp.listing.user"); runner.assertAllFlowFilesContainAttribute(ListFile.FILE_OWNER_ATTRIBUTE); runner.assertAllFlowFilesContainAttribute(ListFile.FILE_GROUP_ATTRIBUTE); runner.assertAllFlowFilesContainAttribute(ListFile.FILE_PERMISSIONS_ATTRIBUTE); runner.assertAllFlowFilesContainAttribute(ListFile.FILE_SIZE_ATTRIBUTE); runner.assertAllFlowFilesContainAttribute(ListFile.FILE_LAST_MODIFY_TIME_ATTRIBUTE); retrievedFile.assertAttributeEquals("ftp.listing.user", username); retrievedFile.assertAttributeEquals("filename", "randombytes-2"); }