Search in sources :

Example 1 with Cause

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

the class TestPostClient method postFormListWithBodyAnn.

@Test
public void postFormListWithBodyAnn() {
    server.enqueue(new MockResponse().setBody(EXPECTED));
    List<Integer> idList = Lists.newArrayList(1, 2, 3);
    Cause cause1 = new Cause();
    cause1.setId(1);
    cause1.setScore(87);
    Cause cause2 = new Cause();
    cause2.setId(2);
    cause2.setScore(73);
    List<Cause> causes = Lists.newArrayList(cause1, cause2);
    assertThat(postClient.postFormListWithBodyAnn("foo", "123456", idList, causes)).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) Test(org.junit.Test)

Example 2 with Cause

use of com.dtflys.test.http.model.Cause 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 3 with Cause

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

the class TestForestFastjsonConverter method testJavaObjectToMap3.

@Test
public void testJavaObjectToMap3() {
    FormListParam param = new FormListParam();
    List<Integer> idList = Lists.newArrayList(1, 2, 3);
    param.setUsername("foo");
    param.setPassword("123456");
    param.setIdList(idList);
    Cause cause1 = new Cause();
    cause1.setId(1);
    cause1.setScore(87);
    Cause cause2 = new Cause();
    cause2.setId(2);
    cause2.setScore(73);
    List<Cause> causes = Lists.newArrayList(cause1, cause2);
    param.setCause(causes);
    ForestFastjsonConverter forestFastjsonConverter = new ForestFastjsonConverter();
    Map map = forestFastjsonConverter.convertObjectToMap(param);
    assertEquals("foo", map.get("username"));
    assertEquals("123456", map.get("password"));
    assertEquals(idList, map.get("idList"));
    assertEquals(causes, map.get("cause"));
}
Also used : ForestFastjsonConverter(com.dtflys.forest.converter.json.ForestFastjsonConverter) Cause(com.dtflys.test.http.model.Cause) FormListParam(com.dtflys.test.http.model.FormListParam) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with Cause

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

the class TestPostClient method postFormListWithBodyAnn3.

@Test
public void postFormListWithBodyAnn3() throws InterruptedException {
    server.enqueue(new MockResponse().setBody(EXPECTED));
    Integer[] idList = 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 };
    assertThat(postClient.postFormListWithBodyAnn3("foo", "123456", idList, causes)).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) Test(org.junit.Test)

Example 5 with Cause

use of com.dtflys.test.http.model.Cause 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)7 Test (org.junit.Test)7 MockResponse (okhttp3.mockwebserver.MockResponse)5 FormListParam (com.dtflys.test.http.model.FormListParam)3 FormArrayParam (com.dtflys.test.http.model.FormArrayParam)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ForestFastjsonConverter (com.dtflys.forest.converter.json.ForestFastjsonConverter)1