Java Code Examples for org.mockftpserver.fake.filesystem.FileSystem#add()

The following examples show how to use org.mockftpserver.fake.filesystem.FileSystem#add() . 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: FakeFTPServerFactory.java    From davos with MIT License 7 votes vote down vote up
public static FakeFtpServer setup() {

        server = new FakeFtpServer();
        server.addUserAccount(new UserAccount("user", "password", "/tmp"));
        server.setServerControlPort(0);

        FileSystem fileSystem = new UnixFakeFileSystem();
        fileSystem.add(new DirectoryEntry("/tmp"));
        fileSystem.add(new FileEntry("/tmp/file1.txt", "hello world"));
        fileSystem.add(new FileEntry("/tmp/file2.txt", "hello world"));
        fileSystem.add(new FileEntry("/tmp/file3.txt", "hello world"));

        server.setFileSystem(fileSystem);
        server.start();

        return server;
    }
 
Example 2
Source File: ScannerFactoryTest.java    From DataHubSystem with GNU Affero General Public License v3.0 7 votes vote down vote up
@BeforeClass
 protected void startftp() throws Exception
 {
    fakeFtpServer = new FakeFtpServer();
    fakeFtpServer.setServerControlPort(8089);  // use any free port

    FileSystem fileSystem = new UnixFakeFileSystem();
    fileSystem.add(new FileEntry("/data/s1-level-1-calibration.xsd", "<schema/>"));
    fileSystem.add(new FileEntry("/data/s1-object-types.xsd", "<schema/>"));
    fileSystem.add(new FileEntry("/data/GOM_EXT_2PNPDE20070312_232536_000000542056_00202_26308_1271.N1", "GOMOS DATA!"));
    fileSystem.add(new FileEntry ("/data/S1A_IW_SLC__1SDV_20141003T054235_20141003T054304_002661_002F66_D5C8.SAFE/manifest.safe", "<XFDU/>"));
    fileSystem.add(new FileEntry ("/data/S1A_EW_GRDH_1SSH_20120101T022934_20120101T022945_001770_000001_AF02.SAFE/manifest.safe", "<XFDU/>"));
    fileSystem.add(new FileEntry("/data/manifest.safe", "<XFDU/>"));
    
    fakeFtpServer.setFileSystem(fileSystem);

    UserAccount userAccount = new UserAccount("user", "password", "/");
    fakeFtpServer.addUserAccount(userAccount);
    
    fakeFtpServer.start();
}
 
Example 3
Source File: TestFTP.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: GetTest.java    From cs-actions with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {

    FileSystem fileSystem = new UnixFakeFileSystem();
    fileSystem.add(new DirectoryEntry("/data"));
    fileSystem.add(new FileEntry("/data/foobar.txt","abdef 1234567890"));

    fakeFtpServer = new FakeFtpServer();
    fakeFtpServer.setFileSystem(fileSystem);
    fakeFtpServer.setServerControlPort(0);
    fakeFtpServer.addUserAccount(new UserAccount("user","password","/data"));
    fakeFtpServer.start();

    getOperation  = new Get();
    ftpService  = new FTPService();

}
 
Example 5
Source File: TestFTP.java    From nifi with Apache License 2.0 6 votes vote down vote up
@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 6
Source File: FtpClientIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Before
public void setup() throws IOException {
    fakeFtpServer = new FakeFtpServer();
    fakeFtpServer.addUserAccount(new UserAccount("user", "password", "/data"));

    FileSystem fileSystem = new UnixFakeFileSystem();
    fileSystem.add(new DirectoryEntry("/data"));
    fileSystem.add(new FileEntry("/data/foobar.txt", "abcdef 1234567890"));
    fakeFtpServer.setFileSystem(fileSystem);
    fakeFtpServer.setServerControlPort(0);

    fakeFtpServer.start();

    ftpClient = new FtpClient("localhost", fakeFtpServer.getServerControlPort(), "user", "password");
    ftpClient.open();
}
 
Example 7
Source File: TestFTP.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 8
Source File: TestFTP.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 9
Source File: TestFTP.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: TestFTP.java    From nifi with Apache License 2.0 5 votes vote down vote up
@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");
}
 
Example 11
Source File: JdkFtpClientIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Before
public void setup() throws IOException {
    fakeFtpServer = new FakeFtpServer();
    fakeFtpServer.addUserAccount(new UserAccount("user", "password", "/data"));

    FileSystem fileSystem = new UnixFakeFileSystem();
    fileSystem.add(new DirectoryEntry("/data"));
    fileSystem.add(new FileEntry("/data/foobar.txt", "abcdef 1234567890"));
    fakeFtpServer.setFileSystem(fileSystem);
    fakeFtpServer.setServerControlPort(0);

    fakeFtpServer.start();
}