Search in sources :

Example 36 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class RequestBuilderTest method queryMapSupportsSubclasses.

@Test
public void queryMapSupportsSubclasses() {
    class Foo extends HashMap<String, String> {
    }
    class Example {

        //
        @GET("/")
        Call<ResponseBody> method(@QueryMap Foo a) {
            return null;
        }
    }
    Foo foo = new Foo();
    foo.put("hello", "world");
    Request request = buildRequest(Example.class, foo);
    assertThat(request.url().toString()).isEqualTo("http://example.com/?hello=world");
}
Also used : QueryMap(retrofit2.http.QueryMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 37 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class RequestBuilderTest method multipartOkHttpArrayPart.

@Test
public void multipartOkHttpArrayPart() throws IOException {
    class Example {

        //
        @Multipart
        //
        @POST("/foo/bar/")
        Call<ResponseBody> method(@Part MultipartBody.Part[] part) {
            return null;
        }
    }
    MultipartBody.Part part1 = MultipartBody.Part.createFormData("foo", "bar");
    MultipartBody.Part part2 = MultipartBody.Part.createFormData("kit", "kat");
    Request request = buildRequest(Example.class, new Object[] { new MultipartBody.Part[] { part1, part2 } });
    assertThat(request.method()).isEqualTo("POST");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
    RequestBody body = request.body();
    Buffer buffer = new Buffer();
    body.writeTo(buffer);
    String bodyString = buffer.readUtf8();
    assertThat(bodyString).contains("Content-Disposition: form-data;").contains("name=\"foo\"\r\n").contains("\r\nbar\r\n--");
    assertThat(bodyString).contains("Content-Disposition: form-data;").contains("name=\"kit\"\r\n").contains("\r\nkat\r\n--");
}
Also used : Buffer(okio.Buffer) Part(retrofit2.http.Part) MultipartBody(okhttp3.MultipartBody) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) RequestBody(okhttp3.RequestBody) Test(org.junit.Test)

Example 38 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class RequestBuilderTest method options.

@Test
public void options() {
    class Example {

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

Example 39 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class RequestBuilderTest method malformedContentTypeHeaderThrows.

@Test
public void malformedContentTypeHeaderThrows() {
    class Example {

        //
        @POST("/")
        //
        @Headers("Content-Type: hello, world!")
        Call<ResponseBody> method(@Body RequestBody body) {
            return null;
        }
    }
    RequestBody body = RequestBody.create(MediaType.parse("text/plain"), "hi");
    try {
        buildRequest(Example.class, body);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessage("Malformed content type: hello, world!\n" + "    for method Example.method");
    }
}
Also used : RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) MultipartBody(okhttp3.MultipartBody) Body(retrofit2.http.Body) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 40 with ResponseBody

use of okhttp3.ResponseBody in project retrofit by square.

the class RequestBuilderTest method get.

@Test
public void get() {
    class Example {

        //
        @GET("/foo/bar/")
        Call<ResponseBody> method() {
            return null;
        }
    }
    Request request = buildRequest(Example.class);
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
    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