【问题标题】:How to create a "FTPS" Mock Server to unit test File Transfer in Java如何创建“FTPS”模拟服务器以对 Java 中的文件传输进行单元测试
【发布时间】:2012-12-26 14:34:37
【问题描述】:

我有一个创建 FTPS 连接的 CreateFTPConnection 类。使用此连接传输文件。这是TransferFile类的代码

public class TransferFile
{
   private CreateFTPConnection ftpConnection;
   private FTPSClient client;

public TransferFile(CreateFTPConnection ftpConnection) {
    this.ftpConnection = ftpConnection;
    this.client = ftpConnection.getClient();
}

public void transfer(Message<?> msg)
{
    InputStream inputStream = null;
    try
    {
        if(!client.isConnected()){
            ftpConnection.init();
            client = ftpConnection.getClient();
        }
        File file = (File) msg.getPayload();
        inputStream = new FileInputStream(file);
        client.storeFile(file.getName(), inputStream);
        client.sendNoOp();
    } catch (Exception e) {
        try
        {
            client.disconnect();
        }
        catch (IOException e1) {
            e1.printStackTrace();
        }
    }
    finally
    {
        try {
            inputStream.close();
        } 
        catch (IOException e) {
            e.printStackTrace();
        }
    }
}
}

我必须为这个类编写 jUnit 测试用例。为此,我必须创建一个 FTPS 模拟服务器连接,并且必须使用该连接来测试文件传输。所以任何人都可以给我任何关于如何制作 FTPS 模拟服务器和做测试用例的想法。我对此进行了谷歌搜索,但我得到的是 FTP 或 SFTP,而不是 FTPS。请帮帮我。

【问题讨论】:

    标签: java junit mocking ftps


    【解决方案1】:

    您可能会发现这很有用MockFTPServer

    问题是这些模拟服务器没有实现我所看到的 TLS 部分。您可能需要做一些工作以允许通过 TLS 进行连接。

    为了您的测试,您应该能够在此处搜索并找到一些关于处理证书(或在某些情况下绕过它们)的文章。

    这是另一个Article,它完成了创建基本 FTP 服务器测试的步骤。

    缺少完整的 FTP 服务器(Apache http w/mod_ftp add on),似乎没有任何有用的东西来做这件事。

    【讨论】:

    • 感谢 Mike 的快速回复,我将再次浏览这些文章。
    猜你喜欢
    • 1970-01-01
    • 2019-12-13
    • 2017-06-25
    • 1970-01-01
    • 2015-11-29
    • 1970-01-01
    • 2016-12-31
    • 1970-01-01
    相关资源
    最近更新 更多