Search in sources :

Example 11 with IdOnlyResource

use of org.dataportabilityproject.shared.IdOnlyResource in project data-transfer-project by google.

the class FlickrPhotoServiceTest method exportPhotosFromPhotoset.

@Test
public void exportPhotosFromPhotoset() throws FlickrException, IOException {
    // Situation: getting photos from a set with id photosetsId and page 1
    int page = 1;
    String photosetsId = "photosetsId";
    ExportInformation exportInformation = new ExportInformation(Optional.of(new IdOnlyResource(photosetsId)), Optional.empty());
    // Make a bunch of photos, add them to PhotoList, and add pagination information
    int numPhotos = 4;
    PhotoList<Photo> listOfPhotos = new PhotoList<>();
    for (int i = 0; i < numPhotos; i++) {
        Photo photo = initializePhoto("title" + i, "url" + i, "description" + i);
        listOfPhotos.add(photo);
    }
    listOfPhotos.setPage(page);
    listOfPhotos.setPages(page + 1);
    when(photosetsInterface.getPhotos(anyString(), anySet(), anyInt(), anyInt(), anyInt())).thenReturn(listOfPhotos);
    // Run test
    PhotosModelWrapper result = photoService.export(exportInformation);
    assertThat(result.getPhotos().size()).isEqualTo(numPhotos);
    assertThat(result.getAlbums()).isEmpty();
    assertThat(result.getContinuationInformation().getSubResources()).isEmpty();
    assertThat(result.getContinuationInformation().getPaginationInformation()).isEqualTo(new FlickrPaginationInformation(page + 1));
}
Also used : ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) PhotoList(com.flickr4java.flickr.photos.PhotoList) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) Photo(com.flickr4java.flickr.photos.Photo) Matchers.anyString(org.mockito.Matchers.anyString) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) Test(org.junit.Test)

Example 12 with IdOnlyResource

use of org.dataportabilityproject.shared.IdOnlyResource in project data-transfer-project by google.

the class FlickrPhotoServiceTest method exportAlbumInitial.

@Test
public void exportAlbumInitial() throws IOException, FlickrException {
    // Set up initial export information, such as what FlickrPhotoService would see when a transfer
    // is initiated
    ExportInformation emptyExportInfo = new ExportInformation(Optional.empty(), Optional.empty());
    // Set up auth
    when(user.getId()).thenReturn("userId");
    // Set up photoset
    String photosetId = "photosetId";
    String photosetTitle = "title";
    String photosetDescription = "description";
    Photoset photoset = initializePhotoset(photosetId, photosetTitle, photosetDescription);
    // Set up photosets list (aka album view)
    int page = 1;
    Photosets photosetList = new Photosets();
    photosetList.setPage(page);
    photosetList.setPages(page + 1);
    photosetList.setPhotosets(Collections.singletonList(photoset));
    when(photosetsInterface.getList(anyString(), anyInt(), anyInt(), anyString())).thenReturn(photosetList);
    // Run test
    PhotosModelWrapper result = photoService.export(emptyExportInfo);
    // Make sure album/photo information is correct
    assertThat(result.getPhotos()).isEmpty();
    Collection<PhotoAlbum> albums = result.getAlbums();
    assertThat(albums.size()).isEqualTo(1);
    assertThat(albums).containsExactly(new PhotoAlbum(photosetId, photosetTitle, photosetDescription));
    // Make sure continuation information is correct
    ContinuationInformation continuationInformation = result.getContinuationInformation();
    assertThat((FlickrPaginationInformation) continuationInformation.getPaginationInformation()).isEqualTo(new FlickrPaginationInformation(page + 1));
    Collection<? extends Resource> subResources = continuationInformation.getSubResources();
    assertThat(subResources.size()).isEqualTo(1);
    assertThat(subResources).containsExactly(new IdOnlyResource(photosetId));
}
Also used : ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Photoset(com.flickr4java.flickr.photosets.Photoset) Photosets(com.flickr4java.flickr.photosets.Photosets) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) Matchers.anyString(org.mockito.Matchers.anyString) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) Test(org.junit.Test)

Example 13 with IdOnlyResource

use of org.dataportabilityproject.shared.IdOnlyResource in project data-transfer-project by google.

the class GoogleCalendarServiceTest method testExportEventSubsequentSet.

@Test
public void testExportEventSubsequentSet() throws IOException {
    setUpSingleEventResponse();
    ;
    // Looking at subsequent page, with no pages after it
    Resource resource = new IdOnlyResource(CALENDAR_ID);
    PaginationInformation paginationInformation = new StringPaginationToken(NEXT_TOKEN);
    ExportInformation resourceExportInformation = new ExportInformation(Optional.of(resource), Optional.of(paginationInformation));
    eventListResponse.setNextPageToken(null);
    // Run test
    CalendarModelWrapper wrapper = calendarService.export(resourceExportInformation);
    // Check results
    // Verify correct methods were called in order
    InOrder inOrder = Mockito.inOrder(eventListRequest);
    inOrder.verify(eventListRequest).setPageToken(NEXT_TOKEN);
    inOrder.verify(eventListRequest).execute();
    // Check pagination token
    StringPaginationToken paginationToken = (StringPaginationToken) wrapper.getContinuationInformation().getPaginationInformation();
    assertThat(paginationToken).isNull();
}
Also used : CalendarModelWrapper(org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper) ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) InOrder(org.mockito.InOrder) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken) Test(org.junit.Test)

Example 14 with IdOnlyResource

use of org.dataportabilityproject.shared.IdOnlyResource in project data-transfer-project by google.

the class GoogleCalendarServiceTest method testExportEventFirstSet.

@Test
public void testExportEventFirstSet() throws IOException {
    setUpSingleEventResponse();
    // Looking at first page, with at least one page after it
    Resource resource = new IdOnlyResource(CALENDAR_ID);
    ExportInformation resourceExportInformation = new ExportInformation(Optional.of(resource), Optional.empty());
    eventListResponse.setNextPageToken(NEXT_TOKEN);
    // Run test
    CalendarModelWrapper wrapper = calendarService.export(resourceExportInformation);
    // Check results
    // Verify correct methods were called
    verify(calendarEvents).list(CALENDAR_ID);
    verify(eventListRequest).setMaxAttendees(GoogleStaticObjects.MAX_ATTENDEES);
    verify(eventListRequest).execute();
    // Check events
    Collection<CalendarEventModel> events = wrapper.getEvents();
    assertThat(events.stream().map(CalendarEventModel::getCalendarId).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
    assertThat(events.stream().map(CalendarEventModel::getTitle).collect(Collectors.toList())).containsExactly(EVENT_DESCRIPTION);
    // Check pagination token
    StringPaginationToken paginationToken = (StringPaginationToken) wrapper.getContinuationInformation().getPaginationInformation();
    assertThat(paginationToken.getId()).isEqualTo(NEXT_TOKEN);
}
Also used : CalendarModelWrapper(org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper) ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) CalendarEventModel(org.dataportabilityproject.dataModels.calendar.CalendarEventModel) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken) Test(org.junit.Test)

Aggregations

IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)14 Resource (org.dataportabilityproject.dataModels.Resource)11 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)9 ArrayList (java.util.ArrayList)7 StringPaginationToken (org.dataportabilityproject.shared.StringPaginationToken)6 IOException (java.io.IOException)5 ExportInformation (org.dataportabilityproject.dataModels.ExportInformation)5 PaginationInformation (org.dataportabilityproject.dataModels.PaginationInformation)5 CalendarModelWrapper (org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper)5 PhotosModelWrapper (org.dataportabilityproject.dataModels.photos.PhotosModelWrapper)5 PhotoAlbum (org.dataportabilityproject.dataModels.photos.PhotoAlbum)4 Test (org.junit.Test)4 CalendarModel (org.dataportabilityproject.dataModels.calendar.CalendarModel)3 Photoset (com.flickr4java.flickr.photosets.Photoset)2 Photosets (com.flickr4java.flickr.photosets.Photosets)2 CalendarList (com.google.api.services.calendar.model.CalendarList)2 CalendarListEntry (com.google.api.services.calendar.model.CalendarListEntry)2 URL (java.net.URL)2 CalendarEventModel (org.dataportabilityproject.dataModels.calendar.CalendarEventModel)2 TaskListModel (org.dataportabilityproject.dataModels.tasks.TaskListModel)2