use of model.Person in project data-transfer-project by google.
the class VCardToGoogleContactConverterTest method testConversionToGoogleNames.
@Test
public void testConversionToGoogleNames() {
// Set up vCard with a primary name and one secondary name
String primaryGivenName = "Mark";
String primaryFamilyName = "Twain";
String primarySourceType = "CONTACT";
StructuredName primaryName = makeStructuredName(primaryGivenName, primaryFamilyName, primarySourceType);
String altGivenName = "Samuel";
String altFamilyName = "Clemens";
String altSourceType = "PROFILE";
StructuredName altName = makeStructuredName(altGivenName, altFamilyName, altSourceType);
VCard vCard = new VCard();
vCard.addProperty(primaryName);
vCard.addPropertyAlt(StructuredName.class, Collections.singleton(altName));
// Run test
Person person = VCardToGoogleContactConverter.convert(vCard);
// Check results
// Correct number of names
assertThat(person.getNames().size()).isEqualTo(1);
// Check primary names
List<Name> actualPrimaryNames = person.getNames().stream().filter(a -> a.getMetadata().getPrimary()).collect(Collectors.toList());
List<Pair<String, String>> actualPrimaryNameValues = actualPrimaryNames.stream().map(VCardToGoogleContactConverterTest::getGivenAndFamilyValues).collect(Collectors.toList());
assertThat(actualPrimaryNameValues).containsExactly(Pair.of(primaryGivenName, primaryFamilyName));
List<String> actualPrimaryNameSourceValues = actualPrimaryNames.stream().map(a -> a.getMetadata().getSource().getType()).collect(Collectors.toList());
assertThat(actualPrimaryNameSourceValues).containsExactly(primarySourceType);
// Check secondary names - there shouldn't be any
List<Name> actualSecondaryNames = person.getNames().stream().filter(a -> !a.getMetadata().getPrimary()).collect(Collectors.toList());
assertThat(actualSecondaryNames).isEmpty();
}
use of model.Person 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);
}
use of model.Person in project compss by bsc-wdc.
the class External method testPSCOTarget.
private static void testPSCOTarget() {
String id = "person_" + UUID.randomUUID().toString();
Person p = new Person("PName1", 1, 1);
p.makePersistent(id);
// Create mergeable p2
String id2 = "person_" + UUID.randomUUID().toString();
Person p2 = new Person("PName2", 1, 2);
p2.makePersistent(id2);
p.taskPSCOTargetWithParams("Another", p2);
String name = p.getName();
int age = p.getAge();
int numC = p.getNumComputers();
System.out.println("[LOG][PSCO_TARGET] Person " + name + " with age " + age + " has " + numC + " computers");
System.out.println("[LOG][PSCO_TARGET] BeginId = " + id + " EndId = " + p.getID());
}
use of model.Person in project compss by bsc-wdc.
the class Internal method testPSCOInOut.
private static void testPSCOInOut() {
String id = "person_" + UUID.randomUUID().toString();
Person p = new Person("PName2", 2, 2);
p.makePersistent(id);
InternalImpl.taskPSCOInOut(p);
String name = p.getName();
int age = p.getAge();
int numC = p.getNumComputers();
System.out.println("[LOG][PSCO_INOUT] Person " + name + " with age " + age + " has " + numC + " computers");
System.out.println("[LOG][PSCO_INOUT] BeginId = " + id + " EndId = " + p.getID());
}
use of model.Person in project compss by bsc-wdc.
the class Internal method testNewVersionAndConsolidate.
private static void testNewVersionAndConsolidate() throws StorageException {
Person original = new Person("Original", 0, 0);
original.makePersistent("Original");
Stack<String> personStack = new Stack<>();
personStack.push("Original");
System.out.println("[LOG][PSCO_NEW_VERSION_CONSOLIDATE] Id 0: Original");
for (int i = 1; i <= 10; ++i) {
original.setAge(i);
original.setName("person_" + i);
String oldId = original.getID();
String newId = StorageItf.newVersion(oldId, true, "none");
original = (Person) StorageItf.getByID(newId);
System.out.println("[LOG][PSCO_NEW_VERSION_CONSOLIDATE] Id " + i + ": " + newId);
personStack.push(newId);
}
StorageItf.consolidateVersion(personStack.pop());
boolean success = true;
while (!personStack.isEmpty() && success) {
String currentId = personStack.pop();
try {
StorageItf.getByID(currentId);
System.out.println("[LOG][PSCO_NEW_VERSION_CONSOLIDATE] Error, id " + currentId + " is still in Redis!");
success = false;
} catch (StorageException e) {
System.out.println("[LOG][PSCO_NEW_VERSION_CONSOLIDATE] Ok, id " + currentId + " is no longer in Redis!");
}
}
System.out.println("[LOG][PSCO_NEW_VERSION_CONSOLIDATE]: " + (success ? "OK" : "ERROR"));
}
Aggregations