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.
This commit is contained in:
Michael Muller 2020-08-21 11:11:01 -04:00 committed by GitHub
parent 876d65e232
commit 19d696798c
2 changed files with 34 additions and 3 deletions

View file

@ -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<VKey<HostResource>> nsHosts) {
this.nsHosts = nsHosts;
this.nsHosts = forceEmptyToNull(nsHosts);
}
// Hibernate needs this in order to populate gracePeriods but no one else should ever use it

View file

@ -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)