From 64cbaf17ff172c7467d6d7798c6f71a70b54b565 Mon Sep 17 00:00:00 2001 From: Lai Jiang Date: Tue, 25 May 2021 18:48:47 -0400 Subject: [PATCH] Change BillingEvent parent to Key (#1178) --- .gitignore | 1 + .../flows/domain/DomainUpdateFlow.java | 5 +- .../registry/model/billing/BillingEvent.java | 13 ++-- .../ofy/DatastoreTransactionManager.java | 11 ++- .../JpaTransactionManagerImpl.java | 13 ++-- .../batch/DeleteExpiredDomainsActionTest.java | 4 +- .../batch/DeleteProberDataActionTest.java | 2 +- ...xpandRecurringBillingEventsActionTest.java | 65 ++++++++++------- .../beam/initsql/InitSqlPipelineTest.java | 4 +- .../flows/EppLifecycleDomainTest.java | 3 +- .../google/registry/flows/EppTestCase.java | 25 ++++--- .../flows/domain/DomainCreateFlowTest.java | 3 +- .../flows/domain/DomainDeleteFlowTest.java | 12 ++-- .../flows/domain/DomainInfoFlowTest.java | 2 +- .../flows/domain/DomainRenewFlowTest.java | 8 ++- .../domain/DomainRestoreRequestFlowTest.java | 8 +-- .../domain/DomainTransferApproveFlowTest.java | 8 +-- .../domain/DomainTransferFlowTestCase.java | 20 +++--- .../domain/DomainTransferRequestFlowTest.java | 5 +- .../flows/domain/DomainUpdateFlowTest.java | 4 +- .../registry/model/domain/DomainBaseTest.java | 2 +- .../model/domain/GracePeriodTest.java | 2 +- .../java/google/registry/rde/RdeFixtures.java | 2 +- .../registry/testing/DatabaseHelper.java | 2 +- ...dupeOneTimeBillingEventIdsCommandTest.java | 11 +-- .../registry/tools/DomainLockUtilsTest.java | 12 ++-- .../registry/tools/EppLifecycleToolsTest.java | 9 +-- .../tools/UnrenewDomainCommandTest.java | 4 +- .../tools/UpdateDomainCommandTest.java | 3 +- .../server/KillAllEppResourcesActionTest.java | 71 ++++++++++--------- .../RegistryLockVerifyActionTest.java | 9 ++- .../google/registry/model/schema.txt | 8 +-- 32 files changed, 202 insertions(+), 149 deletions(-) diff --git a/.gitignore b/.gitignore index db2ef22c7..e96f748ef 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ ###################################################################### # Java Ignores +gjf.out *.class # Mobile Tools for Java (J2ME) diff --git a/core/src/main/java/google/registry/flows/domain/DomainUpdateFlow.java b/core/src/main/java/google/registry/flows/domain/DomainUpdateFlow.java index abf97d7ca..311577ece 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainUpdateFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainUpdateFlow.java @@ -290,10 +290,7 @@ public final class DomainUpdateFlow implements TransactionalFlow { /** Some status updates cost money. Bill only once no matter how many of them are changed. */ private Optional createBillingEventForStatusUpdates( - DomainBase existingDomain, - DomainBase newDomain, - HistoryEntry historyEntry, - DateTime now) { + DomainBase existingDomain, DomainBase newDomain, DomainHistory historyEntry, DateTime now) { Optional metadataExtension = eppInput.getSingleExtension(MetadataExtension.class); if (metadataExtension.isPresent() && metadataExtension.get().getRequestedByRegistrar()) { diff --git a/core/src/main/java/google/registry/model/billing/BillingEvent.java b/core/src/main/java/google/registry/model/billing/BillingEvent.java index fcf3ed42a..d8f209112 100644 --- a/core/src/main/java/google/registry/model/billing/BillingEvent.java +++ b/core/src/main/java/google/registry/model/billing/BillingEvent.java @@ -46,7 +46,6 @@ import google.registry.model.domain.DomainHistory; import google.registry.model.domain.GracePeriod; import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.token.AllocationToken; -import google.registry.model.reporting.HistoryEntry; import google.registry.model.transfer.TransferData.TransferServerApproveEntity; import google.registry.persistence.BillingVKey.BillingEventVKey; import google.registry.persistence.BillingVKey.BillingRecurrenceVKey; @@ -115,7 +114,7 @@ public abstract class BillingEvent extends ImmutableObject /** Entity id. */ @Id @javax.persistence.Id Long id; - @Parent @DoNotHydrate @Transient Key parent; + @Parent @DoNotHydrate @Transient Key parent; /** The registrar to bill. */ @Index @@ -154,7 +153,7 @@ public abstract class BillingEvent extends ImmutableObject parent = Key.create( Key.create(DomainBase.class, domainRepoId), - HistoryEntry.class, + DomainHistory.class, domainHistoryRevisionId); } @@ -192,7 +191,7 @@ public abstract class BillingEvent extends ImmutableObject return targetId; } - public Key getParentKey() { + public Key getParentKey() { return parent; } @@ -254,12 +253,12 @@ public abstract class BillingEvent extends ImmutableObject return thisCastToDerived(); } - public B setParent(HistoryEntry parent) { + public B setParent(DomainHistory parent) { getInstance().parent = Key.create(parent); return thisCastToDerived(); } - public B setParent(Key parentKey) { + public B setParent(Key parentKey) { getInstance().parent = parentKey; return thisCastToDerived(); } @@ -735,7 +734,7 @@ public abstract class BillingEvent extends ImmutableObject * because it is needed by one-off scrap tools that need to make billing adjustments. */ public static Modification createRefundFor( - OneTime billingEvent, HistoryEntry historyEntry, String description) { + OneTime billingEvent, DomainHistory historyEntry, String description) { return new Builder() .setClientId(billingEvent.getClientId()) .setFlags(billingEvent.getFlags()) diff --git a/core/src/main/java/google/registry/model/ofy/DatastoreTransactionManager.java b/core/src/main/java/google/registry/model/ofy/DatastoreTransactionManager.java index 74bd821be..d91911f68 100644 --- a/core/src/main/java/google/registry/model/ofy/DatastoreTransactionManager.java +++ b/core/src/main/java/google/registry/model/ofy/DatastoreTransactionManager.java @@ -222,9 +222,17 @@ public class DatastoreTransactionManager implements TransactionManager { entry -> keyMap.get(entry.getKey()), entry -> toSqlEntity(entry.getValue()))); } + @SuppressWarnings("unchecked") @Override public ImmutableList loadByEntitiesIfPresent(Iterable entities) { - return ImmutableList.copyOf(getOfy().load().entities(entities).values()); + return getOfy() + .load() + .entities(toDatastoreEntities(ImmutableList.copyOf(entities))) + .values() + .stream() + .map(DatastoreTransactionManager::toSqlEntity) + .map(entity -> (T) entity) + .collect(toImmutableList()); } @Override @@ -250,6 +258,7 @@ public class DatastoreTransactionManager implements TransactionManager { return result; } + @SuppressWarnings("unchecked") @Override public T loadByEntity(T entity) { return (T) toSqlEntity(auditedOfy().load().entity(toDatastoreEntity(entity)).now()); diff --git a/core/src/main/java/google/registry/persistence/transaction/JpaTransactionManagerImpl.java b/core/src/main/java/google/registry/persistence/transaction/JpaTransactionManagerImpl.java index f5efbfd23..573805fbe 100644 --- a/core/src/main/java/google/registry/persistence/transaction/JpaTransactionManagerImpl.java +++ b/core/src/main/java/google/registry/persistence/transaction/JpaTransactionManagerImpl.java @@ -458,11 +458,14 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager { assertInTransaction(); // If the caller requested a HistoryEntry, load the corresponding *History class T possibleChild = toSqlEntity(entity); - return (T) - loadByKey( - VKey.createSql( - possibleChild.getClass(), - emf.getPersistenceUnitUtil().getIdentifier(possibleChild))); + @SuppressWarnings("unchecked") + T returnValue = + (T) + loadByKey( + VKey.createSql( + possibleChild.getClass(), + emf.getPersistenceUnitUtil().getIdentifier(possibleChild))); + return returnValue; } @Override diff --git a/core/src/test/java/google/registry/batch/DeleteExpiredDomainsActionTest.java b/core/src/test/java/google/registry/batch/DeleteExpiredDomainsActionTest.java index 8fdf6fcb3..f3906faf6 100644 --- a/core/src/test/java/google/registry/batch/DeleteExpiredDomainsActionTest.java +++ b/core/src/test/java/google/registry/batch/DeleteExpiredDomainsActionTest.java @@ -165,7 +165,7 @@ class DeleteExpiredDomainsActionTest { private DomainBase persistNonAutorenewingDomain(String domainName) { DomainBase pendingExpirationDomain = persistActiveDomain(domainName); - HistoryEntry createHistoryEntry = + DomainHistory createHistoryEntry = persistResource( new DomainHistory.Builder() .setType(DOMAIN_CREATE) @@ -190,7 +190,7 @@ class DeleteExpiredDomainsActionTest { } private BillingEvent.Recurring.Builder createAutorenewBillingEvent( - HistoryEntry createHistoryEntry) { + DomainHistory createHistoryEntry) { return new BillingEvent.Recurring.Builder() .setReason(Reason.RENEW) .setFlags(ImmutableSet.of(Flag.AUTO_RENEW)) diff --git a/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java b/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java index 0656f8116..be6bb6a12 100644 --- a/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java +++ b/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java @@ -280,7 +280,7 @@ class DeleteProberDataActionTest extends MapreduceTestCase persistDomainAndDescendants(String fqdn) { DomainBase domain = persistDeletedDomain(fqdn, DELETION_TIME); - HistoryEntry historyEntry = + DomainHistory historyEntry = persistSimpleResource( new DomainHistory.Builder() .setDomain(domain) diff --git a/core/src/test/java/google/registry/batch/ExpandRecurringBillingEventsActionTest.java b/core/src/test/java/google/registry/batch/ExpandRecurringBillingEventsActionTest.java index 5739dccf6..4c5389dd3 100644 --- a/core/src/test/java/google/registry/batch/ExpandRecurringBillingEventsActionTest.java +++ b/core/src/test/java/google/registry/batch/ExpandRecurringBillingEventsActionTest.java @@ -75,7 +75,7 @@ public class ExpandRecurringBillingEventsActionTest private final FakeClock clock = new FakeClock(beginningOfTest); private DomainBase domain; - private HistoryEntry historyEntry; + private DomainHistory historyEntry; private BillingEvent.Recurring recurring; @BeforeEach @@ -173,7 +173,8 @@ public class ExpandRecurringBillingEventsActionTest persistResource(recurring); action.cursorTimeParam = Optional.of(START_OF_TIME); runMapreduce(); - HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); + DomainHistory persistedEntry = + getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertHistoryEntryMatches( domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); BillingEvent.OneTime expected = defaultOneTimeBuilder() @@ -209,9 +210,13 @@ public class ExpandRecurringBillingEventsActionTest .build()); action.cursorTimeParam = Optional.of(START_OF_TIME); runMapreduce(); - HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(deletedDomain, DOMAIN_AUTORENEW); + DomainHistory persistedEntry = + getOnlyHistoryEntryOfType(deletedDomain, DOMAIN_AUTORENEW, DomainHistory.class); assertHistoryEntryMatches( - deletedDomain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), + deletedDomain, + persistedEntry, + "TheRegistrar", + DateTime.parse("2000-02-19T00:00:00Z"), true); BillingEvent.OneTime expected = defaultOneTimeBuilder() @@ -227,7 +232,8 @@ public class ExpandRecurringBillingEventsActionTest persistResource(recurring); action.cursorTimeParam = Optional.of(START_OF_TIME); runMapreduce(); - HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); + DomainHistory persistedEntry = + getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertHistoryEntryMatches( domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build(); @@ -259,7 +265,8 @@ public class ExpandRecurringBillingEventsActionTest persistResource(recurring); action.cursorTimeParam = Optional.of(START_OF_TIME); runMapreduce(); - HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); + DomainHistory persistedEntry = + getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertHistoryEntryMatches( domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build(); @@ -280,8 +287,8 @@ public class ExpandRecurringBillingEventsActionTest .build()); action.cursorTimeParam = Optional.of(START_OF_TIME); runMapreduce(); - List persistedEntries = - getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW); + List persistedEntries = + getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); for (HistoryEntry persistedEntry : persistedEntries) { assertHistoryEntryMatches( domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); @@ -332,7 +339,8 @@ public class ExpandRecurringBillingEventsActionTest persistResource(recurring); action.cursorTimeParam = Optional.of(DateTime.parse("2000-02-19T00:00:00Z")); runMapreduce(); - HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); + DomainHistory persistedEntry = + getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertHistoryEntryMatches( domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build(); @@ -345,7 +353,8 @@ public class ExpandRecurringBillingEventsActionTest persistResource(recurring); action.cursorTimeParam = Optional.of(DateTime.parse("2000-01-12T00:00:00Z")); runMapreduce(); - HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); + DomainHistory persistedEntry = + getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertHistoryEntryMatches( domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build(); @@ -379,7 +388,8 @@ public class ExpandRecurringBillingEventsActionTest recurring.asBuilder().setEventTime(recurring.getEventTime().plusYears(2)).build()); clock.setTo(testTime); runMapreduce(); - HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); + DomainHistory persistedEntry = + getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertHistoryEntryMatches( domain, persistedEntry, "TheRegistrar", DateTime.parse("2002-02-19T00:00:00Z"), true); BillingEvent.OneTime expected = defaultOneTimeBuilder() @@ -397,7 +407,8 @@ public class ExpandRecurringBillingEventsActionTest persistResource(recurring); saveCursor(START_OF_TIME); runMapreduce(); - HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); + DomainHistory persistedEntry = + getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertHistoryEntryMatches( domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build(); @@ -451,8 +462,8 @@ public class ExpandRecurringBillingEventsActionTest expectedEvents.add(persistResource(recurring)); action.cursorTimeParam = Optional.of(START_OF_TIME); runMapreduce(); - List persistedEntries = - getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW); + List persistedEntries = + getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertThat(persistedEntries).hasSize(6); DateTime eventDate = DateTime.parse("2000-01-05T00:00:00Z"); DateTime billingDate = DateTime.parse("2000-02-19T00:00:00Z"); @@ -482,8 +493,8 @@ public class ExpandRecurringBillingEventsActionTest expectedEvents.add(persistResource(recurring)); saveCursor(DateTime.parse("2003-10-02T00:00:00Z")); runMapreduce(); - List persistedEntries = - getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW); + List persistedEntries = + getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertThat(persistedEntries).hasSize(2); DateTime eventDate = DateTime.parse("2004-01-05T00:00:00Z"); DateTime billingDate = DateTime.parse("2004-02-19T00:00:00Z"); @@ -528,7 +539,8 @@ public class ExpandRecurringBillingEventsActionTest .build()); action.cursorTimeParam = Optional.of(START_OF_TIME); runMapreduce(); - HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); + DomainHistory persistedEntry = + getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertHistoryEntryMatches( domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), false); BillingEvent.OneTime expected = defaultOneTimeBuilder() @@ -553,7 +565,8 @@ public class ExpandRecurringBillingEventsActionTest .build()); action.cursorTimeParam = Optional.of(START_OF_TIME); runMapreduce(); - HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); + DomainHistory persistedEntry = + getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertHistoryEntryMatches( domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); BillingEvent.OneTime expected = defaultOneTimeBuilder() @@ -572,7 +585,8 @@ public class ExpandRecurringBillingEventsActionTest recurring.asBuilder().setEventTime(DateTime.parse("2000-01-15T00:00:00Z")).build()); action.cursorTimeParam = Optional.of(START_OF_TIME); runMapreduce(); - HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); + DomainHistory persistedEntry = + getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertHistoryEntryMatches( domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-29T00:00:00Z"), true); BillingEvent.OneTime expected = defaultOneTimeBuilder() @@ -593,7 +607,8 @@ public class ExpandRecurringBillingEventsActionTest action.cursorTimeParam = Optional.of(START_OF_TIME); clock.setTo(testTime); runMapreduce(); - HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); + DomainHistory persistedEntry = + getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertHistoryEntryMatches( domain, persistedEntry, "TheRegistrar", DateTime.parse("2001-03-01T00:00:00Z"), true); BillingEvent.OneTime expected = defaultOneTimeBuilder() @@ -615,7 +630,8 @@ public class ExpandRecurringBillingEventsActionTest .build()); action.cursorTimeParam = Optional.of(START_OF_TIME); runMapreduce(); - List persistedEntries = getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW); + List persistedEntries = + getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertThat(persistedEntries).hasSize(2); assertHistoryEntryMatches( domain, persistedEntries.get(0), "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), @@ -649,7 +665,8 @@ public class ExpandRecurringBillingEventsActionTest persistResource(recurring); action.cursorTimeParam = Optional.of(START_OF_TIME); runMapreduce(); - HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); + DomainHistory persistedEntry = + getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertHistoryEntryMatches( domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); BillingEvent.OneTime expected = defaultOneTimeBuilder() @@ -675,8 +692,8 @@ public class ExpandRecurringBillingEventsActionTest persistResource(recurring); action.cursorTimeParam = Optional.of(START_OF_TIME); runMapreduce(); - List persistedEntries = - getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW); + List persistedEntries = + getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class); assertThat(persistedEntries).hasSize(2); DateTime eventDate = DateTime.parse("2000-01-05T00:00:00Z"); DateTime billingDate = DateTime.parse("2000-02-19T00:00:00Z"); diff --git a/core/src/test/java/google/registry/beam/initsql/InitSqlPipelineTest.java b/core/src/test/java/google/registry/beam/initsql/InitSqlPipelineTest.java index 7d578376f..6ca9a8694 100644 --- a/core/src/test/java/google/registry/beam/initsql/InitSqlPipelineTest.java +++ b/core/src/test/java/google/registry/beam/initsql/InitSqlPipelineTest.java @@ -129,7 +129,7 @@ class InitSqlPipelineTest { private transient ContactResource contact2; private transient HostResource hostResource; - private transient HistoryEntry historyEntry; + private transient DomainHistory historyEntry; @BeforeEach void beforeEach() throws Exception { @@ -187,7 +187,7 @@ class InitSqlPipelineTest { .build()); persistResource( new AllocationToken.Builder().setToken("abc123").setTokenType(SINGLE_USE).build()); - Key historyEntryKey = Key.create(historyEntry); + Key historyEntryKey = Key.create(historyEntry); BillingEvent.OneTime onetimeBillEvent = new BillingEvent.OneTime.Builder() .setId(1) diff --git a/core/src/test/java/google/registry/flows/EppLifecycleDomainTest.java b/core/src/test/java/google/registry/flows/EppLifecycleDomainTest.java index 7a9f32a55..d0f099dd1 100644 --- a/core/src/test/java/google/registry/flows/EppLifecycleDomainTest.java +++ b/core/src/test/java/google/registry/flows/EppLifecycleDomainTest.java @@ -42,6 +42,7 @@ import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent.OneTime; import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.domain.DomainBase; +import google.registry.model.domain.DomainHistory; import google.registry.model.registry.Registry; import google.registry.model.registry.Registry.TldState; import google.registry.model.reporting.HistoryEntry.Type; @@ -549,7 +550,7 @@ class EppLifecycleDomainTest extends EppTestCase { .setCost(Money.parse("USD 100.00")) .setEventTime(createTime) .setBillingTime(createTime.plus(Registry.get("tld").getRenewGracePeriodLength())) - .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE)) + .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE, DomainHistory.class)) .build(); // The expected one-time billing event, that should have an associated Cancellation. diff --git a/core/src/test/java/google/registry/flows/EppTestCase.java b/core/src/test/java/google/registry/flows/EppTestCase.java index bacb6d95b..50e37623e 100644 --- a/core/src/test/java/google/registry/flows/EppTestCase.java +++ b/core/src/test/java/google/registry/flows/EppTestCase.java @@ -35,10 +35,10 @@ import google.registry.model.billing.BillingEvent.Flag; import google.registry.model.billing.BillingEvent.OneTime; import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.domain.DomainBase; +import google.registry.model.domain.DomainHistory; import google.registry.model.eppcommon.EppXmlTransformer; import google.registry.model.ofy.Ofy; import google.registry.model.registry.Registry; -import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.HistoryEntry.Type; import google.registry.monitoring.whitebox.EppMetric; import google.registry.persistence.VKey; @@ -81,8 +81,7 @@ public class EppTestCase { * *

When the credentials are null, the login flow still checks the EPP password from the xml, * which is sufficient for all tests that aren't explicitly testing a form of login credentials - * such as {@link EppLoginUserTest}, {@link EppLoginAdminUserTest} and {@link EppLoginTlsTest}. - * Therefore, only those tests should call this method. + * such as {@link EppLoginTlsTest}. Therefore, only those tests should call this method. */ void setTransportCredentials(TransportCredentials credentials) { this.credentials = credentials; @@ -326,7 +325,7 @@ public class EppTestCase { .setPeriodYears(2) .setEventTime(createTime) .setBillingTime(createTime.plus(Registry.get(domain.getTld()).getAddGracePeriodLength())) - .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE)) + .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE, DomainHistory.class)) .build(); } @@ -340,7 +339,7 @@ public class EppTestCase { .setPeriodYears(3) .setEventTime(renewTime) .setBillingTime(renewTime.plus(Registry.get(domain.getTld()).getRenewGracePeriodLength())) - .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_RENEW)) + .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_RENEW, DomainHistory.class)) .build(); } @@ -348,19 +347,25 @@ public class EppTestCase { static BillingEvent.Recurring makeRecurringCreateBillingEvent( DomainBase domain, DateTime eventTime, DateTime endTime) { return makeRecurringBillingEvent( - domain, getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE), eventTime, endTime); + domain, + getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE, DomainHistory.class), + eventTime, + endTime); } /** Makes a recurring billing event corresponding to the given domain's renewal. */ static BillingEvent.Recurring makeRecurringRenewBillingEvent( DomainBase domain, DateTime eventTime, DateTime endTime) { return makeRecurringBillingEvent( - domain, getOnlyHistoryEntryOfType(domain, Type.DOMAIN_RENEW), eventTime, endTime); + domain, + getOnlyHistoryEntryOfType(domain, Type.DOMAIN_RENEW, DomainHistory.class), + eventTime, + endTime); } /** Makes a recurring billing event corresponding to the given history entry. */ protected static BillingEvent.Recurring makeRecurringBillingEvent( - DomainBase domain, HistoryEntry historyEntry, DateTime eventTime, DateTime endTime) { + DomainBase domain, DomainHistory historyEntry, DateTime eventTime, DateTime endTime) { return new BillingEvent.Recurring.Builder() .setReason(Reason.RENEW) .setFlags(ImmutableSet.of(Flag.AUTO_RENEW)) @@ -382,7 +387,7 @@ public class EppTestCase { .setOneTimeEventKey(VKey.from(findKeyToActualOneTimeBillingEvent(billingEventToCancel))) .setBillingTime(createTime.plus(Registry.get(domain.getTld()).getAddGracePeriodLength())) .setReason(Reason.CREATE) - .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_DELETE)) + .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_DELETE, DomainHistory.class)) .build(); } @@ -396,7 +401,7 @@ public class EppTestCase { .setOneTimeEventKey(VKey.from(findKeyToActualOneTimeBillingEvent(billingEventToCancel))) .setBillingTime(renewTime.plus(Registry.get(domain.getTld()).getRenewGracePeriodLength())) .setReason(Reason.RENEW) - .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_DELETE)) + .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_DELETE, DomainHistory.class)) .build(); } diff --git a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java index 0deb989ea..f64178739 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java @@ -145,6 +145,7 @@ import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent.Flag; import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.domain.DomainBase; +import google.registry.model.domain.DomainHistory; import google.registry.model.domain.GracePeriod; import google.registry.model.domain.launch.LaunchNotice; import google.registry.model.domain.rgp.GracePeriodStatus; @@ -266,7 +267,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase protected ContactResource contact; protected DomainBase domain; HostResource subordinateHost; - private HistoryEntry historyEntryDomainCreate; + private DomainHistory historyEntryDomainCreate; DomainTransferFlowTestCase() { checkState(!Registry.DEFAULT_TRANSFER_GRACE_PERIOD.isShorterThan(TIME_SINCE_REQUEST)); @@ -120,17 +121,16 @@ abstract class DomainTransferFlowTestCase domain = persistResource( domain.asBuilder().addSubordinateHost(subordinateHost.getHostName()).build()); - historyEntryDomainCreate = getOnlyHistoryEntryOfType(domain, DOMAIN_CREATE); + historyEntryDomainCreate = + getOnlyHistoryEntryOfType(domain, DOMAIN_CREATE, DomainHistory.class); } BillingEvent.OneTime getBillingEventForImplicitTransfer() { - HistoryEntry historyEntry = - getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST); + DomainHistory historyEntry = + getOnlyHistoryEntryOfType( + domain, HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST, DomainHistory.class); return createBillingEventForTransfer( - domain, - historyEntry, - TRANSFER_REQUEST_TIME, - TRANSFER_EXPIRATION_TIME); + domain, historyEntry, TRANSFER_REQUEST_TIME, TRANSFER_EXPIRATION_TIME); } /** Get the autorenew event that the losing client will have after a SERVER_APPROVED transfer. */ @@ -155,7 +155,9 @@ abstract class DomainTransferFlowTestCase .setClientId("NewRegistrar") .setEventTime(EXTENDED_REGISTRATION_EXPIRATION_TIME) .setRecurrenceEndTime(END_OF_TIME) - .setParent(getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST)) + .setParent( + getOnlyHistoryEntryOfType( + domain, HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST, DomainHistory.class)) .build(); } diff --git a/core/src/test/java/google/registry/flows/domain/DomainTransferRequestFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainTransferRequestFlowTest.java index fb24be5b5..559194ec8 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainTransferRequestFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainTransferRequestFlowTest.java @@ -86,6 +86,7 @@ import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.contact.ContactAuthInfo; import google.registry.model.domain.DomainAuthInfo; import google.registry.model.domain.DomainBase; +import google.registry.model.domain.DomainHistory; import google.registry.model.domain.GracePeriod; import google.registry.model.domain.Period; import google.registry.model.domain.Period.Unit; @@ -250,8 +251,8 @@ class DomainTransferRequestFlowTest boolean expectTransferBillingEvent, BillingEvent.Cancellation.Builder... extraExpectedBillingEvents) { Registry registry = Registry.get(domain.getTld()); - final HistoryEntry historyEntryTransferRequest = - getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REQUEST); + final DomainHistory historyEntryTransferRequest = + getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REQUEST, DomainHistory.class); // Construct the billing events we expect to exist, starting with the (optional) billing // event for the transfer itself. diff --git a/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java index 5ef5cb2a6..31afb7b23 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java @@ -687,7 +687,9 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase { DomainBase domain; - HistoryEntry historyEntry; + DomainHistory historyEntry; PollMessage.Autorenew autorenewToResave; BillingEvent.OneTime billingEventToResave; @@ -111,7 +111,7 @@ class DedupeOneTimeBillingEventIdsCommandTest .build()); } - private BillingEvent.OneTime persistBillingEvent(HistoryEntry historyEntry) { + private BillingEvent.OneTime persistBillingEvent(DomainHistory historyEntry) { return persistResource( new BillingEvent.OneTime.Builder() .setClientId("a registrar") @@ -126,9 +126,10 @@ class DedupeOneTimeBillingEventIdsCommandTest .build()); } - private HistoryEntry persistHistoryEntry(EppResource parent) { + private DomainHistory persistHistoryEntry(DomainBase parent) { return persistResource( - HistoryEntry.createBuilderForResource(parent) + new DomainHistory.Builder() + .setDomain(parent) .setType(HistoryEntry.Type.DOMAIN_CREATE) .setPeriod(Period.create(1, Period.Unit.YEARS)) .setXmlBytes("".getBytes(UTF_8)) diff --git a/core/src/test/java/google/registry/tools/DomainLockUtilsTest.java b/core/src/test/java/google/registry/tools/DomainLockUtilsTest.java index 4dfa4c2f4..32d28ba10 100644 --- a/core/src/test/java/google/registry/tools/DomainLockUtilsTest.java +++ b/core/src/test/java/google/registry/tools/DomainLockUtilsTest.java @@ -41,6 +41,7 @@ import google.registry.batch.RelockDomainAction; import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.domain.DomainBase; +import google.registry.model.domain.DomainHistory; import google.registry.model.host.HostResource; import google.registry.model.registry.Registry; import google.registry.model.reporting.HistoryEntry; @@ -479,7 +480,8 @@ public final class DomainLockUtilsTest { private void verifyProperlyLockedDomain(boolean isAdmin) { assertThat(loadByEntity(domain).getStatusValues()) .containsAtLeastElementsIn(REGISTRY_LOCK_STATUSES); - HistoryEntry historyEntry = getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_UPDATE); + DomainHistory historyEntry = + getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_UPDATE, DomainHistory.class); assertThat(historyEntry.getRequestedByRegistrar()).isEqualTo(!isAdmin); assertThat(historyEntry.getBySuperuser()).isEqualTo(isAdmin); assertThat(historyEntry.getReason()) @@ -493,8 +495,8 @@ public final class DomainLockUtilsTest { private void verifyProperlyUnlockedDomain(boolean isAdmin) { assertThat(loadByEntity(domain).getStatusValues()).containsNoneIn(REGISTRY_LOCK_STATUSES); - ImmutableList historyEntries = - getHistoryEntriesOfType(domain, HistoryEntry.Type.DOMAIN_UPDATE); + ImmutableList historyEntries = + getHistoryEntriesOfType(domain, HistoryEntry.Type.DOMAIN_UPDATE, DomainHistory.class); assertThat(historyEntries.size()).isEqualTo(2); historyEntries.forEach( entry -> { @@ -514,11 +516,11 @@ public final class DomainLockUtilsTest { assertThat(loadByEntity(domain)).isEqualTo(domain); } - private void assertBillingEvent(HistoryEntry historyEntry) { + private void assertBillingEvent(DomainHistory historyEntry) { assertBillingEvents(ImmutableList.of(historyEntry)); } - private void assertBillingEvents(ImmutableList historyEntries) { + private void assertBillingEvents(ImmutableList historyEntries) { Set expectedEvents = historyEntries.stream() .map( diff --git a/core/src/test/java/google/registry/tools/EppLifecycleToolsTest.java b/core/src/test/java/google/registry/tools/EppLifecycleToolsTest.java index 84343bbf1..3855ea6a2 100644 --- a/core/src/test/java/google/registry/tools/EppLifecycleToolsTest.java +++ b/core/src/test/java/google/registry/tools/EppLifecycleToolsTest.java @@ -26,6 +26,7 @@ import google.registry.flows.EppTestCase; import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.domain.DomainBase; +import google.registry.model.domain.DomainHistory; import google.registry.model.reporting.HistoryEntry.Type; import google.registry.testing.AppEngineExtension; import google.registry.util.Clock; @@ -149,7 +150,7 @@ class EppLifecycleToolsTest extends EppTestCase { .setPeriodYears(4) .setEventTime(DateTime.parse("2000-06-07T00:00:00Z")) .setBillingTime(DateTime.parse("2000-06-12T00:00:00Z")) - .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_RENEW)) + .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_RENEW, DomainHistory.class)) .build(); assertBillingEventsForResource( @@ -159,19 +160,19 @@ class EppLifecycleToolsTest extends EppTestCase { // The initial autorenew billing event, which was closed at the time of the explicit renew. makeRecurringBillingEvent( domain, - getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE), + getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE, DomainHistory.class), createTime.plusYears(2), DateTime.parse("2000-06-07T00:00:00.000Z")), // The renew's autorenew billing event, which was closed at the time of the unrenew. makeRecurringBillingEvent( domain, - getOnlyHistoryEntryOfType(domain, Type.DOMAIN_RENEW), + getOnlyHistoryEntryOfType(domain, Type.DOMAIN_RENEW, DomainHistory.class), DateTime.parse("2006-06-01T00:02:00.000Z"), DateTime.parse("2001-06-07T00:00:00.000Z")), // The remaining active autorenew billing event which was created by the unrenew. makeRecurringBillingEvent( domain, - getOnlyHistoryEntryOfType(domain, Type.SYNTHETIC), + getOnlyHistoryEntryOfType(domain, Type.SYNTHETIC, DomainHistory.class), DateTime.parse("2003-06-01T00:02:00.000Z"), END_OF_TIME)); diff --git a/core/src/test/java/google/registry/tools/UnrenewDomainCommandTest.java b/core/src/test/java/google/registry/tools/UnrenewDomainCommandTest.java index 6d4e29ee2..90ed8dce0 100644 --- a/core/src/test/java/google/registry/tools/UnrenewDomainCommandTest.java +++ b/core/src/test/java/google/registry/tools/UnrenewDomainCommandTest.java @@ -41,10 +41,10 @@ import google.registry.model.billing.BillingEvent.Flag; import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.contact.ContactResource; import google.registry.model.domain.DomainBase; +import google.registry.model.domain.DomainHistory; import google.registry.model.eppcommon.StatusValue; import google.registry.model.ofy.Ofy; import google.registry.model.poll.PollMessage; -import google.registry.model.reporting.HistoryEntry; import google.registry.testing.DualDatabaseTest; import google.registry.testing.InjectExtension; import google.registry.testing.TestOfyAndSql; @@ -132,7 +132,7 @@ public class UnrenewDomainCommandTest extends CommandTestCase descendantBuilder = + new ImmutableList.Builder() + .add( + history, + new PollMessage.OneTime.Builder() + .setParent(history) + .setClientId("") + .setEventTime(START_OF_TIME) + .build(), + new PollMessage.Autorenew.Builder() + .setParent(history) + .setClientId("") + .setEventTime(START_OF_TIME) + .build()); + if (history instanceof DomainHistory) { + descendantBuilder.add( + new BillingEvent.OneTime.Builder() + .setParent((DomainHistory) history) + .setBillingTime(START_OF_TIME) + .setEventTime(START_OF_TIME) + .setClientId("") + .setTargetId("") + .setReason(Reason.CREATE) + .setPeriodYears(1) + .setCost(Money.of(CurrencyUnit.USD, 1)) + .build(), + new BillingEvent.Recurring.Builder() + .setParent((DomainHistory) history) + .setEventTime(START_OF_TIME) + .setClientId("") + .setTargetId("") + .setReason(Reason.RENEW) + .build()); } + descendantBuilder.build().forEach(DatabaseHelper::persistResource); } ImmutableMultimap beforeContents = getDatastoreContents(); assertThat(beforeContents.keySet()).containsAtLeastElementsIn(AFFECTED_KINDS); diff --git a/core/src/test/java/google/registry/ui/server/registrar/RegistryLockVerifyActionTest.java b/core/src/test/java/google/registry/ui/server/registrar/RegistryLockVerifyActionTest.java index d6140c408..2c5f2d902 100644 --- a/core/src/test/java/google/registry/ui/server/registrar/RegistryLockVerifyActionTest.java +++ b/core/src/test/java/google/registry/ui/server/registrar/RegistryLockVerifyActionTest.java @@ -37,6 +37,7 @@ import google.registry.batch.AsyncTaskEnqueuerTest; import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.domain.DomainBase; +import google.registry.model.domain.DomainHistory; import google.registry.model.host.HostResource; import google.registry.model.registry.Registry; import google.registry.model.reporting.HistoryEntry; @@ -102,7 +103,8 @@ final class RegistryLockVerifyActionTest { assertThat(response.getStatus()).isEqualTo(SC_OK); assertThat(reloadDomain().getStatusValues()).containsExactlyElementsIn(REGISTRY_LOCK_STATUSES); assertThat(response.getPayload()).contains("Success: lock has been applied to example.tld"); - HistoryEntry historyEntry = getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_UPDATE); + DomainHistory historyEntry = + getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_UPDATE, DomainHistory.class); assertThat(historyEntry.getRequestedByRegistrar()).isTrue(); assertThat(historyEntry.getBySuperuser()).isFalse(); assertThat(historyEntry.getReason()) @@ -119,7 +121,8 @@ final class RegistryLockVerifyActionTest { assertThat(response.getStatus()).isEqualTo(SC_OK); assertThat(response.getPayload()).contains("Success: unlock has been applied to example.tld"); assertThat(reloadDomain().getStatusValues()).containsNoneIn(REGISTRY_LOCK_STATUSES); - HistoryEntry historyEntry = getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_UPDATE); + DomainHistory historyEntry = + getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_UPDATE, DomainHistory.class); assertThat(historyEntry.getRequestedByRegistrar()).isTrue(); assertThat(historyEntry.getBySuperuser()).isFalse(); assertThat(historyEntry.getReason()) @@ -308,7 +311,7 @@ final class RegistryLockVerifyActionTest { assertThat(reloadDomain()).isEqualTo(domain); } - private void assertBillingEvent(HistoryEntry historyEntry) { + private void assertBillingEvent(DomainHistory historyEntry) { DatabaseHelper.assertBillingEvents( new BillingEvent.OneTime.Builder() .setReason(Reason.SERVER_STATUS) diff --git a/core/src/test/resources/google/registry/model/schema.txt b/core/src/test/resources/google/registry/model/schema.txt index bdf4ff2dd..e6edcaeed 100644 --- a/core/src/test/resources/google/registry/model/schema.txt +++ b/core/src/test/resources/google/registry/model/schema.txt @@ -6,7 +6,7 @@ class google.registry.model.UpdateAutoTimestamp { } class google.registry.model.billing.BillingEvent$Cancellation { @Id java.lang.Long id; - @Parent com.googlecode.objectify.Key parent; + @Parent com.googlecode.objectify.Key parent; google.registry.model.billing.BillingEvent$Reason reason; google.registry.persistence.BillingVKey$BillingEventVKey refOneTime; google.registry.persistence.BillingVKey$BillingRecurrenceVKey refRecurring; @@ -27,7 +27,7 @@ enum google.registry.model.billing.BillingEvent$Flag { } class google.registry.model.billing.BillingEvent$Modification { @Id java.lang.Long id; - @Parent com.googlecode.objectify.Key parent; + @Parent com.googlecode.objectify.Key parent; com.googlecode.objectify.Key eventRef; google.registry.model.billing.BillingEvent$Reason reason; java.lang.String clientId; @@ -39,7 +39,7 @@ class google.registry.model.billing.BillingEvent$Modification { } class google.registry.model.billing.BillingEvent$OneTime { @Id java.lang.Long id; - @Parent com.googlecode.objectify.Key parent; + @Parent com.googlecode.objectify.Key parent; google.registry.model.billing.BillingEvent$Reason reason; google.registry.persistence.VKey cancellationMatchingBillingEvent; google.registry.persistence.VKey allocationToken; @@ -63,7 +63,7 @@ enum google.registry.model.billing.BillingEvent$Reason { } class google.registry.model.billing.BillingEvent$Recurring { @Id java.lang.Long id; - @Parent com.googlecode.objectify.Key parent; + @Parent com.googlecode.objectify.Key parent; google.registry.model.billing.BillingEvent$Reason reason; google.registry.model.common.TimeOfYear recurrenceTimeOfYear; java.lang.String clientId;