use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class TestBaseRedirectClient method testAutoRedirect_303.
@Test
public void testAutoRedirect_303() {
server.enqueue(new MockResponse().addHeader("Location", "http://localhost:" + server.getPort() + "/b").setResponseCode(303));
server.enqueue(new MockResponse().setBody(EXPECTED));
AtomicReference<ForestRequest> atomicReq = new AtomicReference<>(null);
ForestResponse<String> response = redirectClient.testAutoRedirect(((redirectReq, prevReq, prevRes) -> {
atomicReq.set(redirectReq);
}));
assertThat(atomicReq.get()).isNotNull();
assertThat(atomicReq.get().path()).isEqualTo("/b");
assertThat(response).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(200);
String result = response.getResult();
assertThat(result).isNotNull().isEqualTo(EXPECTED);
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class TestTimeoutClient method testConnectTimeout.
@Test
public void testConnectTimeout() {
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AT_START));
ForestRequest request = timeoutClient.testConnectTimeout();
assertThat(request).isNotNull();
assertThat(request.getConnectTimeout()).isEqualTo(10);
ForestResponse response = (ForestResponse) request.execute(ForestResponse.class);
assertThat(response).isNotNull();
assertThat(response.isTimeout()).isTrue();
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class TestEncoderClient method testJackson.
@Test
public void testJackson() {
EncoderClient.Entry entry = new EncoderClient.Entry("AAA", "BBB");
server.enqueue(new MockResponse().setBody(EXPECTED));
ForestRequest request = encoderClient.testJackson(entry);
assertThat(request).isNotNull();
assertThat(request.bodyType()).isNotNull().isEqualTo(ForestDataType.JSON);
assertThat(request.getEncoder()).isNotNull().isInstanceOf(ForestJacksonConverter.class);
request.execute();
mockRequest(server).assertBodyEquals("{\"name\":\"AAA\",\"value\":\"BBB\"}");
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class TestEncoderClient method testEncoder.
@Test
public void testEncoder() {
server.enqueue(new MockResponse().setBody(EXPECTED));
ForestRequest request = encoderClient.testEncoder("AAA", "BBB");
assertThat(request).isNotNull();
assertThat(request.bodyType()).isNotNull().isEqualTo(ForestDataType.JSON);
request.execute();
mockRequest(server).assertHeaderEquals("Content-Type", ContentType.APPLICATION_X_WWW_FORM_URLENCODED).assertBodyEquals("{\"name\":\"AAA\",\"value\":\"BBB\"}");
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class TestEncoderClient method testMultipart.
@Test
public void testMultipart() {
EncoderClient.Entry entry = new EncoderClient.Entry("AAA", "BBB");
server.enqueue(new MockResponse().setBody(EXPECTED));
ForestRequest request = encoderClient.testMutlipart(entry);
assertThat(request).isNotNull();
assertThat(request.bodyType()).isNotNull().isEqualTo(ForestDataType.MULTIPART);
request.execute();
}
Aggregations