Search in sources :

Example 1 with JsonTestList

use of com.dtflys.test.http.model.JsonTestList 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\"}]}]");
}
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 2 with JsonTestList

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

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

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

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

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