use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method put.
@Test
public void put() {
class Example {
//
@PUT("/foo/bar/")
Call<ResponseBody> method(@Body RequestBody body) {
return null;
}
}
RequestBody body = RequestBody.create(MediaType.parse("text/plain"), "hi");
Request request = buildRequest(Example.class, body);
assertThat(request.method()).isEqualTo("PUT");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
assertBody(request.body(), "hi");
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method headerParam.
@Test
public void headerParam() {
class Example {
//
@GET("/foo/bar/")
//
@Headers("ping: pong")
Call<ResponseBody> method(@Header("kit") String kit) {
return null;
}
}
Request request = buildRequest(Example.class, "kat");
assertThat(request.method()).isEqualTo("GET");
okhttp3.Headers headers = request.headers();
assertThat(headers.size()).isEqualTo(2);
assertThat(headers.get("ping")).isEqualTo("pong");
assertThat(headers.get("kit")).isEqualTo("kat");
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
assertThat(request.body()).isNull();
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method queryParamOptional.
@Test
public void queryParamOptional() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@Query("foo") String foo, @Query("ping") String ping, @Query("kit") String kit) {
return null;
}
}
Request request = buildRequest(Example.class, "bar", null, "kat");
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?foo=bar&kit=kat");
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method multipartNullRemovesPart.
@Test
public void multipartNullRemovesPart() throws IOException {
class Example {
//
@Multipart
//
@POST("/foo/bar/")
Call<ResponseBody> method(@Part("ping") String ping, @Part("fizz") String fizz) {
return null;
}
}
Request request = buildRequest(Example.class, "pong", null);
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=\"ping\"").contains("\r\npong\r\n--");
}
use of retrofit2.http 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();
}
Aggregations