use of feign.Response in project feign by OpenFeign.
the class JAXBCodecTest method doesntDecodeParameterizedTypes.
@Test
public void doesntDecodeParameterizedTypes() throws Exception {
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("JAXB only supports decoding raw types. Found java.util.Map<java.lang.String, ?>");
class ParameterizedHolder {
Map<String, ?> field;
}
Type parameterized = ParameterizedHolder.class.getDeclaredField("field").getGenericType();
Response response = Response.builder().status(200).reason("OK").headers(Collections.<String, Collection<String>>emptyMap()).body("<foo/>", UTF_8).build();
new JAXBDecoder(new JAXBContextFactory.Builder().build()).decode(response, parameterized);
}
use of feign.Response in project feign by OpenFeign.
the class JAXBCodecTest 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 JAXBDecoder(new JAXBContextFactory.Builder().build()).decode(response, byte[].class)).isEmpty();
}
use of feign.Response in project feign by OpenFeign.
the class JAXBCodecTest method decodesXml.
@Test
public void decodesXml() throws Exception {
MockObject mock = new MockObject();
mock.value = "Test";
String mockXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><mockObject>" + "<value>Test</value></mockObject>";
Response response = Response.builder().status(200).reason("OK").headers(Collections.<String, Collection<String>>emptyMap()).body(mockXml, UTF_8).build();
JAXBDecoder decoder = new JAXBDecoder(new JAXBContextFactory.Builder().build());
assertEquals(mock, decoder.decode(response, MockObject.class));
}
use of feign.Response in project feign by OpenFeign.
the class GsonCodecTest 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 GsonDecoder().decode(response, byte[].class)).isEmpty();
}
use of feign.Response in project feign by OpenFeign.
the class GsonCodecTest method customDecoder.
@Test
public void customDecoder() throws Exception {
GsonDecoder decoder = new GsonDecoder(Arrays.<TypeAdapter<?>>asList(upperZone));
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 TypeToken<List<Zone>>() {
}.getType()));
}
Aggregations