Search in sources :

Example 6 with ForestLogger

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

the class SSLTest 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);
    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");
}
Also used : SSLKeyStore(com.dtflys.forest.ssl.SSLKeyStore) ForestLogger(com.dtflys.forest.logging.ForestLogger) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with ForestLogger

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

the class Test0 method testRetry.

@Test
public void testRetry() {
    ForestLogger logger = Mockito.mock(ForestLogger.class);
    config0.getLogHandler().setLogger(logger);
    try {
        beastshopClient.testRetry();
    } catch (ForestRuntimeException e) {
    }
    HttpBackend backend = config0.getBackend();
    String backendName = backend.getName();
    Mockito.verify(logger).info("[Forest] Request (" + backendName + "): \n" + "\t[Retry]: 1\n" + "\tGET https://www.thebeastshop.com/autopage/shops.htm HTTPS");
    Mockito.verify(logger).info("[Forest] Request (" + backendName + "): \n" + "\t[Retry]: 2\n" + "\tGET https://www.thebeastshop.com/autopage/shops.htm HTTPS");
    Mockito.verify(logger).info("[Forest] Request (" + backendName + "): \n" + "\t[Retry]: 3\n" + "\tGET https://www.thebeastshop.com/autopage/shops.htm HTTPS");
    Mockito.verify(logger).info("[Forest] Request (" + backendName + "): \n" + "\t[Retry]: 4\n" + "\tGET https://www.thebeastshop.com/autopage/shops.htm HTTPS");
    Mockito.verify(logger).info("[Forest] Request (" + backendName + "): \n" + "\t[Retry]: 5\n" + "\tGET https://www.thebeastshop.com/autopage/shops.htm HTTPS");
// Mockito.verify(logger).info("[Forest] [Network Error]: connect timed out");
}
Also used : ForestRuntimeException(com.dtflys.forest.exceptions.ForestRuntimeException) ForestLogger(com.dtflys.forest.logging.ForestLogger) HttpBackend(com.dtflys.forest.backend.HttpBackend) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with ForestLogger

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

the class Test2 method testClient1.

@Test
public void testClient1() {
    ForestLogger logger = Mockito.mock(ForestLogger.class);
    ForestRequest<String> request = giteeClient.index();
    assertThat(request).isNotNull();
    request.getLogConfiguration().getLogHandler().setLogger(logger);
    String result = (String) request.execute();
    assertThat(result.startsWith("Global: ")).isTrue();
    Mockito.verify(logger).info("[Forest] [Test1] 请求: \n" + "\tGET https://gitee.com/dt_flys/forest HTTPS");
}
Also used : ForestLogger(com.dtflys.forest.logging.ForestLogger) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with ForestLogger

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

the class Test2 method testClient2.

@Test
public void testClient2() {
    ForestLogger logger = Mockito.mock(ForestLogger.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");
}
Also used : ForestLogger(com.dtflys.forest.logging.ForestLogger) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with ForestLogger

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

the class TestInterceptor method testSimpleInterceptor.

@Test
public void testSimpleInterceptor() {
    server.enqueue(new MockResponse().setBody(EXPECTED));
    ForestLogger logger = Mockito.mock(ForestLogger.class);
    configuration.getLogHandler().setLogger(logger);
    assertThat(interceptorClient.simple()).isNotNull().isEqualTo("XX: " + EXPECTED);
    Mockito.verify(logger).info("[Forest] Request (" + configuration.getBackend().getName() + "): \n" + "\t[Type Change]: POST -> GET\n" + "\tGET http://localhost:" + server.getPort() + "/hello/user?username=foo&username=foo HTTP\n" + "\tHeaders: \n" + "\t\tAccept: text/plain");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) ForestLogger(com.dtflys.forest.logging.ForestLogger) Test(org.junit.Test) BaseClientTest(com.dtflys.test.http.BaseClientTest)

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