Search in sources :

Example 11 with Response

use of feign.Response in project feign by OpenFeign.

the class AbstractClientTest method postWithSpacesInPath.

@Test
public void postWithSpacesInPath() throws IOException, InterruptedException {
    server.enqueue(new MockResponse().setBody("foo"));
    TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
    Response response = api.post("current documents", "foo");
    MockWebServerAssertions.assertThat(server.takeRequest()).hasMethod("POST").hasPath("/path/current%20documents/resource").hasBody("foo");
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 12 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonCodecTest method nullBodyDecodesToNull.

@Test
public void nullBodyDecodesToNull() throws Exception {
    Response response = Response.builder().status(204).reason("OK").headers(Collections.<String, Collection<String>>emptyMap()).build();
    assertNull(new JacksonDecoder().decode(response, String.class));
}
Also used : Response(feign.Response) Collection(java.util.Collection) Test(org.junit.Test)

Example 13 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonCodecTest method emptyBodyDecodesToNull.

@Test
public void emptyBodyDecodesToNull() throws Exception {
    Response response = Response.builder().status(204).reason("OK").headers(Collections.<String, Collection<String>>emptyMap()).body(new byte[0]).build();
    assertNull(new JacksonDecoder().decode(response, String.class));
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 14 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonCodecTest 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 JacksonDecoder().decode(response, byte[].class)).isEmpty();
}
Also used : Response(feign.Response) Collection(java.util.Collection) Test(org.junit.Test)

Example 15 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonCodecTest method customDecoder.

@Test
public void customDecoder() throws Exception {
    JacksonDecoder decoder = new JacksonDecoder(Arrays.<Module>asList(new SimpleModule().addDeserializer(Zone.class, new ZoneDeserializer())));
    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 TypeReference<List<Zone>>() {
    }.getType()));
}
Also used : Response(feign.Response) LinkedList(java.util.LinkedList) List(java.util.List) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) 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