Search in sources :

Example 16 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class WireConverterFactoryTest method deserializeWrongClass.

@Test
public void deserializeWrongClass() throws IOException {
    ByteString encoded = ByteString.decodeBase64("Cg4oNTE5KSA4NjctNTMwOQ==");
    server.enqueue(new MockResponse().setBody(new Buffer().write(encoded)));
    try {
        service.wrongClass();
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessage("" + "Unable to create converter for class java.lang.String\n" + "    for method Service.wrongClass");
        assertThat(e.getCause()).hasMessage("" + "Could not locate ResponseBody converter for class java.lang.String.\n" + "  Tried:\n" + "   * retrofit2.BuiltInConverters\n" + "   * retrofit2.converter.wire.WireConverterFactory");
    }
}
Also used : Buffer(okio.Buffer) MockResponse(okhttp3.mockwebserver.MockResponse) ByteString(okio.ByteString) Test(org.junit.Test)

Example 17 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class RequestBuilderTest method getWithEncodedPathStillPreventsRequestSplitting.

@Test
public void getWithEncodedPathStillPreventsRequestSplitting() {
    class Example {

        //
        @GET("/foo/bar/{ping}/")
        Call<ResponseBody> method(@Path(value = "ping", encoded = true) String ping) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "baz/\r\npong");
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/baz/pong/");
    assertThat(request.body()).isNull();
}
Also used : Path(retrofit2.http.Path) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 18 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class RequestBuilderTest method formEncodedWithEncodedNameFieldParamMap.

@Test
public void formEncodedWithEncodedNameFieldParamMap() {
    class Example {

        //
        @FormUrlEncoded
        //
        @POST("/foo")
        Call<ResponseBody> method(@FieldMap(encoded = true) Map<String, Object> fieldMap) {
            return null;
        }
    }
    Map<String, Object> fieldMap = new LinkedHashMap<>();
    fieldMap.put("k%20it", "k%20at");
    fieldMap.put("pin%20g", "po%20ng");
    Request request = buildRequest(Example.class, fieldMap);
    assertBody(request.body(), "k%20it=k%20at&pin%20g=po%20ng");
}
Also used : FieldMap(retrofit2.http.FieldMap) Request(okhttp3.Request) PartMap(retrofit2.http.PartMap) HashMap(java.util.HashMap) HeaderMap(retrofit2.http.HeaderMap) FieldMap(retrofit2.http.FieldMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) QueryMap(retrofit2.http.QueryMap) ResponseBody(okhttp3.ResponseBody) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 19 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class RequestBuilderTest method normalPostWithPathParam.

@Test
public void normalPostWithPathParam() {
    class Example {

        //
        @POST("/foo/bar/{ping}/")
        Call<ResponseBody> method(@Path("ping") String ping, @Body RequestBody body) {
            return null;
        }
    }
    RequestBody body = RequestBody.create(TEXT_PLAIN, "Hi!");
    Request request = buildRequest(Example.class, "pong", body);
    assertThat(request.method()).isEqualTo("POST");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/pong/");
    assertBody(request.body(), "Hi!");
}
Also used : Path(retrofit2.http.Path) Request(okhttp3.Request) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) MultipartBody(okhttp3.MultipartBody) Body(retrofit2.http.Body) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 20 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class RequestBuilderTest method customMethodNoBody.

@Test
public void customMethodNoBody() {
    class Example {

        @HTTP(method = "CUSTOM1", path = "/foo")
        Call<ResponseBody> method() {
            return null;
        }
    }
    Request request = buildRequest(Example.class);
    assertThat(request.method()).isEqualTo("CUSTOM1");
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo");
    assertThat(request.body()).isNull();
}
Also used : Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Aggregations

ResponseBody (okhttp3.ResponseBody)584 DateTimeRfc1123 (com.microsoft.rest.DateTimeRfc1123)332 DateTime (org.joda.time.DateTime)332 ServiceCall (com.microsoft.rest.ServiceCall)140 Test (org.junit.Test)123 Request (okhttp3.Request)112 Observable (rx.Observable)97 Response (retrofit2.Response)94 ServiceResponse (com.microsoft.rest.ServiceResponse)92 PagedList (com.microsoft.azure.PagedList)80 ServiceResponseWithHeaders (com.microsoft.rest.ServiceResponseWithHeaders)78 List (java.util.List)64 IOException (java.io.IOException)33 Response (okhttp3.Response)33 Buffer (okio.Buffer)33 RequestBody (okhttp3.RequestBody)31 PageImpl (com.microsoft.azure.batch.protocol.models.PageImpl)26 MockResponse (okhttp3.mockwebserver.MockResponse)24 InputStream (java.io.InputStream)19 MultipartBody (okhttp3.MultipartBody)16