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 e48ebf459..3c8143d22 100644 --- a/core/src/main/java/google/registry/model/domain/DomainContent.java +++ b/core/src/main/java/google/registry/model/domain/DomainContent.java @@ -380,7 +380,7 @@ public class DomainContent extends EppResource // Hibernate needs this in order to populate nsHosts but no one else should ever use it @SuppressWarnings("UnusedMethod") private void setNsHosts(Set> nsHosts) { - this.nsHosts = nsHosts; + this.nsHosts = forceEmptyToNull(nsHosts); } // Hibernate needs this in order to populate gracePeriods but no one else should ever use it diff --git a/core/src/test/java/google/registry/model/domain/DomainBaseSqlTest.java b/core/src/test/java/google/registry/model/domain/DomainBaseSqlTest.java index 809a90273..a6ecd6fab 100644 --- a/core/src/test/java/google/registry/model/domain/DomainBaseSqlTest.java +++ b/core/src/test/java/google/registry/model/domain/DomainBaseSqlTest.java @@ -144,11 +144,10 @@ public class DomainBaseSqlTest { EntityManager em = jpaTm().getEntityManager(); DomainBase result = em.find(DomainBase.class, "4-COM"); - // Fix grace period and DS data, since we can't persist them yet. + // Fix DS data, since we can't persist it yet. result = result .asBuilder() - .setRegistrant(contactKey) .setDsData( ImmutableSet.of( DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2}))) @@ -193,6 +192,38 @@ public class DomainBaseSqlTest { }); } + @Test + void testUpdates() { + jpaTm() + .transact( + () -> { + jpaTm().saveNew(contact); + jpaTm().saveNew(contact2); + jpaTm().saveNew(domain); + jpaTm().saveNew(host); + }); + domain = domain.asBuilder().setNameservers(ImmutableSet.of()).build(); + jpaTm().transact(() -> jpaTm().saveNewOrUpdate(domain)); + jpaTm() + .transact( + () -> { + DomainBase result = jpaTm().load(domain.createVKey()); + + // Fix DS data, since we can't persist that yet. + result = + result + .asBuilder() + .setDsData( + ImmutableSet.of( + DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2}))) + .build(); + + assertAboutImmutableObjects() + .that(result) + .isEqualExceptFields(domain, "updateTimestamp", "creationTime"); + }); + } + static ContactResource makeContact(String repoId) { return new ContactResource.Builder() .setRepoId(repoId)