Search in sources :

Example 61 with retrofit2.http

use of retrofit2.http in project retrofit by square.

the class RequestBuilderTest method getWithHttpUrl.

@Test
public void getWithHttpUrl() {
    class Example {

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

Example 62 with retrofit2.http

use of retrofit2.http in project retrofit by square.

the class RequestBuilderTest method headerMapSupportsSubclasses.

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

        @GET("/search")
        Call<ResponseBody> method(@HeaderMap Foo headers) {
            return null;
        }
    }
    Foo headers = new Foo();
    headers.put("Accept", "text/plain");
    Request request = buildRequest(Example.class, headers);
    assertThat(request.url().toString()).isEqualTo("http://example.com/search");
    assertThat(request.headers().size()).isEqualTo(1);
    assertThat(request.header("Accept")).isEqualTo("text/plain");
}
Also used : HeaderMap(retrofit2.http.HeaderMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 63 with retrofit2.http

use of retrofit2.http in project retrofit by square.

the class RequestBuilderTest method postWithUrl.

@Test
public void postWithUrl() {
    class Example {

        @POST
        Call<ResponseBody> method(@Url String url, @Body RequestBody body) {
            return null;
        }
    }
    RequestBody body = RequestBody.create(MediaType.parse("text/plain"), "hi");
    Request request = buildRequest(Example.class, "http://example.com/foo/bar", body);
    assertThat(request.method()).isEqualTo("POST");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar");
    assertBody(request.body(), "hi");
}
Also used : Request(okhttp3.Request) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) MultipartBody(okhttp3.MultipartBody) Body(retrofit2.http.Body) Url(retrofit2.http.Url) HttpUrl(okhttp3.HttpUrl) RequestBody(okhttp3.RequestBody) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 64 with retrofit2.http

use of retrofit2.http in project retrofit by square.

the class RequestBuilderTest method getWithJavaUriUrl.

@Test
public void getWithJavaUriUrl() {
    class Example {

        @GET
        Call<ResponseBody> method(@Url URI url) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, URI.create("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) URI(java.net.URI) Url(retrofit2.http.Url) HttpUrl(okhttp3.HttpUrl) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 65 with retrofit2.http

use of retrofit2.http in project retrofit by square.

the class FallbackParserFinderTest method converterFactoryFallsBackToParserField.

@Test
public void converterFactoryFallsBackToParserField() {
    Retrofit retrofit = new Retrofit.Builder().baseUrl("http://localhost/").build();
    ProtoConverterFactory factory = ProtoConverterFactory.create();
    Converter<ResponseBody, ?> converter = factory.responseBodyConverter(FakePhone.class, new Annotation[0], retrofit);
    assertThat(converter).isNotNull();
}
Also used : Retrofit(retrofit2.Retrofit) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)82 ResponseBody (okhttp3.ResponseBody)76 Request (okhttp3.Request)72 Retrofit (retrofit2.Retrofit)39 OkHttpClient (okhttp3.OkHttpClient)28 RequestBody (okhttp3.RequestBody)22 IOException (java.io.IOException)19 Query (retrofit2.http.Query)15 MultipartBody (okhttp3.MultipartBody)12 Buffer (okio.Buffer)12 Path (retrofit2.http.Path)12 Interceptor (okhttp3.Interceptor)11 HttpUrl (okhttp3.HttpUrl)10 Response (okhttp3.Response)10 HashMap (java.util.HashMap)9 LinkedHashMap (java.util.LinkedHashMap)9 Response (retrofit2.Response)9 Part (retrofit2.http.Part)9 List (java.util.List)8 QueryMap (retrofit2.http.QueryMap)8