Search in sources :

Example 1 with FormArrayParam

use of com.dtflys.test.http.model.FormArrayParam in project forest by dromara.

the class TestPostClient method postFormListWithBodyAnn4.

@Test
public void postFormListWithBodyAnn4() {
    server.enqueue(new MockResponse().setBody(EXPECTED));
    FormArrayParam param = new FormArrayParam();
    param.setUsername("foo");
    param.setPassword("123456");
    param.setIdList(new Integer[] { 1, 2, 3 });
    Cause cause1 = new Cause();
    cause1.setId(1);
    cause1.setScore(87);
    Cause cause2 = new Cause();
    cause2.setId(2);
    cause2.setScore(73);
    Cause[] causes = new Cause[] { cause1, cause2 };
    param.setCause(causes);
    assertThat(postClient.postFormListWithBodyAnn4(param)).isNotNull().isEqualTo(EXPECTED);
    mockRequest(server).assertMethodEquals("POST").assertPathEquals("/form-array").assertHeaderEquals("Content-Type", "application/x-www-form-urlencoded").assertBodyEquals("username=foo&password=123456&idList=1,2,3&cause[0].id=1&cause[0].score=87&cause[1].id=2&cause[1].score=73");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Cause(com.dtflys.test.http.model.Cause) FormArrayParam(com.dtflys.test.http.model.FormArrayParam) Test(org.junit.Test)

Example 2 with FormArrayParam

use of com.dtflys.test.http.model.FormArrayParam in project forest by dromara.

the class TestPostClient method postFormListWithBodyAnn_jsonParam.

@Test
public void postFormListWithBodyAnn_jsonParam() throws UnsupportedEncodingException {
    server.enqueue(new MockResponse().setBody(EXPECTED));
    FormArrayParam param = new FormArrayParam();
    param.setUsername("中文名");
    param.setPassword("123456");
    param.setIdList(new Integer[] { 1, 2, 3 });
    Cause cause1 = new Cause();
    cause1.setId(1);
    cause1.setScore(87);
    Cause cause2 = new Cause();
    cause2.setId(2);
    cause2.setScore(73);
    Cause[] causes = new Cause[] { cause1, cause2 };
    param.setCause(causes);
    String paramStr = JSONObject.toJSONString(param);
    assertThat(postClient.postFormListWithBodyAnn_jsonParam(paramStr)).isNotNull().isEqualTo(EXPECTED);
    mockRequest(server).assertMethodEquals("POST").assertPathEquals("/form-array").assertHeaderEquals("Content-Type", "application/x-www-form-urlencoded").assertBodyEquals("param={\"username\":\"" + URLEncoder.encode("中文名", "UTF-8") + "\",\"password\":\"123456\",\"idList\":[1,2,3],\"cause\":[{\"id\":1,\"score\":87},{\"id\":2,\"score\":73}]}");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Cause(com.dtflys.test.http.model.Cause) FormArrayParam(com.dtflys.test.http.model.FormArrayParam) Test(org.junit.Test)

Aggregations

Cause (com.dtflys.test.http.model.Cause)2 FormArrayParam (com.dtflys.test.http.model.FormArrayParam)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 Test (org.junit.Test)2