Search in sources :

Example 61 with Request

use of com.tonyodev.fetch2.Request 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)

Example 62 with Request

use of com.tonyodev.fetch2.Request in project retrofit by square.

the class RequestBuilderTest method multipartPartsShouldBeInOrder.

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

        @Multipart
        @POST("/foo")
        Call<ResponseBody> get(@Part("first") String data, @Part("second") String dataTwo, @Part("third") String dataThree) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "firstParam", "secondParam", "thirdParam");
    MultipartBody body = (MultipartBody) request.body();
    Buffer buffer = new Buffer();
    body.writeTo(buffer);
    String readBody = buffer.readUtf8();
    assertThat(readBody.indexOf("firstParam")).isLessThan(readBody.indexOf("secondParam"));
    assertThat(readBody.indexOf("secondParam")).isLessThan(readBody.indexOf("thirdParam"));
}
Also used : Buffer(okio.Buffer) Part(retrofit2.http.Part) MultipartBody(okhttp3.MultipartBody) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 63 with Request

use of com.tonyodev.fetch2.Request in project retrofit by square.

the class RequestBuilderTest method getWithUrlAbsoluteSameHost.

@Test
public void getWithUrlAbsoluteSameHost() {
    class Example {

        @GET
        Call<ResponseBody> method(@Url String url) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "http://example.com/foo/bar/");
    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) Url(retrofit2.http.Url) HttpUrl(okhttp3.HttpUrl) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 64 with Request

use of com.tonyodev.fetch2.Request in project retrofit by square.

the class RequestBuilderTest method getWithHeaderMap.

@Test
public void getWithHeaderMap() {
    class Example {

        @GET("/search")
        Call<ResponseBody> method(@HeaderMap Map<String, Object> headers) {
            return null;
        }
    }
    Map<String, Object> headers = new LinkedHashMap<>();
    headers.put("Accept", "text/plain");
    headers.put("Accept-Charset", "utf-8");
    Request request = buildRequest(Example.class, headers);
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.url().toString()).isEqualTo("http://example.com/search");
    assertThat(request.body()).isNull();
    assertThat(request.headers().size()).isEqualTo(2);
    assertThat(request.header("Accept")).isEqualTo("text/plain");
    assertThat(request.header("Accept-Charset")).isEqualTo("utf-8");
}
Also used : HeaderMap(retrofit2.http.HeaderMap) 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 65 with Request

use of com.tonyodev.fetch2.Request in project keywhiz by square.

the class XsrfServletFilterIntegrationTest method rejectsForAdminUrlWithoutXsrf.

@Test
public void rejectsForAdminUrlWithoutXsrf() throws Exception {
    noXsrfClient.newCall(buildLoginPost(DbSeedCommand.defaultUser, DbSeedCommand.defaultPassword)).execute();
    Request request = new Request.Builder().url(testUrl("/admin/clients")).get().build();
    Response response = noXsrfClient.newCall(request).execute();
    assertThat(response.code()).isEqualTo(401);
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) Test(org.junit.Test)

Aggregations

Request (okhttp3.Request)1617 Response (okhttp3.Response)1022 IOException (java.io.IOException)525 Test (org.junit.Test)407 OkHttpClient (okhttp3.OkHttpClient)331 RequestBody (okhttp3.RequestBody)256 Call (okhttp3.Call)239 ResponseBody (okhttp3.ResponseBody)189 HttpUrl (okhttp3.HttpUrl)146 Callback (okhttp3.Callback)109 Map (java.util.Map)85 File (java.io.File)77 InputStream (java.io.InputStream)77 JSONObject (org.json.JSONObject)76 MediaType (okhttp3.MediaType)75 Buffer (okio.Buffer)73 List (java.util.List)71 Headers (okhttp3.Headers)71 FormBody (okhttp3.FormBody)64 HashMap (java.util.HashMap)63