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");
}
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");
}
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"));
}
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");
}
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}]}");
}
Aggregations