@Test public void testUploadPhotoReturnsOk() throws Exception { stubFor(post(urlPathEqualTo("/v2/photomap.add")) .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", "application/json") .withBodyFile("upload-ok.json"))); Upload.Result result = apiClient.uploadPhoto("arnold", "cyberdyne101", -0.5, 53, 12345678, "scifi", "evilrobots", "The Cyberdyne Model 101", null); verify(postRequestedFor(urlPathEqualTo("/v2/photomap.add")) .withHeader("Content-Type", matching("multipart/form-data; boundary=.*")) .withRequestBody(matching(".*username.*arnold.*password.*cyberdyne101.*longitude.*-0.5.*latitude.*53.*datetime.*12345678.*category.*scifi.*metacategory.*evilrobots.*caption.*The Cyberdyne Model 101.*")) .withQueryParam("key", equalTo("myApiKey"))); assertThat(result.ok()).isTrue(); assertThat(result.url()).isEqualTo("https: }
public Upload.Result uploadPhoto(final String username, final String password, final double lon, final double lat, final long dateTime, final String category, final String metaCat, final String caption, final String filename) throws IOException { MultipartBody.Part filePart = null; if (filename != null) { File file = new File(filename); RequestBody fileBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); filePart = MultipartBody.Part.createFormData("mediaupload", file.getName(), fileBody); } RequestBody usernamePart = RequestBody.create(MediaType.parse("text/plain"), username); RequestBody passwordPart = RequestBody.create(MediaType.parse("text/plain"), password); RequestBody categoryPart = RequestBody.create(MediaType.parse("text/plain"), category); RequestBody metaCatPart = RequestBody.create(MediaType.parse("text/plain"), metaCat); RequestBody captionPart = RequestBody.create(MediaType.parse("text/plain"), caption); Response<UploadPhotoResponseDto> response = v2Api.uploadPhoto(usernamePart, passwordPart, lon, lat, dateTime, categoryPart, metaCatPart, captionPart, filePart).execute(); return response.body().toUploadResult(); }
RetrofitApiClient { public Upload.Result uploadPhoto(final String username, final String password, final double lon, final double lat, final long dateTime, final String category, final String metaCat, final String caption, final String filename) throws IOException { MultipartBody.Part filePart = null; if (filename != null) { File file = new File(filename); RequestBody fileBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); filePart = MultipartBody.Part.createFormData("mediaupload", file.getName(), fileBody); } RequestBody usernamePart = RequestBody.create(MediaType.parse("text/plain"), username); RequestBody passwordPart = RequestBody.create(MediaType.parse("text/plain"), password); RequestBody categoryPart = RequestBody.create(MediaType.parse("text/plain"), category); RequestBody metaCatPart = RequestBody.create(MediaType.parse("text/plain"), metaCat); RequestBody captionPart = RequestBody.create(MediaType.parse("text/plain"), caption); Response<UploadPhotoResponseDto> response = v2Api.uploadPhoto(usernamePart, passwordPart, lon, lat, dateTime, categoryPart, metaCatPart, captionPart, filePart).execute(); return response.body().toUploadResult(); } }
RetrofitApiClient { public Upload.Result uploadPhoto(final String username, final String password, final double lon, final double lat, final long dateTime, final String category, final String metaCat, final String caption, final String filename) throws IOException { MultipartBody.Part filePart = null; if (filename != null) { File file = new File(filename); RequestBody fileBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); filePart = MultipartBody.Part.createFormData("mediaupload", file.getName(), fileBody); } RequestBody usernamePart = RequestBody.create(MediaType.parse("text/plain"), username); RequestBody passwordPart = RequestBody.create(MediaType.parse("text/plain"), password); RequestBody categoryPart = RequestBody.create(MediaType.parse("text/plain"), category); RequestBody metaCatPart = RequestBody.create(MediaType.parse("text/plain"), metaCat); RequestBody captionPart = RequestBody.create(MediaType.parse("text/plain"), caption); Response<UploadPhotoResponseDto> response = v2Api.uploadPhoto(usernamePart, passwordPart, lon, lat, dateTime, categoryPart, metaCatPart, captionPart, filePart).execute(); return response.body().toUploadResult(); } @SuppressWarnings("deprecation")  RetrofitApiClient(Builder builder); }
RetrofitApiClient { public Upload.Result uploadPhoto(final String username, final String password, final double lon, final double lat, final long dateTime, final String category, final String metaCat, final String caption, final String filename) throws IOException { MultipartBody.Part filePart = null; if (filename != null) { File file = new File(filename); RequestBody fileBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); filePart = MultipartBody.Part.createFormData("mediaupload", file.getName(), fileBody); } RequestBody usernamePart = RequestBody.create(MediaType.parse("text/plain"), username); RequestBody passwordPart = RequestBody.create(MediaType.parse("text/plain"), password); RequestBody categoryPart = RequestBody.create(MediaType.parse("text/plain"), category); RequestBody metaCatPart = RequestBody.create(MediaType.parse("text/plain"), metaCat); RequestBody captionPart = RequestBody.create(MediaType.parse("text/plain"), caption); Response<UploadPhotoResponseDto> response = v2Api.uploadPhoto(usernamePart, passwordPart, lon, lat, dateTime, categoryPart, metaCatPart, captionPart, filePart).execute(); return response.body().toUploadResult(); } @SuppressWarnings("deprecation")  RetrofitApiClient(Builder builder); String getJourneyJson(final String plan,
                               final String itineraryPoints,
                               final String leaving,
                               final String arriving,
                               final int speed); String retrievePreviousJourneyJson(final String plan,
                                            final long itineraryId); Blog getBlogEntries(); POICategories getPOICategories(); List<POI> getPOIs(final String type,
                           final double lonW,
                           final double latS,
                           final double lonE,
                           final double latN); List<POI> getPOIs(final String type,
                           final double lon,
                           final double lat,
                           final int radius); GeoPlaces geoCoder(final String search,
                            final double lonW,
                            final double latS,
                            final double lonE,
                            final double latN); PhotomapCategories getPhotomapCategories(); Photos getPhotos(final double lonW,
                          final double latS,
                          final double lonE,
                          final double latN); Photos getPhoto(final long photoId); UserJourneys getUserJourneys(final String username); Result register(final String username,
                         final String password,
                         final String name,
                         final String email); Signin.Result authenticate(final String identifier,
                                    final String password); Result sendFeedback(final int itinerary,
                             final String comments,
                             final String name,
                             final String email); Upload.Result uploadPhoto(final String username,
                                   final String password,
                                   final double lon,
                                   final double lat,
                                   final long dateTime,
                                   final String category,
                                   final String metaCat,
                                   final String caption,
                                   final String filename); }
RetrofitApiClient { public Upload.Result uploadPhoto(final String username, final String password, final double lon, final double lat, final long dateTime, final String category, final String metaCat, final String caption, final String filename) throws IOException { MultipartBody.Part filePart = null; if (filename != null) { File file = new File(filename); RequestBody fileBody = RequestBody.create(MediaType.parse("multipart/form-data"), file); filePart = MultipartBody.Part.createFormData("mediaupload", file.getName(), fileBody); } RequestBody usernamePart = RequestBody.create(MediaType.parse("text/plain"), username); RequestBody passwordPart = RequestBody.create(MediaType.parse("text/plain"), password); RequestBody categoryPart = RequestBody.create(MediaType.parse("text/plain"), category); RequestBody metaCatPart = RequestBody.create(MediaType.parse("text/plain"), metaCat); RequestBody captionPart = RequestBody.create(MediaType.parse("text/plain"), caption); Response<UploadPhotoResponseDto> response = v2Api.uploadPhoto(usernamePart, passwordPart, lon, lat, dateTime, categoryPart, metaCatPart, captionPart, filePart).execute(); return response.body().toUploadResult(); } @SuppressWarnings("deprecation")  RetrofitApiClient(Builder builder); String getJourneyJson(final String plan,
                               final String itineraryPoints,
                               final String leaving,
                               final String arriving,
                               final int speed); String retrievePreviousJourneyJson(final String plan,
                                            final long itineraryId); Blog getBlogEntries(); POICategories getPOICategories(); List<POI> getPOIs(final String type,
                           final double lonW,
                           final double latS,
                           final double lonE,
                           final double latN); List<POI> getPOIs(final String type,
                           final double lon,
                           final double lat,
                           final int radius); GeoPlaces geoCoder(final String search,
                            final double lonW,
                            final double latS,
                            final double lonE,
                            final double latN); PhotomapCategories getPhotomapCategories(); Photos getPhotos(final double lonW,
                          final double latS,
                          final double lonE,
                          final double latN); Photos getPhoto(final long photoId); UserJourneys getUserJourneys(final String username); Result register(final String username,
                         final String password,
                         final String name,
                         final String email); Signin.Result authenticate(final String identifier,
                                    final String password); Result sendFeedback(final int itinerary,
                             final String comments,
                             final String name,
                             final String email); Upload.Result uploadPhoto(final String username,
                                   final String password,
                                   final double lon,
                                   final double lat,
                                   final long dateTime,
                                   final String category,
                                   final String metaCat,
                                   final String caption,
                                   final String filename);  }