diff --git a/core/src/test/java/google/registry/flows/domain/DomainCheckFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainCheckFlowTest.java index 50cb2214a..e17c1a7f7 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainCheckFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainCheckFlowTest.java @@ -82,29 +82,21 @@ import google.registry.model.tld.Registry; import google.registry.model.tld.Registry.TldState; import google.registry.model.tld.label.ReservedList; import google.registry.testing.DatabaseHelper; -import google.registry.testing.SetClockExtension; import java.math.BigDecimal; -import org.joda.money.CurrencyUnit; import org.joda.money.Money; import org.joda.time.DateTime; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link DomainCheckFlow}. */ class DomainCheckFlowTest extends ResourceCheckFlowTestCase { - @Order(value = Order.DEFAULT - 3) - @RegisterExtension - final SetClockExtension setClockExtension = new SetClockExtension(clock, "2009-01-01T10:00:00Z"); - DomainCheckFlowTest() { setEppInput("domain_check_one_tld.xml"); + clock.setTo(DateTime.parse("2009-01-01T10:00:00Z")); } - private ReservedList createReservedList() { + private static ReservedList createReservedList() { persistResource( new AllocationToken.Builder() .setDomainName("anchor.tld") @@ -951,10 +943,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase { - @Order(value = Order.DEFAULT - 3) - @RegisterExtension - final SetClockExtension setClockExtension = - new SetClockExtension(clock, "2005-03-03T22:00:00.000Z"); - /** * The domain_info_fee.xml default substitutions common to most tests. * @@ -99,6 +92,8 @@ class DomainInfoFlowTest extends ResourceFlowTestCase { "CURRENCY", "USD", "UNIT", "y"); + private static final Pattern OK_PATTERN = Pattern.compile("\"ok\""); + private ContactResource registrant; private ContactResource contact; private Host host1; @@ -109,6 +104,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase { @BeforeEach void setup() { setEppInput("domain_info.xml"); + clock.setTo(DateTime.parse("2005-03-03T22:00:00.000Z")); sessionMetadata.setRegistrarId("NewRegistrar"); createTld("tld"); persistResource( @@ -175,7 +171,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase { String expected = loadFile(expectedXmlFilename, updateSubstitutions(substitutions, "ROID", "2FF-TLD")); if (inactive) { - expected = expected.replaceAll("\"ok\"", "\"inactive\""); + expected = OK_PATTERN.matcher(expected).replaceAll("\"inactive\""); } runFlowAssertResponse(expected); if (!expectHistoryAndBilling) { @@ -379,9 +375,9 @@ class DomainInfoFlowTest extends ResourceFlowTestCase { .setModificationTime(clock.nowUtc()) .setRegistrarId(domain.getCreationRegistrarId()) .build()); - BillingEvent.Recurring renewEvent = + Recurring renewEvent = persistResource( - new BillingEvent.Recurring.Builder() + new Recurring.Builder() .setReason(Reason.RENEW) .setFlags(ImmutableSet.of(Flag.AUTO_RENEW)) .setTargetId(getUniqueIdFromCommand()) @@ -390,7 +386,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase { .setRecurrenceEndTime(END_OF_TIME) .setDomainHistory(historyEntry) .build()); - VKey recurringVKey = renewEvent.createVKey(); + VKey recurringVKey = renewEvent.createVKey(); // Add an AUTO_RENEW grace period to the saved resource. persistResource( domain diff --git a/core/src/test/java/google/registry/flows/domain/DomainRenewFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainRenewFlowTest.java index 3e0c7440c..0faaaf3bc 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainRenewFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainRenewFlowTest.java @@ -29,7 +29,6 @@ import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.getOnlyHistoryEntryOfType; import static google.registry.testing.DatabaseHelper.loadByKey; import static google.registry.testing.DatabaseHelper.loadRegistrar; -import static google.registry.testing.DatabaseHelper.newDomain; import static google.registry.testing.DatabaseHelper.persistActiveDomain; import static google.registry.testing.DatabaseHelper.persistDeletedDomain; import static google.registry.testing.DatabaseHelper.persistPremiumList; @@ -95,16 +94,13 @@ import google.registry.model.reporting.HistoryEntry; import google.registry.model.tld.Registry; import google.registry.persistence.VKey; import google.registry.testing.DatabaseHelper; -import google.registry.testing.SetClockExtension; import java.util.Map; import javax.annotation.Nullable; import org.joda.money.Money; import org.joda.time.DateTime; import org.joda.time.Duration; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link DomainRenewFlow}. */ class DomainRenewFlowTest extends ResourceFlowTestCase { @@ -126,13 +122,9 @@ class DomainRenewFlowTest extends ResourceFlowTestCase private final DateTime expirationTime = DateTime.parse("2000-04-03T22:00:00.0Z"); - @Order(value = Order.DEFAULT - 3) - @RegisterExtension - final SetClockExtension setClockExtension = - new SetClockExtension(clock, expirationTime.minusMillis(20)); - @BeforeEach void initDomainTest() { + clock.setTo(expirationTime.minusMillis(20)); createTld("tld"); persistResource( loadRegistrar("TheRegistrar") diff --git a/core/src/test/java/google/registry/flows/poll/PollAckFlowTest.java b/core/src/test/java/google/registry/flows/poll/PollAckFlowTest.java index 1a86d7ee4..57ba255ff 100644 --- a/core/src/test/java/google/registry/flows/poll/PollAckFlowTest.java +++ b/core/src/test/java/google/registry/flows/poll/PollAckFlowTest.java @@ -32,20 +32,13 @@ import google.registry.model.contact.ContactResource; import google.registry.model.domain.Domain; import google.registry.model.poll.PollMessage; import google.registry.testing.DatabaseHelper; -import google.registry.testing.SetClockExtension; import org.joda.time.DateTime; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link PollAckFlow}. */ class PollAckFlowTest extends FlowTestCase { - @Order(value = Order.DEFAULT - 3) - @RegisterExtension - final SetClockExtension setClockExtension = new SetClockExtension(clock, "2011-01-02T01:01:01Z"); - /** This is the message id being sent in the ACK request. */ private static final long MESSAGE_ID = 3; @@ -55,6 +48,7 @@ class PollAckFlowTest extends FlowTestCase { @BeforeEach void setUp() { setEppInput("poll_ack.xml", ImmutableMap.of("MSGID", "1-3-EXAMPLE-4-3-2011")); + clock.setTo(DateTime.parse("2011-01-02T01:01:01Z")); setRegistrarIdForFlow("NewRegistrar"); createTld("example"); contact = persistActiveContact("jd1234"); diff --git a/core/src/test/java/google/registry/flows/poll/PollRequestFlowTest.java b/core/src/test/java/google/registry/flows/poll/PollRequestFlowTest.java index c9541f30d..0f7d9253e 100644 --- a/core/src/test/java/google/registry/flows/poll/PollRequestFlowTest.java +++ b/core/src/test/java/google/registry/flows/poll/PollRequestFlowTest.java @@ -40,19 +40,13 @@ import google.registry.model.transfer.TransferResponse.ContactTransferResponse; import google.registry.model.transfer.TransferResponse.DomainTransferResponse; import google.registry.model.transfer.TransferStatus; import google.registry.testing.DatabaseHelper; -import google.registry.testing.SetClockExtension; +import org.joda.time.DateTime; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; /** Unit tests for {@link PollRequestFlow}. */ class PollRequestFlowTest extends FlowTestCase { - @Order(value = Order.DEFAULT - 3) - @RegisterExtension - final SetClockExtension setClockExtension = new SetClockExtension(clock, "2011-01-02T01:01:01Z"); - private Domain domain; private ContactResource contact; private Host host; @@ -60,6 +54,7 @@ class PollRequestFlowTest extends FlowTestCase { @BeforeEach void setUp() { setEppInput("poll.xml"); + clock.setTo(DateTime.parse("2011-01-02T01:01:01Z")); setRegistrarIdForFlow("NewRegistrar"); createTld("example"); persistNewRegistrar("BadRegistrar"); diff --git a/core/src/test/java/google/registry/testing/SetClockExtension.java b/core/src/test/java/google/registry/testing/SetClockExtension.java deleted file mode 100644 index df443cefa..000000000 --- a/core/src/test/java/google/registry/testing/SetClockExtension.java +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2021 The Nomulus Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package google.registry.testing; - -import org.joda.time.DateTime; -import org.junit.jupiter.api.extension.BeforeEachCallback; -import org.junit.jupiter.api.extension.ExtensionContext; - -/** - * Extension used for tests that a) set the clock to a specific time and b) make use of - * ReplayExtension or any other test feature that requires writing to a commit log from test - * utilities that aren't controlled by the ultimate test class (e.g. AppEngineExtension). - */ -public class SetClockExtension implements BeforeEachCallback { - - private FakeClock clock; - private DateTime dateTime; - - /** Construct from a DateTime, that being the time to set the clock to. */ - public SetClockExtension(FakeClock clock, DateTime dateTime) { - this.clock = clock; - this.dateTime = dateTime; - } - - /** Construct from a dateTime (the time to set the clock to) represented as a string. */ - public SetClockExtension(FakeClock clock, String dateTime) { - this.clock = clock; - this.dateTime = DateTime.parse(dateTime); - } - - @Override - public void beforeEach(ExtensionContext context) { - clock.setTo(dateTime); - } -}