本文整理汇总了Java中retrofit2.http.Multipart类的典型用法代码示例。如果您正苦于以下问题:Java Multipart类的具体用法?Java Multipart怎么用?Java Multipart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Multipart类属于retrofit2.http包,在下文中一共展示了Multipart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onlyOneEncodingIsAllowedMultipartFirst
import retrofit2.http.Multipart; //导入依赖的package包/类
@Test public void onlyOneEncodingIsAllowedMultipartFirst() {
class Example {
@Multipart //
@FormUrlEncoded //
@POST("/") //
Call<ResponseBody> method() {
return null;
}
}
try {
buildRequest(Example.class);
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage(
"Only one encoding annotation is allowed.\n for method Example.method");
}
}
示例2: onlyOneEncodingIsAllowedFormEncodingFirst
import retrofit2.http.Multipart; //导入依赖的package包/类
@Test public void onlyOneEncodingIsAllowedFormEncodingFirst() {
class Example {
@FormUrlEncoded //
@Multipart //
@POST("/") //
Call<ResponseBody> method() {
return null;
}
}
try {
buildRequest(Example.class);
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage(
"Only one encoding annotation is allowed.\n for method Example.method");
}
}
示例3: multipartFailsOnNonBodyMethod
import retrofit2.http.Multipart; //导入依赖的package包/类
@Test public void multipartFailsOnNonBodyMethod() {
class Example {
@Multipart //
@GET("/") //
Call<ResponseBody> method() {
return null;
}
}
try {
buildRequest(Example.class);
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage(
"Multipart can only be specified on HTTP methods with request body (e.g., @POST).\n for method Example.method");
}
}
示例4: multipartFailsWithNoParts
import retrofit2.http.Multipart; //导入依赖的package包/类
@Test public void multipartFailsWithNoParts() {
class Example {
@Multipart //
@POST("/") //
Call<ResponseBody> method() {
return null;
}
}
try {
buildRequest(Example.class);
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage(
"Multipart method must contain at least one @Part.\n for method Example.method");
}
}
示例5: multipartIterableRequiresName
import retrofit2.http.Multipart; //导入依赖的package包/类
@Test public void multipartIterableRequiresName() {
class Example {
@Multipart //
@POST("/foo/bar/") //
Call<ResponseBody> method(@Part List<RequestBody> part) {
return null;
}
}
try {
buildRequest(Example.class, new Object[] { null });
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage(
"@Part annotation must supply a name or use MultipartBody.Part parameter type. (parameter #1)\n"
+ " for method Example.method");
}
}
示例6: multipartArrayRequiresName
import retrofit2.http.Multipart; //导入依赖的package包/类
@Test public void multipartArrayRequiresName() {
class Example {
@Multipart //
@POST("/foo/bar/") //
Call<ResponseBody> method(@Part RequestBody[] part) {
return null;
}
}
try {
buildRequest(Example.class, new Object[] { null });
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage(
"@Part annotation must supply a name or use MultipartBody.Part parameter type. (parameter #1)\n"
+ " for method Example.method");
}
}
示例7: multipartOkHttpPartForbidsName
import retrofit2.http.Multipart; //导入依赖的package包/类
@Test public void multipartOkHttpPartForbidsName() {
class Example {
@Multipart //
@POST("/foo/bar/") //
Call<ResponseBody> method(@Part("name") MultipartBody.Part part) {
return null;
}
}
try {
buildRequest(Example.class, new Object[] { null });
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage(
"@Part parameters using the MultipartBody.Part must not include a part name in the annotation. (parameter #1)\n"
+ " for method Example.method");
}
}
示例8: multipartIterableOkHttpPart
import retrofit2.http.Multipart; //导入依赖的package包/类
@Test public void multipartIterableOkHttpPart() {
class Example {
@Multipart //
@POST("/foo/bar/") //
Call<ResponseBody> method(@Part("ping") List<MultipartBody.Part> part) {
return null;
}
}
try {
buildRequest(Example.class, new Object[] { null });
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage(
"@Part parameters using the MultipartBody.Part must not include a part name in the annotation. (parameter #1)\n"
+ " for method Example.method");
}
}
示例9: multipartArrayOkHttpPart
import retrofit2.http.Multipart; //导入依赖的package包/类
@Test public void multipartArrayOkHttpPart() {
class Example {
@Multipart //
@POST("/foo/bar/") //
Call<ResponseBody> method(@Part("ping") MultipartBody.Part[] part) {
return null;
}
}
try {
buildRequest(Example.class, new Object[] { null });
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage(
"@Part parameters using the MultipartBody.Part must not include a part name in the annotation. (parameter #1)\n"
+ " for method Example.method");
}
}
示例10: multipartPartMapRejectsOkHttpPartValues
import retrofit2.http.Multipart; //导入依赖的package包/类
@Test public void multipartPartMapRejectsOkHttpPartValues() {
class Example {
@Multipart //
@POST("/foo/bar/") //
Call<ResponseBody> method(@PartMap Map<String, MultipartBody.Part> parts) {
return null;
}
}
try {
buildRequest(Example.class, new Object[] { null });
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage(
"@PartMap values cannot be MultipartBody.Part. Use @Part List<Part> or a different value type instead. (parameter #1)\n"
+ " for method Example.method");
}
}
示例11: multipartPartMapRejectsNull
import retrofit2.http.Multipart; //导入依赖的package包/类
@Test public void multipartPartMapRejectsNull() {
class Example {
@Multipart //
@POST("/foo/bar/") //
Call<ResponseBody> method(@PartMap Map<String, RequestBody> parts) {
return null;
}
}
try {
buildRequest(Example.class, new Object[] { null });
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("Part map was null.");
}
}
示例12: multipartPartMapRejectsNullValues
import retrofit2.http.Multipart; //导入依赖的package包/类
@Test public void multipartPartMapRejectsNullValues() {
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", null);
try {
buildRequest(Example.class, params);
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("Part map contained null value for key 'kit'.");
}
}
示例13: multipartPartMapMustBeMap
import retrofit2.http.Multipart; //导入依赖的package包/类
@Test public void multipartPartMapMustBeMap() {
class Example {
@Multipart //
@POST("/foo/bar/") //
Call<ResponseBody> method(@PartMap List<Object> parts) {
return null;
}
}
try {
buildRequest(Example.class, Collections.emptyList());
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage(
"@PartMap parameter type must be Map. (parameter #1)\n for method Example.method");
}
}
示例14: multipartNullRemovesPart
import retrofit2.http.Multipart; //导入依赖的package包/类
@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--");
}
示例15: multipartPartsShouldBeInOrder
import retrofit2.http.Multipart; //导入依赖的package包/类
@Test public void multipartPartsShouldBeInOrder() throws IOException {
class Example {
@Multipart
@POST("/foo")
Call<ResponseBody> get(@Part("first") String data, @Part("second") String dataTwo, @Part("third") String dataThree) {
return null;
}
}
Request request = buildRequest(Example.class, "firstParam", "secondParam", "thirdParam");
MultipartBody body = (MultipartBody) request.body();
Buffer buffer = new Buffer();
body.writeTo(buffer);
String readBody = buffer.readUtf8();
assertThat(readBody.indexOf("firstParam")).isLessThan(readBody.indexOf("secondParam"));
assertThat(readBody.indexOf("secondParam")).isLessThan(readBody.indexOf("thirdParam"));
}