use of com.google.api.services.people.v1.model.Address in project data-transfer-project by google.
the class GoogleContactsExportConversionTest method testConversionToVCardAddress.
@Test
public void testConversionToVCardAddress() {
// Set up test: person with a primary address and a secondary address
String primaryStreet = "221B Baker St";
String primaryCity = "London";
String primaryPostcode = "NW1";
String primaryCountry = "United Kingdom";
com.google.api.services.people.v1.model.Address primaryAddress = new com.google.api.services.people.v1.model.Address().setStreetAddress(primaryStreet).setCity(primaryCity).setPostalCode(primaryPostcode).setCountry(primaryCountry).setMetadata(PRIMARY_FIELD_METADATA);
String altStreet = "42 Wallaby Way";
String altCity = "Sydney";
String altRegion = "New South Wales";
String altCountry = "Australia";
com.google.api.services.people.v1.model.Address altAddress = new com.google.api.services.people.v1.model.Address().setStreetAddress(altStreet).setCity(altCity).setRegion(altRegion).setCountry(altCountry).setMetadata(SECONDARY_FIELD_METADATA);
Person person = DEFAULT_PERSON.setAddresses(Arrays.asList(altAddress, primaryAddress));
// Run test
VCard vCard = GoogleContactsExporter.convert(person);
// Check results for correct values and preferences
List<Address> actualPrimaryAddressList = getPropertiesWithPreference(vCard, Address.class, VCARD_PRIMARY_PREF);
assertThat(actualPrimaryAddressList.stream().map(Address::getStreetAddress).collect(Collectors.toList())).containsExactly(primaryStreet);
List<Address> actualAltAddressList = getPropertiesWithPreference(vCard, Address.class, VCARD_PRIMARY_PREF + 1);
assertThat(actualAltAddressList.stream().map(Address::getRegion).collect(Collectors.toList())).containsExactly(altRegion);
}
use of com.google.api.services.people.v1.model.Address in project data-transfer-project by google.
the class GoogleContactsImportConversionTest 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 = GoogleContactsImporter.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 com.google.api.services.people.v1.model.Address in project data-transfer-project by google.
the class GoogleContactToVCardConverterTest method testConversionToVCardAddress.
@Test
public void testConversionToVCardAddress() {
// Set up test: person with a primary address and a secondary address
String primaryStreet = "221B Baker St";
String primaryCity = "London";
String primaryPostcode = "NW1";
String primaryCountry = "United Kingdom";
com.google.api.services.people.v1.model.Address primaryAddress = new com.google.api.services.people.v1.model.Address().setStreetAddress(primaryStreet).setCity(primaryCity).setPostalCode(primaryPostcode).setCountry(primaryCountry).setMetadata(PRIMARY_FIELD_METADATA);
String altStreet = "42 Wallaby Way";
String altCity = "Sydney";
String altRegion = "New South Wales";
String altCountry = "Australia";
com.google.api.services.people.v1.model.Address altAddress = new com.google.api.services.people.v1.model.Address().setStreetAddress(altStreet).setCity(altCity).setRegion(altRegion).setCountry(altCountry).setMetadata(SECONDARY_FIELD_METADATA);
Person person = DEFAULT_PERSON.setAddresses(Arrays.asList(altAddress, primaryAddress));
// Run test
VCard vCard = GoogleContactToVCardConverter.convert(person);
// Check results for correct values and preferences
List<Address> actualPrimaryAddressList = getPropertiesWithPreference(vCard, Address.class, VCARD_PRIMARY_PREF);
assertThat(actualPrimaryAddressList.stream().map(Address::getStreetAddress).collect(Collectors.toList())).containsExactly(primaryStreet);
List<Address> actualAltAddressList = getPropertiesWithPreference(vCard, Address.class, VCARD_PRIMARY_PREF + 1);
assertThat(actualAltAddressList.stream().map(Address::getRegion).collect(Collectors.toList())).containsExactly(altRegion);
}
use of com.google.api.services.people.v1.model.Address in project gpconnect-demonstrator by nhsconnect.
the class OrganizationResourceProvider method getValidAddress.
private Address getValidAddress() {
Address orgAddress = new Address();
orgAddress.setType(AddressType.PHYSICAL);
orgAddress.setUse(AddressUse.WORK);
return orgAddress;
}
use of com.google.api.services.people.v1.model.Address in project cloudbreak by hortonworks.
the class AwsResourceConnector method releaseReservedIp.
private void releaseReservedIp(AmazonEC2 client, Iterable<CloudResource> resources) {
CloudResource elasticIpResource = getReservedIp(resources);
if (elasticIpResource != null && elasticIpResource.getName() != null) {
Address address;
try {
DescribeAddressesResult describeResult = client.describeAddresses(new DescribeAddressesRequest().withAllocationIds(elasticIpResource.getName()));
address = describeResult.getAddresses().get(0);
} catch (AmazonServiceException e) {
if (e.getErrorMessage().equals("The allocation ID '" + elasticIpResource.getName() + "' does not exist")) {
LOGGER.warn("Elastic IP with allocation ID '{}' not found. Ignoring IP release.", elasticIpResource.getName());
return;
} else {
throw e;
}
}
if (address.getAssociationId() != null) {
client.disassociateAddress(new DisassociateAddressRequest().withAssociationId(elasticIpResource.getName()));
}
client.releaseAddress(new ReleaseAddressRequest().withAllocationId(elasticIpResource.getName()));
}
}
Aggregations