|
32 | 32 | import com.google.api.client.http.json.JsonHttpContent; |
33 | 33 | import com.google.api.client.json.JsonFactory; |
34 | 34 | import com.google.common.collect.ImmutableMap; |
| 35 | +import com.google.photos.types.proto.MediaItem; |
35 | 36 | import java.io.ByteArrayInputStream; |
36 | 37 | import java.io.IOException; |
37 | 38 | import java.io.InputStream; |
| 39 | +import java.util.ArrayList; |
38 | 40 | import java.util.HashMap; |
39 | 41 | import java.util.LinkedHashMap; |
| 42 | +import java.util.List; |
40 | 43 | import java.util.Map; |
41 | 44 | import java.util.Optional; |
42 | 45 | import org.datatransferproject.api.launcher.Monitor; |
|
46 | 49 | import org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum; |
47 | 50 | import org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem; |
48 | 51 | import org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse; |
| 52 | +import org.datatransferproject.datatransfer.google.mediaModels.NewMediaItem; |
49 | 53 | import org.datatransferproject.datatransfer.google.mediaModels.NewMediaItemResult; |
50 | 54 | import org.datatransferproject.datatransfer.google.mediaModels.NewMediaItemUpload; |
51 | 55 | import org.datatransferproject.spi.transfer.types.InvalidTokenException; |
@@ -272,29 +276,30 @@ void uploadEmptyMediaContent() |
272 | 276 | void createPhotos() throws Exception { |
273 | 277 | BatchMediaItemResponse batchMediaItemResponse = new BatchMediaItemResponse( |
274 | 278 | new NewMediaItemResult[]{}); |
| 279 | + List<NewMediaItem> newMediaItem = new ArrayList<>(); |
| 280 | + NewMediaItemUpload newMediaItemUpload = new NewMediaItemUpload(ALBUM_ID,newMediaItem); |
275 | 281 | TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() { |
276 | 282 | }; |
277 | | - Map<String, Object> albumMap = objectMapper.readValue( |
278 | | - objectMapper.writeValueAsString(batchMediaItemResponse), typeRef); |
279 | | - Map<String, Object> params = ImmutableMap.of("album", albumMap); |
| 283 | + Map<String, Object> params = objectMapper.readValue( |
| 284 | + objectMapper.writeValueAsString(newMediaItemUpload), typeRef); |
280 | 285 |
|
281 | 286 | GooglePhotosInterface photosInterfaceSpy = Mockito.spy(this.googlePhotosInterface); |
282 | 287 | Mockito.doReturn(batchMediaItemResponse).when(photosInterfaceSpy) |
283 | 288 | .makePostRequest(anyString(), any(), any(), any(), any()); |
284 | 289 |
|
285 | | - BatchMediaItemResponse apiResponse = googlePhotosInterface.createPhotos( |
286 | | - any(NewMediaItemUpload.class)); |
| 290 | + BatchMediaItemResponse apiResponse = photosInterfaceSpy.createPhotos( |
| 291 | + newMediaItemUpload); |
287 | 292 |
|
288 | 293 | ArgumentCaptor<String> urlStringCaptor = ArgumentCaptor.forClass(String.class); |
289 | 294 | ArgumentCaptor<JsonHttpContent> contentCaptor = ArgumentCaptor.forClass(JsonHttpContent.class); |
290 | 295 | Mockito.verify(photosInterfaceSpy) |
291 | 296 | .makePostRequest(urlStringCaptor.capture(), any(), any(), contentCaptor.capture(), any()); |
292 | 297 | assertEquals(batchMediaItemResponse, apiResponse); |
293 | | - assertEquals(BASE_URL + "albums", urlStringCaptor.getValue()); |
| 298 | + assertEquals(BASE_URL + "mediaItems:batchCreate", urlStringCaptor.getValue()); |
294 | 299 | assertEquals(params, contentCaptor.getValue().getData()); |
295 | 300 | } |
296 | 301 |
|
297 | | - @Test |
| 302 | +// @Test |
298 | 303 | void makePostRequest() { |
299 | 304 | // Discussion: I Believe this method should be kept private for the interface to make sense |
300 | 305 | } |
|
0 commit comments