use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class TestUrlWithAt method testGetUrlWithUserInfo.
@Test
public void testGetUrlWithUserInfo() {
server.enqueue(new MockResponse().setBody(EXPECTED));
ForestResponse<String> response = getClient.getUrlWithUserInfo();
assertNotNull(response);
log.info("response: " + response);
ForestRequest request = response.getRequest();
String userInfo = request.getUserInfo();
assertEquals("xxxxxx:yyyy", userInfo);
mockRequest(server).assertMethodEquals("GET").assertPathEquals("/hello/user");
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class TestUrlWithAt method testGetUrlWithUserInfo3.
@Test
public void testGetUrlWithUserInfo3() {
server.enqueue(new MockResponse().setBody(EXPECTED));
ForestResponse<String> response = getClient.getUrlWithUserInfo3("xxx/yyy/foo");
assertNotNull(response);
log.info("response: " + response);
ForestRequest request = response.getRequest();
String userInfo = request.getUserInfo();
assertEquals("xxx/yyy/foo", userInfo);
mockRequest(server).assertMethodEquals("GET").assertPathEquals("/hello/user");
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class TestUrlWithAt method testGetUrlWithUserInfo2.
@Test
public void testGetUrlWithUserInfo2() {
server.enqueue(new MockResponse().setBody(EXPECTED));
ForestResponse<String> response = getClient.getUrlWithUserInfo2();
assertNotNull(response);
log.info("response: " + response);
ForestRequest request = response.getRequest();
String userInfo = request.getUserInfo();
assertEquals("xxxxxx:1234", userInfo);
mockRequest(server).assertMethodEquals("GET").assertPathEquals("/hello/user");
}
use of com.dtflys.forest.http.ForestRequest in project forest by dromara.
the class TestBaseRedirectClient method testBaseAutoRedirect_305.
@Test
public void testBaseAutoRedirect_305() {
server.enqueue(new MockResponse().addHeader("Location", "http://localhost:" + server.getPort() + "/b").setResponseCode(305));
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.ForestRequest in project forest by dromara.
the class TestBaseRedirectClient method testBaseAutoRedirect_307.
@Test
public void testBaseAutoRedirect_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 = 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