Search in sources :

Example 1 with VCARD_PRIMARY_PREF

use of org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF in project data-transfer-project by google.

the class VCardToGoogleContactConverterTest method testConversionToGooglePhones.

@Test
public void testConversionToGooglePhones() {
    // Set up test: vCard with 2 primary phone numbers and 1 secondary phone number
    String primaryValue1 = "334-844-4244";
    String primaryValue2 = "411";
    String secondaryValue = "(555) 867-5309";
    Telephone primaryTelephone1 = new Telephone(primaryValue1);
    primaryTelephone1.setPref(VCARD_PRIMARY_PREF);
    Telephone primaryTelephone2 = new Telephone(primaryValue2);
    primaryTelephone2.setPref(VCARD_PRIMARY_PREF);
    Telephone secondaryTelephone = new Telephone(secondaryValue);
    secondaryTelephone.setPref(VCARD_PRIMARY_PREF + 1);
    // Add numbers to vCard.  Order shouldn't matter.
    VCard vCard = defaultVCard;
    vCard.addTelephoneNumber(secondaryTelephone);
    vCard.addTelephoneNumber(primaryTelephone1);
    vCard.addTelephoneNumber(primaryTelephone2);
    // Run test
    Person person = VCardToGoogleContactConverter.convert(vCard);
    // Check results
    // Correct number of phone numbers
    assertThat(person.getPhoneNumbers().size()).isEqualTo(3);
    // Check primary phone numbers
    List<PhoneNumber> actualPrimaryNumbers = person.getPhoneNumbers().stream().filter(a -> a.getMetadata().getPrimary()).collect(Collectors.toList());
    List<String> actualPrimaryNumberStrings = getValuesFromFields(actualPrimaryNumbers, PhoneNumber::getValue);
    assertThat(actualPrimaryNumberStrings).containsExactly(primaryValue1, primaryValue2);
    // Check secondary phone numbers
    List<PhoneNumber> actualSecondaryNumbers = person.getPhoneNumbers().stream().filter(a -> !a.getMetadata().getPrimary()).collect(Collectors.toList());
    List<String> actualSecondaryNumberStrings = getValuesFromFields(actualSecondaryNumbers, PhoneNumber::getValue);
    assertThat(actualSecondaryNumberStrings).containsExactly(secondaryValue);
}
Also used : VCard(ezvcard.VCard) VCARD_PRIMARY_PREF(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Telephone(ezvcard.property.Telephone) SOURCE_PARAM_NAME_TYPE(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.SOURCE_PARAM_NAME_TYPE) Test(org.junit.Test) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) Truth.assertThat(com.google.common.truth.Truth.assertThat) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) StructuredName(ezvcard.property.StructuredName) Pair(com.google.gdata.util.common.base.Pair) Person(com.google.api.services.people.v1.model.Person) List(java.util.List) CONTACT_SOURCE_TYPE(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.CONTACT_SOURCE_TYPE) Nullable(com.google.gdata.util.common.base.Nullable) Address(com.google.api.services.people.v1.model.Address) Email(ezvcard.property.Email) Name(com.google.api.services.people.v1.model.Name) Collections(java.util.Collections) Before(org.junit.Before) Telephone(ezvcard.property.Telephone) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) VCard(ezvcard.VCard) Person(com.google.api.services.people.v1.model.Person) Test(org.junit.Test)

Example 2 with VCARD_PRIMARY_PREF

use of org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF in project data-transfer-project by google.

the class VCardToGoogleContactConverterTest method testConversionToGoogleAddresses.

@Test
public void testConversionToGoogleAddresses() {
    // Set up vCard with a primary address and a secondary address
    String primaryStreet = "221B Baker St";
    String primaryLocality = "London";
    ezvcard.property.Address primaryAddress = new ezvcard.property.Address();
    primaryAddress.setStreetAddress(primaryStreet);
    primaryAddress.setLocality(primaryLocality);
    primaryAddress.setPref(VCARD_PRIMARY_PREF);
    String altStreet = "42 Wallaby Way";
    String altLocality = "Sydney";
    ezvcard.property.Address altAddress = new ezvcard.property.Address();
    altAddress.setStreetAddress(altStreet);
    altAddress.setLocality(altLocality);
    altAddress.setPref(VCARD_PRIMARY_PREF + 1);
    // Add addresses to vCard.  Order shouldn't matter.
    VCard vCard = defaultVCard;
    vCard.addAddress(primaryAddress);
    vCard.addAddress(altAddress);
    // Run test
    Person person = VCardToGoogleContactConverter.convert(vCard);
    // Check results
    // Check correct number of addresses
    assertThat(person.getAddresses().size()).isEqualTo(2);
    // Check primary address
    List<Address> actualPrimaryAddresses = person.getAddresses().stream().filter(a -> a.getMetadata().getPrimary()).collect(Collectors.toList());
    List<String> actualPrimaryAddressStreets = getValuesFromFields(actualPrimaryAddresses, Address::getStreetAddress);
    assertThat(actualPrimaryAddressStreets).containsExactly(primaryStreet);
    // Check secondary address
    List<Address> actualSecondaryAddresses = person.getAddresses().stream().filter(a -> !a.getMetadata().getPrimary()).collect(Collectors.toList());
    List<String> actualSecondaryAddressStreets = getValuesFromFields(actualSecondaryAddresses, Address::getStreetAddress);
    assertThat(actualSecondaryAddressStreets).containsExactly(altStreet);
}
Also used : VCard(ezvcard.VCard) VCARD_PRIMARY_PREF(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Telephone(ezvcard.property.Telephone) SOURCE_PARAM_NAME_TYPE(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.SOURCE_PARAM_NAME_TYPE) Test(org.junit.Test) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) Truth.assertThat(com.google.common.truth.Truth.assertThat) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) StructuredName(ezvcard.property.StructuredName) Pair(com.google.gdata.util.common.base.Pair) Person(com.google.api.services.people.v1.model.Person) List(java.util.List) CONTACT_SOURCE_TYPE(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.CONTACT_SOURCE_TYPE) Nullable(com.google.gdata.util.common.base.Nullable) Address(com.google.api.services.people.v1.model.Address) Email(ezvcard.property.Email) Name(com.google.api.services.people.v1.model.Name) Collections(java.util.Collections) Before(org.junit.Before) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Address(com.google.api.services.people.v1.model.Address) VCard(ezvcard.VCard) Person(com.google.api.services.people.v1.model.Person) Test(org.junit.Test)

Example 3 with VCARD_PRIMARY_PREF

use of org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF in project data-transfer-project by google.

the class VCardToGoogleContactConverterTest method testConversionToGoogleEmails.

@Test
public void testConversionToGoogleEmails() {
    // Set up test: person with 1 primary email and 2 secondary emails
    String primaryString = "primary@email.com";
    String secondaryString1 = "secondary1@email.com";
    String secondaryString2 = "secondary2@email.com";
    Email primaryEmail = new Email(primaryString);
    primaryEmail.setPref(VCARD_PRIMARY_PREF);
    Email secondaryEmail1 = new Email(secondaryString1);
    secondaryEmail1.setPref(VCARD_PRIMARY_PREF + 1);
    Email secondaryEmail2 = new Email(secondaryString2);
    secondaryEmail2.setPref(VCARD_PRIMARY_PREF + 1);
    // Add emails to vCard.  Order shouldn't matter.
    VCard vCard = defaultVCard;
    vCard.addEmail(secondaryEmail1);
    vCard.addEmail(primaryEmail);
    vCard.addEmail(secondaryEmail2);
    // Run test
    Person person = VCardToGoogleContactConverter.convert(vCard);
    // Check results
    // Correct number of emails
    assertThat(person.getEmailAddresses().size()).isEqualTo(3);
    // Check primary email addresses
    List<EmailAddress> actualPrimaryEmails = person.getEmailAddresses().stream().filter(a -> a.getMetadata().getPrimary()).collect(Collectors.toList());
    List<String> actualPrimaryEmailsStrings = getValuesFromFields(actualPrimaryEmails, EmailAddress::getValue);
    assertThat(actualPrimaryEmailsStrings).containsExactly(primaryString);
    // Check secondary email addresses
    List<EmailAddress> actualSecondaryEmails = person.getEmailAddresses().stream().filter(a -> !a.getMetadata().getPrimary()).collect(Collectors.toList());
    List<String> actualSecondaryEmailsStrings = getValuesFromFields(actualSecondaryEmails, EmailAddress::getValue);
    assertThat(actualSecondaryEmailsStrings).containsExactly(secondaryString1, secondaryString2);
}
Also used : VCard(ezvcard.VCard) VCARD_PRIMARY_PREF(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Telephone(ezvcard.property.Telephone) SOURCE_PARAM_NAME_TYPE(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.SOURCE_PARAM_NAME_TYPE) Test(org.junit.Test) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) Truth.assertThat(com.google.common.truth.Truth.assertThat) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) StructuredName(ezvcard.property.StructuredName) Pair(com.google.gdata.util.common.base.Pair) Person(com.google.api.services.people.v1.model.Person) List(java.util.List) CONTACT_SOURCE_TYPE(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.CONTACT_SOURCE_TYPE) Nullable(com.google.gdata.util.common.base.Nullable) Address(com.google.api.services.people.v1.model.Address) Email(ezvcard.property.Email) Name(com.google.api.services.people.v1.model.Name) Collections(java.util.Collections) Before(org.junit.Before) Email(ezvcard.property.Email) VCard(ezvcard.VCard) Person(com.google.api.services.people.v1.model.Person) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Test(org.junit.Test)

Aggregations

Address (com.google.api.services.people.v1.model.Address)3 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)3 Name (com.google.api.services.people.v1.model.Name)3 Person (com.google.api.services.people.v1.model.Person)3 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 Nullable (com.google.gdata.util.common.base.Nullable)3 Pair (com.google.gdata.util.common.base.Pair)3 VCard (ezvcard.VCard)3 Email (ezvcard.property.Email)3 StructuredName (ezvcard.property.StructuredName)3 Telephone (ezvcard.property.Telephone)3 Collections (java.util.Collections)3 List (java.util.List)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3 CONTACT_SOURCE_TYPE (org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.CONTACT_SOURCE_TYPE)3 SOURCE_PARAM_NAME_TYPE (org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.SOURCE_PARAM_NAME_TYPE)3 VCARD_PRIMARY_PREF (org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF)3 Before (org.junit.Before)3