Search in sources :

Example 31 with Person

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();
}
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) StructuredName(ezvcard.property.StructuredName) VCard(ezvcard.VCard) Person(com.google.api.services.people.v1.model.Person) StructuredName(ezvcard.property.StructuredName) Name(com.google.api.services.people.v1.model.Name) Pair(com.google.gdata.util.common.base.Pair) Test(org.junit.Test)

Example 32 with Person

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);
}
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)

Example 33 with Person

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());
}
Also used : Person(model.Person)

Example 34 with Person

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());
}
Also used : Person(model.Person)

Example 35 with Person

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"));
}
Also used : Person(model.Person) StorageException(storage.StorageException) Stack(java.util.Stack)

Aggregations

Person (com.google.api.services.people.v1.model.Person)25 VCard (ezvcard.VCard)20 Test (org.junit.Test)16 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)15 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)13 Email (ezvcard.property.Email)13 Telephone (ezvcard.property.Telephone)13 Person (model.Person)13 List (java.util.List)12 Collectors (java.util.stream.Collectors)12 Name (com.google.api.services.people.v1.model.Name)11 StructuredName (ezvcard.property.StructuredName)11 Truth.assertThat (com.google.common.truth.Truth.assertThat)10 Pair (com.google.gdata.util.common.base.Pair)10 Collections (java.util.Collections)10 Function (java.util.function.Function)10 Address (com.google.api.services.people.v1.model.Address)9 Nullable (com.google.gdata.util.common.base.Nullable)8 Before (org.junit.Before)8 SOURCE_PARAM_NAME_TYPE (org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.SOURCE_PARAM_NAME_TYPE)6