use of com.dtflys.test.http.model.JsonTestUser in project forest by dromara.
the class TestGetClient method testQueryObjectGet.
@Test
public void testQueryObjectGet() throws InterruptedException {
server.enqueue(new MockResponse().setHeader("Content-Type", "application/json").setHeader("Content-Encoding", "UTF-8").setBody(EXPECTED));
JsonTestUser user = new JsonTestUser();
user.setUsername("foo");
assertThat(getClient.queryObjectGet(user)).isNotNull().isEqualTo(EXPECTED);
mockRequest(server).assertHeaderEquals("Accept", "text/plain").assertPathEquals("/hello/user").assertQueryEquals("username", "foo");
}
use of com.dtflys.test.http.model.JsonTestUser in project forest by dromara.
the class TestPostClient method testPostJsonObjectWithoutLog.
@Test
public void testPostJsonObjectWithoutLog() {
server.enqueue(new MockResponse().setBody(EXPECTED));
ForestLogger logger = Mockito.mock(ForestLogger.class);
configuration.getLogHandler().setLogger(logger);
JsonTestUser user = new JsonTestUser();
user.setUsername("foo");
assertThat(postClient.postJsonObjectWithoutLog(user)).isNotNull().isEqualTo(EXPECTED);
Mockito.verify(logger, Mockito.never()).info("[Forest] Request (" + configuration.getBackend().getName() + "): \n" + "\tPOST http://localhost:" + server.getPort() + "/json HTTP\n" + "\tHeaders: \n" + "\t\tContent-Type: application/json\n" + "\tBody: {\"username\":\"foo\"}");
}
use of com.dtflys.test.http.model.JsonTestUser in project forest by dromara.
the class TestPostClient method testPostJsonObjectWithLog_content_noStatus.
@Test
public void testPostJsonObjectWithLog_content_noStatus() {
server.enqueue(new MockResponse().setBody(EXPECTED));
ForestLogger logger = Mockito.mock(ForestLogger.class);
configuration.getLogHandler().setLogger(logger);
JsonTestUser user = new JsonTestUser();
user.setUsername("foo");
assertThat(postClient.postJsonObjectWithLog_content_noStatus(user)).isNotNull().isEqualTo(EXPECTED);
Mockito.verify(logger).info("[Forest] Request (" + configuration.getBackend().getName() + "): \n" + "\tPOST http://localhost:" + server.getPort() + "/json HTTP\n" + "\tHeaders: \n" + "\t\tAccept-Encoding: UTF-8\n" + "\t\tContent-Type: application/json\n" + "\tBody: {\"username\":\"foo\"}");
Mockito.verify(logger).info("[Forest] Response Content:\n\t" + EXPECTED);
}
use of com.dtflys.test.http.model.JsonTestUser in project forest by dromara.
the class TestPostClient method testPostJsonObjListInData.
@Test
public void testPostJsonObjListInData() throws InterruptedException {
server.enqueue(new MockResponse().setBody(EXPECTED));
JsonTestUser user = new JsonTestUser();
user.setUsername("foo");
JsonTestList testList = new JsonTestList();
testList.setUserList(Collections.singletonList(user));
List<JsonTestList> list = new ArrayList<>();
list.add(testList);
assertThat(postClient.postJsonObjListInDataProperty(list)).isNotNull().isEqualTo(EXPECTED);
mockRequest(server).assertMethodEquals("POST").assertPathEquals("/json").assertHeaderEquals("Content-Type", "application/json; charset=utf-8").assertBodyEquals("[{\"userList\":[{\"username\":\"foo\"}]}]");
}
use of com.dtflys.test.http.model.JsonTestUser in project forest by dromara.
the class TestPostClient method testPostJsonWithLog.
@Test
public void testPostJsonWithLog() {
server.enqueue(new MockResponse().setBody(EXPECTED));
ForestLogger logger = Mockito.mock(ForestLogger.class);
configuration.getLogHandler().setLogger(logger);
JsonTestUser user = new JsonTestUser();
user.setUsername("foo");
ForestResponse<String> response = postClient.postJsonWithLog("foo", "1111111111111");
assertThat(response).isNotNull();
assertThat(response.getResult()).isNotNull().isEqualTo(EXPECTED);
ForestRequest request = response.getRequest();
assertThat(request.getRequestLogMessage()).isNotNull().extracting(RequestLogMessage::getRequest).isEqualTo(request);
Mockito.verify(logger).info("[Forest] Request (" + configuration.getBackend().getName() + "): \n" + "\tPOST http://localhost:" + server.getPort() + "/json HTTP\n" + "\tHeaders: \n" + "\t\tAccept: application/json\n" + "\t\tAuthorization: 1111111111111\n" + "\t\tContent-Type: application/json\n" + "\tBody: {\"username\":\"foo\"}");
}
Aggregations