use of model.Person in project data-transfer-project by google.
the class GoogleContactToVCardConverterTest 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 = GoogleContactToVCardConverter.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 GoogleContactToVCardConverterTest method testConversionToVCardNames.
@Test
public void testConversionToVCardNames() {
// Set up Person with a primary name and two secondary names
String primaryGivenName = "Mark";
String primaryFamilyName = "Twain";
Name primaryName = new Name().setGivenName(primaryGivenName).setFamilyName(primaryFamilyName).setMetadata(PRIMARY_FIELD_METADATA);
String alternateGivenName1 = "Samuel";
String alternateFamilyName1 = "Clemens";
String alternateSourceType1 = "PROFILE";
Name alternateName1 = new Name().setGivenName(alternateGivenName1).setFamilyName(alternateFamilyName1).setMetadata(new FieldMetadata().setPrimary(false).setSource(new Source().setType(alternateSourceType1)));
String alternateGivenName2 = "Louis";
String alternateFamilyName2 = "de Conte";
String alternateSourceType2 = "PEN_NAME";
Name alternateName2 = new Name().setGivenName(alternateGivenName2).setFamilyName(alternateFamilyName2).setMetadata(new FieldMetadata().setPrimary(false).setSource(new Source().setType(alternateSourceType2)));
// Order shouldn't matter
Person person = new Person().setNames(Arrays.asList(alternateName2, alternateName1, primaryName));
// Run test
VCard vCard = GoogleContactToVCardConverter.convert(person);
// Check name conversion correctness
List<StructuredName> structuredNames = vCard.getStructuredNames();
assertThat(structuredNames.size()).isEqualTo(3);
// Check primary (non-alternate) names
List<StructuredName> actualPrimaryNames = structuredNames.stream().filter(n -> n.getAltId() == null).collect(Collectors.toList());
List<Pair<String, String>> actualPrimaryNamesValues = actualPrimaryNames.stream().map(GoogleContactToVCardConverterTest::getGivenAndFamilyNames).collect(Collectors.toList());
assertThat(actualPrimaryNamesValues).containsExactly(Pair.of(primaryGivenName, primaryFamilyName));
List<String> actualPrimarySourceValues = actualPrimaryNames.stream().map(a -> a.getParameter(SOURCE_PARAM_NAME_TYPE)).collect(Collectors.toList());
assertThat(actualPrimarySourceValues).containsExactly(DEFAULT_SOURCE_TYPE);
// Check alternate names
List<StructuredName> actualAlternateNames = structuredNames.stream().filter(n -> n.getAltId() != null).collect(Collectors.toList());
List<Pair<String, String>> actualAlternateNamesValues = actualAlternateNames.stream().map(GoogleContactToVCardConverterTest::getGivenAndFamilyNames).collect(Collectors.toList());
assertThat(actualAlternateNamesValues).containsExactly(Pair.of(alternateGivenName1, alternateFamilyName1), Pair.of(alternateGivenName2, alternateFamilyName2));
List<String> actualAlternateSourceValues = actualAlternateNames.stream().map(a -> a.getParameter(SOURCE_PARAM_NAME_TYPE)).collect(Collectors.toList());
assertThat(actualAlternateSourceValues).containsExactly(alternateSourceType1, alternateSourceType2);
}
use of model.Person 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);
}
use of model.Person 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);
}
use of model.Person in project compss by bsc-wdc.
the class External method testMergeReduceTarget.
public static void testMergeReduceTarget() {
// Init
Person[] people = new Person[4];
for (int i = 0; i < people.length; ++i) {
String id = "person_" + UUID.randomUUID().toString();
System.out.println("[LOG][PSCO_MR_TARGET] Person " + i + " BeginId = " + id);
people[i] = new Person("PName" + i, i, i);
people[i].makePersistent(id);
}
// Map
for (int i = 0; i < people.length; ++i) {
people[i].taskMap("NewName" + i);
}
// Reduce
LinkedList<Integer> q = new LinkedList<Integer>();
for (int i = 0; i < people.length; i++) {
q.add(i);
}
int x = 0;
while (!q.isEmpty()) {
x = q.poll();
int y;
if (!q.isEmpty()) {
y = q.poll();
people[x].taskReduce(people[y]);
q.add(x);
}
}
// Get (sync) and write result
Person p1 = people[0];
String name = p1.getName();
int age = p1.getAge();
int numC = p1.getNumComputers();
System.out.println("[LOG][PSCO_MR_TARGET] Person " + name + " with age " + age + " has " + numC + " computers");
System.out.println("[LOG][PSCO_MR_TARGET] EndId = " + p1.getID());
}
Aggregations