Search in sources :

Example 61 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class RequestBuilderTest method formEncodedFieldOptional.

@Test
public void formEncodedFieldOptional() {
    class Example {

        //
        @FormUrlEncoded
        //
        @POST("/foo")
        Call<ResponseBody> method(@Field("foo") String foo, @Field("ping") String ping, @Field("kit") String kit) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "bar", null, "kat");
    assertBody(request.body(), "foo=bar&kit=kat");
}
Also used : Field(retrofit2.http.Field) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 62 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class RequestBuilderTest method bodyWithPathParams.

@Test
public void bodyWithPathParams() {
    class Example {

        //
        @POST("/foo/bar/{ping}/{kit}/")
        Call<ResponseBody> method(@Path("ping") String ping, @Body RequestBody body, @Path("kit") String kit) {
            return null;
        }
    }
    RequestBody body = RequestBody.create(TEXT_PLAIN, "Hi!");
    Request request = buildRequest(Example.class, "pong", body, "kat");
    assertThat(request.method()).isEqualTo("POST");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/pong/kat/");
    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 63 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class RequestBuilderTest method headerParamToString.

@Test
public void headerParamToString() {
    class Example {

        //
        @GET("/foo/bar/")
        Call<ResponseBody> method(@Header("kit") BigInteger kit) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, new BigInteger("1234"));
    assertThat(request.method()).isEqualTo("GET");
    okhttp3.Headers headers = request.headers();
    assertThat(headers.size()).isEqualTo(1);
    assertThat(headers.get("kit")).isEqualTo("1234");
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
    assertThat(request.body()).isNull();
}
Also used : Header(retrofit2.http.Header) Request(okhttp3.Request) BigInteger(java.math.BigInteger) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 64 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class ResponseTest method errorWithSuccessRawResponseThrows.

@Test
public void errorWithSuccessRawResponseThrows() {
    ResponseBody errorBody = ResponseBody.create(null, "Broken!");
    try {
        Response.error(errorBody, successResponse);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessage("rawResponse should not be successful response");
    }
}
Also used : ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 65 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class ResponseTest method errorWithSuccessCodeThrows.

@Test
public void errorWithSuccessCodeThrows() {
    ResponseBody errorBody = ResponseBody.create(null, "Broken!");
    try {
        Response.error(200, errorBody);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessage("code < 400: 200");
    }
}
Also used : 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