@Test public void multipartPartMapRejectsNonStringKeys() { class Example { @Multipart // @POST("/foo/bar/") // Call<ResponseBody> method(@PartMap Map<Object, RequestBody> parts) { return null; } } try { buildRequest(Example.class, new Object[] { null }); fail(); } catch (IllegalArgumentException e) { assertThat(e).hasMessage( "@PartMap keys must be of type String: class java.lang.Object (parameter #1)\n" + " for method Example.method"); } }
@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"); } }
@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."); } }
@Test public void multipartPartMapRejectsNullKeys() { 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(null, RequestBody.create(null, "kat")); try { buildRequest(Example.class, params); fail(); } catch (IllegalArgumentException e) { assertThat(e).hasMessage("Part map contained null key."); } }
@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'."); } }
@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"); } }
@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--"); }
@Test public void implicitMultipartWithPartMapForbidden() { class Example { @POST("/") // Call<ResponseBody> method(@PartMap Map<String, String> params) { return null; } } try { buildRequest(Example.class); fail(); } catch (IllegalArgumentException e) { assertThat(e).hasMessage( "@PartMap parameters can only be used with multipart encoding. (parameter #1)\n for method Example.method"); } }
@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--"); }
@Test public void multipartPartMapWithEncoding() throws IOException { class Example { @Multipart // @POST("/foo/bar/") // Call<ResponseBody> method(@PartMap(encoding = "8-bit") 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("Content-Transfer-Encoding: 8-bit") .contains("\r\npong\r\n--"); assertThat(bodyString) .contains("Content-Disposition: form-data;") .contains("name=\"kit\"") .contains("Content-Transfer-Encoding: 8-bit") .contains("\r\nkat\r\n--"); }
@POST("user/regist/person") @Multipart Flowable<ResponseDto<User>> regPerson( @PartMap Map<String, RequestBody> param, @Part MultipartBody.Part front, @Part MultipartBody.Part back );
@POST("ad/new") @Multipart Flowable<ResponseDto<User>> add( @PartMap Map<String, RequestBody> param, @Part MultipartBody.Part adFile, @Part MultipartBody.Part coverFile );
@Multipart @POST("user") Observable<BaseBean<String>> array_post( /** * key: String * value:把value用RequestBody包装放到Map中 */ @PartMap Map<String, RequestBody> map );
@POST("file//upload/v1") @Multipart Flowable<ResponseDto> add( @PartMap Map<String, RequestBody> param, @Part MultipartBody.Part file );
@POST("user/regist/company") @Multipart Flowable<ResponseDto<User>> regCompany( @PartMap Map<String, RequestBody> param, @Part MultipartBody.Part front );
@POST("ad/new") @Multipart Flowable<ResponseDto<User>> add( @PartMap Map<String, RequestBody> param, @Part MultipartBody.Part adFile );
@POST("ad/delete") @Multipart Flowable<ResponseDto> delete( @PartMap Map<String, RequestBody> param );
@Multipart @POST("/multipart/start") Call<StartResponse> start(@PartMap Map<String, RequestBody> parameters);
@Multipart @POST("/multipart/upload") Call<UploadResponse> upload(@PartMap Map<String, RequestBody> parameters);
@Multipart @POST("/multipart/commit") Call<ResponseBody> commit(@PartMap Map<String, RequestBody> parameters);
@Multipart @POST("/multipart/complete") Call<CompleteResponse> complete(@PartMap Map<String, RequestBody> parameters);
@Multipart @POST() Observable<ResponseBody> uploadFiles(@Url() String url, @PartMap() Map<String, RequestBody> maps);
@Multipart @POST Flowable<ResponseBody> uploadFileWithPartMap( @Url() String url, @PartMap() Map<String, RequestBody> partMap, @Part("file") MultipartBody.Part file);
@Multipart @POST() Observable<ResponseBody> uploadFiles(@Url String url, @PartMap() Map<String, RequestBody> maps);
@POST(Constants.FanFou.DESTROY_STATUSES_URL) @Multipart Observable<HttpResponseData<StatusRes>> destroyStatus( @PartMap Map<String, RequestBody> bodyMap);
@Multipart @POST(Constants.FanFou.UPDATE_STATUSES_URL) Observable<HttpResponseData<StatusRes>> updateStatus(@PartMap Map<String, RequestBody> bodyMap);
@POST(Constants.FanFou.PHOTOS_UPLOAD_URL) @Multipart Observable<HttpResponseData<StatusRes>> uploadPhoto(@PartMap Map<String, RequestBody> bodyMap);
@POST(Constants.FanFou.SEND_DIRECT_MESSAGE_URL) @Multipart Observable<HttpResponseData<DirectMessagesRes>> sendDirectMessage( @PartMap Map<String, RequestBody> bodyMap);
@POST(Constants.FanFou.CREATE_FRIENDSHIP_URL) @Multipart Observable<HttpResponseData<UserRes>> createFriendship( @PartMap Map<String, RequestBody> bodyMap);
@POST(Constants.FanFou.DESTROY_FRIENDSHIP_URL) @Multipart Observable<HttpResponseData<UserRes>> destoryFriendship( @PartMap Map<String, RequestBody> bodyMap);