use of feign.Response in project feign by OpenFeign.
the class Http2ClientAsyncTest method responseCoercesToStringBody.
@Test
public void responseCoercesToStringBody() throws Throwable {
server.enqueue(new MockResponse().setBody("foo"));
final TestInterfaceAsync api = newAsyncBuilder().target("http://localhost:" + server.getPort());
final Response response = unwrap(api.response());
assertTrue(response.body().isRepeatable());
assertEquals("foo", Util.toString(response.body().asReader(StandardCharsets.UTF_8)));
}
use of feign.Response in project feign by OpenFeign.
the class JacksonIteratorTest method responseIsClosedAfterIteration.
@Test
public void responseIsClosedAfterIteration() throws IOException {
final AtomicBoolean closed = new AtomicBoolean();
byte[] jsonBytes = "[false, true]".getBytes(UTF_8);
InputStream inputStream = new ByteArrayInputStream(jsonBytes) {
@Override
public void close() throws IOException {
closed.set(true);
super.close();
}
};
Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).body(inputStream, jsonBytes.length).build();
assertThat(iterator(Boolean.class, response)).toIterable().hasSize(2);
assertThat(closed.get()).isTrue();
}
use of feign.Response in project feign by OpenFeign.
the class JAXBCodecTest method doesntDecodeParameterizedTypes.
@Test
public void doesntDecodeParameterizedTypes() throws Exception {
thrown.expect(feign.codec.DecodeException.class);
thrown.expectMessage("java.util.Map is an interface, and JAXB can't handle interfaces.\n" + "\tthis problem is related to the following location:\n" + "\t\tat java.util.Map");
class ParameterizedHolder {
Map<String, ?> field;
}
Type parameterized = ParameterizedHolder.class.getDeclaredField("field").getGenericType();
Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).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 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").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.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 JacksonJaxbCodecTest method decodeTest.
@Test
public void decodeTest() throws Exception {
Response response = Response.builder().status(200).reason("OK").request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)).headers(Collections.emptyMap()).body("{\"value\":\"Test\"}", UTF_8).build();
JacksonJaxbJsonDecoder decoder = new JacksonJaxbJsonDecoder();
assertThat(decoder.decode(response, MockObject.class)).isEqualTo(new MockObject("Test"));
}
Aggregations