Search in sources :

Example 1 with Path

use of retrofit2.http.Path 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 2 with Path

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

the class RequestBuilderTest method normalPostWithPathParam.

@Test
public void normalPostWithPathParam() {
    class Example {

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

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

the class RequestBuilderTest method getWithEncodedPathSegments.

@Test
public void getWithEncodedPathSegments() {
    class Example {

        //
        @GET("/foo/bar/{ping}/")
        Call<ResponseBody> method(@Path(value = "ping", encoded = true) String ping) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "baz/pong/more");
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/baz/pong/more/");
    assertThat(request.body()).isNull();
}
Also used : Path(retrofit2.http.Path) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 4 with Path

use of retrofit2.http.Path 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)

Example 5 with Path

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

the class RequestBuilderTest method getWithEncodedPathParam.

@Test
public void getWithEncodedPathParam() {
    class Example {

        //
        @GET("/foo/bar/{ping}/")
        Call<ResponseBody> method(@Path(value = "ping", encoded = true) String ping) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "po%20ng");
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/po%20ng/");
    assertThat(request.body()).isNull();
}
Also used : Path(retrofit2.http.Path) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Aggregations

ResponseBody (okhttp3.ResponseBody)16 Request (okhttp3.Request)13 Test (org.junit.Test)13 Path (retrofit2.http.Path)12 Response (retrofit2.Response)5 ServiceResponse (com.microsoft.rest.ServiceResponse)4 Query (retrofit2.http.Query)4 MultipartBody (okhttp3.MultipartBody)3 RequestBody (okhttp3.RequestBody)3 Body (retrofit2.http.Body)3 TypeToken (com.google.common.reflect.TypeToken)2 LoadParameters (com.microsoft.azure.management.cdn.LoadParameters)2 PurgeParameters (com.microsoft.azure.management.cdn.PurgeParameters)2 Observable (rx.Observable)2 Timed (com.codahale.metrics.annotation.Timed)1 ApiOperation (io.swagger.annotations.ApiOperation)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 MockResponse (okhttp3.mockwebserver.MockResponse)1