Search in sources :

Example 6 with ExportInformation

use of org.dataportabilityproject.dataModels.ExportInformation 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 7 with ExportInformation

use of org.dataportabilityproject.dataModels.ExportInformation 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 8 with ExportInformation

use of org.dataportabilityproject.dataModels.ExportInformation 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 9 with ExportInformation

use of org.dataportabilityproject.dataModels.ExportInformation in project data-transfer-project by google.

the class GoogleCalendarServiceTest method testExportCalendarSubsequentSet.

@Test
public void testExportCalendarSubsequentSet() throws IOException {
    setUpSingleCalendarResponse();
    // Looking at subsequent page, with no page after it
    ExportInformation nextPageExportInformation = new ExportInformation(Optional.empty(), Optional.of(new StringPaginationToken(NEXT_TOKEN)));
    calendarListResponse.setNextPageToken(null);
    // Run test
    CalendarModelWrapper wrapper = calendarService.export(nextPageExportInformation);
    // Check results
    // Verify correct calls were made
    InOrder inOrder = Mockito.inOrder(calendarListRequest);
    inOrder.verify(calendarListRequest).setPageToken(NEXT_TOKEN);
    inOrder.verify(calendarListRequest).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) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken) Test(org.junit.Test)

Example 10 with ExportInformation

use of org.dataportabilityproject.dataModels.ExportInformation 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

ExportInformation (org.dataportabilityproject.dataModels.ExportInformation)11 Test (org.junit.Test)8 StringPaginationToken (org.dataportabilityproject.shared.StringPaginationToken)7 IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)5 InOrder (org.mockito.InOrder)5 Resource (org.dataportabilityproject.dataModels.Resource)4 CalendarModelWrapper (org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper)4 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)3 ContactsModelWrapper (org.dataportabilityproject.dataModels.contacts.ContactsModelWrapper)3 VCard (ezvcard.VCard)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 Collectors (java.util.stream.Collectors)2 JobDataCache (org.dataportabilityproject.cloud.interfaces.JobDataCache)2 PaginationInformation (org.dataportabilityproject.dataModels.PaginationInformation)2 CalendarEventModel (org.dataportabilityproject.dataModels.calendar.CalendarEventModel)2 PhotosModelWrapper (org.dataportabilityproject.dataModels.photos.PhotosModelWrapper)2 GoogleStaticObjects (org.dataportabilityproject.serviceProviders.google.GoogleStaticObjects)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Photo (com.flickr4java.flickr.photos.Photo)1