Change BillingEvent parent to Key<DomainHistory> (#1178)

This commit is contained in:
Lai Jiang 2021-05-25 18:48:47 -04:00 committed by GitHub
parent eb1aeab223
commit 64cbaf17ff
32 changed files with 202 additions and 149 deletions

1
.gitignore vendored
View file

@ -4,6 +4,7 @@
###################################################################### ######################################################################
# Java Ignores # Java Ignores
gjf.out
*.class *.class
# Mobile Tools for Java (J2ME) # Mobile Tools for Java (J2ME)

View file

@ -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. */ /** Some status updates cost money. Bill only once no matter how many of them are changed. */
private Optional<BillingEvent.OneTime> createBillingEventForStatusUpdates( private Optional<BillingEvent.OneTime> createBillingEventForStatusUpdates(
DomainBase existingDomain, DomainBase existingDomain, DomainBase newDomain, DomainHistory historyEntry, DateTime now) {
DomainBase newDomain,
HistoryEntry historyEntry,
DateTime now) {
Optional<MetadataExtension> metadataExtension = Optional<MetadataExtension> metadataExtension =
eppInput.getSingleExtension(MetadataExtension.class); eppInput.getSingleExtension(MetadataExtension.class);
if (metadataExtension.isPresent() && metadataExtension.get().getRequestedByRegistrar()) { if (metadataExtension.isPresent() && metadataExtension.get().getRequestedByRegistrar()) {

View file

@ -46,7 +46,6 @@ import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.GracePeriod; import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.token.AllocationToken; import google.registry.model.domain.token.AllocationToken;
import google.registry.model.reporting.HistoryEntry;
import google.registry.model.transfer.TransferData.TransferServerApproveEntity; import google.registry.model.transfer.TransferData.TransferServerApproveEntity;
import google.registry.persistence.BillingVKey.BillingEventVKey; import google.registry.persistence.BillingVKey.BillingEventVKey;
import google.registry.persistence.BillingVKey.BillingRecurrenceVKey; import google.registry.persistence.BillingVKey.BillingRecurrenceVKey;
@ -115,7 +114,7 @@ public abstract class BillingEvent extends ImmutableObject
/** Entity id. */ /** Entity id. */
@Id @javax.persistence.Id Long id; @Id @javax.persistence.Id Long id;
@Parent @DoNotHydrate @Transient Key<? extends HistoryEntry> parent; @Parent @DoNotHydrate @Transient Key<DomainHistory> parent;
/** The registrar to bill. */ /** The registrar to bill. */
@Index @Index
@ -154,7 +153,7 @@ public abstract class BillingEvent extends ImmutableObject
parent = parent =
Key.create( Key.create(
Key.create(DomainBase.class, domainRepoId), Key.create(DomainBase.class, domainRepoId),
HistoryEntry.class, DomainHistory.class,
domainHistoryRevisionId); domainHistoryRevisionId);
} }
@ -192,7 +191,7 @@ public abstract class BillingEvent extends ImmutableObject
return targetId; return targetId;
} }
public Key<? extends HistoryEntry> getParentKey() { public Key<DomainHistory> getParentKey() {
return parent; return parent;
} }
@ -254,12 +253,12 @@ public abstract class BillingEvent extends ImmutableObject
return thisCastToDerived(); return thisCastToDerived();
} }
public B setParent(HistoryEntry parent) { public B setParent(DomainHistory parent) {
getInstance().parent = Key.create(parent); getInstance().parent = Key.create(parent);
return thisCastToDerived(); return thisCastToDerived();
} }
public B setParent(Key<? extends HistoryEntry> parentKey) { public B setParent(Key<DomainHistory> parentKey) {
getInstance().parent = parentKey; getInstance().parent = parentKey;
return thisCastToDerived(); 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. * because it is needed by one-off scrap tools that need to make billing adjustments.
*/ */
public static Modification createRefundFor( public static Modification createRefundFor(
OneTime billingEvent, HistoryEntry historyEntry, String description) { OneTime billingEvent, DomainHistory historyEntry, String description) {
return new Builder() return new Builder()
.setClientId(billingEvent.getClientId()) .setClientId(billingEvent.getClientId())
.setFlags(billingEvent.getFlags()) .setFlags(billingEvent.getFlags())

View file

@ -222,9 +222,17 @@ public class DatastoreTransactionManager implements TransactionManager {
entry -> keyMap.get(entry.getKey()), entry -> toSqlEntity(entry.getValue()))); entry -> keyMap.get(entry.getKey()), entry -> toSqlEntity(entry.getValue())));
} }
@SuppressWarnings("unchecked")
@Override @Override
public <T> ImmutableList<T> loadByEntitiesIfPresent(Iterable<T> entities) { public <T> ImmutableList<T> loadByEntitiesIfPresent(Iterable<T> 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 @Override
@ -250,6 +258,7 @@ public class DatastoreTransactionManager implements TransactionManager {
return result; return result;
} }
@SuppressWarnings("unchecked")
@Override @Override
public <T> T loadByEntity(T entity) { public <T> T loadByEntity(T entity) {
return (T) toSqlEntity(auditedOfy().load().entity(toDatastoreEntity(entity)).now()); return (T) toSqlEntity(auditedOfy().load().entity(toDatastoreEntity(entity)).now());

View file

@ -458,11 +458,14 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
assertInTransaction(); assertInTransaction();
// If the caller requested a HistoryEntry, load the corresponding *History class // If the caller requested a HistoryEntry, load the corresponding *History class
T possibleChild = toSqlEntity(entity); T possibleChild = toSqlEntity(entity);
return (T) @SuppressWarnings("unchecked")
T returnValue =
(T)
loadByKey( loadByKey(
VKey.createSql( VKey.createSql(
possibleChild.getClass(), possibleChild.getClass(),
emf.getPersistenceUnitUtil().getIdentifier(possibleChild))); emf.getPersistenceUnitUtil().getIdentifier(possibleChild)));
return returnValue;
} }
@Override @Override

View file

@ -165,7 +165,7 @@ class DeleteExpiredDomainsActionTest {
private DomainBase persistNonAutorenewingDomain(String domainName) { private DomainBase persistNonAutorenewingDomain(String domainName) {
DomainBase pendingExpirationDomain = persistActiveDomain(domainName); DomainBase pendingExpirationDomain = persistActiveDomain(domainName);
HistoryEntry createHistoryEntry = DomainHistory createHistoryEntry =
persistResource( persistResource(
new DomainHistory.Builder() new DomainHistory.Builder()
.setType(DOMAIN_CREATE) .setType(DOMAIN_CREATE)
@ -190,7 +190,7 @@ class DeleteExpiredDomainsActionTest {
} }
private BillingEvent.Recurring.Builder createAutorenewBillingEvent( private BillingEvent.Recurring.Builder createAutorenewBillingEvent(
HistoryEntry createHistoryEntry) { DomainHistory createHistoryEntry) {
return new BillingEvent.Recurring.Builder() return new BillingEvent.Recurring.Builder()
.setReason(Reason.RENEW) .setReason(Reason.RENEW)
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW)) .setFlags(ImmutableSet.of(Flag.AUTO_RENEW))

View file

@ -280,7 +280,7 @@ class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDataActio
*/ */
private static Set<ImmutableObject> persistDomainAndDescendants(String fqdn) { private static Set<ImmutableObject> persistDomainAndDescendants(String fqdn) {
DomainBase domain = persistDeletedDomain(fqdn, DELETION_TIME); DomainBase domain = persistDeletedDomain(fqdn, DELETION_TIME);
HistoryEntry historyEntry = DomainHistory historyEntry =
persistSimpleResource( persistSimpleResource(
new DomainHistory.Builder() new DomainHistory.Builder()
.setDomain(domain) .setDomain(domain)

View file

@ -75,7 +75,7 @@ public class ExpandRecurringBillingEventsActionTest
private final FakeClock clock = new FakeClock(beginningOfTest); private final FakeClock clock = new FakeClock(beginningOfTest);
private DomainBase domain; private DomainBase domain;
private HistoryEntry historyEntry; private DomainHistory historyEntry;
private BillingEvent.Recurring recurring; private BillingEvent.Recurring recurring;
@BeforeEach @BeforeEach
@ -173,7 +173,8 @@ public class ExpandRecurringBillingEventsActionTest
persistResource(recurring); persistResource(recurring);
action.cursorTimeParam = Optional.of(START_OF_TIME); action.cursorTimeParam = Optional.of(START_OF_TIME);
runMapreduce(); runMapreduce();
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); DomainHistory persistedEntry =
getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertHistoryEntryMatches( assertHistoryEntryMatches(
domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true);
BillingEvent.OneTime expected = defaultOneTimeBuilder() BillingEvent.OneTime expected = defaultOneTimeBuilder()
@ -209,9 +210,13 @@ public class ExpandRecurringBillingEventsActionTest
.build()); .build());
action.cursorTimeParam = Optional.of(START_OF_TIME); action.cursorTimeParam = Optional.of(START_OF_TIME);
runMapreduce(); runMapreduce();
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(deletedDomain, DOMAIN_AUTORENEW); DomainHistory persistedEntry =
getOnlyHistoryEntryOfType(deletedDomain, DOMAIN_AUTORENEW, DomainHistory.class);
assertHistoryEntryMatches( assertHistoryEntryMatches(
deletedDomain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), deletedDomain,
persistedEntry,
"TheRegistrar",
DateTime.parse("2000-02-19T00:00:00Z"),
true); true);
BillingEvent.OneTime expected = BillingEvent.OneTime expected =
defaultOneTimeBuilder() defaultOneTimeBuilder()
@ -227,7 +232,8 @@ public class ExpandRecurringBillingEventsActionTest
persistResource(recurring); persistResource(recurring);
action.cursorTimeParam = Optional.of(START_OF_TIME); action.cursorTimeParam = Optional.of(START_OF_TIME);
runMapreduce(); runMapreduce();
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); DomainHistory persistedEntry =
getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertHistoryEntryMatches( assertHistoryEntryMatches(
domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true);
BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build(); BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build();
@ -259,7 +265,8 @@ public class ExpandRecurringBillingEventsActionTest
persistResource(recurring); persistResource(recurring);
action.cursorTimeParam = Optional.of(START_OF_TIME); action.cursorTimeParam = Optional.of(START_OF_TIME);
runMapreduce(); runMapreduce();
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); DomainHistory persistedEntry =
getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertHistoryEntryMatches( assertHistoryEntryMatches(
domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true);
BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build(); BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build();
@ -280,8 +287,8 @@ public class ExpandRecurringBillingEventsActionTest
.build()); .build());
action.cursorTimeParam = Optional.of(START_OF_TIME); action.cursorTimeParam = Optional.of(START_OF_TIME);
runMapreduce(); runMapreduce();
List<HistoryEntry> persistedEntries = List<DomainHistory> persistedEntries =
getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW); getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
for (HistoryEntry persistedEntry : persistedEntries) { for (HistoryEntry persistedEntry : persistedEntries) {
assertHistoryEntryMatches( assertHistoryEntryMatches(
domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true);
@ -332,7 +339,8 @@ public class ExpandRecurringBillingEventsActionTest
persistResource(recurring); persistResource(recurring);
action.cursorTimeParam = Optional.of(DateTime.parse("2000-02-19T00:00:00Z")); action.cursorTimeParam = Optional.of(DateTime.parse("2000-02-19T00:00:00Z"));
runMapreduce(); runMapreduce();
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); DomainHistory persistedEntry =
getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertHistoryEntryMatches( assertHistoryEntryMatches(
domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true);
BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build(); BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build();
@ -345,7 +353,8 @@ public class ExpandRecurringBillingEventsActionTest
persistResource(recurring); persistResource(recurring);
action.cursorTimeParam = Optional.of(DateTime.parse("2000-01-12T00:00:00Z")); action.cursorTimeParam = Optional.of(DateTime.parse("2000-01-12T00:00:00Z"));
runMapreduce(); runMapreduce();
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); DomainHistory persistedEntry =
getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertHistoryEntryMatches( assertHistoryEntryMatches(
domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true);
BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build(); BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build();
@ -379,7 +388,8 @@ public class ExpandRecurringBillingEventsActionTest
recurring.asBuilder().setEventTime(recurring.getEventTime().plusYears(2)).build()); recurring.asBuilder().setEventTime(recurring.getEventTime().plusYears(2)).build());
clock.setTo(testTime); clock.setTo(testTime);
runMapreduce(); runMapreduce();
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); DomainHistory persistedEntry =
getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertHistoryEntryMatches( assertHistoryEntryMatches(
domain, persistedEntry, "TheRegistrar", DateTime.parse("2002-02-19T00:00:00Z"), true); domain, persistedEntry, "TheRegistrar", DateTime.parse("2002-02-19T00:00:00Z"), true);
BillingEvent.OneTime expected = defaultOneTimeBuilder() BillingEvent.OneTime expected = defaultOneTimeBuilder()
@ -397,7 +407,8 @@ public class ExpandRecurringBillingEventsActionTest
persistResource(recurring); persistResource(recurring);
saveCursor(START_OF_TIME); saveCursor(START_OF_TIME);
runMapreduce(); runMapreduce();
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); DomainHistory persistedEntry =
getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertHistoryEntryMatches( assertHistoryEntryMatches(
domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true);
BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build(); BillingEvent.OneTime expected = defaultOneTimeBuilder().setParent(persistedEntry).build();
@ -451,8 +462,8 @@ public class ExpandRecurringBillingEventsActionTest
expectedEvents.add(persistResource(recurring)); expectedEvents.add(persistResource(recurring));
action.cursorTimeParam = Optional.of(START_OF_TIME); action.cursorTimeParam = Optional.of(START_OF_TIME);
runMapreduce(); runMapreduce();
List<HistoryEntry> persistedEntries = List<DomainHistory> persistedEntries =
getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW); getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertThat(persistedEntries).hasSize(6); assertThat(persistedEntries).hasSize(6);
DateTime eventDate = DateTime.parse("2000-01-05T00:00:00Z"); DateTime eventDate = DateTime.parse("2000-01-05T00:00:00Z");
DateTime billingDate = DateTime.parse("2000-02-19T00:00:00Z"); DateTime billingDate = DateTime.parse("2000-02-19T00:00:00Z");
@ -482,8 +493,8 @@ public class ExpandRecurringBillingEventsActionTest
expectedEvents.add(persistResource(recurring)); expectedEvents.add(persistResource(recurring));
saveCursor(DateTime.parse("2003-10-02T00:00:00Z")); saveCursor(DateTime.parse("2003-10-02T00:00:00Z"));
runMapreduce(); runMapreduce();
List<HistoryEntry> persistedEntries = List<DomainHistory> persistedEntries =
getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW); getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertThat(persistedEntries).hasSize(2); assertThat(persistedEntries).hasSize(2);
DateTime eventDate = DateTime.parse("2004-01-05T00:00:00Z"); DateTime eventDate = DateTime.parse("2004-01-05T00:00:00Z");
DateTime billingDate = DateTime.parse("2004-02-19T00:00:00Z"); DateTime billingDate = DateTime.parse("2004-02-19T00:00:00Z");
@ -528,7 +539,8 @@ public class ExpandRecurringBillingEventsActionTest
.build()); .build());
action.cursorTimeParam = Optional.of(START_OF_TIME); action.cursorTimeParam = Optional.of(START_OF_TIME);
runMapreduce(); runMapreduce();
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); DomainHistory persistedEntry =
getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertHistoryEntryMatches( assertHistoryEntryMatches(
domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), false); domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), false);
BillingEvent.OneTime expected = defaultOneTimeBuilder() BillingEvent.OneTime expected = defaultOneTimeBuilder()
@ -553,7 +565,8 @@ public class ExpandRecurringBillingEventsActionTest
.build()); .build());
action.cursorTimeParam = Optional.of(START_OF_TIME); action.cursorTimeParam = Optional.of(START_OF_TIME);
runMapreduce(); runMapreduce();
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); DomainHistory persistedEntry =
getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertHistoryEntryMatches( assertHistoryEntryMatches(
domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true);
BillingEvent.OneTime expected = defaultOneTimeBuilder() BillingEvent.OneTime expected = defaultOneTimeBuilder()
@ -572,7 +585,8 @@ public class ExpandRecurringBillingEventsActionTest
recurring.asBuilder().setEventTime(DateTime.parse("2000-01-15T00:00:00Z")).build()); recurring.asBuilder().setEventTime(DateTime.parse("2000-01-15T00:00:00Z")).build());
action.cursorTimeParam = Optional.of(START_OF_TIME); action.cursorTimeParam = Optional.of(START_OF_TIME);
runMapreduce(); runMapreduce();
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); DomainHistory persistedEntry =
getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertHistoryEntryMatches( assertHistoryEntryMatches(
domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-29T00:00:00Z"), true); domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-29T00:00:00Z"), true);
BillingEvent.OneTime expected = defaultOneTimeBuilder() BillingEvent.OneTime expected = defaultOneTimeBuilder()
@ -593,7 +607,8 @@ public class ExpandRecurringBillingEventsActionTest
action.cursorTimeParam = Optional.of(START_OF_TIME); action.cursorTimeParam = Optional.of(START_OF_TIME);
clock.setTo(testTime); clock.setTo(testTime);
runMapreduce(); runMapreduce();
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); DomainHistory persistedEntry =
getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertHistoryEntryMatches( assertHistoryEntryMatches(
domain, persistedEntry, "TheRegistrar", DateTime.parse("2001-03-01T00:00:00Z"), true); domain, persistedEntry, "TheRegistrar", DateTime.parse("2001-03-01T00:00:00Z"), true);
BillingEvent.OneTime expected = defaultOneTimeBuilder() BillingEvent.OneTime expected = defaultOneTimeBuilder()
@ -615,7 +630,8 @@ public class ExpandRecurringBillingEventsActionTest
.build()); .build());
action.cursorTimeParam = Optional.of(START_OF_TIME); action.cursorTimeParam = Optional.of(START_OF_TIME);
runMapreduce(); runMapreduce();
List<HistoryEntry> persistedEntries = getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW); List<DomainHistory> persistedEntries =
getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertThat(persistedEntries).hasSize(2); assertThat(persistedEntries).hasSize(2);
assertHistoryEntryMatches( assertHistoryEntryMatches(
domain, persistedEntries.get(0), "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), domain, persistedEntries.get(0), "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"),
@ -649,7 +665,8 @@ public class ExpandRecurringBillingEventsActionTest
persistResource(recurring); persistResource(recurring);
action.cursorTimeParam = Optional.of(START_OF_TIME); action.cursorTimeParam = Optional.of(START_OF_TIME);
runMapreduce(); runMapreduce();
HistoryEntry persistedEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW); DomainHistory persistedEntry =
getOnlyHistoryEntryOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertHistoryEntryMatches( assertHistoryEntryMatches(
domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true); domain, persistedEntry, "TheRegistrar", DateTime.parse("2000-02-19T00:00:00Z"), true);
BillingEvent.OneTime expected = defaultOneTimeBuilder() BillingEvent.OneTime expected = defaultOneTimeBuilder()
@ -675,8 +692,8 @@ public class ExpandRecurringBillingEventsActionTest
persistResource(recurring); persistResource(recurring);
action.cursorTimeParam = Optional.of(START_OF_TIME); action.cursorTimeParam = Optional.of(START_OF_TIME);
runMapreduce(); runMapreduce();
List<HistoryEntry> persistedEntries = List<DomainHistory> persistedEntries =
getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW); getHistoryEntriesOfType(domain, DOMAIN_AUTORENEW, DomainHistory.class);
assertThat(persistedEntries).hasSize(2); assertThat(persistedEntries).hasSize(2);
DateTime eventDate = DateTime.parse("2000-01-05T00:00:00Z"); DateTime eventDate = DateTime.parse("2000-01-05T00:00:00Z");
DateTime billingDate = DateTime.parse("2000-02-19T00:00:00Z"); DateTime billingDate = DateTime.parse("2000-02-19T00:00:00Z");

View file

@ -129,7 +129,7 @@ class InitSqlPipelineTest {
private transient ContactResource contact2; private transient ContactResource contact2;
private transient HostResource hostResource; private transient HostResource hostResource;
private transient HistoryEntry historyEntry; private transient DomainHistory historyEntry;
@BeforeEach @BeforeEach
void beforeEach() throws Exception { void beforeEach() throws Exception {
@ -187,7 +187,7 @@ class InitSqlPipelineTest {
.build()); .build());
persistResource( persistResource(
new AllocationToken.Builder().setToken("abc123").setTokenType(SINGLE_USE).build()); new AllocationToken.Builder().setToken("abc123").setTokenType(SINGLE_USE).build());
Key<HistoryEntry> historyEntryKey = Key.create(historyEntry); Key<DomainHistory> historyEntryKey = Key.create(historyEntry);
BillingEvent.OneTime onetimeBillEvent = BillingEvent.OneTime onetimeBillEvent =
new BillingEvent.OneTime.Builder() new BillingEvent.OneTime.Builder()
.setId(1) .setId(1)

View file

@ -42,6 +42,7 @@ import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.OneTime; import google.registry.model.billing.BillingEvent.OneTime;
import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState; import google.registry.model.registry.Registry.TldState;
import google.registry.model.reporting.HistoryEntry.Type; import google.registry.model.reporting.HistoryEntry.Type;
@ -549,7 +550,7 @@ class EppLifecycleDomainTest extends EppTestCase {
.setCost(Money.parse("USD 100.00")) .setCost(Money.parse("USD 100.00"))
.setEventTime(createTime) .setEventTime(createTime)
.setBillingTime(createTime.plus(Registry.get("tld").getRenewGracePeriodLength())) .setBillingTime(createTime.plus(Registry.get("tld").getRenewGracePeriodLength()))
.setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE)) .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE, DomainHistory.class))
.build(); .build();
// The expected one-time billing event, that should have an associated Cancellation. // The expected one-time billing event, that should have an associated Cancellation.

View file

@ -35,10 +35,10 @@ import google.registry.model.billing.BillingEvent.Flag;
import google.registry.model.billing.BillingEvent.OneTime; import google.registry.model.billing.BillingEvent.OneTime;
import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.eppcommon.EppXmlTransformer; import google.registry.model.eppcommon.EppXmlTransformer;
import google.registry.model.ofy.Ofy; import google.registry.model.ofy.Ofy;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.reporting.HistoryEntry;
import google.registry.model.reporting.HistoryEntry.Type; import google.registry.model.reporting.HistoryEntry.Type;
import google.registry.monitoring.whitebox.EppMetric; import google.registry.monitoring.whitebox.EppMetric;
import google.registry.persistence.VKey; import google.registry.persistence.VKey;
@ -81,8 +81,7 @@ public class EppTestCase {
* *
* <p>When the credentials are null, the login flow still checks the EPP password from the xml, * <p>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 * 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}. * such as {@link EppLoginTlsTest}. Therefore, only those tests should call this method.
* Therefore, only those tests should call this method.
*/ */
void setTransportCredentials(TransportCredentials credentials) { void setTransportCredentials(TransportCredentials credentials) {
this.credentials = credentials; this.credentials = credentials;
@ -326,7 +325,7 @@ public class EppTestCase {
.setPeriodYears(2) .setPeriodYears(2)
.setEventTime(createTime) .setEventTime(createTime)
.setBillingTime(createTime.plus(Registry.get(domain.getTld()).getAddGracePeriodLength())) .setBillingTime(createTime.plus(Registry.get(domain.getTld()).getAddGracePeriodLength()))
.setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE)) .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE, DomainHistory.class))
.build(); .build();
} }
@ -340,7 +339,7 @@ public class EppTestCase {
.setPeriodYears(3) .setPeriodYears(3)
.setEventTime(renewTime) .setEventTime(renewTime)
.setBillingTime(renewTime.plus(Registry.get(domain.getTld()).getRenewGracePeriodLength())) .setBillingTime(renewTime.plus(Registry.get(domain.getTld()).getRenewGracePeriodLength()))
.setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_RENEW)) .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_RENEW, DomainHistory.class))
.build(); .build();
} }
@ -348,19 +347,25 @@ public class EppTestCase {
static BillingEvent.Recurring makeRecurringCreateBillingEvent( static BillingEvent.Recurring makeRecurringCreateBillingEvent(
DomainBase domain, DateTime eventTime, DateTime endTime) { DomainBase domain, DateTime eventTime, DateTime endTime) {
return makeRecurringBillingEvent( 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. */ /** Makes a recurring billing event corresponding to the given domain's renewal. */
static BillingEvent.Recurring makeRecurringRenewBillingEvent( static BillingEvent.Recurring makeRecurringRenewBillingEvent(
DomainBase domain, DateTime eventTime, DateTime endTime) { DomainBase domain, DateTime eventTime, DateTime endTime) {
return makeRecurringBillingEvent( 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. */ /** Makes a recurring billing event corresponding to the given history entry. */
protected static BillingEvent.Recurring makeRecurringBillingEvent( 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() return new BillingEvent.Recurring.Builder()
.setReason(Reason.RENEW) .setReason(Reason.RENEW)
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW)) .setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
@ -382,7 +387,7 @@ public class EppTestCase {
.setOneTimeEventKey(VKey.from(findKeyToActualOneTimeBillingEvent(billingEventToCancel))) .setOneTimeEventKey(VKey.from(findKeyToActualOneTimeBillingEvent(billingEventToCancel)))
.setBillingTime(createTime.plus(Registry.get(domain.getTld()).getAddGracePeriodLength())) .setBillingTime(createTime.plus(Registry.get(domain.getTld()).getAddGracePeriodLength()))
.setReason(Reason.CREATE) .setReason(Reason.CREATE)
.setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_DELETE)) .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_DELETE, DomainHistory.class))
.build(); .build();
} }
@ -396,7 +401,7 @@ public class EppTestCase {
.setOneTimeEventKey(VKey.from(findKeyToActualOneTimeBillingEvent(billingEventToCancel))) .setOneTimeEventKey(VKey.from(findKeyToActualOneTimeBillingEvent(billingEventToCancel)))
.setBillingTime(renewTime.plus(Registry.get(domain.getTld()).getRenewGracePeriodLength())) .setBillingTime(renewTime.plus(Registry.get(domain.getTld()).getRenewGracePeriodLength()))
.setReason(Reason.RENEW) .setReason(Reason.RENEW)
.setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_DELETE)) .setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_DELETE, DomainHistory.class))
.build(); .build();
} }

View file

@ -145,6 +145,7 @@ import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Flag; import google.registry.model.billing.BillingEvent.Flag;
import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.GracePeriod; import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.launch.LaunchNotice; import google.registry.model.domain.launch.LaunchNotice;
import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.rgp.GracePeriodStatus;
@ -266,7 +267,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
? clock.nowUtc().plus(Registry.get(domainTld).getAnchorTenantAddGracePeriodLength()) ? clock.nowUtc().plus(Registry.get(domainTld).getAnchorTenantAddGracePeriodLength())
: clock.nowUtc().plus(Registry.get(domainTld).getAddGracePeriodLength()); : clock.nowUtc().plus(Registry.get(domainTld).getAddGracePeriodLength());
assertLastHistoryContainsResource(domain); assertLastHistoryContainsResource(domain);
HistoryEntry historyEntry = getHistoryEntries(domain).get(0); DomainHistory historyEntry = getHistoryEntries(domain, DomainHistory.class).get(0);
assertAboutDomains() assertAboutDomains()
.that(domain) .that(domain)
.hasRegistrationExpirationTime( .hasRegistrationExpirationTime(

View file

@ -229,14 +229,14 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
} }
private void assertAutorenewClosedAndCancellationCreatedFor( private void assertAutorenewClosedAndCancellationCreatedFor(
BillingEvent.OneTime graceBillingEvent, HistoryEntry historyEntryDomainDelete) { BillingEvent.OneTime graceBillingEvent, DomainHistory historyEntryDomainDelete) {
assertAutorenewClosedAndCancellationCreatedFor( assertAutorenewClosedAndCancellationCreatedFor(
graceBillingEvent, historyEntryDomainDelete, clock.nowUtc()); graceBillingEvent, historyEntryDomainDelete, clock.nowUtc());
} }
private void assertAutorenewClosedAndCancellationCreatedFor( private void assertAutorenewClosedAndCancellationCreatedFor(
BillingEvent.OneTime graceBillingEvent, BillingEvent.OneTime graceBillingEvent,
HistoryEntry historyEntryDomainDelete, DomainHistory historyEntryDomainDelete,
DateTime eventTime) { DateTime eventTime) {
assertBillingEvents( assertBillingEvents(
createAutorenewBillingEvent("TheRegistrar").setRecurrenceEndTime(eventTime).build(), createAutorenewBillingEvent("TheRegistrar").setRecurrenceEndTime(eventTime).build(),
@ -360,7 +360,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
assertThat(reloadResourceByForeignKey()).isNull(); assertThat(reloadResourceByForeignKey()).isNull();
// The add grace period is for a billable action, so it should trigger a cancellation. // The add grace period is for a billable action, so it should trigger a cancellation.
assertAutorenewClosedAndCancellationCreatedFor( assertAutorenewClosedAndCancellationCreatedFor(
graceBillingEvent, getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE)); graceBillingEvent, getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE, DomainHistory.class));
assertDnsTasksEnqueued("example.tld"); assertDnsTasksEnqueued("example.tld");
// There should be no poll messages. The previous autorenew poll message should now be deleted. // There should be no poll messages. The previous autorenew poll message should now be deleted.
assertThat(getPollMessages("TheRegistrar")).isEmpty(); assertThat(getPollMessages("TheRegistrar")).isEmpty();
@ -461,7 +461,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
assertLastHistoryContainsResource(resource); assertLastHistoryContainsResource(resource);
// All existing grace periods that were for billable actions should cause cancellations. // All existing grace periods that were for billable actions should cause cancellations.
assertAutorenewClosedAndCancellationCreatedFor( assertAutorenewClosedAndCancellationCreatedFor(
renewBillingEvent, getOnlyHistoryEntryOfType(resource, DOMAIN_DELETE)); renewBillingEvent, getOnlyHistoryEntryOfType(resource, DOMAIN_DELETE, DomainHistory.class));
// All existing grace periods should be gone, and a new REDEMPTION one should be added. // All existing grace periods should be gone, and a new REDEMPTION one should be added.
assertThat(resource.getGracePeriods()) assertThat(resource.getGracePeriods())
.containsExactly( .containsExactly(
@ -755,7 +755,9 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
runFlowAssertResponse(loadFile("generic_success_response.xml")); runFlowAssertResponse(loadFile("generic_success_response.xml"));
assertDnsTasksEnqueued("example.tld"); assertDnsTasksEnqueued("example.tld");
assertAutorenewClosedAndCancellationCreatedFor( assertAutorenewClosedAndCancellationCreatedFor(
graceBillingEvent, getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE), eventTime); graceBillingEvent,
getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE, DomainHistory.class),
eventTime);
} }
@TestOfyAndSql @TestOfyAndSql

View file

@ -361,7 +361,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
@TestOfyAndSql @TestOfyAndSql
void testSuccess_autoRenewGracePeriod() throws Exception { void testSuccess_autoRenewGracePeriod() throws Exception {
persistTestEntities(false); persistTestEntities(false);
HistoryEntry historyEntry = DomainHistory historyEntry =
persistResource( persistResource(
new DomainHistory.Builder() new DomainHistory.Builder()
.setDomain(domain) .setDomain(domain)

View file

@ -201,8 +201,8 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
CommitMode.LIVE, userPrivileges, loadFile(responseFilename, substitutions)); CommitMode.LIVE, userPrivileges, loadFile(responseFilename, substitutions));
DomainBase domain = reloadResourceByForeignKey(); DomainBase domain = reloadResourceByForeignKey();
assertLastHistoryContainsResource(domain); assertLastHistoryContainsResource(domain);
HistoryEntry historyEntryDomainRenew = DomainHistory historyEntryDomainRenew =
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RENEW); getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RENEW, DomainHistory.class);
assertThat(loadByKey(domain.getAutorenewBillingEvent()).getEventTime()) assertThat(loadByKey(domain.getAutorenewBillingEvent()).getEventTime())
.isEqualTo(newExpiration); .isEqualTo(newExpiration);
assertAboutDomains() assertAboutDomains()
@ -238,7 +238,9 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
.setClientId("TheRegistrar") .setClientId("TheRegistrar")
.setEventTime(expirationTime) .setEventTime(expirationTime)
.setRecurrenceEndTime(clock.nowUtc()) .setRecurrenceEndTime(clock.nowUtc())
.setParent(getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_CREATE)) .setParent(
getOnlyHistoryEntryOfType(
domain, HistoryEntry.Type.DOMAIN_CREATE, DomainHistory.class))
.build(), .build(),
new BillingEvent.Recurring.Builder() new BillingEvent.Recurring.Builder()
.setReason(Reason.RENEW) .setReason(Reason.RENEW)

View file

@ -162,8 +162,8 @@ class DomainRestoreRequestFlowTest
assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1))).hasSize(1); assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1))).hasSize(1);
runFlowAssertResponse(loadFile("generic_success_response.xml")); runFlowAssertResponse(loadFile("generic_success_response.xml"));
DomainBase domain = reloadResourceByForeignKey(); DomainBase domain = reloadResourceByForeignKey();
HistoryEntry historyEntryDomainRestore = DomainHistory historyEntryDomainRestore =
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RESTORE); getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RESTORE, DomainHistory.class);
assertLastHistoryContainsResource(domain); assertLastHistoryContainsResource(domain);
assertThat(loadByKey(domain.getAutorenewBillingEvent()).getEventTime()) assertThat(loadByKey(domain.getAutorenewBillingEvent()).getEventTime())
.isEqualTo(expirationTime); .isEqualTo(expirationTime);
@ -231,8 +231,8 @@ class DomainRestoreRequestFlowTest
assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1))).hasSize(1); assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1))).hasSize(1);
runFlowAssertResponse(loadFile("generic_success_response.xml")); runFlowAssertResponse(loadFile("generic_success_response.xml"));
DomainBase domain = reloadResourceByForeignKey(); DomainBase domain = reloadResourceByForeignKey();
HistoryEntry historyEntryDomainRestore = DomainHistory historyEntryDomainRestore =
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RESTORE); getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RESTORE, DomainHistory.class);
assertLastHistoryContainsResource(domain); assertLastHistoryContainsResource(domain);
assertThat(loadByKey(domain.getAutorenewBillingEvent()).getEventTime()) assertThat(loadByKey(domain.getAutorenewBillingEvent()).getEventTime())
.isEqualTo(newExpirationTime); .isEqualTo(newExpirationTime);

View file

@ -260,8 +260,8 @@ class DomainTransferApproveFlowTest
throws Exception { throws Exception {
Registry registry = Registry.get(tld); Registry registry = Registry.get(tld);
domain = reloadResourceByForeignKey(); domain = reloadResourceByForeignKey();
final HistoryEntry historyEntryTransferApproved = final DomainHistory historyEntryTransferApproved =
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_APPROVE); getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_APPROVE, DomainHistory.class);
// We expect three billing events: one for the transfer, a closed autorenew for the losing // We expect three billing events: one for the transfer, a closed autorenew for the losing
// client and an open autorenew for the gaining client that begins at the new expiration time. // client and an open autorenew for the gaining client that begins at the new expiration time.
OneTime transferBillingEvent = OneTime transferBillingEvent =
@ -308,8 +308,8 @@ class DomainTransferApproveFlowTest
private void assertHistoryEntriesDoNotContainTransferBillingEventsOrGracePeriods( private void assertHistoryEntriesDoNotContainTransferBillingEventsOrGracePeriods(
BillingEvent.Cancellation.Builder... expectedCancellationBillingEvents) throws Exception { BillingEvent.Cancellation.Builder... expectedCancellationBillingEvents) throws Exception {
domain = reloadResourceByForeignKey(); domain = reloadResourceByForeignKey();
final HistoryEntry historyEntryTransferApproved = final DomainHistory historyEntryTransferApproved =
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_APPROVE); getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_APPROVE, DomainHistory.class);
// We expect two billing events: a closed autorenew for the losing client and an open autorenew // We expect two billing events: a closed autorenew for the losing client and an open autorenew
// for the gaining client that begins at the new expiration time. // for the gaining client that begins at the new expiration time.
assertBillingEventsForResource( assertBillingEventsForResource(

View file

@ -37,6 +37,7 @@ import google.registry.model.billing.BillingEvent.Flag;
import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.contact.ContactResource; import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
@ -73,7 +74,7 @@ abstract class DomainTransferFlowTestCase<F extends Flow, R extends EppResource>
protected ContactResource contact; protected ContactResource contact;
protected DomainBase domain; protected DomainBase domain;
HostResource subordinateHost; HostResource subordinateHost;
private HistoryEntry historyEntryDomainCreate; private DomainHistory historyEntryDomainCreate;
DomainTransferFlowTestCase() { DomainTransferFlowTestCase() {
checkState(!Registry.DEFAULT_TRANSFER_GRACE_PERIOD.isShorterThan(TIME_SINCE_REQUEST)); checkState(!Registry.DEFAULT_TRANSFER_GRACE_PERIOD.isShorterThan(TIME_SINCE_REQUEST));
@ -120,17 +121,16 @@ abstract class DomainTransferFlowTestCase<F extends Flow, R extends EppResource>
domain = domain =
persistResource( persistResource(
domain.asBuilder().addSubordinateHost(subordinateHost.getHostName()).build()); domain.asBuilder().addSubordinateHost(subordinateHost.getHostName()).build());
historyEntryDomainCreate = getOnlyHistoryEntryOfType(domain, DOMAIN_CREATE); historyEntryDomainCreate =
getOnlyHistoryEntryOfType(domain, DOMAIN_CREATE, DomainHistory.class);
} }
BillingEvent.OneTime getBillingEventForImplicitTransfer() { BillingEvent.OneTime getBillingEventForImplicitTransfer() {
HistoryEntry historyEntry = DomainHistory historyEntry =
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST); getOnlyHistoryEntryOfType(
domain, HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST, DomainHistory.class);
return createBillingEventForTransfer( return createBillingEventForTransfer(
domain, domain, historyEntry, TRANSFER_REQUEST_TIME, TRANSFER_EXPIRATION_TIME);
historyEntry,
TRANSFER_REQUEST_TIME,
TRANSFER_EXPIRATION_TIME);
} }
/** Get the autorenew event that the losing client will have after a SERVER_APPROVED transfer. */ /** Get the autorenew event that the losing client will have after a SERVER_APPROVED transfer. */
@ -155,7 +155,9 @@ abstract class DomainTransferFlowTestCase<F extends Flow, R extends EppResource>
.setClientId("NewRegistrar") .setClientId("NewRegistrar")
.setEventTime(EXTENDED_REGISTRATION_EXPIRATION_TIME) .setEventTime(EXTENDED_REGISTRATION_EXPIRATION_TIME)
.setRecurrenceEndTime(END_OF_TIME) .setRecurrenceEndTime(END_OF_TIME)
.setParent(getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST)) .setParent(
getOnlyHistoryEntryOfType(
domain, HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST, DomainHistory.class))
.build(); .build();
} }

View file

@ -86,6 +86,7 @@ import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.contact.ContactAuthInfo; import google.registry.model.contact.ContactAuthInfo;
import google.registry.model.domain.DomainAuthInfo; import google.registry.model.domain.DomainAuthInfo;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.GracePeriod; import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.Period; import google.registry.model.domain.Period;
import google.registry.model.domain.Period.Unit; import google.registry.model.domain.Period.Unit;
@ -250,8 +251,8 @@ class DomainTransferRequestFlowTest
boolean expectTransferBillingEvent, boolean expectTransferBillingEvent,
BillingEvent.Cancellation.Builder... extraExpectedBillingEvents) { BillingEvent.Cancellation.Builder... extraExpectedBillingEvents) {
Registry registry = Registry.get(domain.getTld()); Registry registry = Registry.get(domain.getTld());
final HistoryEntry historyEntryTransferRequest = final DomainHistory historyEntryTransferRequest =
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REQUEST); getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REQUEST, DomainHistory.class);
// Construct the billing events we expect to exist, starting with the (optional) billing // Construct the billing events we expect to exist, starting with the (optional) billing
// event for the transfer itself. // event for the transfer itself.

View file

@ -687,7 +687,9 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
.setBillingTime(clock.nowUtc()) .setBillingTime(clock.nowUtc())
.setParent( .setParent(
getOnlyHistoryEntryOfType( getOnlyHistoryEntryOfType(
reloadResourceByForeignKey(), HistoryEntry.Type.DOMAIN_UPDATE)) reloadResourceByForeignKey(),
HistoryEntry.Type.DOMAIN_UPDATE,
DomainHistory.class))
.build()); .build());
} else { } else {
assertNoBillingEvents(); assertNoBillingEvents();

View file

@ -363,7 +363,7 @@ public class DomainBaseTest extends EntityTestCase {
} }
private void doExpiredTransferTest(DateTime oldExpirationTime) { private void doExpiredTransferTest(DateTime oldExpirationTime) {
HistoryEntry historyEntry = DomainHistory historyEntry =
new DomainHistory.Builder() new DomainHistory.Builder()
.setDomain(domain) .setDomain(domain)
.setModificationTime(fakeClock.nowUtc()) .setModificationTime(fakeClock.nowUtc())

View file

@ -55,7 +55,7 @@ public class GracePeriodTest {
.setClientId("TheRegistrar") .setClientId("TheRegistrar")
.setCost(Money.of(CurrencyUnit.USD, 42)) .setCost(Money.of(CurrencyUnit.USD, 42))
.setParent( .setParent(
Key.create(Key.create(DomainBase.class, "domain"), HistoryEntry.class, 12345)) Key.create(Key.create(DomainBase.class, "domain"), DomainHistory.class, 12345))
.setReason(Reason.CREATE) .setReason(Reason.CREATE)
.setPeriodYears(1) .setPeriodYears(1)
.setTargetId("foo.google") .setTargetId("foo.google")

View file

@ -66,7 +66,7 @@ final class RdeFixtures {
makeContactResource(clock, "5372808-ERL", "(◕‿◕) nevermore", "prophet@evil.みんな") makeContactResource(clock, "5372808-ERL", "(◕‿◕) nevermore", "prophet@evil.みんな")
.createVKey()) .createVKey())
.build(); .build();
HistoryEntry historyEntry = DomainHistory historyEntry =
persistResource( persistResource(
new DomainHistory.Builder() new DomainHistory.Builder()
.setDomain(domain) .setDomain(domain)

View file

@ -521,7 +521,7 @@ public class DatabaseHelper {
} }
public static BillingEvent.OneTime createBillingEventForTransfer( public static BillingEvent.OneTime createBillingEventForTransfer(
DomainBase domain, HistoryEntry historyEntry, DateTime costLookupTime, DateTime eventTime) { DomainBase domain, DomainHistory historyEntry, DateTime costLookupTime, DateTime eventTime) {
return new BillingEvent.OneTime.Builder() return new BillingEvent.OneTime.Builder()
.setReason(Reason.TRANSFER) .setReason(Reason.TRANSFER)
.setTargetId(domain.getDomainName()) .setTargetId(domain.getDomainName())

View file

@ -25,10 +25,10 @@ import static org.junit.Assert.assertThrows;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.model.EppResource;
import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.Period; import google.registry.model.domain.Period;
import google.registry.model.eppcommon.Trid; import google.registry.model.eppcommon.Trid;
import google.registry.model.poll.PollMessage; import google.registry.model.poll.PollMessage;
@ -49,7 +49,7 @@ class DedupeOneTimeBillingEventIdsCommandTest
extends CommandTestCase<DedupeOneTimeBillingEventIdsCommand> { extends CommandTestCase<DedupeOneTimeBillingEventIdsCommand> {
DomainBase domain; DomainBase domain;
HistoryEntry historyEntry; DomainHistory historyEntry;
PollMessage.Autorenew autorenewToResave; PollMessage.Autorenew autorenewToResave;
BillingEvent.OneTime billingEventToResave; BillingEvent.OneTime billingEventToResave;
@ -111,7 +111,7 @@ class DedupeOneTimeBillingEventIdsCommandTest
.build()); .build());
} }
private BillingEvent.OneTime persistBillingEvent(HistoryEntry historyEntry) { private BillingEvent.OneTime persistBillingEvent(DomainHistory historyEntry) {
return persistResource( return persistResource(
new BillingEvent.OneTime.Builder() new BillingEvent.OneTime.Builder()
.setClientId("a registrar") .setClientId("a registrar")
@ -126,9 +126,10 @@ class DedupeOneTimeBillingEventIdsCommandTest
.build()); .build());
} }
private HistoryEntry persistHistoryEntry(EppResource parent) { private DomainHistory persistHistoryEntry(DomainBase parent) {
return persistResource( return persistResource(
HistoryEntry.createBuilderForResource(parent) new DomainHistory.Builder()
.setDomain(parent)
.setType(HistoryEntry.Type.DOMAIN_CREATE) .setType(HistoryEntry.Type.DOMAIN_CREATE)
.setPeriod(Period.create(1, Period.Unit.YEARS)) .setPeriod(Period.create(1, Period.Unit.YEARS))
.setXmlBytes("<xml></xml>".getBytes(UTF_8)) .setXmlBytes("<xml></xml>".getBytes(UTF_8))

View file

@ -41,6 +41,7 @@ import google.registry.batch.RelockDomainAction;
import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.HistoryEntry;
@ -479,7 +480,8 @@ public final class DomainLockUtilsTest {
private void verifyProperlyLockedDomain(boolean isAdmin) { private void verifyProperlyLockedDomain(boolean isAdmin) {
assertThat(loadByEntity(domain).getStatusValues()) assertThat(loadByEntity(domain).getStatusValues())
.containsAtLeastElementsIn(REGISTRY_LOCK_STATUSES); .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.getRequestedByRegistrar()).isEqualTo(!isAdmin);
assertThat(historyEntry.getBySuperuser()).isEqualTo(isAdmin); assertThat(historyEntry.getBySuperuser()).isEqualTo(isAdmin);
assertThat(historyEntry.getReason()) assertThat(historyEntry.getReason())
@ -493,8 +495,8 @@ public final class DomainLockUtilsTest {
private void verifyProperlyUnlockedDomain(boolean isAdmin) { private void verifyProperlyUnlockedDomain(boolean isAdmin) {
assertThat(loadByEntity(domain).getStatusValues()).containsNoneIn(REGISTRY_LOCK_STATUSES); assertThat(loadByEntity(domain).getStatusValues()).containsNoneIn(REGISTRY_LOCK_STATUSES);
ImmutableList<HistoryEntry> historyEntries = ImmutableList<DomainHistory> historyEntries =
getHistoryEntriesOfType(domain, HistoryEntry.Type.DOMAIN_UPDATE); getHistoryEntriesOfType(domain, HistoryEntry.Type.DOMAIN_UPDATE, DomainHistory.class);
assertThat(historyEntries.size()).isEqualTo(2); assertThat(historyEntries.size()).isEqualTo(2);
historyEntries.forEach( historyEntries.forEach(
entry -> { entry -> {
@ -514,11 +516,11 @@ public final class DomainLockUtilsTest {
assertThat(loadByEntity(domain)).isEqualTo(domain); assertThat(loadByEntity(domain)).isEqualTo(domain);
} }
private void assertBillingEvent(HistoryEntry historyEntry) { private void assertBillingEvent(DomainHistory historyEntry) {
assertBillingEvents(ImmutableList.of(historyEntry)); assertBillingEvents(ImmutableList.of(historyEntry));
} }
private void assertBillingEvents(ImmutableList<HistoryEntry> historyEntries) { private void assertBillingEvents(ImmutableList<DomainHistory> historyEntries) {
Set<BillingEvent> expectedEvents = Set<BillingEvent> expectedEvents =
historyEntries.stream() historyEntries.stream()
.map( .map(

View file

@ -26,6 +26,7 @@ import google.registry.flows.EppTestCase;
import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.reporting.HistoryEntry.Type; import google.registry.model.reporting.HistoryEntry.Type;
import google.registry.testing.AppEngineExtension; import google.registry.testing.AppEngineExtension;
import google.registry.util.Clock; import google.registry.util.Clock;
@ -149,7 +150,7 @@ class EppLifecycleToolsTest extends EppTestCase {
.setPeriodYears(4) .setPeriodYears(4)
.setEventTime(DateTime.parse("2000-06-07T00:00:00Z")) .setEventTime(DateTime.parse("2000-06-07T00:00:00Z"))
.setBillingTime(DateTime.parse("2000-06-12T00: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(); .build();
assertBillingEventsForResource( assertBillingEventsForResource(
@ -159,19 +160,19 @@ class EppLifecycleToolsTest extends EppTestCase {
// The initial autorenew billing event, which was closed at the time of the explicit renew. // The initial autorenew billing event, which was closed at the time of the explicit renew.
makeRecurringBillingEvent( makeRecurringBillingEvent(
domain, domain,
getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE), getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE, DomainHistory.class),
createTime.plusYears(2), createTime.plusYears(2),
DateTime.parse("2000-06-07T00:00:00.000Z")), DateTime.parse("2000-06-07T00:00:00.000Z")),
// The renew's autorenew billing event, which was closed at the time of the unrenew. // The renew's autorenew billing event, which was closed at the time of the unrenew.
makeRecurringBillingEvent( makeRecurringBillingEvent(
domain, domain,
getOnlyHistoryEntryOfType(domain, Type.DOMAIN_RENEW), getOnlyHistoryEntryOfType(domain, Type.DOMAIN_RENEW, DomainHistory.class),
DateTime.parse("2006-06-01T00:02:00.000Z"), DateTime.parse("2006-06-01T00:02:00.000Z"),
DateTime.parse("2001-06-07T00:00:00.000Z")), DateTime.parse("2001-06-07T00:00:00.000Z")),
// The remaining active autorenew billing event which was created by the unrenew. // The remaining active autorenew billing event which was created by the unrenew.
makeRecurringBillingEvent( makeRecurringBillingEvent(
domain, domain,
getOnlyHistoryEntryOfType(domain, Type.SYNTHETIC), getOnlyHistoryEntryOfType(domain, Type.SYNTHETIC, DomainHistory.class),
DateTime.parse("2003-06-01T00:02:00.000Z"), DateTime.parse("2003-06-01T00:02:00.000Z"),
END_OF_TIME)); END_OF_TIME));

View file

@ -41,10 +41,10 @@ import google.registry.model.billing.BillingEvent.Flag;
import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.contact.ContactResource; import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.StatusValue;
import google.registry.model.ofy.Ofy; import google.registry.model.ofy.Ofy;
import google.registry.model.poll.PollMessage; import google.registry.model.poll.PollMessage;
import google.registry.model.reporting.HistoryEntry;
import google.registry.testing.DualDatabaseTest; import google.registry.testing.DualDatabaseTest;
import google.registry.testing.InjectExtension; import google.registry.testing.InjectExtension;
import google.registry.testing.TestOfyAndSql; import google.registry.testing.TestOfyAndSql;
@ -132,7 +132,7 @@ public class UnrenewDomainCommandTest extends CommandTestCase<UnrenewDomainComma
.bySuperuser(true) .bySuperuser(true)
.and() .and()
.hasMetadataRequestedByRegistrar(false); .hasMetadataRequestedByRegistrar(false);
HistoryEntry synthetic = getOnlyHistoryEntryOfType(domain, SYNTHETIC); DomainHistory synthetic = getOnlyHistoryEntryOfType(domain, SYNTHETIC, DomainHistory.class);
assertBillingEventsEqual( assertBillingEventsEqual(
loadByKey(domain.getAutorenewBillingEvent()), loadByKey(domain.getAutorenewBillingEvent()),

View file

@ -42,7 +42,6 @@ import google.registry.model.domain.GracePeriod;
import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
import google.registry.model.ofy.Ofy; import google.registry.model.ofy.Ofy;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey; import google.registry.persistence.VKey;
import google.registry.testing.DualDatabaseTest; import google.registry.testing.DualDatabaseTest;
import google.registry.testing.InjectExtension; import google.registry.testing.InjectExtension;
@ -293,7 +292,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
@TestOfyAndSql @TestOfyAndSql
void testSuccess_disableAutorenew_inAutorenewGracePeriod() throws Exception { void testSuccess_disableAutorenew_inAutorenewGracePeriod() throws Exception {
HistoryEntry createHistoryEntry = DomainHistory createHistoryEntry =
persistResource( persistResource(
new DomainHistory.Builder() new DomainHistory.Builder()
.setModificationTime(fakeClock.nowUtc()) .setModificationTime(fakeClock.nowUtc())

View file

@ -14,23 +14,23 @@
package google.registry.tools.server; package google.registry.tools.server;
import static com.google.appengine.repackaged.com.google.common.collect.Sets.difference;
import static com.google.common.base.Predicates.in; import static com.google.common.base.Predicates.in;
import static com.google.common.base.Predicates.instanceOf; import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.base.Predicates.not; import static com.google.common.base.Predicates.not;
import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Multimaps.filterKeys; import static com.google.common.collect.Multimaps.filterKeys;
import static com.google.common.collect.Sets.difference;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.auditedOfy; import static google.registry.model.ofy.ObjectifyService.auditedOfy;
import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.persistActiveContact; import static google.registry.testing.DatabaseHelper.persistActiveContact;
import static google.registry.testing.DatabaseHelper.persistActiveDomain; import static google.registry.testing.DatabaseHelper.persistActiveDomain;
import static google.registry.testing.DatabaseHelper.persistActiveHost; import static google.registry.testing.DatabaseHelper.persistActiveHost;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import com.google.appengine.api.datastore.Entity; import com.google.appengine.api.datastore.Entity;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -42,6 +42,7 @@ import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.contact.ContactResource; import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
import google.registry.model.index.EppResourceIndex; import google.registry.model.index.EppResourceIndex;
import google.registry.model.index.ForeignKeyIndex.ForeignKeyContactIndex; import google.registry.model.index.ForeignKeyIndex.ForeignKeyContactIndex;
@ -49,6 +50,7 @@ import google.registry.model.index.ForeignKeyIndex.ForeignKeyDomainIndex;
import google.registry.model.index.ForeignKeyIndex.ForeignKeyHostIndex; import google.registry.model.index.ForeignKeyIndex.ForeignKeyHostIndex;
import google.registry.model.poll.PollMessage; import google.registry.model.poll.PollMessage;
import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.HistoryEntry;
import google.registry.testing.DatabaseHelper;
import google.registry.testing.FakeResponse; import google.registry.testing.FakeResponse;
import google.registry.testing.mapreduce.MapreduceTestCase; import google.registry.testing.mapreduce.MapreduceTestCase;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -111,8 +113,9 @@ class KillAllEppResourcesActionTest extends MapreduceTestCase<KillAllEppResource
.setModificationTime(resource.getCreationTime()) .setModificationTime(resource.getCreationTime())
.setType(HISTORY_ENTRY_CREATE_TYPES.get(resource.getClass())) .setType(HISTORY_ENTRY_CREATE_TYPES.get(resource.getClass()))
.build(); .build();
for (ImmutableObject descendant : ImmutableList.Builder<ImmutableObject> descendantBuilder =
asList( new ImmutableList.Builder<ImmutableObject>()
.add(
history, history,
new PollMessage.OneTime.Builder() new PollMessage.OneTime.Builder()
.setParent(history) .setParent(history)
@ -123,9 +126,11 @@ class KillAllEppResourcesActionTest extends MapreduceTestCase<KillAllEppResource
.setParent(history) .setParent(history)
.setClientId("") .setClientId("")
.setEventTime(START_OF_TIME) .setEventTime(START_OF_TIME)
.build(), .build());
if (history instanceof DomainHistory) {
descendantBuilder.add(
new BillingEvent.OneTime.Builder() new BillingEvent.OneTime.Builder()
.setParent(history) .setParent((DomainHistory) history)
.setBillingTime(START_OF_TIME) .setBillingTime(START_OF_TIME)
.setEventTime(START_OF_TIME) .setEventTime(START_OF_TIME)
.setClientId("") .setClientId("")
@ -135,14 +140,14 @@ class KillAllEppResourcesActionTest extends MapreduceTestCase<KillAllEppResource
.setCost(Money.of(CurrencyUnit.USD, 1)) .setCost(Money.of(CurrencyUnit.USD, 1))
.build(), .build(),
new BillingEvent.Recurring.Builder() new BillingEvent.Recurring.Builder()
.setParent(history) .setParent((DomainHistory) history)
.setEventTime(START_OF_TIME) .setEventTime(START_OF_TIME)
.setClientId("") .setClientId("")
.setTargetId("") .setTargetId("")
.setReason(Reason.RENEW) .setReason(Reason.RENEW)
.build())) { .build());
persistResource(descendant);
} }
descendantBuilder.build().forEach(DatabaseHelper::persistResource);
} }
ImmutableMultimap<String, Object> beforeContents = getDatastoreContents(); ImmutableMultimap<String, Object> beforeContents = getDatastoreContents();
assertThat(beforeContents.keySet()).containsAtLeastElementsIn(AFFECTED_KINDS); assertThat(beforeContents.keySet()).containsAtLeastElementsIn(AFFECTED_KINDS);

View file

@ -37,6 +37,7 @@ import google.registry.batch.AsyncTaskEnqueuerTest;
import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.HistoryEntry;
@ -102,7 +103,8 @@ final class RegistryLockVerifyActionTest {
assertThat(response.getStatus()).isEqualTo(SC_OK); assertThat(response.getStatus()).isEqualTo(SC_OK);
assertThat(reloadDomain().getStatusValues()).containsExactlyElementsIn(REGISTRY_LOCK_STATUSES); assertThat(reloadDomain().getStatusValues()).containsExactlyElementsIn(REGISTRY_LOCK_STATUSES);
assertThat(response.getPayload()).contains("Success: lock has been applied to example.tld"); 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.getRequestedByRegistrar()).isTrue();
assertThat(historyEntry.getBySuperuser()).isFalse(); assertThat(historyEntry.getBySuperuser()).isFalse();
assertThat(historyEntry.getReason()) assertThat(historyEntry.getReason())
@ -119,7 +121,8 @@ final class RegistryLockVerifyActionTest {
assertThat(response.getStatus()).isEqualTo(SC_OK); assertThat(response.getStatus()).isEqualTo(SC_OK);
assertThat(response.getPayload()).contains("Success: unlock has been applied to example.tld"); assertThat(response.getPayload()).contains("Success: unlock has been applied to example.tld");
assertThat(reloadDomain().getStatusValues()).containsNoneIn(REGISTRY_LOCK_STATUSES); 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.getRequestedByRegistrar()).isTrue();
assertThat(historyEntry.getBySuperuser()).isFalse(); assertThat(historyEntry.getBySuperuser()).isFalse();
assertThat(historyEntry.getReason()) assertThat(historyEntry.getReason())
@ -308,7 +311,7 @@ final class RegistryLockVerifyActionTest {
assertThat(reloadDomain()).isEqualTo(domain); assertThat(reloadDomain()).isEqualTo(domain);
} }
private void assertBillingEvent(HistoryEntry historyEntry) { private void assertBillingEvent(DomainHistory historyEntry) {
DatabaseHelper.assertBillingEvents( DatabaseHelper.assertBillingEvents(
new BillingEvent.OneTime.Builder() new BillingEvent.OneTime.Builder()
.setReason(Reason.SERVER_STATUS) .setReason(Reason.SERVER_STATUS)

View file

@ -6,7 +6,7 @@ class google.registry.model.UpdateAutoTimestamp {
} }
class google.registry.model.billing.BillingEvent$Cancellation { class google.registry.model.billing.BillingEvent$Cancellation {
@Id java.lang.Long id; @Id java.lang.Long id;
@Parent com.googlecode.objectify.Key<? extends google.registry.model.reporting.HistoryEntry> parent; @Parent com.googlecode.objectify.Key<google.registry.model.domain.DomainHistory> parent;
google.registry.model.billing.BillingEvent$Reason reason; google.registry.model.billing.BillingEvent$Reason reason;
google.registry.persistence.BillingVKey$BillingEventVKey refOneTime; google.registry.persistence.BillingVKey$BillingEventVKey refOneTime;
google.registry.persistence.BillingVKey$BillingRecurrenceVKey refRecurring; google.registry.persistence.BillingVKey$BillingRecurrenceVKey refRecurring;
@ -27,7 +27,7 @@ enum google.registry.model.billing.BillingEvent$Flag {
} }
class google.registry.model.billing.BillingEvent$Modification { class google.registry.model.billing.BillingEvent$Modification {
@Id java.lang.Long id; @Id java.lang.Long id;
@Parent com.googlecode.objectify.Key<? extends google.registry.model.reporting.HistoryEntry> parent; @Parent com.googlecode.objectify.Key<google.registry.model.domain.DomainHistory> parent;
com.googlecode.objectify.Key<google.registry.model.billing.BillingEvent$OneTime> eventRef; com.googlecode.objectify.Key<google.registry.model.billing.BillingEvent$OneTime> eventRef;
google.registry.model.billing.BillingEvent$Reason reason; google.registry.model.billing.BillingEvent$Reason reason;
java.lang.String clientId; java.lang.String clientId;
@ -39,7 +39,7 @@ class google.registry.model.billing.BillingEvent$Modification {
} }
class google.registry.model.billing.BillingEvent$OneTime { class google.registry.model.billing.BillingEvent$OneTime {
@Id java.lang.Long id; @Id java.lang.Long id;
@Parent com.googlecode.objectify.Key<? extends google.registry.model.reporting.HistoryEntry> parent; @Parent com.googlecode.objectify.Key<google.registry.model.domain.DomainHistory> parent;
google.registry.model.billing.BillingEvent$Reason reason; google.registry.model.billing.BillingEvent$Reason reason;
google.registry.persistence.VKey<google.registry.model.billing.BillingEvent$Recurring> cancellationMatchingBillingEvent; google.registry.persistence.VKey<google.registry.model.billing.BillingEvent$Recurring> cancellationMatchingBillingEvent;
google.registry.persistence.VKey<google.registry.model.domain.token.AllocationToken> allocationToken; google.registry.persistence.VKey<google.registry.model.domain.token.AllocationToken> allocationToken;
@ -63,7 +63,7 @@ enum google.registry.model.billing.BillingEvent$Reason {
} }
class google.registry.model.billing.BillingEvent$Recurring { class google.registry.model.billing.BillingEvent$Recurring {
@Id java.lang.Long id; @Id java.lang.Long id;
@Parent com.googlecode.objectify.Key<? extends google.registry.model.reporting.HistoryEntry> parent; @Parent com.googlecode.objectify.Key<google.registry.model.domain.DomainHistory> parent;
google.registry.model.billing.BillingEvent$Reason reason; google.registry.model.billing.BillingEvent$Reason reason;
google.registry.model.common.TimeOfYear recurrenceTimeOfYear; google.registry.model.common.TimeOfYear recurrenceTimeOfYear;
java.lang.String clientId; java.lang.String clientId;