Search in sources :

Example 21 with ContainerResource

use of org.datatransferproject.types.common.models.ContainerResource in project data-transfer-project by google.

the class PortabilityInMemoryDataCopierTest method storeStackContainingPaginationDataAndMultipleSubResourcesInJobStore.

@Test
public void storeStackContainingPaginationDataAndMultipleSubResourcesInJobStore() throws CopyException, IOException {
    // Arrange
    PaginationData paginationData = Mockito.mock(PaginationData.class);
    ContainerResource subResource1 = Mockito.mock(ContainerResource.class);
    ContainerResource subResource2 = Mockito.mock(ContainerResource.class);
    ExportInformation paginationExportInfo = new ExportInformation(paginationData, null);
    ExportInformation subResource1ExportInfo = new ExportInformation(null, subResource1);
    ExportInformation subResource2ExportInfo = new ExportInformation(null, subResource2);
    Stack<ExportInformation> jobStack = new Stack<>();
    jobStack.push(subResource2ExportInfo);
    jobStack.push(subResource1ExportInfo);
    jobStack.push(paginationExportInfo);
    Mockito.when(continuationData.getPaginationData()).thenReturn(paginationData);
    Mockito.when(continuationData.getContainerResources()).thenReturn(Arrays.asList(subResource1, subResource2));
    Mockito.when(initialExportResult.getContinuationData()).thenReturn(continuationData);
    Mockito.doReturn(initialExportResult).when(stackInMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(exportInfo), jobIdPrefix, 1);
    // Act
    stackInMemoryDataCopier.copy(exportAuthData, importAuthData, jobId, Optional.of(exportInfo));
    // Assert
    InOrder orderVerifier = Mockito.inOrder(stackInMemoryDataCopier.jobStore);
    orderVerifier.verify(stackInMemoryDataCopier.jobStore).storeJobStack(jobId, jobStack);
    jobStack.pop();
    orderVerifier.verify(stackInMemoryDataCopier.jobStore).storeJobStack(jobId, jobStack);
    jobStack.pop();
    orderVerifier.verify(stackInMemoryDataCopier.jobStore).storeJobStack(jobId, jobStack);
    jobStack.pop();
    orderVerifier.verify(stackInMemoryDataCopier.jobStore).storeJobStack(jobId, jobStack);
}
Also used : ExportInformation(org.datatransferproject.types.common.ExportInformation) PaginationData(org.datatransferproject.types.common.PaginationData) InOrder(org.mockito.InOrder) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) Stack(java.util.Stack) Test(org.junit.Test)

Example 22 with ContainerResource

use of org.datatransferproject.types.common.models.ContainerResource in project data-transfer-project by google.

the class PortabilityInMemoryDataCopierTest method continuationDataWithSingleSubResource.

@Test
public void continuationDataWithSingleSubResource() throws CopyException, IOException {
    // Arrange
    ContainerResource subResource = Mockito.mock(ContainerResource.class);
    ExportInformation subResourceExportInfo = new ExportInformation(null, subResource);
    Mockito.when(continuationData.getContainerResources()).thenReturn(Arrays.asList(subResource));
    Mockito.when(initialExportResult.getContinuationData()).thenReturn(continuationData);
    Mockito.doReturn(initialExportResult).when(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(exportInfo), jobIdPrefix, 1);
    // Act
    inMemoryDataCopier.copy(exportAuthData, importAuthData, jobId, Optional.of(exportInfo));
    // Assert
    InOrder orderVerifier = Mockito.inOrder(inMemoryDataCopier);
    orderVerifier.verify(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(exportInfo), jobIdPrefix, 1);
    orderVerifier.verify(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(subResourceExportInfo), jobIdPrefix, 2);
}
Also used : ExportInformation(org.datatransferproject.types.common.ExportInformation) InOrder(org.mockito.InOrder) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) Test(org.junit.Test)

Example 23 with ContainerResource

use of org.datatransferproject.types.common.models.ContainerResource in project data-transfer-project by google.

the class PortabilityInMemoryDataCopierTest method continuationDataWithPaginationDataAndNestedSubResource.

@Test
public void continuationDataWithPaginationDataAndNestedSubResource() throws CopyException, IOException {
    // Arrange
    PaginationData paginationData = Mockito.mock(PaginationData.class);
    ContinuationData paginationContinuationData = Mockito.mock(ContinuationData.class);
    ExportResult<?> paginationExportResult = Mockito.mock(ExportResult.class);
    ContainerResource subResource = Mockito.mock(ContainerResource.class);
    ContainerResource paginationSubResource = Mockito.mock(ContainerResource.class);
    ExportInformation paginationExportInfo = new ExportInformation(paginationData, null);
    ExportInformation subResourceExportInfo = new ExportInformation(null, subResource);
    ExportInformation paginationSubResourceExportInfo = new ExportInformation(null, paginationSubResource);
    Mockito.when(continuationData.getPaginationData()).thenReturn(paginationData);
    Mockito.when(continuationData.getContainerResources()).thenReturn(Arrays.asList(subResource));
    Mockito.when(paginationContinuationData.getContainerResources()).thenReturn(Arrays.asList(paginationSubResource));
    Mockito.when(initialExportResult.getContinuationData()).thenReturn(continuationData);
    Mockito.when(paginationExportResult.getContinuationData()).thenReturn(paginationContinuationData);
    Mockito.doReturn(initialExportResult).when(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(exportInfo), jobIdPrefix, 1);
    Mockito.doReturn(paginationExportResult).when(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(paginationExportInfo), jobIdPrefix, 2);
    // Act
    inMemoryDataCopier.copy(exportAuthData, importAuthData, jobId, Optional.of(exportInfo));
    // Assert
    InOrder orderVerifier = Mockito.inOrder(inMemoryDataCopier);
    orderVerifier.verify(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(exportInfo), jobIdPrefix, 1);
    orderVerifier.verify(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(paginationExportInfo), jobIdPrefix, 2);
    orderVerifier.verify(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(paginationSubResourceExportInfo), jobIdPrefix, 3);
    orderVerifier.verify(inMemoryDataCopier).copyIteration(jobId, exportAuthData, importAuthData, Optional.of(subResourceExportInfo), jobIdPrefix, 4);
}
Also used : ExportInformation(org.datatransferproject.types.common.ExportInformation) PaginationData(org.datatransferproject.types.common.PaginationData) InOrder(org.mockito.InOrder) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) Test(org.junit.Test)

Example 24 with ContainerResource

use of org.datatransferproject.types.common.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, 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);
}
Also used : MAX_ATTENDEES(org.datatransferproject.datatransfer.google.common.GoogleStaticObjects.MAX_ATTENDEES) CalendarContainerResource(org.datatransferproject.types.common.models.calendar.CalendarContainerResource) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult) CalendarEventModel(org.datatransferproject.types.common.models.calendar.CalendarEventModel) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) EVENT_TOKEN_PREFIX(org.datatransferproject.datatransfer.google.common.GoogleStaticObjects.EVENT_TOKEN_PREFIX) ExportInformation(org.datatransferproject.types.common.ExportInformation) Events(com.google.api.services.calendar.model.Events) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Calendar(com.google.api.services.calendar.Calendar) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) Before(org.junit.Before) Event(com.google.api.services.calendar.model.Event) InOrder(org.mockito.InOrder) CalendarList(com.google.api.services.calendar.model.CalendarList) Collection(java.util.Collection) IOException(java.io.IOException) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) PaginationData(org.datatransferproject.types.common.PaginationData) Truth.assertThat(com.google.common.truth.Truth.assertThat) CALENDAR_TOKEN_PREFIX(org.datatransferproject.datatransfer.google.common.GoogleStaticObjects.CALENDAR_TOKEN_PREFIX) Collectors(java.util.stream.Collectors) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) Mockito.verify(org.mockito.Mockito.verify) CalendarModel(org.datatransferproject.types.common.models.calendar.CalendarModel) Mockito(org.mockito.Mockito) List(java.util.List) CalendarListEntry(com.google.api.services.calendar.model.CalendarListEntry) Optional(java.util.Optional) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) CalendarContainerResource(org.datatransferproject.types.common.models.calendar.CalendarContainerResource) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) CalendarModel(org.datatransferproject.types.common.models.calendar.CalendarModel) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) CalendarEventModel(org.datatransferproject.types.common.models.calendar.CalendarEventModel) CalendarContainerResource(org.datatransferproject.types.common.models.calendar.CalendarContainerResource) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Aggregations

ContainerResource (org.datatransferproject.types.common.models.ContainerResource)24 Test (org.junit.Test)20 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)12 ExportInformation (org.datatransferproject.types.common.ExportInformation)11 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)10 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)7 InOrder (org.mockito.InOrder)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 PaginationData (org.datatransferproject.types.common.PaginationData)6 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)6 Truth.assertThat (com.google.common.truth.Truth.assertThat)5 IOException (java.io.IOException)5 Collection (java.util.Collection)5 Optional (java.util.Optional)5 UUID (java.util.UUID)5 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)5 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)5