@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(); }
@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"); }
@Test public void basicFileUpload() throws IOException { TestRunner runner = TestRunners.newTestRunner(PutFTP.class); runner.setProperty(FTPTransfer.HOSTNAME, "localhost"); runner.setProperty(FTPTransfer.USERNAME, username); runner.setProperty(FTPTransfer.PASSWORD, password); runner.setProperty(FTPTransfer.PORT, Integer.toString(ftpPort)); try (FileInputStream fis = new FileInputStream("src/test/resources/randombytes-1");) { Map<String, String> attributes = new HashMap<String, String>(); attributes.put(CoreAttributes.FILENAME.key(), "randombytes-1"); runner.enqueue(fis, attributes); runner.run(); } runner.assertQueueEmpty(); runner.assertAllFlowFilesTransferred(PutFTP.REL_SUCCESS); FileSystem results = fakeFtpServer.getFileSystem(); // Check file was uploaded Assert.assertTrue(results.exists("c:\\data\\randombytes-1")); }
/** * @see java.lang.Object#toString() */ public String toString() { return "File['" + getPath() + "' size=" + getSize() + " lastModified=" + getLastModified() + " owner=" + getOwner() + " group=" + getGroup() + " permissions=" + getPermissions() + "]"; }
/** * @see java.lang.Object#toString() */ public String toString() { return "Directory['" + getPath() + "' lastModified=" + getLastModified() + " owner=" + getOwner() + " group=" + getGroup() + " permissions=" + getPermissions() + "]"; }
/** * Return true if the specified path designates an existing file, false otherwise * * @param path - the path * @return true if path is a file, false otherwise * @throws AssertionError - if path is null * @see org.mockftpserver.fake.filesystem.FileSystem#isFile(java.lang.String) */ public boolean isFile(String path) { Assert.notNull(path, "path"); FileSystemEntry entry = getEntry(path); return entry != null && !entry.isDirectory(); }
/** * Construct a new instance and initialize the directoryListingFormatter to a UnixDirectoryListingFormatter. */ public UnixFakeFileSystem() { this.setDirectoryListingFormatter(new UnixDirectoryListingFormatter()); }
/** * Construct a new instance and initialize the directoryListingFormatter to a WindowsDirectoryListingFormatter. */ public WindowsFakeFileSystem() { this.setDirectoryListingFormatter(new WindowsDirectoryListingFormatter()); }
/** * Throw an InvalidFilenameException if the specified path is not valid. * * @param path - the path */ protected void checkForInvalidFilename(String path) { if (!isValidName(path)) { throw new InvalidFilenameException(path); } }
/** * Return the standard, normalized form of the path. * * @param path - the path * @return the path in a standard, unique, canonical form * @throws AssertionError - if path is null */ protected String normalize(String path) { return componentsToPath(normalizedComponents(path)); }
/** * If the specified path has a parent, then verify that the parent exists * * @param path - the path * @return true if the parent of the specified path exists */ private boolean parentDirectoryExists(String path) { String parent = getParent(path); return parent == null || pathExists(parent); }
/** * 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 the normalized and unique key used to access the file system entry * * @param path - the path * @return the corresponding normalized key */ protected String getFileSystemEntryKey(String path) { return normalize(path); }
/** * Return true if the specified path exists * * @param path - the path * @return true if the path exists */ private boolean pathExists(String path) { return getEntry(path) != null; }
/** * Return the size of this file * * @return the file size in bytes */ public long getSize() { return getCurrentBytes().length; }
/** * Return true if the specified path designates an absolute file path. * * @param path - the path * @return true if path is absolute, false otherwise * @throws AssertionError - if path is null */ public boolean isAbsolute(String path) { return isValidName(path); }
@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"); }
/** * Return true if the specified path designates an existing directory, false otherwise * * @param path - the path * @return true if path is a directory, false otherwise * @throws AssertionError - if path is null * @see org.mockftpserver.fake.filesystem.FileSystem#isDirectory(java.lang.String) */ public boolean isDirectory(String path) { Assert.notNull(path, "path"); FileSystemEntry entry = getEntry(path); return entry != null && entry.isDirectory(); }
FileSystem results = fakeFtpServer.getFileSystem(); FileEntry sampleFile = new FileEntry("c:\\data\\randombytes-2"); sampleFile.setContents("Just some random test test test chocolate"); results.add(sampleFile); Assert.assertTrue(results.exists("c:\\data\\randombytes-2"));