Convert remaining Contact flows to tm() (#924)

* Convert remaining Contact flows to tm()

* Add a test to verify street fileds get populated from XML
This commit is contained in:
Shicong Huang 2021-01-13 13:50:23 -05:00 committed by GitHub
parent c45129f9ac
commit f669e3ca59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 108 additions and 56 deletions

View file

@ -19,9 +19,9 @@ import static google.registry.flows.ResourceFlowUtils.verifyResourceDoesNotExist
import static google.registry.flows.contact.ContactFlowUtils.validateAsciiPostalInfo; import static google.registry.flows.contact.ContactFlowUtils.validateAsciiPostalInfo;
import static google.registry.flows.contact.ContactFlowUtils.validateContactAgainstPolicy; import static google.registry.flows.contact.ContactFlowUtils.validateContactAgainstPolicy;
import static google.registry.model.EppResourceUtils.createRepoId; import static google.registry.model.EppResourceUtils.createRepoId;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.config.RegistryConfig.Config; import google.registry.config.RegistryConfig.Config;
import google.registry.flows.EppException; import google.registry.flows.EppException;
@ -95,11 +95,12 @@ public final class ContactCreateFlow implements TransactionalFlow {
.setModificationTime(now) .setModificationTime(now)
.setXmlBytes(null) // We don't want to store contact details in the history entry. .setXmlBytes(null) // We don't want to store contact details in the history entry.
.setParent(Key.create(newContact)); .setParent(Key.create(newContact));
ofy().save().entities( tm().insertAll(
ImmutableSet.of(
newContact, newContact,
historyBuilder.build(), historyBuilder.build().toChildHistoryEntity(),
ForeignKeyIndex.create(newContact, newContact.getDeletionTime()), ForeignKeyIndex.create(newContact, newContact.getDeletionTime()),
EppResourceIndex.create(Key.create(newContact))); EppResourceIndex.create(Key.create(newContact))));
return responseBuilder return responseBuilder
.setResData(ContactCreateData.create(newContact.getContactId(), now)) .setResData(ContactCreateData.create(newContact.getContactId(), now))
.build(); .build();

View file

@ -24,7 +24,6 @@ import static google.registry.flows.ResourceFlowUtils.verifyOptionalAuthInfo;
import static google.registry.flows.ResourceFlowUtils.verifyResourceOwnership; import static google.registry.flows.ResourceFlowUtils.verifyResourceOwnership;
import static google.registry.flows.contact.ContactFlowUtils.validateAsciiPostalInfo; import static google.registry.flows.contact.ContactFlowUtils.validateAsciiPostalInfo;
import static google.registry.flows.contact.ContactFlowUtils.validateContactAgainstPolicy; import static google.registry.flows.contact.ContactFlowUtils.validateContactAgainstPolicy;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -151,7 +150,8 @@ public final class ContactUpdateFlow implements TransactionalFlow {
} }
validateAsciiPostalInfo(newContact.getInternationalizedPostalInfo()); validateAsciiPostalInfo(newContact.getInternationalizedPostalInfo());
validateContactAgainstPolicy(newContact); validateContactAgainstPolicy(newContact);
ofy().save().<Object>entities(newContact, historyBuilder.build()); tm().insert(historyBuilder.build().toChildHistoryEntity());
tm().update(newContact);
return responseBuilder.build(); return responseBuilder.build();
} }

View file

@ -35,6 +35,7 @@ import javax.persistence.Embeddable;
import javax.persistence.MappedSuperclass; import javax.persistence.MappedSuperclass;
import javax.persistence.PostLoad; import javax.persistence.PostLoad;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
@ -177,12 +178,7 @@ public class Address extends ImmutableObject implements Jsonifiable {
* persisted in the Datastore. TODO(shicong): Delete this method after database migration. * persisted in the Datastore. TODO(shicong): Delete this method after database migration.
*/ */
void onLoad(@AlsoLoad("street") List<String> street) { void onLoad(@AlsoLoad("street") List<String> street) {
if (street == null || street.size() == 0) { mapStreetListToIndividualFields(street);
return;
}
streetLine1 = street.get(0);
streetLine2 = street.size() >= 2 ? street.get(1) : null;
streetLine3 = street.size() >= 3 ? street.get(2) : null;
} }
/** /**
@ -202,4 +198,23 @@ public class Address extends ImmutableObject implements Jsonifiable {
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(toImmutableList()); .collect(toImmutableList());
} }
/**
* Sets {@link #streetLine1}, {@link #streetLine2} and {@link #streetLine3} when the entity is
* reconstructed from XML message.
*
* <p>This is a callback function that JAXB invokes after unmarshalling the XML message.
*/
void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
mapStreetListToIndividualFields(street);
}
private void mapStreetListToIndividualFields(List<String> street) {
if (street == null || street.size() == 0) {
return;
}
streetLine1 = street.get(0);
streetLine2 = street.size() >= 2 ? street.get(1) : null;
streetLine3 = street.size() >= 3 ? street.get(2) : null;
}
} }

View file

@ -24,16 +24,18 @@ import google.registry.flows.EppException;
import google.registry.flows.ResourceCheckFlowTestCase; import google.registry.flows.ResourceCheckFlowTestCase;
import google.registry.flows.exceptions.TooManyResourceChecksException; import google.registry.flows.exceptions.TooManyResourceChecksException;
import google.registry.model.contact.ContactResource; import google.registry.model.contact.ContactResource;
import org.junit.jupiter.api.Test; import google.registry.testing.DualDatabaseTest;
import google.registry.testing.TestOfyAndSql;
/** Unit tests for {@link ContactCheckFlow}. */ /** Unit tests for {@link ContactCheckFlow}. */
@DualDatabaseTest
class ContactCheckFlowTest extends ResourceCheckFlowTestCase<ContactCheckFlow, ContactResource> { class ContactCheckFlowTest extends ResourceCheckFlowTestCase<ContactCheckFlow, ContactResource> {
ContactCheckFlowTest() { ContactCheckFlowTest() {
setEppInput("contact_check.xml"); setEppInput("contact_check.xml");
} }
@Test @TestOfyAndSql
void testNothingExists() throws Exception { void testNothingExists() throws Exception {
// These ids come from the check xml. // These ids come from the check xml.
doCheckTest( doCheckTest(
@ -42,7 +44,7 @@ class ContactCheckFlowTest extends ResourceCheckFlowTestCase<ContactCheckFlow, C
create(true, "8013sah", null)); create(true, "8013sah", null));
} }
@Test @TestOfyAndSql
void testOneExists() throws Exception { void testOneExists() throws Exception {
persistActiveContact("sh8013"); persistActiveContact("sh8013");
// These ids come from the check xml. // These ids come from the check xml.
@ -52,7 +54,7 @@ class ContactCheckFlowTest extends ResourceCheckFlowTestCase<ContactCheckFlow, C
create(true, "8013sah", null)); create(true, "8013sah", null));
} }
@Test @TestOfyAndSql
void testOneExistsButWasDeleted() throws Exception { void testOneExistsButWasDeleted() throws Exception {
persistDeletedContact("sh8013", clock.nowUtc().minusDays(1)); persistDeletedContact("sh8013", clock.nowUtc().minusDays(1));
// These ids come from the check xml. // These ids come from the check xml.
@ -62,27 +64,27 @@ class ContactCheckFlowTest extends ResourceCheckFlowTestCase<ContactCheckFlow, C
create(true, "8013sah", null)); create(true, "8013sah", null));
} }
@Test @TestOfyAndSql
void testXmlMatches() throws Exception { void testXmlMatches() throws Exception {
persistActiveContact("sah8013"); persistActiveContact("sah8013");
runFlowAssertResponse(loadFile("contact_check_response.xml")); runFlowAssertResponse(loadFile("contact_check_response.xml"));
} }
@Test @TestOfyAndSql
void test50IdsAllowed() throws Exception { void test50IdsAllowed() throws Exception {
// Make sure we don't have a regression that reduces the number of allowed checks. // Make sure we don't have a regression that reduces the number of allowed checks.
setEppInput("contact_check_50.xml"); setEppInput("contact_check_50.xml");
runFlow(); runFlow();
} }
@Test @TestOfyAndSql
void testTooManyIds() { void testTooManyIds() {
setEppInput("contact_check_51.xml"); setEppInput("contact_check_51.xml");
EppException thrown = assertThrows(TooManyResourceChecksException.class, this::runFlow); EppException thrown = assertThrows(TooManyResourceChecksException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testIcannActivityReportField_getsLogged() throws Exception { void testIcannActivityReportField_getsLogged() throws Exception {
runFlow(); runFlow();
assertIcannReportingActivityFieldLogged("srs-cont-check"); assertIcannReportingActivityFieldLogged("srs-cont-check");

View file

@ -15,6 +15,7 @@
package google.registry.flows.contact; package google.registry.flows.contact;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.ContactResourceSubject.assertAboutContacts; import static google.registry.testing.ContactResourceSubject.assertAboutContacts;
import static google.registry.testing.DatabaseHelper.assertNoBillingEvents; import static google.registry.testing.DatabaseHelper.assertNoBillingEvents;
import static google.registry.testing.DatabaseHelper.newContactResource; import static google.registry.testing.DatabaseHelper.newContactResource;
@ -31,10 +32,12 @@ import google.registry.flows.contact.ContactFlowUtils.DeclineContactDisclosureFi
import google.registry.flows.exceptions.ResourceAlreadyExistsForThisClientException; import google.registry.flows.exceptions.ResourceAlreadyExistsForThisClientException;
import google.registry.flows.exceptions.ResourceCreateContentionException; import google.registry.flows.exceptions.ResourceCreateContentionException;
import google.registry.model.contact.ContactResource; import google.registry.model.contact.ContactResource;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.TestOfyAndSql;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link ContactCreateFlow}. */ /** Unit tests for {@link ContactCreateFlow}. */
@DualDatabaseTest
class ContactCreateFlowTest extends ResourceFlowTestCase<ContactCreateFlow, ContactResource> { class ContactCreateFlowTest extends ResourceFlowTestCase<ContactCreateFlow, ContactResource> {
ContactCreateFlowTest() { ContactCreateFlowTest() {
@ -51,27 +54,29 @@ class ContactCreateFlowTest extends ResourceFlowTestCase<ContactCreateFlow, Cont
.hasOnlyOneHistoryEntryWhich() .hasOnlyOneHistoryEntryWhich()
.hasNoXml(); .hasNoXml();
assertNoBillingEvents(); assertNoBillingEvents();
if (tm().isOfy()) {
assertEppResourceIndexEntityFor(reloadResourceByForeignKey()); assertEppResourceIndexEntityFor(reloadResourceByForeignKey());
} }
}
@Test @TestOfyAndSql
void testDryRun() throws Exception { void testDryRun() throws Exception {
dryRunFlowAssertResponse(loadFile("contact_create_response.xml")); dryRunFlowAssertResponse(loadFile("contact_create_response.xml"));
} }
@Test @TestOfyAndSql
void testSuccess_neverExisted() throws Exception { void testSuccess_neverExisted() throws Exception {
doSuccessfulTest(); doSuccessfulTest();
} }
@Test @TestOfyAndSql
void testSuccess_existedButWasDeleted() throws Exception { void testSuccess_existedButWasDeleted() throws Exception {
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
clock.advanceOneMilli(); clock.advanceOneMilli();
doSuccessfulTest(); doSuccessfulTest();
} }
@Test @TestOfyAndSql
void testFailure_alreadyExists() throws Exception { void testFailure_alreadyExists() throws Exception {
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
ResourceAlreadyExistsForThisClientException thrown = ResourceAlreadyExistsForThisClientException thrown =
@ -83,7 +88,7 @@ class ContactCreateFlowTest extends ResourceFlowTestCase<ContactCreateFlow, Cont
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_resourceContention() throws Exception { void testFailure_resourceContention() throws Exception {
String targetId = getUniqueIdFromCommand(); String targetId = getUniqueIdFromCommand();
persistResource( persistResource(
@ -99,13 +104,13 @@ class ContactCreateFlowTest extends ResourceFlowTestCase<ContactCreateFlow, Cont
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testSuccess_nonAsciiInLocAddress() throws Exception { void testSuccess_nonAsciiInLocAddress() throws Exception {
setEppInput("contact_create_hebrew_loc.xml"); setEppInput("contact_create_hebrew_loc.xml");
doSuccessfulTest(); doSuccessfulTest();
} }
@Test @TestOfyAndSql
void testFailure_nonAsciiInIntAddress() { void testFailure_nonAsciiInIntAddress() {
setEppInput("contact_create_hebrew_int.xml"); setEppInput("contact_create_hebrew_int.xml");
EppException thrown = EppException thrown =
@ -113,7 +118,7 @@ class ContactCreateFlowTest extends ResourceFlowTestCase<ContactCreateFlow, Cont
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_declineDisclosure() { void testFailure_declineDisclosure() {
setEppInput("contact_create_decline_disclosure.xml"); setEppInput("contact_create_decline_disclosure.xml");
EppException thrown = EppException thrown =
@ -121,7 +126,7 @@ class ContactCreateFlowTest extends ResourceFlowTestCase<ContactCreateFlow, Cont
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testIcannActivityReportField_getsLogged() throws Exception { void testIcannActivityReportField_getsLogged() throws Exception {
runFlow(); runFlow();
assertIcannReportingActivityFieldLogged("srs-cont-create"); assertIcannReportingActivityFieldLogged("srs-cont-create");

View file

@ -41,9 +41,11 @@ import google.registry.model.contact.ContactResource;
import google.registry.model.contact.PostalInfo; import google.registry.model.contact.PostalInfo;
import google.registry.model.contact.PostalInfo.Type; import google.registry.model.contact.PostalInfo.Type;
import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.StatusValue;
import org.junit.jupiter.api.Test; import google.registry.testing.DualDatabaseTest;
import google.registry.testing.TestOfyAndSql;
/** Unit tests for {@link ContactUpdateFlow}. */ /** Unit tests for {@link ContactUpdateFlow}. */
@DualDatabaseTest
class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, ContactResource> { class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, ContactResource> {
ContactUpdateFlowTest() { ContactUpdateFlowTest() {
@ -63,18 +65,18 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
assertNoBillingEvents(); assertNoBillingEvents();
} }
@Test @TestOfyAndSql
void testDryRun() throws Exception { void testDryRun() throws Exception {
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
dryRunFlowAssertResponse(loadFile("generic_success_response.xml")); dryRunFlowAssertResponse(loadFile("generic_success_response.xml"));
} }
@Test @TestOfyAndSql
void testSuccess() throws Exception { void testSuccess() throws Exception {
doSuccessfulTest(); doSuccessfulTest();
} }
@Test @TestOfyAndSql
void testSuccess_updatingInternationalizedPostalInfoDeletesLocalized() throws Exception { void testSuccess_updatingInternationalizedPostalInfoDeletesLocalized() throws Exception {
ContactResource contact = ContactResource contact =
persistResource( persistResource(
@ -112,7 +114,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
.build()); .build());
} }
@Test @TestOfyAndSql
void testSuccess_updatingLocalizedPostalInfoDeletesInternationalized() throws Exception { void testSuccess_updatingLocalizedPostalInfoDeletesInternationalized() throws Exception {
setEppInput("contact_update_localized.xml"); setEppInput("contact_update_localized.xml");
ContactResource contact = ContactResource contact =
@ -151,7 +153,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
.build()); .build());
} }
@Test @TestOfyAndSql
void testSuccess_partialPostalInfoUpdate() throws Exception { void testSuccess_partialPostalInfoUpdate() throws Exception {
setEppInput("contact_update_partial_postalinfo.xml"); setEppInput("contact_update_partial_postalinfo.xml");
persistResource( persistResource(
@ -187,7 +189,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
.build()); .build());
} }
@Test @TestOfyAndSql
void testSuccess_updateOnePostalInfo_touchOtherPostalInfoPreservesIt() throws Exception { void testSuccess_updateOnePostalInfo_touchOtherPostalInfoPreservesIt() throws Exception {
setEppInput("contact_update_partial_postalinfo_preserve_int.xml"); setEppInput("contact_update_partial_postalinfo_preserve_int.xml");
persistResource( persistResource(
@ -253,7 +255,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
.build()); .build());
} }
@Test @TestOfyAndSql
void testFailure_neverExisted() throws Exception { void testFailure_neverExisted() throws Exception {
ResourceDoesNotExistException thrown = ResourceDoesNotExistException thrown =
assertThrows(ResourceDoesNotExistException.class, this::runFlow); assertThrows(ResourceDoesNotExistException.class, this::runFlow);
@ -261,7 +263,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_existedButWasDeleted() throws Exception { void testFailure_existedButWasDeleted() throws Exception {
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
ResourceDoesNotExistException thrown = ResourceDoesNotExistException thrown =
@ -270,7 +272,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_statusValueNotClientSettable() throws Exception { void testFailure_statusValueNotClientSettable() throws Exception {
setEppInput("contact_update_prohibited_status.xml"); setEppInput("contact_update_prohibited_status.xml");
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
@ -278,7 +280,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testSuccess_superuserStatusValueNotClientSettable() throws Exception { void testSuccess_superuserStatusValueNotClientSettable() throws Exception {
setEppInput("contact_update_prohibited_status.xml"); setEppInput("contact_update_prohibited_status.xml");
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
@ -287,7 +289,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("generic_success_response.xml")); CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("generic_success_response.xml"));
} }
@Test @TestOfyAndSql
void testFailure_unauthorizedClient() throws Exception { void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
@ -295,7 +297,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testSuccess_superuserUnauthorizedClient() throws Exception { void testSuccess_superuserUnauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
@ -304,7 +306,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("generic_success_response.xml")); CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("generic_success_response.xml"));
} }
@Test @TestOfyAndSql
void testSuccess_clientUpdateProhibited_removed() throws Exception { void testSuccess_clientUpdateProhibited_removed() throws Exception {
setEppInput("contact_update_remove_client_update_prohibited.xml"); setEppInput("contact_update_remove_client_update_prohibited.xml");
persistResource( persistResource(
@ -318,7 +320,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
.doesNotHaveStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED); .doesNotHaveStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED);
} }
@Test @TestOfyAndSql
void testSuccess_superuserClientUpdateProhibited_notRemoved() throws Exception { void testSuccess_superuserClientUpdateProhibited_notRemoved() throws Exception {
setEppInput("contact_update_prohibited_status.xml"); setEppInput("contact_update_prohibited_status.xml");
persistResource( persistResource(
@ -336,7 +338,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
.hasStatusValue(StatusValue.SERVER_DELETE_PROHIBITED); .hasStatusValue(StatusValue.SERVER_DELETE_PROHIBITED);
} }
@Test @TestOfyAndSql
void testFailure_clientUpdateProhibited_notRemoved() throws Exception { void testFailure_clientUpdateProhibited_notRemoved() throws Exception {
persistResource( persistResource(
newContactResource(getUniqueIdFromCommand()) newContactResource(getUniqueIdFromCommand())
@ -348,7 +350,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_serverUpdateProhibited() throws Exception { void testFailure_serverUpdateProhibited() throws Exception {
persistResource( persistResource(
newContactResource(getUniqueIdFromCommand()) newContactResource(getUniqueIdFromCommand())
@ -361,7 +363,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_pendingDeleteProhibited() throws Exception { void testFailure_pendingDeleteProhibited() throws Exception {
persistResource( persistResource(
newContactResource(getUniqueIdFromCommand()) newContactResource(getUniqueIdFromCommand())
@ -374,13 +376,13 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testSuccess_nonAsciiInLocAddress() throws Exception { void testSuccess_nonAsciiInLocAddress() throws Exception {
setEppInput("contact_update_hebrew_loc.xml"); setEppInput("contact_update_hebrew_loc.xml");
doSuccessfulTest(); doSuccessfulTest();
} }
@Test @TestOfyAndSql
void testFailure_nonAsciiInIntAddress() throws Exception { void testFailure_nonAsciiInIntAddress() throws Exception {
setEppInput("contact_update_hebrew_int.xml"); setEppInput("contact_update_hebrew_int.xml");
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
@ -389,7 +391,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_declineDisclosure() throws Exception { void testFailure_declineDisclosure() throws Exception {
setEppInput("contact_update_decline_disclosure.xml"); setEppInput("contact_update_decline_disclosure.xml");
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
@ -398,7 +400,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_addRemoveSameValue() throws Exception { void testFailure_addRemoveSameValue() throws Exception {
setEppInput("contact_update_add_remove_same.xml"); setEppInput("contact_update_add_remove_same.xml");
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
@ -406,7 +408,7 @@ class ContactUpdateFlowTest extends ResourceFlowTestCase<ContactUpdateFlow, Cont
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testIcannActivityReportField_getsLogged() throws Exception { void testIcannActivityReportField_getsLogged() throws Exception {
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
clock.advanceOneMilli(); clock.advanceOneMilli();

View file

@ -14,12 +14,17 @@
package google.registry.model.contact; package google.registry.model.contact;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.eppcommon.EppXmlTransformer.marshalInput; import static google.registry.model.eppcommon.EppXmlTransformer.marshalInput;
import static google.registry.model.eppcommon.EppXmlTransformer.validateInput; import static google.registry.model.eppcommon.EppXmlTransformer.validateInput;
import static google.registry.xml.ValidationMode.LENIENT; import static google.registry.xml.ValidationMode.LENIENT;
import static google.registry.xml.XmlTestUtils.assertXmlEquals; import static google.registry.xml.XmlTestUtils.assertXmlEquals;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.collect.ImmutableList;
import google.registry.model.contact.ContactCommand.Update;
import google.registry.model.contact.ContactCommand.Update.Change;
import google.registry.model.eppinput.EppInput.ResourceCommandWrapper;
import google.registry.testing.AppEngineExtension; import google.registry.testing.AppEngineExtension;
import google.registry.testing.EppLoader; import google.registry.testing.EppLoader;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -61,6 +66,28 @@ public class ContactCommandTest {
doXmlRoundtripTest("contact_update.xml"); doXmlRoundtripTest("contact_update.xml");
} }
@Test
void testUpdate_individualStreetFieldsGetPopulatedCorrectly() throws Exception {
EppLoader eppLoader = new EppLoader(this, "contact_update.xml");
Update command =
(Update)
(((ResourceCommandWrapper) (eppLoader.getEpp().getCommandWrapper().getCommand()))
.getResourceCommand());
Change change = command.getInnerChange();
assertThat(change.getInternationalizedPostalInfo().getAddress())
.isEqualTo(
new ContactAddress.Builder()
.setCity("Dulles")
.setCountryCode("US")
.setState("VA")
.setZip("20166-6503")
.setStreet(
ImmutableList.of(
"124 Example Dr.",
"Suite 200")) // streetLine1 and streetLine2 get set inside the builder
.build());
}
@Test @Test
void testInfo() throws Exception { void testInfo() throws Exception {
doXmlRoundtripTest("contact_info.xml"); doXmlRoundtripTest("contact_info.xml");