use of com.dtflys.forest.http.ForestResponse in project forest by dromara.
the class TestBaseRedirectClient method testAutoRedirect_307.
@Test
public void testAutoRedirect_307() {
server.enqueue(new MockResponse().addHeader("Location", "http://localhost:" + server.getPort() + "/b").setResponseCode(307));
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.ForestResponse in project forest by dromara.
the class TestBaseRedirectClient method testBaseAutoRedirect_301.
/**
* ====================================================== 测试Base拦截器自动重定向 ======================================================
*/
@Test
public void testBaseAutoRedirect_301() {
server.enqueue(new MockResponse().addHeader("Location", "http://localhost:" + server.getPort() + "/b").setResponseCode(301));
server.enqueue(new MockResponse().setBody(EXPECTED));
AtomicReference<ForestRequest> atomicReq = new AtomicReference<>(null);
ForestResponse<String> response = baseRedirectClient.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);
mockRequest(server).assertPathEquals("/");
mockRequest(server).assertPathEquals("/b").assertBodyEquals("body=" + RedirectInterceptor.BODY);
}
use of com.dtflys.forest.http.ForestResponse in project forest by dromara.
the class TestBaseRedirectClient method testNotAutoRedirect_303.
@Test
public void testNotAutoRedirect_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.testNotAutoRedirect(((redirectReq, prevReq, prevRes) -> {
atomicReq.set(redirectReq);
}));
assertThat(atomicReq.get()).isNull();
assertThat(response).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(303);
assertThat(response.isRedirection()).isTrue();
assertThat(response.getRedirectionLocation()).isEqualTo("http://localhost:" + server.getPort() + "/b");
String result = response.redirectionRequest().execute(String.class);
assertThat(result).isNotNull().isEqualTo(EXPECTED);
assertThat(atomicReq.get()).isNotNull();
assertThat(atomicReq.get().getPath()).isEqualTo("/b");
}
use of com.dtflys.forest.http.ForestResponse in project forest by dromara.
the class TestBaseRedirectClient method testNotAutoRedirect_302.
@Test
public void testNotAutoRedirect_302() {
server.enqueue(new MockResponse().addHeader("Location", "http://localhost:" + server.getPort() + "/b").setResponseCode(302));
server.enqueue(new MockResponse().setBody(EXPECTED));
AtomicReference<ForestRequest> atomicReq = new AtomicReference<>(null);
ForestResponse<String> response = redirectClient.testNotAutoRedirect(((redirectReq, prevReq, prevRes) -> {
atomicReq.set(redirectReq);
}));
assertThat(response).isNotNull();
assertThat(response.getStatusCode()).isEqualTo(302);
assertThat(response.isRedirection()).isTrue();
assertThat(response.getRedirectionLocation()).isEqualTo("http://localhost:" + server.getPort() + "/b");
String result = response.redirectionRequest().execute(String.class);
assertThat(result).isNotNull().isEqualTo(EXPECTED);
assertThat(atomicReq.get()).isNotNull();
assertThat(atomicReq.get().getPath()).isEqualTo("/b");
}
use of com.dtflys.forest.http.ForestResponse in project forest by dromara.
the class TestBaseRedirectClient method testBaseAutoRedirect_302.
@Test
public void testBaseAutoRedirect_302() {
server.enqueue(new MockResponse().addHeader("Location", "http://localhost:" + server.getPort() + "/b").setResponseCode(302));
server.enqueue(new MockResponse().setBody(EXPECTED));
AtomicReference<ForestRequest> atomicReq = new AtomicReference<>(null);
ForestResponse<String> response = baseRedirectClient.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);
mockRequest(server).assertPathEquals("/");
mockRequest(server).assertPathEquals("/b").assertBodyEquals("body=" + RedirectInterceptor.BODY);
}
Aggregations