如何创建"FTPS"模拟服务器对Java中的文件传输进行单元测试 [英] How to create a "FTPS" Mock Server to unit test File Transfer in Java

查看:117
本文介绍了如何创建"FTPS"模拟服务器对Java中的文件传输进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a CreateFTPConnection class which create a FTPS connection. Using this connection, files are transferred. Here is the code of TransferFile class

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 Testcase.为此,我必须创建一个FTPS Mock Server连接,并必须使用该连接来测试文件传输.因此,任何人都可以给我关于如何制作FTPS Mock Server以及进行测试用例的任何想法.我用谷歌搜索,但是我得到的是FTP或SFTP,而不是FTPS.请帮助我.

I have to write jUnit Testcase for this class. For this, I have to create a FTPS Mock Server connection and have to use that connection to test the File Transfer. So can anyone plz give me any idea of how to make FTPS Mock Server and do the test case. I googled on this, but what I get is on FTP or SFTP, not FTPS. Please help me.

推荐答案

您可能会发现此有用的 MockFTPServer

You might find this useful MockFTPServer

问题在于,根据我的观察,这些模拟服务器未实现TLS部分.您可能需要做一些工作以允许通过TLS进行连接.

The issue is that these mock servers don't implement the TLS portion from what I can see. You may need to do a little work to allow connections via TLS.

为了进行测试,您应该能够在SO上四处搜索并找到有关处理证书(或在某些情况下,绕过它们)的一些文章.

You should be able to search around and find some articles here on SO about dealing with certificates, (or in some cases, bypassing them) for the sake of your testing.

这是另一个文章,完成创建基本FTP服务器测试的步骤.

Here's another Article that goes through the steps of creating a basic FTP server Test.

功能齐全的FTP服务器的简短内容(Apache http w/ mod_ftp 附加),没有似乎没有什么用处.

Short of a full blown FTP server (Apache http w/ mod_ftp add on), there doesn't seem to be anything useful to do this.

这篇关于如何创建"FTPS"模拟服务器对Java中的文件传输进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆