mirror of
https://github.com/google/nomulus.git
synced 2025-07-08 20:23:24 +02:00
Fix vkey reconstruction for PollMessage (#823)
* Fix vkey reconstruction for PollMessage * Add foreign key * Rebase on HEAD
This commit is contained in:
parent
77fabe4dc4
commit
95f6ccc657
8 changed files with 141 additions and 59 deletions
|
@ -59,7 +59,6 @@ public class DomainHistoryTest extends EntityTestCase {
|
|||
void testPersistence() {
|
||||
DomainBase domain = createDomainWithContactsAndHosts();
|
||||
DomainHistory domainHistory = createDomainHistory(domain);
|
||||
domainHistory.id = null;
|
||||
jpaTm().transact(() -> jpaTm().insert(domainHistory));
|
||||
|
||||
jpaTm()
|
||||
|
@ -77,7 +76,6 @@ public class DomainHistoryTest extends EntityTestCase {
|
|||
DomainBase domain = createDomainWithContactsAndHosts();
|
||||
DomainHistory domainHistory =
|
||||
createDomainHistory(domain).asBuilder().setDomainContent(null).build();
|
||||
domainHistory.id = null;
|
||||
jpaTm().transact(() -> jpaTm().insert(domainHistory));
|
||||
|
||||
jpaTm()
|
||||
|
|
|
@ -18,12 +18,15 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
|
||||
import static google.registry.testing.DatastoreHelper.newDomainBase;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveContact;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.SqlHelper.saveRegistrar;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import google.registry.model.EntityTestCase;
|
||||
import google.registry.model.contact.ContactResource;
|
||||
import google.registry.model.domain.DomainBase;
|
||||
import google.registry.model.domain.Period;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
|
@ -34,6 +37,7 @@ import org.junit.jupiter.api.Test;
|
|||
/** Unit tests for {@link PollMessage}. */
|
||||
public class PollMessageTest extends EntityTestCase {
|
||||
|
||||
private DomainBase domain;
|
||||
private HistoryEntry historyEntry;
|
||||
private PollMessage.OneTime oneTime;
|
||||
private PollMessage.Autorenew autoRenew;
|
||||
|
@ -45,15 +49,17 @@ public class PollMessageTest extends EntityTestCase {
|
|||
@BeforeEach
|
||||
void setUp() {
|
||||
createTld("foobar");
|
||||
ContactResource contact = persistActiveContact("contact1234");
|
||||
domain = persistResource(newDomainBase("foo.foobar", contact));
|
||||
historyEntry =
|
||||
persistResource(
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(persistActiveDomain("foo.foobar"))
|
||||
.setParent(domain)
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setPeriod(Period.create(1, Period.Unit.YEARS))
|
||||
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
|
||||
.setModificationTime(fakeClock.nowUtc())
|
||||
.setClientId("foo")
|
||||
.setClientId("TheRegistrar")
|
||||
.setTrid(Trid.create("ABC-123", "server-trid"))
|
||||
.setBySuperuser(false)
|
||||
.setReason("reason")
|
||||
|
@ -75,50 +81,46 @@ public class PollMessageTest extends EntityTestCase {
|
|||
.setAutorenewEndTime(fakeClock.nowUtc().plusDays(365))
|
||||
.setTargetId("foobar.foo")
|
||||
.build();
|
||||
// TODO(shicong): Remove these two lines after we use symmetric vkey and change the cloud sql
|
||||
// schema
|
||||
oneTime.id = null;
|
||||
autoRenew.id = null;
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
saveRegistrar("TheRegistrar");
|
||||
jpaTm().insert(contact);
|
||||
jpaTm().insert(domain);
|
||||
jpaTm().insert(historyEntry.toChildHistoryEntity());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCloudSqlPersistenceOneTime() {
|
||||
saveRegistrar("TheRegistrar");
|
||||
jpaTm().transact(() -> jpaTm().insert(oneTime));
|
||||
PollMessage.OneTime persisted =
|
||||
jpaTm().transact(() -> jpaTm().load(VKey.createSql(PollMessage.OneTime.class, oneTime.id)));
|
||||
persisted.parent = oneTime.parent;
|
||||
assertThat(persisted).isEqualTo(oneTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCloudSqlPersistenceAutorenew() {
|
||||
saveRegistrar("TheRegistrar");
|
||||
jpaTm().transact(() -> jpaTm().insert(autoRenew));
|
||||
PollMessage.Autorenew persisted =
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> jpaTm().load(VKey.createSql(PollMessage.Autorenew.class, autoRenew.id)));
|
||||
persisted.parent = autoRenew.parent;
|
||||
assertThat(persisted).isEqualTo(autoRenew);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCloudSqlSupportForPolymorphicVKey() {
|
||||
saveRegistrar("TheRegistrar");
|
||||
|
||||
jpaTm().transact(() -> jpaTm().insert(oneTime));
|
||||
PollMessage persistedOneTime =
|
||||
jpaTm().transact(() -> jpaTm().load(VKey.createSql(PollMessage.class, oneTime.getId())));
|
||||
assertThat(persistedOneTime).isInstanceOf(PollMessage.OneTime.class);
|
||||
persistedOneTime.parent = oneTime.parent;
|
||||
assertThat(persistedOneTime).isEqualTo(oneTime);
|
||||
|
||||
jpaTm().transact(() -> jpaTm().insert(autoRenew));
|
||||
PollMessage persistedAutoRenew =
|
||||
jpaTm().transact(() -> jpaTm().load(VKey.createSql(PollMessage.class, autoRenew.getId())));
|
||||
assertThat(persistedAutoRenew).isInstanceOf(PollMessage.Autorenew.class);
|
||||
persistedAutoRenew.parent = oneTime.parent;
|
||||
assertThat(persistedAutoRenew).isEqualTo(autoRenew);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue