use of okhttp3.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();
}
use of okhttp3.Response in project feign by OpenFeign.
the class AbstractClientTest method postWithSpacesInPath.
@Test
public void postWithSpacesInPath() throws IOException, InterruptedException {
server.enqueue(new MockResponse().setBody("foo"));
TestInterface api = newBuilder().target(TestInterface.class, "http://localhost:" + server.getPort());
Response response = api.post("current documents", "foo");
MockWebServerAssertions.assertThat(server.takeRequest()).hasMethod("POST").hasPath("/path/current%20documents/resource").hasBody("foo");
}
use of okhttp3.Response in project feign by OpenFeign.
the class FeignTest method ensureRetryerClonesItself.
@Test
public void ensureRetryerClonesItself() {
server.enqueue(new MockResponse().setResponseCode(503).setBody("foo 1"));
server.enqueue(new MockResponse().setResponseCode(200).setBody("foo 2"));
server.enqueue(new MockResponse().setResponseCode(503).setBody("foo 3"));
server.enqueue(new MockResponse().setResponseCode(200).setBody("foo 4"));
MockRetryer retryer = new MockRetryer();
TestInterface api = Feign.builder().retryer(retryer).errorDecoder(new ErrorDecoder() {
@Override
public Exception decode(String methodKey, Response response) {
return new RetryableException("play it again sam!", null);
}
}).target(TestInterface.class, "http://localhost:" + server.getPort());
api.post();
// if retryer instance was reused, this statement will throw an exception
api.post();
assertEquals(4, server.getRequestCount());
}
use of okhttp3.Response in project feign by OpenFeign.
the class FeignBuilderTest method testOverrideEncoder.
@Test
public void testOverrideEncoder() throws Exception {
server.enqueue(new MockResponse().setBody("response data"));
String url = "http://localhost:" + server.getPort();
Encoder encoder = new Encoder() {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
template.body(object.toString());
}
};
TestInterface api = Feign.builder().encoder(encoder).target(TestInterface.class, url);
api.encodedPost(Arrays.asList("This", "is", "my", "request"));
assertThat(server.takeRequest()).hasBody("[This, is, my, request]");
}
use of okhttp3.Response in project feign by OpenFeign.
the class FeignTest method responseCoercesToStringBody.
@Test
public void responseCoercesToStringBody() throws Exception {
server.enqueue(new MockResponse().setBody("foo"));
TestInterface api = new TestInterfaceBuilder().target("http://localhost:" + server.getPort());
Response response = api.response();
assertTrue(response.body().isRepeatable());
assertEquals("foo", response.body().toString());
}
Aggregations