Search in sources :

Example 61 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonJaxbCodecTest 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 JacksonJaxbJsonDecoder().decode(response, byte[].class)).isNull();
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 62 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonCodecTest method decoderCharset.

@Test
public void decoderCharset() throws IOException {
    Zone zone = new Zone("denominator.io.", "ÁÉÍÓÚÀÈÌÒÙÄËÏÖÜÑ");
    Map<String, Collection<String>> headers = new HashMap<String, Collection<String>>();
    headers.put("Content-Type", Arrays.asList("application/json;charset=ISO-8859-1"));
    Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(headers).body(new String(// 
    "" + "{" + System.lineSeparator() + "  \"name\" : \"DENOMINATOR.IO.\"," + System.lineSeparator() + "  \"id\" : \"ÁÉÍÓÚÀÈÌÒÙÄËÏÖÜÑ\"" + System.lineSeparator() + "}").getBytes(StandardCharsets.ISO_8859_1)).build();
    assertEquals(zone.getId(), ((Zone) new JacksonJrDecoder().decode(response, Zone.class)).getId());
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 63 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonCodecTest method decodesToMap.

@Test
public void decodesToMap() throws Exception {
    String json = "{\"name\":\"jim\",\"id\":12}";
    Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).body(json, UTF_8).build();
    Map<String, Object> map = (Map<String, Object>) new JacksonJrDecoder().decode(response, new TypeReference<Map<String, Object>>() {
    }.getType());
    assertEquals(12, map.get("id"));
    assertEquals("jim", map.get("name"));
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 64 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 JacksonJrDecoder().decode(response, byte[].class)).isNull();
}
Also used : Response(feign.Response) Test(org.junit.Test)

Example 65 with Response

use of feign.Response in project feign by OpenFeign.

the class JacksonCodecTest method customDecoder.

@Test
public void customDecoder() throws Exception {
    JacksonJrDecoder decoder = new JacksonJrDecoder(singletonList(new JavaLocalDateExtension()));
    List<LocalDate> dates = new LinkedList<>();
    dates.add(LocalDate.of(2020, 1, 2));
    dates.add(LocalDate.of(2021, 2, 3));
    Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).body(DATES_JSON, UTF_8).build();
    assertEquals(dates, decoder.decode(response, new TypeReference<List<LocalDate>>() {
    }.getType()));
}
Also used : Response(feign.Response) Collections.singletonList(java.util.Collections.singletonList) LocalDate(java.time.LocalDate) 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