use of retrofit2.http.Multipart 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.Multipart in project retrofit by square.
the class RequestBuilderTest method multipartArray.
@Test
public void multipartArray() throws IOException {
class Example {
//
@Multipart
//
@POST("/foo/bar/")
Call<ResponseBody> method(@Part("ping") String[] ping) {
return null;
}
}
Request request = buildRequest(Example.class, new Object[] { new String[] { "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--");
}
use of retrofit2.http.Multipart in project retrofit by square.
the class RequestBuilderTest method multipartPartMapSupportsSubclasses.
@Test
public void multipartPartMapSupportsSubclasses() throws IOException {
class Foo extends HashMap<String, String> {
}
class Example {
//
@Multipart
//
@POST("/foo/bar/")
Call<ResponseBody> method(@PartMap Foo parts) {
return null;
}
}
Foo foo = new Foo();
foo.put("hello", "world");
Request request = buildRequest(Example.class, foo);
Buffer buffer = new Buffer();
request.body().writeTo(buffer);
assertThat(buffer.readUtf8()).contains("name=\"hello\"").contains("\r\n\r\nworld\r\n--");
}
Aggregations