Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将文件上载为FormDataParam进行测试_Java_Rest_Http_Testing_Junit - Fatal编程技术网

Java 将文件上载为FormDataParam进行测试

Java 将文件上载为FormDataParam进行测试,java,rest,http,testing,junit,Java,Rest,Http,Testing,Junit,因此,我在测试我的应用程序时遇到了问题。我正在尝试做REST/HTTP测试。这是我的密码: @Path("/ftpaction") public class JerseyFileUpload { @POST @Path("/upload") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response postMsg(@HeaderParam("FTP-Host") String Host, @HeaderPar

因此,我在测试我的应用程序时遇到了问题。我正在尝试做REST/HTTP测试。这是我的密码:

@Path("/ftpaction")
public class JerseyFileUpload {
    @POST
    @Path("/upload")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response postMsg(@HeaderParam("FTP-Host") String Host, @HeaderParam("FTP-Port") String Port,
            @HeaderParam("FTP-User") String User, @HeaderParam("FTP-Password") String Password,
            @HeaderParam("FTP-Path") String Path, @FormDataParam("file") InputStream inputStream) {
        try {
            InformationHandler informationHandler = new InformationHandler(Path, Host, Port, User, Password);
            CountriesStructure worker = new CountriesStructure();
            worker.prepareCountriesStructure(inputStream, true, informationHandler);
        } catch (UsernameOrPasswordException e) {
            return Response.status(401).entity("Status 401.").build();
        } catch (SocketException e) {
            return Response.status(404).entity("Status 404.").build();
        } catch (IOException e) {
            return Response.status(400).entity("Status 400.").build();
        } catch (JAXBException e) {
            return Response.status(500).entity("Status 500.").build();
        } catch (Exception e) {
            return Response.status(500).entity("Status 500.").build();
        }
        return Response.status(200).entity("Success!").build();
    }
}
还有我的测试:

@RunWith(HttpJUnitRunner.class)
public class TestMain extends TestCase {
    @Rule
    public Destination destination = new Destination(this, "http://localhost:8080");

    @Context
    private Response response;

    @HttpTest(method = Method.POST, path = "/JerseyWebApp/ftpaction/upload", content = "{}", file = "/CountriesList.txt", type = MediaType.MULTIPART_FORM_DATA, headers = {
            @Header(name = "FTP-Host", value = "localhost"), @Header(name = "FTP-Port", value = "21"),
            @Header(name = "FTP-User", value = "ftptest"), @Header(name = "FTP-Password", value = "test"),
            @Header(name = "FTP-Path", value = "/test123"), @Header(name = "Accept-Encoding", value = "multipart/form-data")})
    public void checkPost() {
        System.out.println(response.getBody());
    }
}
我无法通过测试读取文件。我不知道我必须做什么,因为我正在使用文件作为“FormDataParam”。有人知道我如何上传文件作为FormDataParam进行测试吗?因为现在它看不到我的文件,只返回“状态400”