【问题标题】:Passing parameters in integration test JAVA在集成测试JAVA中传递参数
【发布时间】:2016-06-08 16:47:38
【问题描述】:

我尝试在集成测试的发布请求中传递参数,但我得到的响应是未检测到所需的参数“源”。也许你会知道是什么原因。谢谢。

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
}

【问题讨论】:

    标签: java testing junit integration


    【解决方案1】:

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

    httpPost.setRequestBody(postParameters);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-06
      • 2016-12-14
      • 2016-02-16
      • 2016-05-27
      • 1970-01-01
      • 2012-01-22
      • 1970-01-01
      相关资源
      最近更新 更多