use of org.dataportabilityproject.dataModels.contacts.ContactsModelWrapper in project data-transfer-project by google.
the class GoogleContactsServiceTest method importFirstResources.
@Test
public void importFirstResources() throws IOException {
// Set up: small number of VCards to be imported
int numberOfVCards = 5;
List<VCard> vCardList = new LinkedList<>();
for (int i = 0; i < numberOfVCards; i++) {
StructuredName structuredName = new StructuredName();
structuredName.setFamily("Family" + i);
structuredName.setParameter(SOURCE_PARAM_NAME_TYPE, CONTACT_SOURCE_TYPE);
VCard vCard = new VCard();
vCard.setStructuredName(structuredName);
vCardList.add(vCard);
}
ContactsModelWrapper wrapper = new ContactsModelWrapper(vCardList, null);
// Run test
contactsService.importItem(wrapper);
// Check that the right methods were called
verify(people, times(numberOfVCards)).createContact(any(Person.class));
verify(createContact, times(numberOfVCards)).execute();
}
use of org.dataportabilityproject.dataModels.contacts.ContactsModelWrapper in project data-transfer-project by google.
the class GoogleContactsServiceTest method exportSubsequentPage.
@Test
public void exportSubsequentPage() throws IOException {
setUpSinglePersonResponse();
// Looking at a subsequent page, with no pages after it
ExportInformation nextPageExportInformation = new ExportInformation(Optional.empty(), Optional.of(new StringPaginationToken(NEXT_PAGE_TOKEN)));
listConnectionsResponse.setNextPageToken(null);
when(listConnectionsRequest.setPageToken(NEXT_PAGE_TOKEN)).thenReturn(listConnectionsRequest);
// Run test
ContactsModelWrapper wrapper = contactsService.export(nextPageExportInformation);
// Verify correct calls were made - i.e., token was added before execution
InOrder inOrder = Mockito.inOrder(listConnectionsRequest);
inOrder.verify(listConnectionsRequest).setPageToken(NEXT_PAGE_TOKEN);
inOrder.verify(listConnectionsRequest).execute();
// Check continuation information
assertThat(wrapper.getContinuationInformation()).isNull();
}
use of org.dataportabilityproject.dataModels.contacts.ContactsModelWrapper in project data-transfer-project by google.
the class GoogleContactsService method export.
public ContactsModelWrapper export(ExportInformation continuationInformation) throws IOException {
// Set up connection
Connections.List connectionsList = peopleService.people().connections().list(GoogleContactsConstants.SELF_RESOURCE);
// Get next page, if we have a page token
if (continuationInformation.getPaginationInformation().isPresent()) {
String pageToken = ((StringPaginationToken) continuationInformation.getPaginationInformation().get()).getId();
connectionsList.setPageToken(pageToken);
}
// Get list of connections (nb: not a list containing full info of each Person)
ListConnectionsResponse response = connectionsList.setPersonFields(GoogleContactsConstants.PERSON_FIELDS).execute();
List<Person> peopleList = response.getConnections();
// Get list of resource names, then get list of Persons
List<String> resourceNames = peopleList.stream().map(Person::getResourceName).collect(Collectors.toList());
GetPeopleResponse batchResponse = peopleService.people().getBatchGet().setResourceNames(resourceNames).setPersonFields(GoogleContactsConstants.PERSON_FIELDS).execute();
List<PersonResponse> personResponseList = batchResponse.getResponses();
// Convert Persons to VCards
List<VCard> vCards = personResponseList.stream().map(a -> GoogleContactToVCardConverter.convert(a.getPerson())).collect(Collectors.toList());
// Determine if there's a next page
StringPaginationToken newPage = null;
if (response.getNextPageToken() != null) {
newPage = new StringPaginationToken(response.getNextPageToken());
}
ContinuationInformation newContinuationInformation = null;
if (newPage != null) {
newContinuationInformation = new ContinuationInformation(null, newPage);
}
return new ContactsModelWrapper(vCards, newContinuationInformation);
}
use of org.dataportabilityproject.dataModels.contacts.ContactsModelWrapper 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());
}
Aggregations