mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 16:37:13 +02:00
Simplify DomainTransferRequestFlowTest superuser extension testing
This CL deduplicates these two methods in DomainTransferRequestFlowTest: - assertHistoryEntriesContainTransferBillingEventsOrGracePeriods() - assertHistoryEntriesDoNotContainTransferBillingEventsOrGracePeriods() Instead, we have one method with an extra parameter dictating whether or not we should expect a transfer billing event (yes normally, no in the case of a superuser transfer w/ 0 period). This is less code overall and avoids drift between the normal vs special case assertions (if people make changes in one but forget to do so in the other). Also, the methods as named were a little confusing because the "Contain" vs "DoNotContain" naming suggests that the methods are asserting opposite things, but actually they assert some things in common (like the existence of autorenew billing events, and that pre-transfer grace periods are cleared). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=170540417
This commit is contained in:
parent
a50ef39c04
commit
3c0b17dc6f
1 changed files with 53 additions and 93 deletions
|
@ -199,6 +199,7 @@ public class DomainTransferRequestFlowTest
|
||||||
implicitTransferTime,
|
implicitTransferTime,
|
||||||
transferCost,
|
transferCost,
|
||||||
originalGracePeriods,
|
originalGracePeriods,
|
||||||
|
/* expectTransferBillingEvent = */ true,
|
||||||
extraExpectedBillingEvents);
|
extraExpectedBillingEvents);
|
||||||
|
|
||||||
assertPollMessagesEmitted(
|
assertPollMessagesEmitted(
|
||||||
|
@ -213,34 +214,46 @@ public class DomainTransferRequestFlowTest
|
||||||
DateTime implicitTransferTime,
|
DateTime implicitTransferTime,
|
||||||
Optional<Money> transferCost,
|
Optional<Money> transferCost,
|
||||||
ImmutableSet<GracePeriod> originalGracePeriods,
|
ImmutableSet<GracePeriod> originalGracePeriods,
|
||||||
|
boolean expectTransferBillingEvent,
|
||||||
BillingEvent.Cancellation.Builder... extraExpectedBillingEvents)
|
BillingEvent.Cancellation.Builder... extraExpectedBillingEvents)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Registry registry = Registry.get(domain.getTld());
|
Registry registry = Registry.get(domain.getTld());
|
||||||
final HistoryEntry historyEntryTransferRequest =
|
final HistoryEntry historyEntryTransferRequest =
|
||||||
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REQUEST);
|
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REQUEST);
|
||||||
|
|
||||||
// A BillingEvent should be created AUTOMATIC_TRANSFER_DAYS in the future, for the case when the
|
Optional<BillingEvent.OneTime> optionalTransferBillingEvent;
|
||||||
// transfer is implicitly acked, but there should be no grace period yet. There should also be
|
if (expectTransferBillingEvent) {
|
||||||
// two autorenew billing events, one for the losing client that ends at the transfer time, and
|
// For normal transfers, a BillingEvent should be created AUTOMATIC_TRANSFER_DAYS in the
|
||||||
// one for the gaining client that starts at that time.
|
// future, for the case when the transfer is implicitly acked.
|
||||||
BillingEvent.OneTime transferBillingEvent = new BillingEvent.OneTime.Builder()
|
optionalTransferBillingEvent =
|
||||||
.setReason(Reason.TRANSFER)
|
Optional.of(
|
||||||
.setTargetId(domain.getFullyQualifiedDomainName())
|
new BillingEvent.OneTime.Builder()
|
||||||
.setEventTime(implicitTransferTime)
|
.setReason(Reason.TRANSFER)
|
||||||
.setBillingTime(implicitTransferTime.plus(registry.getTransferGracePeriodLength()))
|
.setTargetId(domain.getFullyQualifiedDomainName())
|
||||||
.setClientId("NewRegistrar")
|
.setEventTime(implicitTransferTime)
|
||||||
.setCost(transferCost.or(Money.of(USD, 11)))
|
.setBillingTime(
|
||||||
.setPeriodYears(1)
|
implicitTransferTime.plus(registry.getTransferGracePeriodLength()))
|
||||||
.setParent(historyEntryTransferRequest)
|
.setClientId("NewRegistrar")
|
||||||
.build();
|
.setCost(transferCost.or(Money.of(USD, 11)))
|
||||||
|
.setPeriodYears(1)
|
||||||
|
.setParent(historyEntryTransferRequest)
|
||||||
|
.build());
|
||||||
|
} else {
|
||||||
|
// Superuser transfers with no bundled renewal have no transfer billing event.
|
||||||
|
optionalTransferBillingEvent = Optional.<BillingEvent.OneTime>absent();
|
||||||
|
}
|
||||||
|
// Assert that the billing events we expect are present - any extra cancellations, then the
|
||||||
|
// transfer billing event if there is one, plus two autorenew billing events, one for the losing
|
||||||
|
// client ending at the transfer time, and one for the gaining client starting at the domain's
|
||||||
|
// post-transfer expiration time.
|
||||||
assertBillingEvents(FluentIterable.from(extraExpectedBillingEvents)
|
assertBillingEvents(FluentIterable.from(extraExpectedBillingEvents)
|
||||||
.transform(new Function<BillingEvent.Cancellation.Builder, BillingEvent>() {
|
.transform(new Function<BillingEvent.Cancellation.Builder, BillingEvent>() {
|
||||||
@Override
|
@Override
|
||||||
public BillingEvent apply(Builder builder) {
|
public BillingEvent apply(Builder builder) {
|
||||||
return builder.setParent(historyEntryTransferRequest).build();
|
return builder.setParent(historyEntryTransferRequest).build();
|
||||||
}})
|
}})
|
||||||
|
.append(optionalTransferBillingEvent.asSet())
|
||||||
.append(
|
.append(
|
||||||
transferBillingEvent,
|
|
||||||
// All of the other transfer flow tests happen on day 3 of the transfer, but the initial
|
// All of the other transfer flow tests happen on day 3 of the transfer, but the initial
|
||||||
// request by definition takes place on day 1, so we need to edit the times in the
|
// request by definition takes place on day 1, so we need to edit the times in the
|
||||||
// autorenew events from the base test case.
|
// autorenew events from the base test case.
|
||||||
|
@ -258,71 +271,24 @@ public class DomainTransferRequestFlowTest
|
||||||
assertThat(domainAutorenewEvent.getRecurrenceEndTime()).isEqualTo(implicitTransferTime);
|
assertThat(domainAutorenewEvent.getRecurrenceEndTime()).isEqualTo(implicitTransferTime);
|
||||||
// The original grace periods should remain untouched.
|
// The original grace periods should remain untouched.
|
||||||
assertThat(domain.getGracePeriods()).containsExactlyElementsIn(originalGracePeriods);
|
assertThat(domain.getGracePeriods()).containsExactlyElementsIn(originalGracePeriods);
|
||||||
// If we fast forward AUTOMATIC_TRANSFER_DAYS, we should see the grace period appear, the
|
// If we fast forward AUTOMATIC_TRANSFER_DAYS, the transfer should have cleared out all other
|
||||||
// transfer should have happened, and all other grace periods should be gone. Also, both the
|
// grace periods, but expect a transfer grace period (if there was a transfer billing event).
|
||||||
// gaining and losing registrars should have a new poll message.
|
|
||||||
DomainResource domainAfterAutomaticTransfer = domain.cloneProjectedAtTime(implicitTransferTime);
|
DomainResource domainAfterAutomaticTransfer = domain.cloneProjectedAtTime(implicitTransferTime);
|
||||||
assertGracePeriods(
|
if (expectTransferBillingEvent) {
|
||||||
domainAfterAutomaticTransfer.getGracePeriods(),
|
assertGracePeriods(
|
||||||
ImmutableMap.of(
|
domainAfterAutomaticTransfer.getGracePeriods(),
|
||||||
GracePeriod.create(
|
ImmutableMap.of(
|
||||||
GracePeriodStatus.TRANSFER,
|
GracePeriod.create(
|
||||||
clock.nowUtc()
|
GracePeriodStatus.TRANSFER,
|
||||||
.plus(registry.getAutomaticTransferLength())
|
implicitTransferTime.plus(registry.getTransferGracePeriodLength()),
|
||||||
.plus(registry.getTransferGracePeriodLength()),
|
"NewRegistrar",
|
||||||
"NewRegistrar",
|
null),
|
||||||
null),
|
optionalTransferBillingEvent.get()));
|
||||||
transferBillingEvent));
|
} else {
|
||||||
}
|
assertGracePeriods(
|
||||||
|
domainAfterAutomaticTransfer.getGracePeriods(),
|
||||||
public void assertHistoryEntriesDoNotContainTransferBillingEventsOrGracePeriods(
|
ImmutableMap.<GracePeriod, BillingEvent>of());
|
||||||
DateTime expectedExpirationTime,
|
}
|
||||||
DateTime implicitTransferTime,
|
|
||||||
ImmutableSet<GracePeriod> originalGracePeriods,
|
|
||||||
BillingEvent.Cancellation.Builder... extraExpectedBillingEvents)
|
|
||||||
throws Exception {
|
|
||||||
final HistoryEntry historyEntryTransferRequest =
|
|
||||||
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REQUEST);
|
|
||||||
|
|
||||||
// There should also be two autorenew billing events, one for the losing client that ends at the
|
|
||||||
// transfer time, and one for the gaining client that starts at that time.
|
|
||||||
// All of the other transfer flow tests happen on day 3 of the transfer, but the initial
|
|
||||||
// request by definition takes place on day 1, so we need to edit the times in the
|
|
||||||
// autorenew events from the base test case.
|
|
||||||
assertBillingEvents(
|
|
||||||
FluentIterable.from(extraExpectedBillingEvents)
|
|
||||||
.transform(
|
|
||||||
new Function<BillingEvent.Cancellation.Builder, BillingEvent>() {
|
|
||||||
@Override
|
|
||||||
public BillingEvent apply(Builder builder) {
|
|
||||||
return builder.setParent(historyEntryTransferRequest).build();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.append(
|
|
||||||
getLosingClientAutorenewEvent()
|
|
||||||
.asBuilder()
|
|
||||||
.setRecurrenceEndTime(implicitTransferTime)
|
|
||||||
.build(),
|
|
||||||
getGainingClientAutorenewEvent()
|
|
||||||
.asBuilder()
|
|
||||||
.setEventTime(expectedExpirationTime)
|
|
||||||
.build())
|
|
||||||
.toArray(BillingEvent.class));
|
|
||||||
// The domain's autorenew billing event should still point to the losing client's event.
|
|
||||||
BillingEvent.Recurring domainAutorenewEvent =
|
|
||||||
ofy().load().key(domain.getAutorenewBillingEvent()).now();
|
|
||||||
assertThat(domainAutorenewEvent.getClientId()).isEqualTo("TheRegistrar");
|
|
||||||
assertThat(domainAutorenewEvent.getRecurrenceEndTime()).isEqualTo(implicitTransferTime);
|
|
||||||
// The original grace periods should remain untouched.
|
|
||||||
assertThat(domain.getGracePeriods()).containsExactlyElementsIn(originalGracePeriods);
|
|
||||||
// If we fast forward AUTOMATIC_TRANSFER_DAYS, we should see the grace period appear, the
|
|
||||||
// transfer should have happened, and all other grace periods should be gone. Also, both the
|
|
||||||
// gaining and losing registrars should have a new poll message.
|
|
||||||
DomainResource domainAfterAutomaticTransfer = domain.cloneProjectedAtTime(implicitTransferTime);
|
|
||||||
// There should be no grace period.
|
|
||||||
assertGracePeriods(
|
|
||||||
domainAfterAutomaticTransfer.getGracePeriods(),
|
|
||||||
ImmutableMap.<GracePeriod, BillingEvent>of());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertPollMessagesEmitted(
|
private void assertPollMessagesEmitted(
|
||||||
|
@ -490,20 +456,14 @@ public class DomainTransferRequestFlowTest
|
||||||
.hasOtherClientId("TheRegistrar");
|
.hasOtherClientId("TheRegistrar");
|
||||||
assertAboutHosts().that(subordinateHost).hasNoHistoryEntries();
|
assertAboutHosts().that(subordinateHost).hasNoHistoryEntries();
|
||||||
|
|
||||||
if (expectedPeriod.getValue() == 0) {
|
boolean expectTransferBillingEvent = expectedPeriod.getValue() != 0;
|
||||||
assertHistoryEntriesDoNotContainTransferBillingEventsOrGracePeriods(
|
assertHistoryEntriesContainBillingEventsAndGracePeriods(
|
||||||
expectedExpirationTime,
|
expectedExpirationTime,
|
||||||
implicitTransferTime,
|
implicitTransferTime,
|
||||||
originalGracePeriods,
|
transferCost,
|
||||||
extraExpectedBillingEvents);
|
originalGracePeriods,
|
||||||
} else {
|
expectTransferBillingEvent,
|
||||||
assertHistoryEntriesContainBillingEventsAndGracePeriods(
|
extraExpectedBillingEvents);
|
||||||
expectedExpirationTime,
|
|
||||||
implicitTransferTime,
|
|
||||||
transferCost,
|
|
||||||
originalGracePeriods,
|
|
||||||
extraExpectedBillingEvents);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertPollMessagesEmitted(
|
assertPollMessagesEmitted(
|
||||||
expectedExpirationTime,
|
expectedExpirationTime,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue