Search in sources :

Example 21 with GET

use of retrofit2.http.GET in project retrofit by square.

the class RequestBuilderTest method queryParamsSkippedIfConvertedToNull.

@Test
public void queryParamsSkippedIfConvertedToNull() throws Exception {
    class Example {

        @GET("/query")
        Call<ResponseBody> queryPath(@Query("a") Object a) {
            return null;
        }
    }
    Retrofit.Builder retrofitBuilder = new Retrofit.Builder().baseUrl("http://example.com").addConverterFactory(new NullObjectConverterFactory());
    Request request = buildRequest(Example.class, retrofitBuilder, "Ignored");
    assertThat(request.url().toString()).doesNotContain("Ignored");
}
Also used : NullObjectConverterFactory(retrofit2.helpers.NullObjectConverterFactory) Query(retrofit2.http.Query) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 22 with GET

use of retrofit2.http.GET 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 23 with GET

use of retrofit2.http.GET 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 24 with GET

use of retrofit2.http.GET 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 25 with GET

use of retrofit2.http.GET in project retrofit by square.

the class RequestBuilderTest method getWithUnencodedPathSegmentsPreventsRequestSplitting.

@Test
public void getWithUnencodedPathSegmentsPreventsRequestSplitting() {
    class Example {

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

Aggregations

ResponseBody (okhttp3.ResponseBody)61 Test (org.junit.Test)54 Request (okhttp3.Request)52 Response (retrofit2.Response)27 Retrofit (retrofit2.Retrofit)23 Query (retrofit2.http.Query)15 List (java.util.List)14 IOException (java.io.IOException)12 OkHttpClient (okhttp3.OkHttpClient)12 HttpUrl (okhttp3.HttpUrl)10 Path (retrofit2.http.Path)10 ArrayList (java.util.ArrayList)9 BrainSentences (com.gladysinc.gladys.Models.BrainSentences)8 RetrofitAPI (com.gladysinc.gladys.Utils.RetrofitAPI)8 SelfSigningClientBuilder (com.gladysinc.gladys.Utils.SelfSigningClientBuilder)8 ServiceResponse (com.microsoft.rest.ServiceResponse)8 Call (retrofit2.Call)8 Url (retrofit2.http.Url)8 Uri (android.net.Uri)6 View (android.view.View)6