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));
}
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));
}
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();
}
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);
}
Aggregations