use of retrofit2.http 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");
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method bodyWithPathParams.
@Test
public void bodyWithPathParams() {
class Example {
//
@POST("/foo/bar/{ping}/{kit}/")
Call<ResponseBody> method(@Path("ping") String ping, @Body RequestBody body, @Path("kit") String kit) {
return null;
}
}
RequestBody body = RequestBody.create(TEXT_PLAIN, "Hi!");
Request request = buildRequest(Example.class, "pong", body, "kat");
assertThat(request.method()).isEqualTo("POST");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/pong/kat/");
assertBody(request.body(), "Hi!");
}
use of retrofit2.http 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();
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method post.
@Test
public void post() {
class Example {
//
@POST("/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("POST");
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 multipartIterable.
@Test
public void multipartIterable() throws IOException {
class Example {
//
@Multipart
//
@POST("/foo/bar/")
Call<ResponseBody> method(@Part("ping") List<String> ping) {
return null;
}
}
Request request = buildRequest(Example.class, Arrays.asList("pong1", "pong2"));
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\"\r\n").contains("\r\npong1\r\n--");
assertThat(bodyString).contains("Content-Disposition: form-data;").contains("name=\"ping\"").contains("\r\npong2\r\n--");
}
Aggregations