use of feign.Response in project feign by OpenFeign.
the class JsonDecoderTest method badJsonThrowsWrappedJSONException.
@Test
public void badJsonThrowsWrappedJSONException() throws IOException {
String json = "{\"a\":\"b\",\"c\":1}";
Response response = Response.builder().status(204).reason("OK").headers(Collections.emptyMap()).body(json, UTF_8).request(request).build();
Exception exception = assertThrows(DecodeException.class, () -> new JsonDecoder().decode(response, JSONArray.class));
assertEquals("A JSONArray text must start with '[' at 1 [character 2 line 1]", exception.getMessage());
assertTrue(exception.getCause() instanceof JSONException);
}
use of feign.Response in project feign by OpenFeign.
the class HttpProtocolVersionTest method testMockProtocolVersion.
@Test
public void testMockProtocolVersion() {
Remote remote = Feign.builder().client(new MockClient().ok(HttpMethod.GET, "/test")).target(new MockTarget<>(Remote.class));
Response response = remote.test();
assertNotNull(response.protocolVersion());
assertEquals("MOCK", response.protocolVersion().toString());
}
use of feign.Response in project feign by OpenFeign.
the class Http2ClientAsyncTest method decodingExceptionGetWrappedInDecode404Mode.
@Test
public void decodingExceptionGetWrappedInDecode404Mode() throws Throwable {
server.enqueue(new MockResponse().setResponseCode(404));
thrown.expect(DecodeException.class);
thrown.expectCause(isA(NoSuchElementException.class));
final TestInterfaceAsync api = newAsyncBuilder().decode404().decoder((response, type) -> {
assertEquals(404, response.status());
throw new NoSuchElementException();
}).target("http://localhost:" + server.getPort());
unwrap(api.post());
}
use of feign.Response in project feign by OpenFeign.
the class Http2ClientAsyncTest method throwsFeignExceptionWithoutBody.
@Test
public void throwsFeignExceptionWithoutBody() {
server.enqueue(new MockResponse().setBody("success!"));
final TestInterfaceAsync api = newAsyncBuilder().decoder((response, type) -> {
throw new IOException("timeout");
}).target("http://localhost:" + server.getPort());
try {
api.noContent();
} catch (final FeignException e) {
Assertions.assertThat(e.getMessage()).isEqualTo("timeout reading POST http://localhost:" + server.getPort() + "/");
Assertions.assertThat(e.contentUTF8()).isEqualTo("");
}
}
use of feign.Response in project feign by OpenFeign.
the class Http2ClientAsyncTest method whenReturnTypeIsResponseNoErrorHandling.
@SuppressWarnings("deprecation")
@Test
public void whenReturnTypeIsResponseNoErrorHandling() throws Throwable {
final Map<String, Collection<String>> headers = new LinkedHashMap<String, Collection<String>>();
headers.put("Location", Arrays.asList("http://bar.com"));
final Response response = Response.builder().status(302).reason("Found").headers(headers).request(Request.create(HttpMethod.GET, "/", Collections.emptyMap(), null, Util.UTF_8)).body(new byte[0]).build();
final ExecutorService execs = Executors.newSingleThreadExecutor();
// fake client as Client.Default follows redirects.
final TestInterfaceAsync api = AsyncFeign.<Void>asyncBuilder().client(new AsyncClient.Default<>((request, options) -> response, execs)).target(TestInterfaceAsync.class, "http://localhost:" + server.getPort());
assertThat(unwrap(api.response()).headers().get("Location")).contains("http://bar.com");
execs.shutdown();
}
Aggregations