Search in sources :

Example 6 with Person

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);
}
Also used : Telephone(ezvcard.property.Telephone) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) Person(com.google.api.services.people.v1.model.Person) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 7 with Person

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);
}
Also used : VCard(ezvcard.VCard) Arrays(java.util.Arrays) VCARD_PRIMARY_PREF(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) VCardProperty(ezvcard.property.VCardProperty) 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) Address(ezvcard.property.Address) 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) FieldMetadata(com.google.api.services.people.v1.model.FieldMetadata) Source(com.google.api.services.people.v1.model.Source) Email(ezvcard.property.Email) VCardParameters(ezvcard.parameter.VCardParameters) Name(com.google.api.services.people.v1.model.Name) TextProperty(ezvcard.property.TextProperty) Collections(java.util.Collections) FieldMetadata(com.google.api.services.people.v1.model.FieldMetadata) Person(com.google.api.services.people.v1.model.Person) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) Source(com.google.api.services.people.v1.model.Source) 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 8 with Person

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);
}
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) Telephone(ezvcard.property.Telephone) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) VCard(ezvcard.VCard) Person(com.google.api.services.people.v1.model.Person) Test(org.junit.Test)

Example 9 with Person

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);
}
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) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Address(com.google.api.services.people.v1.model.Address) VCard(ezvcard.VCard) Person(com.google.api.services.people.v1.model.Person) Test(org.junit.Test)

Example 10 with Person

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

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