Search in sources :

Example 1 with ForestLogger

use of com.dtflys.forest.logging.ForestLogger in project forest by dromara.

the class TestPostClient method testPostJsonMapWithoutLog.

@Test
public void testPostJsonMapWithoutLog() {
    server.enqueue(new MockResponse().setBody(EXPECTED));
    ForestLogger logger = Mockito.mock(ForestLogger.class);
    configuration.getLogHandler().setLogger(logger);
    Map<String, Object> userMap = new HashMap<>();
    userMap.put("username", "foo");
    assertThat(postClient.postJsonMapWithoutLog(userMap)).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\"}");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ForestLogger(com.dtflys.forest.logging.ForestLogger) JSONObject(com.alibaba.fastjson.JSONObject) Test(org.junit.Test)

Example 2 with ForestLogger

use of com.dtflys.forest.logging.ForestLogger 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\"}");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) JsonTestUser(com.dtflys.test.http.model.JsonTestUser) ForestLogger(com.dtflys.forest.logging.ForestLogger) Test(org.junit.Test)

Example 3 with ForestLogger

use of com.dtflys.forest.logging.ForestLogger 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);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) JsonTestUser(com.dtflys.test.http.model.JsonTestUser) ForestLogger(com.dtflys.forest.logging.ForestLogger) Test(org.junit.Test)

Example 4 with ForestLogger

use of com.dtflys.forest.logging.ForestLogger in project forest by dromara.

the class TestPostClient method testPostJsonObjectWithLog_content_noStatus2.

@Test
public void testPostJsonObjectWithLog_content_noStatus2() {
    server.enqueue(new MockResponse().setBody(EXPECTED));
    ForestLogHandler logHandler = configuration.getLogHandler();
    ForestLogger logger = Mockito.mock(ForestLogger.class);
    logHandler.setLogger(logger);
    JsonTestUser2 user = new JsonTestUser2();
    user.setUsername("foo");
    assertThat(postClient.postJsonObjectWithLog_content_noStatus(user)).isNotNull().isEqualTo(EXPECTED);
    Mockito.verify(logger).info("[Forest] Response Content:\n\t" + EXPECTED);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) ForestLogHandler(com.dtflys.forest.logging.ForestLogHandler) ForestLogger(com.dtflys.forest.logging.ForestLogger) JsonTestUser2(com.dtflys.test.http.model.JsonTestUser2) Test(org.junit.Test)

Example 5 with ForestLogger

use of com.dtflys.forest.logging.ForestLogger in project forest by dromara.

the class TestPostClient method testSimplePostWithProxy.

@Test
public void testSimplePostWithProxy() {
    server.enqueue(new MockResponse().setBody(EXPECTED));
    ForestLogger logger = Mockito.mock(ForestLogger.class);
    configuration.getLogHandler().setLogger(logger);
    assertThat(postClient.simplePostWithProxy(server.getPort(), "text/plain", "xxxyyy")).isNotNull().isEqualTo(EXPECTED);
    mockRequest(server).assertRequestLineEquals("POST http://localhost:" + server.getPort() + "/hello HTTP/1.1").assertPathEquals("/").assertHeaderEquals("Accept", "text/plain").assertBodyEquals("username=foo&password=123456");
    Mockito.verify(logger).info("[Forest] Request (" + configuration.getBackendName() + "): \n" + "\t[Proxy]: host: 127.0.0.1, port: " + server.getPort() + "\n" + "\tPOST http://localhost:" + server.getPort() + "/hello HTTP\n" + "\tHeaders: \n" + "\t\tAccept: text/plain\n" + "\t\tContent-Type: application/json\n" + "\tBody: username=foo&password=123456");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) ForestLogger(com.dtflys.forest.logging.ForestLogger) Test(org.junit.Test)

Aggregations

ForestLogger (com.dtflys.forest.logging.ForestLogger)14 Test (org.junit.Test)14 MockResponse (okhttp3.mockwebserver.MockResponse)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 JsonTestUser (com.dtflys.test.http.model.JsonTestUser)4 JSONObject (com.alibaba.fastjson.JSONObject)2 ForestRuntimeException (com.dtflys.forest.exceptions.ForestRuntimeException)2 SSLKeyStore (com.dtflys.forest.ssl.SSLKeyStore)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 HttpBackend (com.dtflys.forest.backend.HttpBackend)1 ForestRequest (com.dtflys.forest.http.ForestRequest)1 ForestLogHandler (com.dtflys.forest.logging.ForestLogHandler)1 BaseClientTest (com.dtflys.test.http.BaseClientTest)1 JsonTestList (com.dtflys.test.http.model.JsonTestList)1 JsonTestUser2 (com.dtflys.test.http.model.JsonTestUser2)1 ArrayList (java.util.ArrayList)1