Search in sources :

Example 6 with Response

use of feign.Response in project feign by OpenFeign.

the class DefaultDecoderTest method testDecodesToByteArray.

@Test
public void testDecodesToByteArray() throws Exception {
    Response response = knownResponse();
    Object decodedObject = decoder.decode(response, byte[].class);
    assertEquals(byte[].class, decodedObject.getClass());
    assertEquals("response body", new String((byte[]) decodedObject, UTF_8));
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 7 with Response

use of feign.Response in project feign by OpenFeign.

the class DefaultErrorDecoderTest method throwsFeignExceptionIncludingBody.

@Test
public void throwsFeignExceptionIncludingBody() throws Throwable {
    thrown.expect(FeignException.class);
    thrown.expectMessage("status 500 reading Service#foo(); content:\nhello world");
    Response response = Response.builder().status(500).reason("Internal server error").headers(headers).body("hello world", UTF_8).build();
    throw errorDecoder.decode("Service#foo()", response);
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 8 with Response

use of feign.Response in project feign by OpenFeign.

the class DefaultErrorDecoderTest method retryAfterHeaderThrowsRetryableException.

@Test
public void retryAfterHeaderThrowsRetryableException() throws Throwable {
    thrown.expect(FeignException.class);
    thrown.expectMessage("status 503 reading Service#foo()");
    headers.put(RETRY_AFTER, Arrays.asList("Sat, 1 Jan 2000 00:00:00 GMT"));
    Response response = Response.builder().status(503).reason("Service Unavailable").headers(headers).build();
    throw errorDecoder.decode("Service#foo()", response);
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 9 with Response

use of feign.Response in project feign by OpenFeign.

the class AbstractClientTest method testContentTypeWithoutCharset.

@Test
public void testContentTypeWithoutCharset() 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");
    // 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 10 with Response

use of feign.Response in project feign by OpenFeign.

the class AbstractClientTest method reasonPhraseIsOptional.

@Test
public void reasonPhraseIsOptional() throws IOException, InterruptedException {
    server.enqueue(new MockResponse().setStatus("HTTP/1.1 " + 200));
    TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
    Response response = api.post("foo");
    assertThat(response.status()).isEqualTo(200);
    assertThat(response.reason()).isNullOrEmpty();
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) 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