mirror of
https://github.com/google/nomulus
synced 2026-09-16 13:04:19 +00:00
Add CurrentPackageToken to Domain table (#1720)
* Add allocation token to Domain table * Add tests * Change column name * change test names
This commit is contained in:
@@ -17,11 +17,14 @@ package google.registry.model.domain;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.flows.domain.DomainTransferUtils.createPendingTransferData;
|
||||
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
||||
import static google.registry.model.domain.token.AllocationToken.TokenStatus.NOT_STARTED;
|
||||
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.insertInDb;
|
||||
import static google.registry.testing.DatabaseHelper.loadByEntity;
|
||||
import static google.registry.testing.DatabaseHelper.loadByKey;
|
||||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static google.registry.testing.DatabaseHelper.updateInDb;
|
||||
import static google.registry.testing.SqlHelper.assertThrowForeignKeyViolation;
|
||||
import static google.registry.testing.SqlHelper.saveRegistrar;
|
||||
@@ -31,6 +34,7 @@ import static org.joda.money.CurrencyUnit.USD;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
@@ -44,6 +48,8 @@ import google.registry.model.domain.Period.Unit;
|
||||
import google.registry.model.domain.launch.LaunchNotice;
|
||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||
import google.registry.model.domain.secdns.DelegationSignerData;
|
||||
import google.registry.model.domain.token.AllocationToken;
|
||||
import google.registry.model.domain.token.AllocationToken.TokenStatus;
|
||||
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
|
||||
import google.registry.model.eppcommon.StatusValue;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
@@ -86,6 +92,7 @@ public class DomainSqlTest {
|
||||
private ContactResource contact;
|
||||
private ContactResource contact2;
|
||||
private ImmutableSet<GracePeriod> gracePeriods;
|
||||
private AllocationToken allocationToken;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@@ -138,6 +145,24 @@ public class DomainSqlTest {
|
||||
.build();
|
||||
contact = makeContact("contact_id1");
|
||||
contact2 = makeContact("contact_id2");
|
||||
|
||||
allocationToken =
|
||||
new AllocationToken.Builder()
|
||||
.setToken("abc123Unlimited")
|
||||
.setTokenType(UNLIMITED_USE)
|
||||
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
|
||||
.setAllowedTlds(ImmutableSet.of("dev", "app"))
|
||||
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar, NewRegistrar"))
|
||||
.setDiscountFraction(0.5)
|
||||
.setDiscountPremiums(true)
|
||||
.setDiscountYears(3)
|
||||
.setTokenStatusTransitions(
|
||||
ImmutableSortedMap.<DateTime, TokenStatus>naturalOrder()
|
||||
.put(START_OF_TIME, NOT_STARTED)
|
||||
.put(DateTime.now(UTC), TokenStatus.VALID)
|
||||
.put(DateTime.now(UTC).plusWeeks(8), TokenStatus.ENDED)
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -146,12 +171,27 @@ public class DomainSqlTest {
|
||||
assertEqualDomainExcept(loadByKey(domain.createVKey()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDomainBasePersistenceWithCurrentPackageToken() {
|
||||
domain = domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build();
|
||||
persistResource(allocationToken);
|
||||
persistDomain();
|
||||
assertEqualDomainExcept(loadByKey(domain.createVKey()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHostForeignKeyConstraints() {
|
||||
// Persist the domain without the associated host object.
|
||||
assertThrowForeignKeyViolation(() -> insertInDb(contact, contact2, domain));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCurrentPackageTokenForeignKeyConstraints() {
|
||||
// Persist the domain without the associated allocation token object.
|
||||
domain = domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build();
|
||||
assertThrowForeignKeyViolation(() -> persistDomain());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testContactForeignKeyConstraints() {
|
||||
// Persist the domain without the associated contact objects.
|
||||
|
||||
@@ -106,6 +106,7 @@ class google.registry.model.domain.Domain {
|
||||
google.registry.persistence.VKey<google.registry.model.contact.ContactResource> billingContact;
|
||||
google.registry.persistence.VKey<google.registry.model.contact.ContactResource> registrantContact;
|
||||
google.registry.persistence.VKey<google.registry.model.contact.ContactResource> techContact;
|
||||
google.registry.persistence.VKey<google.registry.model.domain.token.AllocationToken> currentPackageToken;
|
||||
google.registry.persistence.VKey<google.registry.model.poll.PollMessage$Autorenew> autorenewPollMessage;
|
||||
google.registry.persistence.VKey<google.registry.model.poll.PollMessage$OneTime> deletePollMessage;
|
||||
java.lang.String creationClientId;
|
||||
@@ -138,6 +139,7 @@ class google.registry.model.domain.DomainBase {
|
||||
google.registry.persistence.VKey<google.registry.model.contact.ContactResource> billingContact;
|
||||
google.registry.persistence.VKey<google.registry.model.contact.ContactResource> registrantContact;
|
||||
google.registry.persistence.VKey<google.registry.model.contact.ContactResource> techContact;
|
||||
google.registry.persistence.VKey<google.registry.model.domain.token.AllocationToken> currentPackageToken;
|
||||
google.registry.persistence.VKey<google.registry.model.poll.PollMessage$Autorenew> autorenewPollMessage;
|
||||
google.registry.persistence.VKey<google.registry.model.poll.PollMessage$OneTime> deletePollMessage;
|
||||
java.lang.String creationClientId;
|
||||
|
||||
Reference in New Issue
Block a user