Search in sources :

Example 66 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<>();
    zones.add(new Zone("denominator.io."));
    zones.add(new Zone("denominator.io.", "ABCD"));
    String zonesJson = "[{\"name\":\"denominator.io.\"},{\"name\":\"denominator.io.\",\"id\":\"ABCD\"}]";
    Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).body(zonesJson, UTF_8).build();
    assertEquals(zones, new JacksonJrDecoder().decode(response, new TypeReference<List<Zone>>() {
    }.getType()));
}
Also used : Response(feign.Response) Collections.singletonList(java.util.Collections.singletonList) Test(org.junit.Test)

Example 67 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.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").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).body(zonesJson, UTF_8).build();
    assertEquals(zones, decoder.decode(response, new TypeReference<List<Zone>>() {
    }.getType()));
}
Also used : Response(feign.Response) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 68 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonCodecTest method nullBodyDecodesToNullIterator.

@Test
public void nullBodyDecodesToNullIterator() throws Exception {
    Response response = Response.builder().status(204).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).build();
    assertNull(JacksonIteratorDecoder.create().decode(response, Iterator.class));
}
Also used : Response(feign.Response) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 69 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonCodecTest method notFoundDecodesToNull.

/**
 * Enabled via {@link feign.Feign.Builder#decode404()}
 */
@Test
public void notFoundDecodesToNull() throws Exception {
    Response response = Response.builder().status(404).reason("NOT FOUND").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).build();
    assertThat((byte[]) new JacksonDecoder().decode(response, byte[].class)).isNull();
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 70 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").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).body(new byte[0]).build();
    assertNull(new JacksonDecoder().decode(response, String.class));
}
Also used : Response(feign.Response) Test(org.junit.Test)

Aggregations

Response (feign.Response)169 Test (org.junit.Test)118 IOException (java.io.IOException)32 MockResponse (okhttp3.mockwebserver.MockResponse)26 KeyManagementException (org.wso2.carbon.apimgt.core.exception.KeyManagementException)22 Test (org.testng.annotations.Test)20 Collection (java.util.Collection)19 HashMap (java.util.HashMap)16 OAuth2IntrospectionResponse (org.wso2.carbon.apimgt.core.auth.dto.OAuth2IntrospectionResponse)16 ArrayList (java.util.ArrayList)15 Gson (com.google.gson.Gson)13 FeignException (feign.FeignException)13 OAuth2ServiceStubs (org.wso2.carbon.apimgt.core.auth.OAuth2ServiceStubs)13 IdentityProviderException (org.wso2.carbon.apimgt.core.exception.IdentityProviderException)13 Request (feign.Request)11 RetryableException (feign.RetryableException)11 DecodeException (feign.codec.DecodeException)10 Map (java.util.Map)10 ExpectedException (org.junit.rules.ExpectedException)10 Type (java.lang.reflect.Type)9