use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method queryParamOptionalOmitsQuery.
@Test
public void queryParamOptionalOmitsQuery() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@Query("ping") String ping) {
return null;
}
}
Request request = buildRequest(Example.class, new Object[] { null });
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method getWithQueryParamList.
@Test
public void getWithQueryParamList() {
class Example {
//
@GET("/foo/bar/")
Call<ResponseBody> method(@Query("key") List<Object> keys) {
return null;
}
}
List<Object> values = Arrays.<Object>asList(1, 2, null, "three", "1");
Request request = buildRequest(Example.class, values);
assertThat(request.method()).isEqualTo("GET");
assertThat(request.headers().size()).isZero();
assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?key=1&key=2&key=three&key=1");
assertThat(request.body()).isNull();
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method multipleParameterAnnotationsOnlyOneRetrofitAllowed.
@Test
public void multipleParameterAnnotationsOnlyOneRetrofitAllowed() throws Exception {
class Example {
//
@GET("/")
Call<ResponseBody> method(@Query("maybe") @NonNull Object o) {
return null;
}
}
Request request = buildRequest(Example.class, "yep");
assertThat(request.url().toString()).isEqualTo("http://example.com/?maybe=yep");
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method simpleMultipart.
@Test
public void simpleMultipart() throws IOException {
class Example {
//
@Multipart
//
@POST("/foo/bar/")
Call<ResponseBody> method(@Part("ping") String ping, @Part("kit") RequestBody kit) {
return null;
}
}
Request request = buildRequest(Example.class, "pong", RequestBody.create(MediaType.parse("text/plain"), "kat"));
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\npong\r\n--");
assertThat(bodyString).contains("Content-Disposition: form-data;").contains("name=\"kit\"").contains("\r\nkat\r\n--");
}
use of retrofit2.http in project retrofit by square.
the class RequestBuilderTest method multipartPartMap.
@Test
public void multipartPartMap() throws IOException {
class Example {
//
@Multipart
//
@POST("/foo/bar/")
Call<ResponseBody> method(@PartMap Map<String, RequestBody> parts) {
return null;
}
}
Map<String, RequestBody> params = new LinkedHashMap<>();
params.put("ping", RequestBody.create(null, "pong"));
params.put("kit", RequestBody.create(null, "kat"));
Request request = buildRequest(Example.class, params);
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\npong\r\n--");
assertThat(bodyString).contains("Content-Disposition: form-data;").contains("name=\"kit\"").contains("\r\nkat\r\n--");
}
Aggregations