use of com.google.gdata.util.common.base.Pair in project data-transfer-project by google.
the class GoogleContactsImportConversionTest 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 = GoogleContactsImporter.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(GoogleContactsImportConversionTest::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 com.google.gdata.util.common.base.Pair 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 com.google.gdata.util.common.base.Pair in project data-transfer-project by google.
the class GoogleContactsExportConversionTest 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 = GoogleContactsExporter.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(GoogleContactsExportConversionTest::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(GoogleContactsExportConversionTest::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 com.google.gdata.util.common.base.Pair 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();
}
Aggregations