Search in sources :

Example 11 with StringPaginationToken

use of org.dataportabilityproject.shared.StringPaginationToken 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 12 with StringPaginationToken

use of org.dataportabilityproject.shared.StringPaginationToken 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 13 with StringPaginationToken

use of org.dataportabilityproject.shared.StringPaginationToken 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)

Example 14 with StringPaginationToken

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

the class GoogleContactsServiceTest method exportFirstPage.

@Test
public void exportFirstPage() throws IOException {
    setUpSinglePersonResponse();
    // Looking at first page, with at least one page after it
    ExportInformation emptyExportInformation = new ExportInformation(Optional.empty(), Optional.empty());
    listConnectionsResponse.setNextPageToken(NEXT_PAGE_TOKEN);
    // Run test
    ContactsModelWrapper wrapper = contactsService.export(emptyExportInformation);
    // Check that correct methods were called
    verify(connections).list(SELF_RESOURCE);
    InOrder inOrder = Mockito.inOrder(getBatchGet);
    inOrder.verify(getBatchGet).setResourceNames(Collections.singletonList(RESOURCE_NAME));
    inOrder.verify(getBatchGet).setPersonFields(PERSON_FIELDS);
    inOrder.verify(getBatchGet).execute();
    // Check continuation information
    assertThat(wrapper.getContinuationInformation().getSubResources()).isEmpty();
    StringPaginationToken paginationToken = (StringPaginationToken) wrapper.getContinuationInformation().getPaginationInformation();
    assertThat(paginationToken.getId()).isEqualTo(NEXT_PAGE_TOKEN);
    // Check that the right number of VCards was returned
    Collection<VCard> vCardCollection = wrapper.getVCards();
    assertThat(vCardCollection.size()).isEqualTo(connectionsList.size());
}
Also used : ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) InOrder(org.mockito.InOrder) ContactsModelWrapper(org.dataportabilityproject.dataModels.contacts.ContactsModelWrapper) VCard(ezvcard.VCard) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken) Test(org.junit.Test)

Aggregations

StringPaginationToken (org.dataportabilityproject.shared.StringPaginationToken)14 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)8 ExportInformation (org.dataportabilityproject.dataModels.ExportInformation)8 ArrayList (java.util.ArrayList)7 PaginationInformation (org.dataportabilityproject.dataModels.PaginationInformation)7 Resource (org.dataportabilityproject.dataModels.Resource)7 IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)7 CalendarModelWrapper (org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper)6 Test (org.junit.Test)6 InOrder (org.mockito.InOrder)5 IOException (java.io.IOException)4 Collectors (java.util.stream.Collectors)3 JobDataCache (org.dataportabilityproject.cloud.interfaces.JobDataCache)3 CalendarEventModel (org.dataportabilityproject.dataModels.calendar.CalendarEventModel)3 ContactsModelWrapper (org.dataportabilityproject.dataModels.contacts.ContactsModelWrapper)3 GoogleStaticObjects (org.dataportabilityproject.serviceProviders.google.GoogleStaticObjects)3 Credential (com.google.api.client.auth.oauth2.Credential)2 CalendarList (com.google.api.services.calendar.model.CalendarList)2 CalendarListEntry (com.google.api.services.calendar.model.CalendarListEntry)2 Event (com.google.api.services.calendar.model.Event)2