Search in sources :

Example 21 with Response

use of feign.Response in project feign by OpenFeign.

the class GsonCodecTest method decodes.

@Test
public void decodes() throws Exception {
    List<Zone> zones = new LinkedList<Zone>();
    zones.add(new Zone("denominator.io."));
    zones.add(new Zone("denominator.io.", "ABCD"));
    Response response = Response.builder().status(200).reason("OK").headers(Collections.<String, Collection<String>>emptyMap()).body(zonesJson, UTF_8).build();
    assertEquals(zones, new GsonDecoder().decode(response, new TypeToken<List<Zone>>() {
    }.getType()));
}
Also used : Response(feign.Response) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 22 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonCodecTest method decodes.

@Test
public void decodes() throws Exception {
    List<Zone> zones = new LinkedList<Zone>();
    zones.add(new Zone("denominator.io."));
    zones.add(new Zone("denominator.io.", "ABCD"));
    Response response = Response.builder().status(200).reason("OK").headers(Collections.<String, Collection<String>>emptyMap()).body(zonesJson, UTF_8).build();
    assertEquals(zones, new JacksonDecoder().decode(response, new TypeReference<List<Zone>>() {
    }.getType()));
}
Also used : Response(feign.Response) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 23 with Response

use of feign.Response in project feign by OpenFeign.

the class DefaultDecoderTest method testDecodesToString.

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

Example 24 with Response

use of feign.Response in project feign by OpenFeign.

the class DefaultErrorDecoderTest method throwsFeignException.

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

Example 25 with Response

use of feign.Response in project feign by OpenFeign.

the class DefaultErrorDecoderTest method testFeignExceptionIncludesStatus.

@Test
public void testFeignExceptionIncludesStatus() throws Throwable {
    Response response = Response.builder().status(400).reason("Bad request").headers(headers).build();
    Exception exception = errorDecoder.decode("Service#foo()", response);
    assertThat(exception).isInstanceOf(FeignException.class);
    assertThat(((FeignException) exception).status()).isEqualTo(400);
}
Also used : Response(feign.Response) FeignException(feign.FeignException) ExpectedException(org.junit.rules.ExpectedException) FeignException(feign.FeignException) 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