use of com.dtflys.forest.logging.ForestLogger 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\"}");
}
use of com.dtflys.forest.logging.ForestLogger in project forest by dromara.
the class TestPostClient method testPostJsonMapWithLog.
@Test
public void testPostJsonMapWithLog() {
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.postJsonMapWithLog(userMap)).isNotNull().isEqualTo(EXPECTED);
Mockito.verify(logger).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.forest.logging.ForestLogger 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);
}
use of com.dtflys.forest.logging.ForestLogger in project forest by dromara.
the class SSLTest2 method testConfiguration.
@Test
public void testConfiguration() {
ForestLogger logger = Mockito.mock(ForestLogger.class);
assertEquals(Integer.valueOf(300), sslConfig.getMaxConnections());
assertEquals(Integer.valueOf(300), sslConfig.getMaxRouteConnections());
assertEquals(Integer.valueOf(3000), sslConfig.getTimeout());
assertEquals(Integer.valueOf(3000), sslConfig.getConnectTimeout());
assertEquals(Integer.valueOf(2), sslConfig.getMaxRetryCount());
assertEquals(1, sslConfig.getSslKeyStores().size());
SSLKeyStore sslKeyStore = sslConfig.getKeyStore("keystore1");
assertThat(sslKeyStore).isNotNull();
// assertEquals("keystore1", sslKeyStore.getId());
// assertEquals("test.keystore", sslKeyStore.getFilePath());
// assertEquals("123456", sslKeyStore.getKeystorePass());
// assertEquals("123456", sslKeyStore.getCertPass());
// assertEquals(1, sslKeyStore.getProtocols().length);
// assertEquals("SSLv3", sslKeyStore.getProtocols()[0]);
assertThat(sslKeyStore.getSslSocketFactoryBuilder()).isNotNull().isInstanceOf(MySSLSocketFactoryBuilder.class);
assertThat(sslKeyStore.getHostnameVerifier()).isNotNull().isInstanceOf(MyHostnameVerifier.class);
ForestRequest<String> request = giteeClient.index2();
assertThat(request).isNotNull();
request.getLogConfiguration().getLogHandler().setLogger(logger);
String result = (String) request.execute();
assertThat(result.startsWith("Global: ")).isTrue();
Mockito.verify(logger).info("[Forest] [Test2] 请求: \n" + "\tGET https://gitee.com/dt_flys HTTPS");
Throwable th = null;
try {
giteeClient.index3();
} catch (ForestRuntimeException ex) {
th = ex.getCause();
}
assertThat(th).isNotNull();
}
Aggregations