use of com.dtflys.test.model.Result in project forest by dromara.
the class TestGenericForestClient method testRequest_post_json_body_map2.
@Test
public void testRequest_post_json_body_map2() {
server.enqueue(new MockResponse().setBody(EXPECTED));
TypeReference<Result<Integer>> typeReference = new TypeReference<Result<Integer>>() {
};
Map<String, Integer> map = new LinkedHashMap<>();
map.put("a", 1);
map.put("b", 2);
ForestRequest request = Forest.post("http://localhost:" + server.getPort() + "/post").contentTypeJson().addBody(map).addBody("c", 3);
assertThat(request.body().nameValuesMapWithObject()).extracting("a", "b", "c").contains(1, 2, 3);
Result<Integer> result = (Result<Integer>) request.execute(typeReference);
assertThat(result).isNotNull();
assertThat(result.getStatus()).isEqualTo(1);
assertThat(result.getData()).isEqualTo(2);
mockRequest(server).assertMethodEquals("POST").assertPathEquals("/post").assertHeaderEquals(ForestHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON).assertBodyEquals("{\"a\":1,\"b\":2,\"c\":3}");
}
Aggregations