mirror of
https://github.com/google/nomulus.git
synced 2025-07-09 04:33:28 +02:00
Add replay extension to more domain tests (#893)
* Add replay extension to more domain tests Add replay to DomainRenewFlowTest and DomainUpdateFlowTest. * Formatting fix
This commit is contained in:
parent
a8effe8a1e
commit
c7e6192929
2 changed files with 85 additions and 36 deletions
|
@ -26,6 +26,7 @@ import static google.registry.testing.DatabaseHelper.newDomainBase;
|
||||||
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
|
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
|
||||||
import static google.registry.testing.DatabaseHelper.persistDeletedDomain;
|
import static google.registry.testing.DatabaseHelper.persistDeletedDomain;
|
||||||
import static google.registry.testing.DatabaseHelper.persistResource;
|
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||||
|
import static google.registry.testing.DatabaseHelper.persistResources;
|
||||||
import static google.registry.testing.DomainBaseSubject.assertAboutDomains;
|
import static google.registry.testing.DomainBaseSubject.assertAboutDomains;
|
||||||
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
|
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
|
||||||
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
|
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
|
||||||
|
@ -69,12 +70,17 @@ import google.registry.model.registry.Registry;
|
||||||
import google.registry.model.reporting.DomainTransactionRecord;
|
import google.registry.model.reporting.DomainTransactionRecord;
|
||||||
import google.registry.model.reporting.DomainTransactionRecord.TransactionReportField;
|
import google.registry.model.reporting.DomainTransactionRecord.TransactionReportField;
|
||||||
import google.registry.model.reporting.HistoryEntry;
|
import google.registry.model.reporting.HistoryEntry;
|
||||||
|
import google.registry.testing.ReplayExtension;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Order;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
||||||
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
/** Unit tests for {@link DomainRenewFlow}. */
|
/** Unit tests for {@link DomainRenewFlow}. */
|
||||||
class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBase> {
|
class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBase> {
|
||||||
|
@ -96,23 +102,32 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
|
||||||
|
|
||||||
private final DateTime expirationTime = DateTime.parse("2000-04-03T22:00:00.0Z");
|
private final DateTime expirationTime = DateTime.parse("2000-04-03T22:00:00.0Z");
|
||||||
|
|
||||||
|
@Order(value = Order.DEFAULT - 3)
|
||||||
|
@RegisterExtension
|
||||||
|
final SetClockExtension setClockExtension = new SetClockExtension();
|
||||||
|
|
||||||
|
@Order(value = Order.DEFAULT - 2)
|
||||||
|
@RegisterExtension
|
||||||
|
final ReplayExtension replayExtension = new ReplayExtension(clock);
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void initDomainTest() {
|
void initDomainTest() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
clock.setTo(expirationTime.minusMillis(2));
|
|
||||||
setEppInput("domain_renew.xml", ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "5"));
|
setEppInput("domain_renew.xml", ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "5"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void persistDomain(StatusValue... statusValues) throws Exception {
|
private void persistDomain(StatusValue... statusValues) throws Exception {
|
||||||
DomainBase domain = newDomainBase(getUniqueIdFromCommand());
|
DomainBase domain = newDomainBase(getUniqueIdFromCommand());
|
||||||
|
tm().transact(
|
||||||
|
() -> {
|
||||||
|
try {
|
||||||
HistoryEntry historyEntryDomainCreate =
|
HistoryEntry historyEntryDomainCreate =
|
||||||
persistResource(
|
|
||||||
new HistoryEntry.Builder()
|
new HistoryEntry.Builder()
|
||||||
.setParent(domain)
|
.setParent(domain)
|
||||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||||
.build());
|
.setModificationTime(clock.nowUtc())
|
||||||
|
.build();
|
||||||
BillingEvent.Recurring autorenewEvent =
|
BillingEvent.Recurring autorenewEvent =
|
||||||
persistResource(
|
|
||||||
new BillingEvent.Recurring.Builder()
|
new BillingEvent.Recurring.Builder()
|
||||||
.setReason(Reason.RENEW)
|
.setReason(Reason.RENEW)
|
||||||
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
|
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
|
||||||
|
@ -121,9 +136,8 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
|
||||||
.setEventTime(expirationTime)
|
.setEventTime(expirationTime)
|
||||||
.setRecurrenceEndTime(END_OF_TIME)
|
.setRecurrenceEndTime(END_OF_TIME)
|
||||||
.setParent(historyEntryDomainCreate)
|
.setParent(historyEntryDomainCreate)
|
||||||
.build());
|
.build();
|
||||||
PollMessage.Autorenew autorenewPollMessage =
|
PollMessage.Autorenew autorenewPollMessage =
|
||||||
persistResource(
|
|
||||||
new PollMessage.Autorenew.Builder()
|
new PollMessage.Autorenew.Builder()
|
||||||
.setTargetId(getUniqueIdFromCommand())
|
.setTargetId(getUniqueIdFromCommand())
|
||||||
.setClientId("TheRegistrar")
|
.setClientId("TheRegistrar")
|
||||||
|
@ -131,15 +145,23 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
|
||||||
.setAutorenewEndTime(END_OF_TIME)
|
.setAutorenewEndTime(END_OF_TIME)
|
||||||
.setMsg("Domain was auto-renewed.")
|
.setMsg("Domain was auto-renewed.")
|
||||||
.setParent(historyEntryDomainCreate)
|
.setParent(historyEntryDomainCreate)
|
||||||
.build());
|
.build();
|
||||||
persistResource(
|
DomainBase newDomain =
|
||||||
domain
|
domain
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
.setRegistrationExpirationTime(expirationTime)
|
.setRegistrationExpirationTime(expirationTime)
|
||||||
.setStatusValues(ImmutableSet.copyOf(statusValues))
|
.setStatusValues(ImmutableSet.copyOf(statusValues))
|
||||||
.setAutorenewBillingEvent(autorenewEvent.createVKey())
|
.setAutorenewBillingEvent(autorenewEvent.createVKey())
|
||||||
.setAutorenewPollMessage(autorenewPollMessage.createVKey())
|
.setAutorenewPollMessage(autorenewPollMessage.createVKey())
|
||||||
.build());
|
.build();
|
||||||
|
persistResources(
|
||||||
|
ImmutableSet.of(
|
||||||
|
historyEntryDomainCreate, autorenewEvent,
|
||||||
|
autorenewPollMessage, newDomain));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Error persisting domain", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,6 +277,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSuccess() throws Exception {
|
void testSuccess() throws Exception {
|
||||||
|
clock.advanceOneMilli();
|
||||||
persistDomain();
|
persistDomain();
|
||||||
doSuccessfulTest(
|
doSuccessfulTest(
|
||||||
"domain_renew_response.xml",
|
"domain_renew_response.xml",
|
||||||
|
@ -789,4 +812,21 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
|
||||||
TransactionReportField.netRenewsFieldFromYears(5),
|
TransactionReportField.netRenewsFieldFromYears(5),
|
||||||
1));
|
1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Local extension so we can set the clock correctly prior to using it to define basic entities in
|
||||||
|
* AppEngineExtension.
|
||||||
|
*
|
||||||
|
* <p>This has to happen first, we'll get timestamp inversions if we try to set the clock after
|
||||||
|
* these objects are created.
|
||||||
|
*/
|
||||||
|
class SetClockExtension implements BeforeEachCallback {
|
||||||
|
@Override
|
||||||
|
public void beforeEach(ExtensionContext context) {
|
||||||
|
// we have to go far enough back before the expiration time so that the clock advances we do
|
||||||
|
// after each persist don't move us into a grace period. The current value is likely beyond
|
||||||
|
// what is necessary, but this doesn't hurt.
|
||||||
|
clock.setTo(expirationTime.minusMillis(20));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,11 +90,14 @@ 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;
|
||||||
import google.registry.persistence.VKey;
|
import google.registry.persistence.VKey;
|
||||||
|
import google.registry.testing.ReplayExtension;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Order;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
/** Unit tests for {@link DomainUpdateFlow}. */
|
/** Unit tests for {@link DomainUpdateFlow}. */
|
||||||
class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, DomainBase> {
|
class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, DomainBase> {
|
||||||
|
@ -112,6 +115,10 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
||||||
private ContactResource mak21Contact;
|
private ContactResource mak21Contact;
|
||||||
private ContactResource unusedContact;
|
private ContactResource unusedContact;
|
||||||
|
|
||||||
|
@Order(value = Order.DEFAULT - 2)
|
||||||
|
@RegisterExtension
|
||||||
|
final ReplayExtension replayExtension = new ReplayExtension(clock);
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void initDomainTest() {
|
void initDomainTest() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
|
@ -146,6 +153,7 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
||||||
persistResource(
|
persistResource(
|
||||||
new HistoryEntry.Builder()
|
new HistoryEntry.Builder()
|
||||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||||
|
.setModificationTime(clock.nowUtc())
|
||||||
.setParent(domain)
|
.setParent(domain)
|
||||||
.build());
|
.build());
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
|
@ -168,6 +176,7 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
||||||
persistResource(
|
persistResource(
|
||||||
new HistoryEntry.Builder()
|
new HistoryEntry.Builder()
|
||||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||||
|
.setModificationTime(clock.nowUtc())
|
||||||
.setParent(domain)
|
.setParent(domain)
|
||||||
.build());
|
.build());
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue