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();
}
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());
}
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"));
}
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();
}
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()));
}
Aggregations