use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class DefaultLogHandler method redirection.
/**
* 请求重定向信息
* @param requestLogMessage
* @return 请求重定向信息字符串
*/
protected String redirection(RequestLogMessage requestLogMessage) {
ForestRequest request = requestLogMessage.getRequest();
if (request.isRedirection()) {
ForestRequest prevRequest = request.getPrevRequest();
ForestResponse prevResponse = request.getPrevResponse();
return "[Redirect]: From " + prevRequest.getType().getName() + " " + prevRequest.getUrl() + " -> " + prevResponse.getStatusCode() + "\n\t";
}
return "";
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class Test0 method testClient0.
@Test
public void testClient0() {
ForestResponse<String> response = beastshopClient.shops();
assertNotNull(response);
assertNotNull(response.getResult());
ForestRequest request = response.getRequest();
assertNotNull(request);
String name = request.getHeaderValue("MyName");
String pass = request.getHeaderValue("MyPass");
assertEquals("foo", name);
assertEquals("bar", pass);
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class Test1 method testClient1.
@Test
public void testClient1() {
StopWatch sw = new StopWatch();
sw.start();
ForestResponse response = baiduClient.testTimeout("xxx");
sw.stop();
assertNotNull(response);
ForestRequest request = response.getRequest();
int reqTimeout = request.getTimeout();
assertEquals(50, reqTimeout);
long time = sw.getTotalTimeMillis();
assertTrue(time >= 50);
assertTrue(time <= 3600);
LogConfiguration logConfiguration = request.getLogConfiguration();
assertTrue(logConfiguration.isLogEnabled());
assertTrue(logConfiguration.isLogRequest());
// assertTrue(logConfiguration.isLogResponseStatus());
// assertTrue(!logConfiguration.isLogResponseContent());
// assertTrue(logConfiguration.getLogHandler() instanceof TestLogHandler);
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class ErrorTest method testErrorCallback.
public void testErrorCallback() {
configuration.setTimeout(10);
final AtomicInteger count = new AtomicInteger(0);
final boolean[] ts = new boolean[] { false };
errorClient.testError(new OnError() {
@Override
public void onError(ForestRuntimeException ex, ForestRequest request, ForestResponse response) {
int status = response.getStatusCode();
count.incrementAndGet();
assertNotNull(ex);
assertNotNull(request);
}
});
assertEquals(1, count.get());
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class ProgressTest method testProgressWithNegativeTotalBytes.
@Test
public void testProgressWithNegativeTotalBytes() {
ForestRequest request = Mockito.mock(ForestRequest.class);
ForestProgress progress = new ForestProgress(request, -100);
progress.setBegin(true);
assertThat(progress.getTotalBytes()).isEqualTo(-100);
progress.setCurrentBytes(0);
assertThat(progress.getRate()).isEqualTo(0);
progress.setCurrentBytes(10);
assertThat(progress.getRate()).isEqualTo(0);
progress.setCurrentBytes(100);
assertThat(progress.getRate()).isEqualTo(0);
}
Aggregations