use of org.dataportabilityproject.types.transfer.models.ContainerResource in project data-transfer-project by google.
the class GoogleCalendarExporterTest method exportEventFirstSet.
@Test
public void exportEventFirstSet() throws IOException {
setUpSingleEventResponse();
// Looking at first page, with at least one page after it
ContainerResource containerResource = new IdOnlyContainerResource(CALENDAR_ID);
ExportInformation exportInformation = new ExportInformation(null, containerResource);
eventListResponse.setNextPageToken(NEXT_TOKEN);
// Run test
ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(UUID.randomUUID(), null, exportInformation);
// Check results
// Verify correct methods were called
verify(calendarEvents).list(CALENDAR_ID);
verify(eventListRequest).setMaxAttendees(MAX_ATTENDEES);
verify(eventListRequest).execute();
// Check events
Collection<CalendarEventModel> actualEvents = result.getExportedData().getEvents();
assertThat(actualEvents.stream().map(CalendarEventModel::getCalendarId).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
assertThat(actualEvents.stream().map(CalendarEventModel::getTitle).collect(Collectors.toList())).containsExactly(EVENT_DESCRIPTION);
// Check pagination token
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(EVENT_TOKEN_PREFIX + NEXT_TOKEN);
}
use of org.dataportabilityproject.types.transfer.models.ContainerResource 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);
// 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.dataportabilityproject.types.transfer.models.ContainerResource in project data-transfer-project by google.
the class TasksModelWrapperTest method verifySerializeDeserialize.
@Test
public void verifySerializeDeserialize() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerSubtypes(TaskContainerResource.class);
List<TaskListModel> taskLists = ImmutableList.of(new TaskListModel("id1", "List 1"));
List<TaskModel> tasks = ImmutableList.of(new TaskModel("id1", "Write Better tests", "Do this soon"), new TaskModel("id1", "Liberate all the data", "do this in stages"));
ContainerResource data = new TaskContainerResource(taskLists, tasks);
String serialized = objectMapper.writeValueAsString(data);
ContainerResource deserializedModel = objectMapper.readValue(serialized, ContainerResource.class);
Truth.assertThat(deserializedModel).isNotNull();
Truth.assertThat(deserializedModel).isInstanceOf(TaskContainerResource.class);
TaskContainerResource deserialized = (TaskContainerResource) deserializedModel;
Truth.assertThat(deserialized.getLists()).hasSize(1);
Truth.assertThat(deserialized.getTasks()).hasSize(2);
}
use of org.dataportabilityproject.types.transfer.models.ContainerResource in project data-transfer-project by google.
the class PortabilityInMemoryDataCopier method copyHelper.
/**
* Transfers data from the given {@code exporter} optionally starting at the point specified in
* the provided {@code exportInformation}. Imports the data using the provided {@code importer}.
* If there is more data to required to be exported, recursively copies using the specific {@link
* ExportInformation} to continue the process.
*
* @param exportAuthData The auth data for the export
* @param importAuthData The auth data for the import
* @param exportInformation Any pagination or resource information to use for subsequent calls.
*/
private void copyHelper(UUID jobId, AuthData exportAuthData, AuthData importAuthData, ExportInformation exportInformation) {
logger.debug("copy iteration: {}", COPY_ITERATION_COUNTER.incrementAndGet());
// NOTE: order is important below, do the import of all the items, then do continuation
// then do sub resources, this ensures all parents are populated before children get
// processed.
logger.debug("Starting export, ExportInformation: {}", exportInformation);
ExportResult<?> exportResult = exporter.get().export(jobId, exportAuthData, exportInformation);
logger.debug("Finished export, results: {}", exportResult);
logger.debug("Starting import");
importer.get().importItem(jobId, importAuthData, exportResult.getExportedData());
logger.debug("Finished import");
ContinuationData continuationData = (ContinuationData) exportResult.getContinuationData();
if (null != continuationData) {
// Process the next page of items for the resource
if (null != continuationData.getPaginationData()) {
logger.debug("start off a new copy iteration with pagination info");
copyHelper(jobId, exportAuthData, importAuthData, new ExportInformation(continuationData.getPaginationData(), exportInformation.getContainerResource()));
}
// Start processing sub-resources
if (continuationData.getContainerResources() != null && !continuationData.getContainerResources().isEmpty()) {
for (ContainerResource resource : continuationData.getContainerResources()) {
copyHelper(jobId, exportAuthData, importAuthData, new ExportInformation(null, resource));
}
}
}
}
use of org.dataportabilityproject.types.transfer.models.ContainerResource in project data-transfer-project by google.
the class GoogleCalendarExporterTest method exportEventSubsequentSet.
@Test
public void exportEventSubsequentSet() throws IOException {
setUpSingleEventResponse();
// Looking at subsequent page, with no pages after it
ContainerResource containerResource = new IdOnlyContainerResource(CALENDAR_ID);
PaginationData paginationData = new StringPaginationToken(EVENT_TOKEN_PREFIX + NEXT_TOKEN);
ExportInformation exportInformation = new ExportInformation(paginationData, containerResource);
eventListResponse.setNextPageToken(null);
// Run test
ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(UUID.randomUUID(), null, exportInformation);
// 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
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken).isNull();
}
Aggregations