Search in sources :

Example 26 with Response

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)));
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 27 with Response

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();
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 28 with Response

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()));
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 29 with Response

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);
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 30 with Response

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");
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Aggregations

Response (feign.Response)34 Test (org.junit.Test)32 Collection (java.util.Collection)9 MockResponse (okhttp3.mockwebserver.MockResponse)8 List (java.util.List)5 LinkedList (java.util.LinkedList)4 Map (java.util.Map)3 Request (feign.Request)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 LinkedHashMap (java.util.LinkedHashMap)2 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 ClientRequest (com.netflix.client.ClientRequest)1 IResponse (com.netflix.client.IResponse)1 Client (feign.Client)1 Contract (feign.Contract)1 FeignException (feign.FeignException)1 MethodMetadata (feign.MethodMetadata)1 HardCodedTarget (feign.Target.HardCodedTarget)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1