use of feign.Response in project feign by OpenFeign.
the class AbstractClientTest method parsesResponseMissingLength.
@Test
public void parsesResponseMissingLength() throws IOException, InterruptedException {
server.enqueue(new MockResponse().setChunkedBody("foo", 1));
TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
Response response = api.post("testing");
assertThat(response.status()).isEqualTo(200);
assertThat(response.reason()).isEqualTo("OK");
assertThat(response.body().length()).isNull();
assertThat(response.body().asInputStream()).hasContentEqualTo(new ByteArrayInputStream("foo".getBytes(UTF_8)));
}
use of feign.Response in project feign by OpenFeign.
the class AbstractClientTest method testVeryLongResponseNullLength.
@Test
public void testVeryLongResponseNullLength() throws Exception {
server.enqueue(new MockResponse().setBody("AAAAAAAA").addHeader("Content-Length", Long.MAX_VALUE));
TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
Response response = api.post("foo");
// Response length greater than Integer.MAX_VALUE should be null
assertThat(response.body().length()).isNull();
}
use of feign.Response in project feign by OpenFeign.
the class AbstractClientTest method testContentTypeWithCharset.
@Test
public void testContentTypeWithCharset() throws Exception {
server.enqueue(new MockResponse().setBody("AAAAAAAA"));
TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
Response response = api.postWithContentType("foo", "text/plain;charset=utf-8");
// Response length should not be null
assertEquals("AAAAAAAA", Util.toString(response.body().asReader()));
}
use of feign.Response in project feign by OpenFeign.
the class AbstractClientTest method testResponseLength.
@Test
public void testResponseLength() throws Exception {
server.enqueue(new MockResponse().setBody("test"));
TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
Integer expected = 4;
Response response = api.post("");
Integer actual = response.body().length();
assertEquals(expected, actual);
}
use of feign.Response in project feign by OpenFeign.
the class AbstractClientTest method parsesRequestAndResponse.
@Test
public void parsesRequestAndResponse() throws IOException, InterruptedException {
server.enqueue(new MockResponse().setBody("foo").addHeader("Foo: Bar"));
TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
Response response = api.post("foo");
assertThat(response.status()).isEqualTo(200);
assertThat(response.reason()).isEqualTo("OK");
assertThat(response.headers()).containsEntry("Content-Length", asList("3")).containsEntry("Foo", asList("Bar"));
assertThat(response.body().asInputStream()).hasContentEqualTo(new ByteArrayInputStream("foo".getBytes(UTF_8)));
MockWebServerAssertions.assertThat(server.takeRequest()).hasMethod("POST").hasPath("/?foo=bar&foo=baz&qux=").hasHeaders("Foo: Bar", "Foo: Baz", "Qux: ", "Accept: */*", "Content-Length: 3").hasBody("foo");
}
Aggregations