1818
1919import  static  org .datatransferproject .datatransfer .google .music .GoogleMusicExporter .GOOGLE_PLAYLIST_NAME_PREFIX ;
2020import  static  org .datatransferproject .datatransfer .google .music .GoogleMusicExporter .PLAYLIST_TOKEN_PREFIX ;
21+ import  static  org .datatransferproject .datatransfer .google .music .GoogleMusicExporter .RELEASE_TOKEN_PREFIX ;
2122import  static  org .junit .jupiter .api .Assertions .assertEquals ;
2223import  static  com .google .common .truth .Truth .assertThat ;
2324import  static  org .mockito .ArgumentMatchers .any ;
3637import  java .util .stream .Collectors ;
3738import  org .datatransferproject .api .launcher .Monitor ;
3839import  org .datatransferproject .datatransfer .google .common .GoogleCredentialFactory ;
40+ import  org .datatransferproject .datatransfer .google .musicModels .ExportReleaseResponse ;
3941import  org .datatransferproject .datatransfer .google .musicModels .GooglePlaylist ;
4042import  org .datatransferproject .datatransfer .google .musicModels .GooglePlaylistItem ;
4143import  org .datatransferproject .datatransfer .google .musicModels .GoogleRelease ;
4648import  org .datatransferproject .spi .transfer .types .ContinuationData ;
4749import  org .datatransferproject .spi .transfer .types .InvalidTokenException ;
4850import  org .datatransferproject .spi .transfer .types .PermissionDeniedException ;
51+ import  org .datatransferproject .types .common .ExportInformation ;
4952import  org .datatransferproject .types .common .PaginationData ;
5053import  org .datatransferproject .types .common .StringPaginationToken ;
5154import  org .datatransferproject .types .common .models .ContainerResource ;
@@ -62,6 +65,7 @@ public class GoogleMusicExporterTest {
6265
6366  static  final  String  PLAYLIST_PAGE_TOKEN  = "playlist_page_token" ;
6467  static  final  String  PLAYLIST_ITEM_TOKEN  = "playlist_item_token" ;
68+   static  final  String  RELEASE_ITEM_TOKEN  = "release_item_token" ;
6569
6670  private  final  UUID  uuid  = UUID .randomUUID ();
6771
@@ -70,6 +74,7 @@ public class GoogleMusicExporterTest {
7074
7175  private  PlaylistExportResponse  playlistExportResponse ;
7276  private  PlaylistItemExportResponse  playlistItemExportResponse ;
77+   private  ExportReleaseResponse  exportReleaseResponse ;
7378
7479  @ BeforeEach 
7580  public  void  setUp () throws  IOException , InvalidTokenException , PermissionDeniedException  {
@@ -84,10 +89,12 @@ public void setUp() throws IOException, InvalidTokenException, PermissionDeniedE
8489
8590    playlistExportResponse  = mock (PlaylistExportResponse .class );
8691    playlistItemExportResponse  = mock (PlaylistItemExportResponse .class );
92+     exportReleaseResponse  = mock (ExportReleaseResponse .class );
8793
8894    when (musicHttpApi .exportPlaylists (any (Optional .class ))).thenReturn (playlistExportResponse );
8995    when (musicHttpApi .exportPlaylistItems (any (String .class ), any (Optional .class )))
9096        .thenReturn (playlistItemExportResponse );
97+     when (musicHttpApi .exportReleases (any (Optional .class ))).thenReturn (exportReleaseResponse );
9198
9299    verifyNoInteractions (credentialFactory );
93100  }
@@ -229,6 +236,93 @@ public void exportPlaylistItemSubsequentSet()
229236    assertThat (paginationToken ).isNull ();
230237  }
231238
239+   @ Test 
240+   public  void  exportReleaseFirstSet ()
241+       throws  InvalidTokenException , PermissionDeniedException , IOException , ParseException  {
242+     GoogleRelease  release  = setUpSingleRelease ("Test" , "R_icpn" );
243+     when (exportReleaseResponse .getReleases ())
244+         .thenReturn (new  GoogleRelease []{release });
245+     when (exportReleaseResponse .getNextPageToken ()).thenReturn (null );
246+     StringPaginationToken  inputPaginationToken  = new  StringPaginationToken (RELEASE_TOKEN_PREFIX );
247+     ExportInformation  exportInformation  = new  ExportInformation (inputPaginationToken , null );
248+     ExportResult <MusicContainerResource > result  = googleMusicExporter .export (uuid , null , Optional .of (exportInformation ));
249+ 
250+     // Check results 
251+     // Verify correct methods were called 
252+     verify (musicHttpApi ).exportReleases (Optional .empty ());
253+     verify (exportReleaseResponse ).getReleases ();
254+ 
255+     // Check pagination token 
256+     ContinuationData  continuationData  = result .getContinuationData ();
257+     StringPaginationToken  paginationToken  = (StringPaginationToken ) continuationData .getPaginationData ();
258+     assertThat (paginationToken ).isNull ();
259+   }
260+ 
261+   @ Test 
262+   public  void  exportReleaseSubsequentSet ()
263+       throws  InvalidTokenException , PermissionDeniedException , IOException , ParseException  {
264+     GoogleRelease  release  = setUpSingleRelease ("Test" , "R_icpn" );
265+     when (exportReleaseResponse .getReleases ())
266+         .thenReturn (new  GoogleRelease []{release });
267+     when (exportReleaseResponse .getNextPageToken ()).thenReturn (null );
268+     StringPaginationToken  inputPaginationToken  = new  StringPaginationToken (RELEASE_TOKEN_PREFIX  + RELEASE_ITEM_TOKEN );
269+     ExportInformation  exportInformation  = new  ExportInformation (inputPaginationToken , null );
270+     ExportResult <MusicContainerResource > result  = googleMusicExporter .export (uuid , null , Optional .of (exportInformation ));
271+ 
272+     // Check results 
273+     // Verify correct methods were called 
274+     verify (musicHttpApi ).exportReleases (Optional .of (RELEASE_ITEM_TOKEN ));
275+     verify (exportReleaseResponse ).getReleases ();
276+ 
277+     // Check pagination token 
278+     ContinuationData  continuationData  = result .getContinuationData ();
279+     StringPaginationToken  paginationToken  = (StringPaginationToken ) continuationData .getPaginationData ();
280+     assertThat (paginationToken ).isNull ();
281+   }
282+ 
283+   @ Test 
284+   public  void  exportReleaseWithNextPage ()
285+       throws  InvalidTokenException , PermissionDeniedException , IOException , ParseException  {
286+     GoogleRelease  release  = setUpSingleRelease ("Test" , "R_icpn" );
287+     when (exportReleaseResponse .getReleases ())
288+         .thenReturn (new  GoogleRelease []{release });
289+     when (exportReleaseResponse .getNextPageToken ()).thenReturn (RELEASE_ITEM_TOKEN );
290+     StringPaginationToken  inputPaginationToken  = new  StringPaginationToken (RELEASE_TOKEN_PREFIX  + RELEASE_ITEM_TOKEN );
291+     ExportInformation  exportInformation  = new  ExportInformation (inputPaginationToken , null );
292+     ExportResult <MusicContainerResource > result  = googleMusicExporter .export (uuid , null , Optional .of (exportInformation ));
293+ 
294+     // Check results 
295+     // Verify correct methods were called 
296+     verify (musicHttpApi ).exportReleases (Optional .of (RELEASE_ITEM_TOKEN ));
297+     verify (exportReleaseResponse ).getReleases ();
298+ 
299+     // Check pagination token 
300+     ContinuationData  continuationData  = result .getContinuationData ();
301+     StringPaginationToken  paginationToken  = (StringPaginationToken ) continuationData .getPaginationData ();
302+     assertEquals (RELEASE_TOKEN_PREFIX +RELEASE_ITEM_TOKEN , paginationToken .getToken ());
303+   }
304+ 
305+   @ Test 
306+   public  void  exportReleaseWithNoData ()
307+       throws  InvalidTokenException , PermissionDeniedException , IOException , ParseException  {
308+     when (exportReleaseResponse .getReleases ())
309+         .thenReturn (null );
310+     when (exportReleaseResponse .getNextPageToken ()).thenReturn (null );
311+     StringPaginationToken  inputPaginationToken  = new  StringPaginationToken (RELEASE_TOKEN_PREFIX );
312+     ExportInformation  exportInformation  = new  ExportInformation (inputPaginationToken , null );
313+     ExportResult <MusicContainerResource > result  = googleMusicExporter .export (uuid , null , Optional .of (exportInformation ));
314+ 
315+     // Check results 
316+     // Verify correct methods were called 
317+     verify (musicHttpApi ).exportReleases (Optional .empty ());
318+     verify (exportReleaseResponse ).getReleases ();
319+ 
320+     // Check pagination token 
321+     ContinuationData  continuationData  = result .getContinuationData ();
322+     StringPaginationToken  paginationToken  = (StringPaginationToken ) continuationData .getPaginationData ();
323+     assertThat (paginationToken ).isNull ();
324+   }
325+ 
232326  /** 
233327   * Sets up a response with a single playlist, containing a single playlist item 
234328   */ 
@@ -255,4 +349,11 @@ private GooglePlaylistItem setUpSinglePlaylistItem(String isrc, String icpn) {
255349    playlistItemEntry .setTrack (track );
256350    return  playlistItemEntry ;
257351  }
352+ 
353+   private  GoogleRelease  setUpSingleRelease (String  title , String  icpn ){
354+     GoogleRelease  release  = new  GoogleRelease ();
355+     release .setIcpn (icpn );
356+     release .setReleaseTitle (title );
357+     return  release ;
358+   }
258359}
0 commit comments