Search in sources :

Example 6 with JsonTestUser

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

the class TestPostClient method testPostJsonListInObjInDataProperty.

@Test
public void testPostJsonListInObjInDataProperty() throws InterruptedException {
    server.enqueue(new MockResponse().setBody(EXPECTED));
    JsonTestUser user = new JsonTestUser();
    user.setUsername("foo");
    JsonTestList testList = new JsonTestList();
    testList.setUserList(Collections.singletonList(user));
    assertThat(postClient.postJsonListInObjInDataProperty(testList)).isNotNull().isEqualTo(EXPECTED);
    mockRequest(server).assertMethodEquals("POST").assertPathEquals("/json").assertHeaderEquals("Content-Type", "application/json; charset=utf-8").assertBodyEquals("{\"userList\":[{\"username\":\"foo\"}]}");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) JsonTestUser(com.dtflys.test.http.model.JsonTestUser) JsonTestList(com.dtflys.test.http.model.JsonTestList) Test(org.junit.Test)

Example 7 with JsonTestUser

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

the class TestPostClient method testPostJsonObjList.

@Test
public void testPostJsonObjList() 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.postJsonObjListWithDataObjectAnn(list)).isNotNull().isEqualTo(EXPECTED);
    mockRequest(server).assertMethodEquals("POST").assertPathEquals("/json").assertHeaderEquals("Content-Type", "application/json; charset=utf-8").assertBodyEquals("[{\"userList\":[{\"username\":\"foo\"}]}]");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) JsonTestUser(com.dtflys.test.http.model.JsonTestUser) ArrayList(java.util.ArrayList) JsonTestList(com.dtflys.test.http.model.JsonTestList) Test(org.junit.Test)

Example 8 with JsonTestUser

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

the class TestPostClient method testJsonPostBodyObj.

@Test
public void testJsonPostBodyObj() throws InterruptedException {
    server.enqueue(new MockResponse().setBody(EXPECTED));
    JsonTestUser user = new JsonTestUser();
    user.setUsername("foo");
    assertThat(postClient.postJsonBodyObj(user)).isNotNull().isEqualTo(EXPECTED);
    mockRequest(server).assertMethodEquals("POST").assertPathEquals("/json").assertHeaderEquals("Content-Type", "application/json").assertBodyEquals("{\"username\":\"foo\"}");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) JsonTestUser(com.dtflys.test.http.model.JsonTestUser) Test(org.junit.Test)

Example 9 with JsonTestUser

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

the class TestPostClient method testPostJsonObjListWithLog_content_noRequest_noStatus.

@Test
public void testPostJsonObjListWithLog_content_noRequest_noStatus() {
    server.enqueue(new MockResponse().setBody(EXPECTED));
    ForestLogger logger = Mockito.mock(ForestLogger.class);
    configuration.getLogHandler().setLogger(logger);
    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.postJsonObjListWithLog_content_noRequest_noStatus(list)).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; charset=utf-8\n" + "\tBody: [{\"userList\":[{\"username\":\"foo\"}]}]");
    Mockito.verify(logger).info("[Forest] Response Content:\n\t" + EXPECTED);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) JsonTestUser(com.dtflys.test.http.model.JsonTestUser) ArrayList(java.util.ArrayList) ForestLogger(com.dtflys.forest.logging.ForestLogger) JsonTestList(com.dtflys.test.http.model.JsonTestList) Test(org.junit.Test)

Example 10 with JsonTestUser

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

the class TestPostClient method testPostJsonListInObjWithDataObjectAnn.

@Test
public void testPostJsonListInObjWithDataObjectAnn() throws InterruptedException {
    server.enqueue(new MockResponse().setBody(EXPECTED));
    JsonTestUser user = new JsonTestUser();
    user.setUsername("foo");
    JsonTestList testList = new JsonTestList();
    testList.setUserList(Collections.singletonList(user));
    assertThat(postClient.postJsonListInObjWithDataObjectAnn(testList)).isNotNull().isEqualTo(EXPECTED);
    mockRequest(server).assertMethodEquals("POST").assertPathEquals("/json").assertHeaderEquals("Content-Type", "application/json; charset=utf-8").assertBodyEquals("{\"userList\":[{\"username\":\"foo\"}]}");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) JsonTestUser(com.dtflys.test.http.model.JsonTestUser) JsonTestList(com.dtflys.test.http.model.JsonTestList) Test(org.junit.Test)

Aggregations

JsonTestUser (com.dtflys.test.http.model.JsonTestUser)11 MockResponse (okhttp3.mockwebserver.MockResponse)11 Test (org.junit.Test)11 JsonTestList (com.dtflys.test.http.model.JsonTestList)5 ForestLogger (com.dtflys.forest.logging.ForestLogger)4 ArrayList (java.util.ArrayList)3 ForestRequest (com.dtflys.forest.http.ForestRequest)1