diff --git a/core/src/main/java/google/registry/model/domain/DomainContent.java b/core/src/main/java/google/registry/model/domain/DomainContent.java index a038d433f..e40d54046 100644 --- a/core/src/main/java/google/registry/model/domain/DomainContent.java +++ b/core/src/main/java/google/registry/model/domain/DomainContent.java @@ -779,6 +779,10 @@ public class DomainContent extends EppResource */ void setContactFields(Set contacts, boolean includeRegistrant) { // Set the individual contact fields. + billingContact = techContact = adminContact = null; + if (includeRegistrant) { + registrantContact = null; + } for (DesignatedContact contact : contacts) { switch (contact.getType()) { case BILLING: diff --git a/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java index 50059b270..57cab7067 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java @@ -109,7 +109,6 @@ import google.registry.persistence.VKey; import google.registry.testing.DatabaseHelper; import google.registry.testing.DualDatabaseTest; import google.registry.testing.ReplayExtension; -import google.registry.testing.ReplayExtension.NoDatabaseCompare; import google.registry.testing.TestOfyAndSql; import google.registry.testing.TestOfyOnly; import java.util.Optional; @@ -955,7 +954,6 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase oneTimeBillKey; private VKey recurringBillKey; private Key historyEntryKey; + private VKey contact1Key, contact2Key; @BeforeEach void setUp() { @@ -88,14 +89,14 @@ public class DomainBaseTest extends EntityTestCase { .setRepoId("1-COM") .build()) .createVKey(); - VKey contact1Key = + contact1Key = persistResource( new ContactResource.Builder() .setContactId("contact_id1") .setRepoId("2-COM") .build()) .createVKey(); - VKey contact2Key = + contact2Key = persistResource( new ContactResource.Builder() .setContactId("contact_id2") @@ -947,4 +948,61 @@ public class DomainBaseTest extends EntityTestCase { this.billingEventOneTime = billingEventOneTime; } } + + @Test + void testContactFields() { + VKey contact3Key = + persistResource( + new ContactResource.Builder() + .setContactId("contact_id3") + .setRepoId("4-COM") + .build()) + .createVKey(); + VKey contact4Key = + persistResource( + new ContactResource.Builder() + .setContactId("contact_id4") + .setRepoId("5-COM") + .build()) + .createVKey(); + + // Set all of the contacts. + domain.setContactFields( + ImmutableSet.of( + DesignatedContact.create(Type.REGISTRANT, contact1Key), + DesignatedContact.create(Type.ADMIN, contact2Key), + DesignatedContact.create(Type.BILLING, contact3Key), + DesignatedContact.create(Type.TECH, contact4Key)), + true); + assertThat(domain.getRegistrant()).isEqualTo(contact1Key); + assertThat(domain.getAdminContact()).isEqualTo(contact2Key); + assertThat(domain.getBillingContact()).isEqualTo(contact3Key); + assertThat(domain.getTechContact()).isEqualTo(contact4Key); + + // Make sure everything gets nulled out. + domain.setContactFields(ImmutableSet.of(), true); + assertThat(domain.getRegistrant()).isNull(); + assertThat(domain.getAdminContact()).isNull(); + assertThat(domain.getBillingContact()).isNull(); + assertThat(domain.getTechContact()).isNull(); + + // Make sure that changes don't affect the registrant unless requested. + domain.setContactFields( + ImmutableSet.of( + DesignatedContact.create(Type.REGISTRANT, contact1Key), + DesignatedContact.create(Type.ADMIN, contact2Key), + DesignatedContact.create(Type.BILLING, contact3Key), + DesignatedContact.create(Type.TECH, contact4Key)), + false); + assertThat(domain.getRegistrant()).isNull(); + assertThat(domain.getAdminContact()).isEqualTo(contact2Key); + assertThat(domain.getBillingContact()).isEqualTo(contact3Key); + assertThat(domain.getTechContact()).isEqualTo(contact4Key); + domain = domain.asBuilder().setRegistrant(contact1Key).build(); + domain.setContactFields(ImmutableSet.of(), false); + assertThat(domain.getRegistrant()).isEqualTo(contact1Key); + assertThat(domain.getAdminContact()).isNull(); + assertThat(domain.getBillingContact()).isNull(); + assertThat(domain.getTechContact()).isNull(); + } }