From 19d696798c822de2f9537aae2c49f23725de86ee Mon Sep 17 00:00:00 2001 From: Michael Muller Date: Fri, 21 Aug 2020 11:11:01 -0400 Subject: [PATCH] Fix empty Domain nameserver loads (#769) * Fix empty Domain nameserver loads Domains with no nameservers were being loaded from SQL as an empty set instead of null as they should be. Discovered this will trying to test updates, so added a test for updates in the course of it. --- .../registry/model/domain/DomainContent.java | 2 +- .../model/domain/DomainBaseSqlTest.java | 35 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) 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)