Search in sources :

Example 16 with Response

use of feign.Response in project feign by OpenFeign.

the class JAXBCodecTest method doesntDecodeParameterizedTypes.

@Test
public void doesntDecodeParameterizedTypes() throws Exception {
    thrown.expect(UnsupportedOperationException.class);
    thrown.expectMessage("JAXB only supports decoding raw types. Found java.util.Map<java.lang.String, ?>");
    class ParameterizedHolder {

        Map<String, ?> field;
    }
    Type parameterized = ParameterizedHolder.class.getDeclaredField("field").getGenericType();
    Response response = Response.builder().status(200).reason("OK").headers(Collections.<String, Collection<String>>emptyMap()).body("<foo/>", UTF_8).build();
    new JAXBDecoder(new JAXBContextFactory.Builder().build()).decode(response, parameterized);
}
Also used : Response(feign.Response) XmlAccessorType(javax.xml.bind.annotation.XmlAccessorType) XmlAccessType(javax.xml.bind.annotation.XmlAccessType) Type(java.lang.reflect.Type) Map(java.util.Map) Test(org.junit.Test)

Example 17 with Response

use of feign.Response in project feign by OpenFeign.

the class JAXBCodecTest method notFoundDecodesToEmpty.

/** Enabled via {@link feign.Feign.Builder#decode404()} */
@Test
public void notFoundDecodesToEmpty() throws Exception {
    Response response = Response.builder().status(404).reason("NOT FOUND").headers(Collections.<String, Collection<String>>emptyMap()).build();
    assertThat((byte[]) new JAXBDecoder(new JAXBContextFactory.Builder().build()).decode(response, byte[].class)).isEmpty();
}
Also used : Response(feign.Response) Collection(java.util.Collection) Test(org.junit.Test)

Example 18 with Response

use of feign.Response in project feign by OpenFeign.

the class JAXBCodecTest method decodesXml.

@Test
public void decodesXml() throws Exception {
    MockObject mock = new MockObject();
    mock.value = "Test";
    String mockXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><mockObject>" + "<value>Test</value></mockObject>";
    Response response = Response.builder().status(200).reason("OK").headers(Collections.<String, Collection<String>>emptyMap()).body(mockXml, UTF_8).build();
    JAXBDecoder decoder = new JAXBDecoder(new JAXBContextFactory.Builder().build());
    assertEquals(mock, decoder.decode(response, MockObject.class));
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 19 with Response

use of feign.Response in project feign by OpenFeign.

the class GsonCodecTest method notFoundDecodesToEmpty.

/** Enabled via {@link feign.Feign.Builder#decode404()} */
@Test
public void notFoundDecodesToEmpty() throws Exception {
    Response response = Response.builder().status(404).reason("NOT FOUND").headers(Collections.<String, Collection<String>>emptyMap()).build();
    assertThat((byte[]) new GsonDecoder().decode(response, byte[].class)).isEmpty();
}
Also used : Response(feign.Response) Collection(java.util.Collection) Test(org.junit.Test)

Example 20 with Response

use of feign.Response in project feign by OpenFeign.

the class GsonCodecTest method customDecoder.

@Test
public void customDecoder() throws Exception {
    GsonDecoder decoder = new GsonDecoder(Arrays.<TypeAdapter<?>>asList(upperZone));
    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, decoder.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)

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