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