Search in sources :

Example 1 with FormListParam

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

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

the class TestForestJacksonConverter 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);
    Map map = ReflectUtils.convertObjectToMap(param, ForestConfiguration.configuration());
    assertEquals("foo", map.get("username"));
    assertEquals("123456", map.get("password"));
    assertEquals(idList, map.get("idList"));
    assertEquals(causes, map.get("cause"));
}
Also used : 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 3 with FormListParam

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

the class TestPostClient method postFormListWithBodyAnn2.

@Test
public void postFormListWithBodyAnn2() {
    server.enqueue(new MockResponse().setBody(EXPECTED));
    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);
    assertThat(postClient.postFormListWithBodyAnn2(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) FormListParam(com.dtflys.test.http.model.FormListParam) Test(org.junit.Test)

Aggregations

Cause (com.dtflys.test.http.model.Cause)3 FormListParam (com.dtflys.test.http.model.FormListParam)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ForestFastjsonConverter (com.dtflys.forest.converter.json.ForestFastjsonConverter)1 MockResponse (okhttp3.mockwebserver.MockResponse)1