use of org.datatransferproject.types.common.models.calendar.CalendarModel in project data-transfer-project by google.
the class GoogleCalendarExporterTest method exportCalendarFirstSet.
@Test
public void exportCalendarFirstSet() throws IOException {
setUpSingleCalendarResponse();
// Looking at first page, with at least one page after it
calendarListResponse.setNextPageToken(NEXT_TOKEN);
// Run test
ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(JOB_ID, null, Optional.empty());
// Check results
// Verify correct methods were called
verify(calendarClient).calendarList();
verify(calendarCalendarList).list();
verify(calendarListRequest).execute();
// Check pagination token
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(CALENDAR_TOKEN_PREFIX + NEXT_TOKEN);
// Check calendars
Collection<CalendarModel> actualCalendars = result.getExportedData().getCalendars();
assertThat(actualCalendars.stream().map(CalendarModel::getId).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
// Check events (should be empty, even though there is an event in the calendar)
Collection<CalendarEventModel> actualEvents = result.getExportedData().getEvents();
assertThat(actualEvents).isEmpty();
// Should be one container in the resource list
List<ContainerResource> actualResources = continuationData.getContainerResources();
assertThat(actualResources.stream().map(a -> ((IdOnlyContainerResource) a).getId()).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
}
use of org.datatransferproject.types.common.models.calendar.CalendarModel in project data-transfer-project by google.
the class GoogleCalendarImporterTest method importCalendarAndEvent.
@Test
public void importCalendarAndEvent() throws Exception {
String modelCalendarId = "modelCalendarId";
String googleCalendarId = "googleCalendarId";
UUID jobId = UUID.randomUUID();
// Set up calendar, events, and mocks
CalendarModel calendarModel = new CalendarModel(modelCalendarId, null, null);
com.google.api.services.calendar.model.Calendar calendarToInsert = GoogleCalendarImporter.convertToGoogleCalendar(calendarModel);
com.google.api.services.calendar.model.Calendar responseCalendar = new com.google.api.services.calendar.model.Calendar().setId(googleCalendarId);
CalendarEventModel eventModel = new CalendarEventModel(modelCalendarId, null, null, null, null, null, null, null);
Event eventToInsert = GoogleCalendarImporter.convertToGoogleCalendarEvent(eventModel);
Event responseEvent = new Event();
when(eventInsertRequest.execute()).thenReturn(responseEvent);
when(calendarEvents.insert(googleCalendarId, eventToInsert)).thenReturn(eventInsertRequest);
when(calendarInsertRequest.execute()).thenReturn(responseCalendar);
when(calendarCalendars.insert(calendarToInsert)).thenReturn(calendarInsertRequest);
CalendarContainerResource calendarContainerResource = new CalendarContainerResource(Collections.singleton(calendarModel), Collections.singleton(eventModel));
// Run test
calendarService.importItem(jobId, executor, null, calendarContainerResource);
// Check the right methods were called
verify(calendarCalendars).insert(calendarToInsert);
verify(calendarInsertRequest).execute();
verify(calendarEvents).insert(googleCalendarId, eventToInsert);
verify(eventInsertRequest).execute();
}
Aggregations