Search in sources :

Example 1 with EmailAddress

use of com.google.api.services.people.v1.model.EmailAddress in project data-transfer-project by google.

the class GoogleContactToVCardConverterTest method testConversionToVCardEmail.

@Test
public void testConversionToVCardEmail() {
    // 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";
    EmailAddress primaryEmail = new EmailAddress().setValue(primaryString).setMetadata(PRIMARY_FIELD_METADATA);
    EmailAddress secondaryEmail1 = new EmailAddress().setValue(secondaryString1).setMetadata(SECONDARY_FIELD_METADATA);
    EmailAddress secondaryEmail2 = new EmailAddress().setValue(secondaryString2).setMetadata(SECONDARY_FIELD_METADATA);
    Person person = DEFAULT_PERSON.setEmailAddresses(Arrays.asList(secondaryEmail1, primaryEmail, // Making sure order isn't a factor
    secondaryEmail2));
    // Run test - NB, this Person only has emails
    VCard vCard = GoogleContactToVCardConverter.convert(person);
    // Check results for correct values and preferences
    List<Email> resultPrimaryEmailList = getPropertiesWithPreference(vCard, Email.class, VCARD_PRIMARY_PREF);
    assertThat(getValuesFromTextProperties(resultPrimaryEmailList)).containsExactly(primaryString);
    List<Email> resultSecondaryEmailList = getPropertiesWithPreference(vCard, Email.class, VCARD_PRIMARY_PREF + 1);
    assertThat(getValuesFromTextProperties(resultSecondaryEmailList)).containsExactly(secondaryString1, secondaryString2);
}
Also used : Email(ezvcard.property.Email) Person(com.google.api.services.people.v1.model.Person) VCard(ezvcard.VCard) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Test(org.junit.Test)

Example 2 with EmailAddress

use of com.google.api.services.people.v1.model.EmailAddress in project data-transfer-project by google.

the class GoogleContactsImporter method convertToGoogleEmail.

private static EmailAddress convertToGoogleEmail(Email vCardEmail) {
    EmailAddress emailAddress = new EmailAddress();
    emailAddress.setValue(vCardEmail.getValue());
    if (vCardEmail.getPref() != null && vCardEmail.getPref() == VCARD_PRIMARY_PREF) {
        emailAddress.setMetadata(PRIMARY_FIELD_METADATA);
    } else {
        emailAddress.setMetadata(SECONDARY_FIELD_METADATA);
    }
    return emailAddress;
}
Also used : EmailAddress(com.google.api.services.people.v1.model.EmailAddress)

Example 3 with EmailAddress

use of com.google.api.services.people.v1.model.EmailAddress in project data-transfer-project by google.

the class VCardToGoogleContactConverter method convertToGoogleEmail.

private static EmailAddress convertToGoogleEmail(Email vCardEmail) {
    EmailAddress emailAddress = new EmailAddress();
    emailAddress.setValue(vCardEmail.getValue());
    if (vCardEmail.getPref() != null && vCardEmail.getPref() == VCARD_PRIMARY_PREF) {
        emailAddress.setMetadata(PRIMARY_FIELD_METADATA);
    } else {
        emailAddress.setMetadata(SECONDARY_FIELD_METADATA);
    }
    return emailAddress;
}
Also used : EmailAddress(com.google.api.services.people.v1.model.EmailAddress)

Example 4 with EmailAddress

use of com.google.api.services.people.v1.model.EmailAddress in project data-transfer-project by google.

the class GoogleContactsExportConversionTest method testConversionToVCardEmail.

@Test
public void testConversionToVCardEmail() {
    // 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";
    EmailAddress primaryEmail = new EmailAddress().setValue(primaryString).setMetadata(PRIMARY_FIELD_METADATA);
    EmailAddress secondaryEmail1 = new EmailAddress().setValue(secondaryString1).setMetadata(SECONDARY_FIELD_METADATA);
    EmailAddress secondaryEmail2 = new EmailAddress().setValue(secondaryString2).setMetadata(SECONDARY_FIELD_METADATA);
    Person person = DEFAULT_PERSON.setEmailAddresses(Arrays.asList(secondaryEmail1, primaryEmail, // Making sure order isn't a factor
    secondaryEmail2));
    // Run test - NB, this Person only has emails
    VCard vCard = GoogleContactsExporter.convert(person);
    // Check results for correct values and preferences
    List<Email> resultPrimaryEmailList = getPropertiesWithPreference(vCard, Email.class, VCARD_PRIMARY_PREF);
    assertThat(getValuesFromTextProperties(resultPrimaryEmailList)).containsExactly(primaryString);
    List<Email> resultSecondaryEmailList = getPropertiesWithPreference(vCard, Email.class, VCARD_PRIMARY_PREF + 1);
    assertThat(getValuesFromTextProperties(resultSecondaryEmailList)).containsExactly(secondaryString1, secondaryString2);
}
Also used : Email(ezvcard.property.Email) Person(com.google.api.services.people.v1.model.Person) VCard(ezvcard.VCard) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Test(org.junit.Test)

Example 5 with EmailAddress

use of com.google.api.services.people.v1.model.EmailAddress in project data-transfer-project by google.

the class GoogleContactsImportConversionTest 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 = GoogleContactsImporter.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) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Telephone(ezvcard.property.Telephone) 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) SOURCE_PARAM_NAME_TYPE(org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.SOURCE_PARAM_NAME_TYPE) 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.datatransfer.google.common.GoogleStaticObjects.CONTACT_SOURCE_TYPE) Nullable(com.google.gdata.util.common.base.Nullable) Address(com.google.api.services.people.v1.model.Address) Email(ezvcard.property.Email) VCARD_PRIMARY_PREF(org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.VCARD_PRIMARY_PREF) 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

EmailAddress (com.google.api.services.people.v1.model.EmailAddress)6 Person (com.google.api.services.people.v1.model.Person)4 VCard (ezvcard.VCard)4 Email (ezvcard.property.Email)4 Test (org.junit.Test)4 Address (com.google.api.services.people.v1.model.Address)2 Name (com.google.api.services.people.v1.model.Name)2 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 Nullable (com.google.gdata.util.common.base.Nullable)2 Pair (com.google.gdata.util.common.base.Pair)2 StructuredName (ezvcard.property.StructuredName)2 Telephone (ezvcard.property.Telephone)2 Collections (java.util.Collections)2 List (java.util.List)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Before (org.junit.Before)2 CONTACT_SOURCE_TYPE (org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.CONTACT_SOURCE_TYPE)1 SOURCE_PARAM_NAME_TYPE (org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.SOURCE_PARAM_NAME_TYPE)1