在集成测试JAVA中传递参数

时间:2016-02-25 18:25:32

标签: java testing junit integration

我尝试在集成测试中传递post请求中的参数,但是得到了需要参数" source"检测到aint。也许你会知道是什么原因。谢谢。

public void testUploadBundleFromRepository() throws IOException, InterruptedException {

    String boundary = "---------------"+ UUID.randomUUID().toString();

    String uri = String.format("http://%s:%d/upload/", HOST, PORT);

    HttpPost httpPost = new HttpPost(uri);
    httpPost.setHeader(HTTP.CONTENT_TYPE, ContentType.MULTIPART_FORM_DATA.getMimeType()+";boundary="+boundary);

    List<NameValuePair> postParameters = new ArrayList<>();
    postParameters.add(new BasicNameValuePair("source","repo"));
    postParameters.add(new BasicNameValuePair("id","1"));
    postParameters.add(new BasicNameValuePair("start", "true"));
    httpPost.setEntity(new UrlEncodedFormEntity(postParameters, "UTF-8"));

    HttpResponse response = getHttpClient().execute(httpPost);

    //assert in future
}

1 个答案:

答案 0 :(得分:0)

我认为你应该调用setRequestBody而不是setEntity

httpPost.setRequestBody(postParameters);