use of feign.Response in project feign by OpenFeign.
the class DefaultErrorDecoderHttpErrorTest method testExceptionIsHttpSpecific.
@Test
public void testExceptionIsHttpSpecific() throws Throwable {
Response response = Response.builder().status(httpStatus).reason("anything").request(Request.create(HttpMethod.GET, "http://example.com/api", Collections.emptyMap(), null, Util.UTF_8)).headers(headers).body("response body", Util.UTF_8).build();
Exception exception = errorDecoder.decode("Service#foo()", response);
assertThat(exception).isInstanceOf(expectedExceptionClass);
assertThat(((FeignException) exception).status()).isEqualTo(httpStatus);
assertThat(exception.getMessage()).isEqualTo(expectedMessage);
}
use of feign.Response in project feign by OpenFeign.
the class AbstractClientTest method testContentTypeWithoutCharset.
@Test
public void testContentTypeWithoutCharset() throws Exception {
server.enqueue(new MockResponse().setBody("AAAAAAAA"));
TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
Response response = api.postWithContentType("foo", "text/plain");
// Response length should not be null
assertEquals("AAAAAAAA", Util.toString(response.body().asReader(UTF_8)));
}
use of feign.Response in project feign by OpenFeign.
the class AbstractClientTest method testAlternativeCollectionFormat.
@Test
public void testAlternativeCollectionFormat() throws Exception {
server.enqueue(new MockResponse().setBody("body"));
TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
Response response = api.getCSV(Arrays.asList("bar", "baz"));
assertThat(response.status()).isEqualTo(200);
assertThat(response.reason()).isEqualTo("OK");
// Some HTTP libraries percent-encode commas in query parameters and others don't.
MockWebServerAssertions.assertThat(server.takeRequest()).hasMethod("GET").hasOneOfPath("/?foo=bar,baz", "/?foo=bar%2Cbaz");
}
use of feign.Response in project feign by OpenFeign.
the class AbstractClientTest method testDefaultCollectionFormat.
@Test
public void testDefaultCollectionFormat() throws Exception {
server.enqueue(new MockResponse().setBody("body"));
TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
Response response = api.get(Arrays.asList("bar", "baz"));
assertThat(response.status()).isEqualTo(200);
assertThat(response.reason()).isEqualTo("OK");
MockWebServerAssertions.assertThat(server.takeRequest()).hasMethod("GET").hasPath("/?foo=bar&foo=baz");
}
use of feign.Response in project feign by OpenFeign.
the class AbstractClientTest method reasonPhraseIsOptional.
@Test
public void reasonPhraseIsOptional() throws IOException, InterruptedException {
server.enqueue(new MockResponse().setStatus("HTTP/1.1 " + 200));
TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
Response response = api.post("foo");
assertThat(response.status()).isEqualTo(200);
assertThat(response.reason()).isNullOrEmpty();
}
Aggregations