Search in sources :

Example 36 with Response

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();
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 37 with Response

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");
}
Also used : Response(feign.Response) MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Example 38 with Response

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());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) ErrorDecoder(feign.codec.ErrorDecoder) Test(org.junit.Test)

Example 39 with Response

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]");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Type(java.lang.reflect.Type) Encoder(feign.codec.Encoder) Test(org.junit.Test)

Example 40 with Response

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());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)471 Response (okhttp3.Response)444 MockResponse (okhttp3.mockwebserver.MockResponse)380 Request (okhttp3.Request)377 ResponseBody (okhttp3.ResponseBody)351 IOException (java.io.IOException)220 DateTime (org.joda.time.DateTime)194 DateTimeRfc1123 (com.microsoft.rest.DateTimeRfc1123)192 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)178 Response (retrofit2.Response)150 ServiceCall (com.microsoft.rest.ServiceCall)140 ServiceResponse (com.microsoft.rest.ServiceResponse)114 Observable (rx.Observable)104 Call (okhttp3.Call)103 List (java.util.List)95 RequestBody (okhttp3.RequestBody)85 PagedList (com.microsoft.azure.PagedList)80 ServiceResponseWithHeaders (com.microsoft.rest.ServiceResponseWithHeaders)78 OkHttpClient (okhttp3.OkHttpClient)78 HttpURLConnection (java.net.HttpURLConnection)47