use of model.Person in project data-transfer-project by google.
the class GoogleContactsExportConversionTest method testConversionToVCardTelephone.
@Test
public void testConversionToVCardTelephone() {
// Set up test: person with 2 primary phone numbers and 1 secondary phone number
String primaryValue1 = "334-844-4244";
String primaryValue2 = "411";
String secondaryValue = "(555) 867-5309";
PhoneNumber primaryPhone1 = new PhoneNumber().setValue(primaryValue1).setMetadata(PRIMARY_FIELD_METADATA);
PhoneNumber primaryPhone2 = new PhoneNumber().setValue(primaryValue2).setMetadata(PRIMARY_FIELD_METADATA);
PhoneNumber secondaryPhone = new PhoneNumber().setValue(secondaryValue).setMetadata(SECONDARY_FIELD_METADATA);
Person person = DEFAULT_PERSON.setPhoneNumbers(Arrays.asList(secondaryPhone, primaryPhone1, primaryPhone2));
// Run test
VCard vCard = GoogleContactsExporter.convert(person);
// Check results for correct values and preferences
List<Telephone> resultPrimaryPhoneList = getPropertiesWithPreference(vCard, Telephone.class, VCARD_PRIMARY_PREF);
assertThat(getValuesFromProperties(resultPrimaryPhoneList, Telephone::getText)).containsExactly(primaryValue1, primaryValue2);
List<Telephone> resultSecondaryPhoneList = getPropertiesWithPreference(vCard, Telephone.class, VCARD_PRIMARY_PREF + 1);
assertThat(getValuesFromProperties(resultSecondaryPhoneList, Telephone::getText)).containsExactly(secondaryValue);
}
use of model.Person in project data-transfer-project by google.
the class GoogleContactsImportConversionTest 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 = GoogleContactsImporter.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);
}
use of model.Person in project data-transfer-project by google.
the class GoogleContactsImportConversionTest 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 = GoogleContactsImporter.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);
}
use of model.Person 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);
}
use of model.Person in project data-transfer-project by google.
the class GoogleContactToVCardConverterTest method testConversionToVCardAddress.
@Test
public void testConversionToVCardAddress() {
// Set up test: person with a primary address and a secondary address
String primaryStreet = "221B Baker St";
String primaryCity = "London";
String primaryPostcode = "NW1";
String primaryCountry = "United Kingdom";
com.google.api.services.people.v1.model.Address primaryAddress = new com.google.api.services.people.v1.model.Address().setStreetAddress(primaryStreet).setCity(primaryCity).setPostalCode(primaryPostcode).setCountry(primaryCountry).setMetadata(PRIMARY_FIELD_METADATA);
String altStreet = "42 Wallaby Way";
String altCity = "Sydney";
String altRegion = "New South Wales";
String altCountry = "Australia";
com.google.api.services.people.v1.model.Address altAddress = new com.google.api.services.people.v1.model.Address().setStreetAddress(altStreet).setCity(altCity).setRegion(altRegion).setCountry(altCountry).setMetadata(SECONDARY_FIELD_METADATA);
Person person = DEFAULT_PERSON.setAddresses(Arrays.asList(altAddress, primaryAddress));
// Run test
VCard vCard = GoogleContactToVCardConverter.convert(person);
// Check results for correct values and preferences
List<Address> actualPrimaryAddressList = getPropertiesWithPreference(vCard, Address.class, VCARD_PRIMARY_PREF);
assertThat(actualPrimaryAddressList.stream().map(Address::getStreetAddress).collect(Collectors.toList())).containsExactly(primaryStreet);
List<Address> actualAltAddressList = getPropertiesWithPreference(vCard, Address.class, VCARD_PRIMARY_PREF + 1);
assertThat(actualAltAddressList.stream().map(Address::getRegion).collect(Collectors.toList())).containsExactly(altRegion);
}
Aggregations