diff --git a/GEMINI.md b/GEMINI.md index f3186f7f3bc..3c3307fe464 100644 --- a/GEMINI.md +++ b/GEMINI.md @@ -15,7 +15,7 @@ This document outlines foundational mandates, architectural patterns, and projec ## 2. Time and Precision Handling (java.time Migration) -- **Idiomatic java.time Usage:** Avoid redundant conversions between `Instant` and `DateTime`. If a field or parameter is an `Instant`, use it directly. Do not convert to `DateTime` just to call a deprecated method if an `Instant` alternative exists or can be easily created. +- **Idiomatic java.time Usage:** Avoid redundant conversions between `Instant` and `DateTime`. If a field or parameter is an `Instant`, use it directly. Do not convert to `DateTime` just to call a deprecated method if an `Instant` alternative exists or can be easily created. Furthermore, you should not call `toInstant()` or `toDateTime()` conversion methods when not strictly necessary; always prefer to use an alternative method that returns the correct type if one exists (e.g. use `tm().getTxTime()` which returns an `Instant` instead of calling `tm().getTransactionTime().toInstant()`). - **Millisecond Precision:** Always truncate `Instant.now()` to milliseconds (using `.truncatedTo(ChronoUnit.MILLIS)`) to maintain consistency with Joda `DateTime` and the PostgreSQL schema (which enforces millisecond precision via JPA converters). - **Clock Injection:** - Avoid direct calls to `Instant.now()`, `DateTime.now()`, `ZonedDateTime.now()`, or `System.currentTimeMillis()`. @@ -56,6 +56,7 @@ This document outlines foundational mandates, architectural patterns, and projec ## Performance and Efficiency - **Turn Minimization:** Aim for "perfect" code in the first iteration. Iterative fixes for checkstyle or compilation errors consume significant context and time. - **Context Management:** Use sub-agents for batch refactoring or high-volume output tasks to keep the main session history lean and efficient. +- **Code Formatting:** Do not write custom Python scripts or manual regex replacements to fix code formatting issues (e.g., unused imports, import ordering, line length). Instead, use the project's built-in formatting tools: run `./gradlew spotlessApply` to fix unused/unordered imports and `./gradlew javaIncrementalFormatApply` (or `google-java-format --replace `) to automatically fix Java formatting and indentation errors. ## General Code Review Lessons & Avoidable Mistakes Based on historical PR reviews, avoid the following common mistakes: @@ -89,11 +90,28 @@ This document captures high-level architectural patterns, lessons learned from l - **Committing:** Always create a new commit on the branch if one hasn't been created yet for the branch's specific work. Only perform amending (`git commit --amend --no-edit`) for subsequent changes once the initial commit has been successfully created. - **One Commit Per PR:** All changes for a single PR must be squashed into a single commit before merging. - **Default to Amend:** Once an initial commit is created for a PR, all subsequent functional changes should be amended into that same commit by default (`git commit --amend --no-edit`). This ensures the PR remains a single, clean unit of work throughout the development lifecycle. -- **Commit Message Style:** Follow standard Git commit best practices. The subject line (first line) should be concise, capitalized, and **must not end with punctuation** (e.g., a period). -- **Final Validation:** Always run `git status` as the final step before declaring a task complete to ensure all changes are committed and the working directory is clean. -- **Commit Verification:** After any commit or amendment, explicitly verify the success of the operation (e.g., using `git status` and reviewing the diff). Never report a Git operation as "done" without having first successfully executed the command and confirmed the repository state. +- **Commit Message Style:** Follow standard Git commit best practices. The subject line (first line) MUST be a maximum of 50 characters, concise, capitalized, and **must not end with punctuation** (e.g., a period). The body MUST explicitly encapsulate and summarize all changes made across the entire diff, detailing the "what" and "why" comprehensively. +- **Strict Completion Verification:** You MUST NEVER declare a task, commit, or amendment as complete until you have explicitly verified that the workspace is clean. You MUST follow this exact sequence of actions across multiple conversational turns if necessary: + 1. Execute the `git commit` or `git commit --amend` command. + 2. Wait for the tool to return successfully. + 3. Execute `git status`. + 4. Wait for the tool to return and explicitly verify the output contains `nothing to commit, working tree clean` (or similar indication that no unstaged changes remain). If changes remain, stage them and amend the commit, then repeat this verification loop. + 5. **Only after** step 4 has successfully returned a clean working directory may you generate a text response to the user declaring that the task is complete. - **Diff Review:** Before finalizing a task, review the full diff (e.g., `git diff HEAD^`) to ensure all changes are functional and relevant. Identify and revert any formatting-only changes in files that do not contain functional updates to keep the commit focused. +## Self-Review Guidelines +Before finalizing any PR or declaring a task complete, you MUST perform a thorough, rigorous self-review of your entire diff. Run `git diff HEAD^` (or review the staged changes) and actively verify the following against every modified line: + +1. **Imports & FQNs:** Did I leave any fully-qualified class names or static variables inline? Did I add the necessary imports for them? *Crucial Exception:* If the file already imports a class with the identical name (e.g., it uses both `java.time.Duration` and `org.joda.time.Duration`), one MUST remain fully qualified to avoid a compilation conflict. +2. **Redundant Conversions:** Did I use `toDateTime(clock.now())` where `clock.nowUtc()` would suffice? Did I use `toDateTime(END_INSTANT)` instead of `END_OF_TIME`? Did I use `.toInstant()` or `.toDateTime()` on something that could be avoided by using a different method overload (e.g., `tm().getTxTime()`)? +3. **Verbose Math:** Did I write any verbose time conversions inline? Are there `DateTimeUtils` methods I should be using instead? If not, should I abstract this math into `DateTimeUtils`? +4. **Assertion Cleanliness:** Am I polluting test assertions with `toDateTime(...)` wraps? If so, I need to add overloaded assertions to the Truth Subjects instead. +5. **Diff Scope:** Are there any formatting-only changes in files that I did not functionally modify? If so, revert them. Does the total line count of the diff align with the approved scope (e.g., ~1,000 lines for migrations)? +6. **Commit Message:** Does the commit message title fit within 50 characters? Does the body encapsulate the entirety of the changes across the diff cleanly and professionally? +7. **Missing Tests & Coverage:** *Perform a structured check for any new methods or modified behavior.* Did I add a new utility method (like `plusMonths(Instant, int)`) or change core logic? If so, I MUST open the corresponding test file and write tests to cover the new functionality (including edge cases, negative values, and leap years) before considering the task complete. A code review is not thorough if it only checks for compilation. I must actively ensure every new branch of logic has a test. + +Only after actively confirming these checks against your diff are you permitted to finalize the task. + ## Refactoring & Migration Guardrails @@ -115,7 +133,10 @@ This project treats Error Prone warnings as errors. ## 🚫 Common Pitfalls to Avoid +- **Redundant Parses:** Never write `toDateTime(Instant.parse(...))` or `toInstant(DateTime.parse(...))`. If you need a `DateTime`, use `DateTime.parse(...)` directly. If you need an `Instant`, use `Instant.parse(...)` directly. +- **cloneProjectedAtTime vs cloneProjectedAtInstant:** When converting tests and logic that use `clock.now()` to project resource state into the future or past, do not wrap the Java `Instant` in `toDateTime()` just to call `cloneProjectedAtTime()`. Instead, switch the method call to use the native `cloneProjectedAtInstant()` method which is available on all `EppResource` models. - **Do not go in circles with the build:** If you see an `InlineMeSuggester` error, apply the suppression to **ALL** similar methods in that file and related files in one turn. Do not fix them one by one. +- **Exception Conversion in Tests:** When migrating time types (e.g., from Joda `DateTime` to Java `Instant`), be extremely careful with tests that verify parsing failures (e.g., `assertThrows(IllegalArgumentException.class, ...)`). Joda's `DateTime.parse()` throws an `IllegalArgumentException` on failure, but `Instant.parse()` throws a `java.time.format.DateTimeParseException`. You must update the expected exception type in these tests to ensure they actually test the correct behavior, and verify the tests are not failing prematurely on the first line if it contains invalid data meant to be ignored. - Dagger/AutoValue corruption: If you modify a builder or a component incorrectly, Dagger will fail to generate code, leading to hundreds of "cannot find symbol" errors. If this happens, `git checkout` the last working state of the specific file and re-apply changes more surgically. - **`replace` tool context**: When using `replace` on large files (like `Tld.java` or `DomainBase.java`), provide significant surrounding context. These files have many similar method signatures (getters/setters) that can lead to incorrect replacements. diff --git a/common/src/main/java/google/registry/util/DateTimeUtils.java b/common/src/main/java/google/registry/util/DateTimeUtils.java index b395c5c9aac..723e24fe8b2 100644 --- a/common/src/main/java/google/registry/util/DateTimeUtils.java +++ b/common/src/main/java/google/registry/util/DateTimeUtils.java @@ -176,6 +176,18 @@ public static Instant plusYears(Instant now, long years) { : now.atZone(ZoneOffset.UTC).plusYears(1).plusYears(years - 1).toInstant(); } + /** Adds months to a date. */ + public static Instant plusMonths(Instant now, int months) { + checkArgument(months >= 0); + return now.atZone(ZoneOffset.UTC).plusMonths(months).toInstant(); + } + + /** Subtracts months from a date. */ + public static Instant minusMonths(Instant now, int months) { + checkArgument(months >= 0); + return now.atZone(ZoneOffset.UTC).minusMonths(months).toInstant(); + } + /** * Subtracts years from a date, in the {@code Duration} sense of semantic years. Use this instead * of {@link DateTime#minusYears} to ensure that we never end up on February 29. diff --git a/core/src/main/java/google/registry/beam/billing/ExpandBillingRecurrencesPipeline.java b/core/src/main/java/google/registry/beam/billing/ExpandBillingRecurrencesPipeline.java index 21f65ebef44..1678c90919d 100644 --- a/core/src/main/java/google/registry/beam/billing/ExpandBillingRecurrencesPipeline.java +++ b/core/src/main/java/google/registry/beam/billing/ExpandBillingRecurrencesPipeline.java @@ -26,7 +26,6 @@ import static google.registry.util.DateTimeUtils.latestOf; import static google.registry.util.DateTimeUtils.minusYears; import static google.registry.util.DateTimeUtils.plusYears; -import static google.registry.util.DateTimeUtils.toDateTime; import static org.apache.beam.sdk.values.TypeDescriptors.voids; import com.google.common.collect.ImmutableMap; @@ -402,7 +401,7 @@ private void expandOneRecurrence( .getRenewPrice( tld, billingRecurrence.getTargetId(), - toDateTime(eventTime), + eventTime, 1, billingRecurrence, Optional.empty()) diff --git a/core/src/main/java/google/registry/bsa/persistence/DomainsRefresher.java b/core/src/main/java/google/registry/bsa/persistence/DomainsRefresher.java index e2224c19b23..a7b672cae69 100644 --- a/core/src/main/java/google/registry/bsa/persistence/DomainsRefresher.java +++ b/core/src/main/java/google/registry/bsa/persistence/DomainsRefresher.java @@ -45,6 +45,7 @@ import google.registry.model.tld.Tld; import google.registry.model.tld.Tld.TldType; import google.registry.util.BatchedStreams; +import java.time.Duration; import java.time.Instant; import java.util.HashSet; import java.util.List; @@ -95,7 +96,7 @@ public final class DomainsRefresher { public DomainsRefresher( Instant prevRefreshStartTime, Instant now, - java.time.Duration domainTxnMaxDuration, + Duration domainTxnMaxDuration, int transactionBatchSize) { this.prevRefreshStartTime = prevRefreshStartTime.minus(domainTxnMaxDuration); this.now = now; diff --git a/core/src/main/java/google/registry/flows/CheckApiAction.java b/core/src/main/java/google/registry/flows/CheckApiAction.java index 9b282c7face..3947716adf6 100644 --- a/core/src/main/java/google/registry/flows/CheckApiAction.java +++ b/core/src/main/java/google/registry/flows/CheckApiAction.java @@ -35,6 +35,7 @@ import static google.registry.persistence.PersistenceModule.TransactionIsolationLevel.TRANSACTION_REPEATABLE_READ; import static google.registry.persistence.transaction.TransactionManagerFactory.replicaTm; import static google.registry.pricing.PricingEngineProxy.isDomainPremium; +import static google.registry.util.DateTimeUtils.toInstant; import static google.registry.util.DomainNameUtils.canonicalizeHostname; import static org.json.simple.JSONValue.toJSONString; @@ -165,7 +166,7 @@ private Map checkDomainName(InternetDomainName domainName) { metricBuilder.status(SUCCESS).availability(availability); responseBuilder.put("status", "success").put("available", availability.equals(AVAILABLE)); - boolean isPremium = isDomainPremium(domainString, now); + boolean isPremium = isDomainPremium(domainString, toInstant(now)); metricBuilder.tier(isPremium ? PREMIUM : STANDARD); responseBuilder.put("tier", isPremium ? "premium" : "standard"); if (!AVAILABLE.equals(availability)) { diff --git a/core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java b/core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java index ed5776b7c26..e6e8f90092b 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java @@ -53,6 +53,7 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.util.DateTimeUtils.END_INSTANT; import static google.registry.util.DateTimeUtils.plusYears; +import static google.registry.util.DateTimeUtils.toInstant; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -313,7 +314,7 @@ public EppResponse run() throws EppException { // at this point so that we can verify it before the "after validation" extension point. signedMarkId = tmchUtils - .verifySignedMarks(launchCreate.get().getSignedMarks(), domainLabel, now) + .verifySignedMarks(launchCreate.get().getSignedMarks(), domainLabel, toInstant(now)) .getId(); } verifyNotBlockedByBsa(domainName, tld, now, allocationToken); @@ -327,7 +328,7 @@ public EppResponse run() throws EppException { eppInput.getSingleExtension(FeeCreateCommandExtension.class); FeesAndCredits feesAndCredits = pricingLogic.getCreatePrice( - tld, targetId, now, years, isAnchorTenant, isSunriseCreate, allocationToken); + tld, targetId, toInstant(now), years, isAnchorTenant, isSunriseCreate, allocationToken); validateFeeChallenge(feeCreate, feesAndCredits, defaultTokenUsed); Optional secDnsCreate = validateSecDnsExtension(eppInput.getSingleExtension(SecDnsCreateExtension.class)); @@ -434,13 +435,21 @@ public EppResponse run() throws EppException { FeesAndCredits responseFeesAndCredits = shouldShowDefaultPrice ? pricingLogic.getCreatePrice( - tld, targetId, now, years, isAnchorTenant, isSunriseCreate, Optional.empty()) + tld, + targetId, + toInstant(now), + years, + isAnchorTenant, + isSunriseCreate, + Optional.empty()) : feesAndCredits; BeforeResponseReturnData responseData = flowCustomLogic.beforeResponse( BeforeResponseParameters.newBuilder() - .setResData(DomainCreateData.create(targetId, now, registrationExpirationTime)) + .setResData( + DomainCreateData.create( + targetId, toInstant(now), toInstant(registrationExpirationTime))) .setResponseExtensions(createResponseExtensions(feeCreate, responseFeesAndCredits)) .build()); return responseBuilder diff --git a/core/src/main/java/google/registry/flows/domain/DomainDeleteFlow.java b/core/src/main/java/google/registry/flows/domain/DomainDeleteFlow.java index 6cac24304c5..9eff1530f30 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainDeleteFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainDeleteFlow.java @@ -422,7 +422,7 @@ private Money getGracePeriodCost( // If we updated the autorenew billing event, reuse it. DateTime autoRenewTime = billingRecurrence.getRecurrenceTimeOfYear().getLastInstanceBeforeOrAt(now); - return getDomainRenewCost(targetId, autoRenewTime, 1); + return getDomainRenewCost(targetId, toInstant(autoRenewTime), 1); } return tm().loadByKey(checkNotNull(gracePeriod.getBillingEvent())).getCost(); } diff --git a/core/src/main/java/google/registry/flows/domain/DomainFlowTmchUtils.java b/core/src/main/java/google/registry/flows/domain/DomainFlowTmchUtils.java index 52cf0e3fc14..6de8bb26522 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainFlowTmchUtils.java +++ b/core/src/main/java/google/registry/flows/domain/DomainFlowTmchUtils.java @@ -38,10 +38,10 @@ import java.security.cert.CertificateExpiredException; import java.security.cert.CertificateNotYetValidException; import java.security.cert.CertificateRevokedException; +import java.time.Instant; import javax.xml.crypto.MarshalException; import javax.xml.crypto.dsig.XMLSignatureException; import javax.xml.parsers.ParserConfigurationException; -import org.joda.time.DateTime; import org.xml.sax.SAXException; /** TMCH utility functions for domain flows. */ @@ -55,7 +55,7 @@ public DomainFlowTmchUtils(TmchXmlSignature tmchXmlSignature) { } public SignedMark verifySignedMarks( - ImmutableList signedMarks, String domainLabel, DateTime now) + ImmutableList signedMarks, String domainLabel, Instant now) throws EppException { if (signedMarks.size() > 1) { throw new TooManySignedMarksException(); @@ -75,7 +75,7 @@ public SignedMark verifySignedMarkValidForDomainLabel(SignedMark signedMark, Str return signedMark; } - public SignedMark verifyEncodedSignedMark(EncodedSignedMark encodedSignedMark, DateTime now) + public SignedMark verifyEncodedSignedMark(EncodedSignedMark encodedSignedMark, Instant now) throws EppException { if (!encodedSignedMark.getEncoding().equals("base64")) { throw new Base64RequiredForEncodedSignedMarksException(); diff --git a/core/src/main/java/google/registry/flows/domain/DomainFlowUtils.java b/core/src/main/java/google/registry/flows/domain/DomainFlowUtils.java index 45853542593..779ef75f50b 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainFlowUtils.java +++ b/core/src/main/java/google/registry/flows/domain/DomainFlowUtils.java @@ -40,7 +40,7 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.pricing.PricingEngineProxy.isDomainPremium; import static google.registry.util.CollectionUtils.nullToEmpty; -import static google.registry.util.DateTimeUtils.END_OF_TIME; +import static google.registry.util.DateTimeUtils.END_INSTANT; import static google.registry.util.DateTimeUtils.isAtOrAfter; import static google.registry.util.DateTimeUtils.plusYears; import static google.registry.util.DateTimeUtils.toInstant; @@ -124,6 +124,7 @@ import google.registry.tools.DigestType; import google.registry.util.Idn; import java.math.BigDecimal; +import java.time.Instant; import java.util.Comparator; import java.util.List; import java.util.Map.Entry; @@ -474,7 +475,7 @@ static void verifyLaunchPhaseMatchesRegistryPhase( */ static void verifyPremiumNameIsNotBlocked( String domainName, DateTime priceTime, String registrarId) throws EppException { - if (isDomainPremium(domainName, priceTime)) { + if (isDomainPremium(domainName, toInstant(priceTime))) { if (Registrar.loadByRegistrarIdCached(registrarId).get().getBlockPremiumNames()) { throw new PremiumNameBlockedException(); } @@ -504,7 +505,7 @@ public static BillingRecurrence.Builder newAutorenewBillingEvent(Domain domain) .setFlags(ImmutableSet.of(Flag.AUTO_RENEW)) .setTargetId(domain.getDomainName()) .setRegistrarId(domain.getCurrentSponsorRegistrarId()) - .setEventTime(domain.getRegistrationExpirationDateTime()); + .setEventTime(domain.getRegistrationExpirationTime()); } /** @@ -515,7 +516,7 @@ public static Autorenew.Builder newAutorenewPollMessage(Domain domain) { return new Autorenew.Builder() .setTargetId(domain.getDomainName()) .setRegistrarId(domain.getCurrentSponsorRegistrarId()) - .setEventTime(domain.getRegistrationExpirationDateTime()) + .setEventTime(domain.getRegistrationExpirationTime()) .setMsg("Domain was auto-renewed."); } @@ -587,7 +588,7 @@ static void handleFeeRequest( boolean isAvailable, @Nullable BillingRecurrence billingRecurrence) throws EppException { - DateTime now = currentDate; + Instant now = toInstant(currentDate); // Use the custom effective date specified in the fee check request, if there is one. if (feeRequest.getEffectiveDate().isPresent()) { now = feeRequest.getEffectiveDate().get(); @@ -659,7 +660,7 @@ static void handleFeeRequest( // process, don't count as expired for the purposes of requiring an added year of renewal on // restore because they can't be restored in the first place. boolean isExpired = - domain.isPresent() && domain.get().getRegistrationExpirationDateTime().isBefore(now); + domain.isPresent() && domain.get().getRegistrationExpirationTime().isBefore(now); fees = pricingLogic.getRestorePrice(tld, domainNameString, now, isExpired).getFees(); } case TRANSFER -> { @@ -700,16 +701,16 @@ static void handleFeeRequest( // Set the fees, and based on the validDateRange of the fees, set the notAfterDate. if (!fees.isEmpty()) { builder.setFees(fees); - DateTime notAfterDate = null; + Instant notAfterDate = null; for (Fee fee : fees) { if (fee.hasValidDateRange()) { - DateTime endDate = fee.getValidDateRange().upperEndpoint(); + Instant endDate = fee.getValidDateRange().upperEndpoint(); if (notAfterDate == null || notAfterDate.isAfter(endDate)) { notAfterDate = endDate; } } } - if (notAfterDate != null && !notAfterDate.equals(END_OF_TIME)) { + if (notAfterDate != null && !notAfterDate.equals(END_INSTANT)) { builder.setNotAfterDateIfSupported(notAfterDate); } } diff --git a/core/src/main/java/google/registry/flows/domain/DomainInfoFlow.java b/core/src/main/java/google/registry/flows/domain/DomainInfoFlow.java index 8815d2ca7bd..28cfe7240c1 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainInfoFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainInfoFlow.java @@ -121,10 +121,10 @@ public EppResponse run() throws EppException { .setStatusValues(domain.getStatusValues()) .setNameservers( hostsRequest.requestDelegated() ? domain.loadNameserverHostNames() : null) - .setCreationTime(domain.getCreationTime()) - .setLastEppUpdateTime(domain.getLastEppUpdateDateTime()) - .setRegistrationExpirationTime(domain.getRegistrationExpirationDateTime()) - .setLastTransferTime(domain.getLastTransferTime()); + .setCreationTime(domain.getCreationTimeInstant()) + .setLastEppUpdateTime(domain.getLastEppUpdateTime()) + .setRegistrationExpirationTime(domain.getRegistrationExpirationTime()) + .setLastTransferTime(domain.getLastTransferTimeInstant()); // If authInfo is non-null, then the caller is authorized to see the full information since we // will have already verified the authInfo is valid. diff --git a/core/src/main/java/google/registry/flows/domain/DomainPricingLogic.java b/core/src/main/java/google/registry/flows/domain/DomainPricingLogic.java index 9b47261f122..ed535214609 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainPricingLogic.java +++ b/core/src/main/java/google/registry/flows/domain/DomainPricingLogic.java @@ -18,6 +18,7 @@ import static google.registry.flows.domain.DomainFlowUtils.zeroInCurrency; import static google.registry.flows.domain.token.AllocationTokenFlowUtils.discountTokenInvalidForPremiumName; import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName; +import static google.registry.util.DateTimeUtils.toDateTime; import static google.registry.util.PreconditionsUtils.checkArgumentPresent; import com.google.common.net.InternetDomainName; @@ -41,11 +42,11 @@ import google.registry.model.tld.Tld; import jakarta.inject.Inject; import java.math.RoundingMode; +import java.time.Instant; import java.util.Optional; import javax.annotation.Nullable; import org.joda.money.CurrencyUnit; import org.joda.money.Money; -import org.joda.time.DateTime; /** * Provides pricing for create, renew, etc, operations, with call-outs that can be customized by @@ -70,7 +71,7 @@ public DomainPricingLogic(DomainPricingCustomLogic customLogic) { public FeesAndCredits getCreatePrice( Tld tld, String domainName, - DateTime dateTime, + Instant dateTime, int years, boolean isAnchorTenant, boolean isSunriseCreate, @@ -116,7 +117,7 @@ public FeesAndCredits getCreatePrice( .setFeesAndCredits(feesBuilder.build()) .setTld(tld) .setDomainName(InternetDomainName.from(domainName)) - .setAsOfDate(dateTime) + .setAsOfDate(toDateTime(dateTime)) .setYears(years) .build()); } @@ -125,7 +126,7 @@ public FeesAndCredits getCreatePrice( public FeesAndCredits getRenewPrice( Tld tld, String domainName, - DateTime dateTime, + Instant dateTime, int years, @Nullable BillingRecurrence billingRecurrence, Optional allocationToken) { @@ -187,14 +188,14 @@ public FeesAndCredits getRenewPrice( .build()) .setTld(tld) .setDomainName(InternetDomainName.from(domainName)) - .setAsOfDate(dateTime) + .setAsOfDate(toDateTime(dateTime)) .setYears(years) .build()); } /** Returns a new restore price for the pricer. */ public FeesAndCredits getRestorePrice( - Tld tld, String domainName, DateTime dateTime, boolean isExpired) throws EppException { + Tld tld, String domainName, Instant dateTime, boolean isExpired) throws EppException { DomainPrices domainPrices = getPricesForDomainName(domainName, dateTime); FeesAndCredits.Builder feesAndCredits = new FeesAndCredits.Builder() @@ -211,13 +212,13 @@ public FeesAndCredits getRestorePrice( .setFeesAndCredits(feesAndCredits.build()) .setTld(tld) .setDomainName(InternetDomainName.from(domainName)) - .setAsOfDate(dateTime) + .setAsOfDate(toDateTime(dateTime)) .build()); } /** Returns a new transfer price for the pricer. */ public FeesAndCredits getTransferPrice( - Tld tld, String domainName, DateTime dateTime, @Nullable BillingRecurrence billingRecurrence) + Tld tld, String domainName, Instant dateTime, @Nullable BillingRecurrence billingRecurrence) throws EppException { FeesAndCredits renewPrice = getRenewPrice(tld, domainName, dateTime, 1, billingRecurrence, Optional.empty()); @@ -234,12 +235,12 @@ public FeesAndCredits getTransferPrice( .build()) .setTld(tld) .setDomainName(InternetDomainName.from(domainName)) - .setAsOfDate(dateTime) + .setAsOfDate(toDateTime(dateTime)) .build()); } /** Returns a new update price for the pricer. */ - public FeesAndCredits getUpdatePrice(Tld tld, String domainName, DateTime dateTime) + public FeesAndCredits getUpdatePrice(Tld tld, String domainName, Instant dateTime) throws EppException { CurrencyUnit currency = tld.getCurrency(); BaseFee feeOrCredit = Fee.create(zeroInCurrency(currency), FeeType.UPDATE, false); @@ -252,7 +253,7 @@ public FeesAndCredits getUpdatePrice(Tld tld, String domainName, DateTime dateTi .build()) .setTld(tld) .setDomainName(InternetDomainName.from(domainName)) - .setAsOfDate(dateTime) + .setAsOfDate(toDateTime(dateTime)) .build()); } @@ -272,7 +273,7 @@ private Money getDomainCreateCostWithDiscount( private Money getDomainRenewCostWithDiscount( Tld tld, DomainPrices domainPrices, - DateTime dateTime, + Instant dateTime, int years, Optional allocationToken) { // Short-circuit if the user sent an anchor-tenant or otherwise NONPREMIUM-renewal token @@ -349,7 +350,7 @@ private Money getDomainCostWithDiscount( } private DomainPrices applyTokenToDomainPrices( - DomainPrices domainPrices, Tld tld, DateTime dateTime, int years, AllocationToken token) { + DomainPrices domainPrices, Tld tld, Instant dateTime, int years, AllocationToken token) { // Convert to nonpremium iff no premium charges are included (either in create or any renewal) boolean convertToNonPremium = token.getRegistrationBehavior().equals(RegistrationBehavior.NONPREMIUM_CREATE) diff --git a/core/src/main/java/google/registry/flows/domain/DomainRenewFlow.java b/core/src/main/java/google/registry/flows/domain/DomainRenewFlow.java index 1c4eef20b20..57cc04768b1 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainRenewFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainRenewFlow.java @@ -35,6 +35,7 @@ import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_RENEW; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.util.DateTimeUtils.plusYears; +import static google.registry.util.DateTimeUtils.toInstant; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -201,7 +202,7 @@ public EppResponse run() throws EppException { pricingLogic.getRenewPrice( Tld.get(existingDomain.getTld()), targetId, - now, + toInstant(now), years, existingBillingRecurrence, allocationToken); diff --git a/core/src/main/java/google/registry/flows/domain/DomainRestoreRequestFlow.java b/core/src/main/java/google/registry/flows/domain/DomainRestoreRequestFlow.java index 44b0de96be0..2bdd97ccbdf 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainRestoreRequestFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainRestoreRequestFlow.java @@ -31,6 +31,7 @@ import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_RESTORE; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.util.DateTimeUtils.END_INSTANT; +import static google.registry.util.DateTimeUtils.toInstant; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -140,7 +141,8 @@ public EppResponse run() throws EppException { Domain existingDomain = loadAndVerifyExistence(Domain.class, targetId, now); boolean isExpired = existingDomain.getRegistrationExpirationDateTime().isBefore(now); FeesAndCredits feesAndCredits = - pricingLogic.getRestorePrice(Tld.get(existingDomain.getTld()), targetId, now, isExpired); + pricingLogic.getRestorePrice( + Tld.get(existingDomain.getTld()), targetId, toInstant(now), isExpired); Optional feeUpdate = eppInput.getSingleExtension(FeeUpdateCommandExtension.class); verifyRestoreAllowed(command, existingDomain, feeUpdate, feesAndCredits, now); diff --git a/core/src/main/java/google/registry/flows/domain/DomainTransferApproveFlow.java b/core/src/main/java/google/registry/flows/domain/DomainTransferApproveFlow.java index ffabb6d78ae..09ac06217d0 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainTransferApproveFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainTransferApproveFlow.java @@ -163,7 +163,7 @@ public EppResponse run() throws EppException { .getTransferPrice( Tld.get(tldStr), targetId, - transferData.getTransferRequestTime(), + transferData.getTransferRequestTimeInstant(), // When removing a domain from bulk pricing it should return to the // default recurrence billing behavior so the existing recurrence // billing event should not be passed in. diff --git a/core/src/main/java/google/registry/flows/domain/DomainTransferRequestFlow.java b/core/src/main/java/google/registry/flows/domain/DomainTransferRequestFlow.java index ad711a9b722..456e9cd6660 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainTransferRequestFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainTransferRequestFlow.java @@ -198,7 +198,9 @@ public EppResponse run() throws EppException { feesAndCredits = Optional.empty(); } else if (existingDomain.getCurrentBulkToken().isEmpty()) { feesAndCredits = - Optional.of(pricingLogic.getTransferPrice(tld, targetId, now, existingBillingRecurrence)); + Optional.of( + pricingLogic.getTransferPrice( + tld, targetId, toInstant(now), existingBillingRecurrence)); } else { // If existing domain is in a bulk pricing package, calculate the transfer price with default // renewal price @@ -206,7 +208,7 @@ public EppResponse run() throws EppException { feesAndCredits = period.getValue() == 0 ? Optional.empty() - : Optional.of(pricingLogic.getTransferPrice(tld, targetId, now, null)); + : Optional.of(pricingLogic.getTransferPrice(tld, targetId, toInstant(now), null)); } if (feesAndCredits.isPresent()) { diff --git a/core/src/main/java/google/registry/flows/domain/DomainUpdateFlow.java b/core/src/main/java/google/registry/flows/domain/DomainUpdateFlow.java index 752c194ebbf..7098063e161 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainUpdateFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainUpdateFlow.java @@ -38,6 +38,7 @@ import static google.registry.flows.domain.DomainFlowUtils.verifyNotInPendingDelete; import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_UPDATE; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; +import static google.registry.util.DateTimeUtils.toInstant; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -227,7 +228,7 @@ private void verifyUpdateAllowed(Update command, Domain existingDomain, DateTime Tld tld = Tld.get(tldStr); Optional feeUpdate = eppInput.getSingleExtension(FeeUpdateCommandExtension.class); - FeesAndCredits feesAndCredits = pricingLogic.getUpdatePrice(tld, targetId, now); + FeesAndCredits feesAndCredits = pricingLogic.getUpdatePrice(tld, targetId, toInstant(now)); validateFeesAckedIfPresent(feeUpdate, feesAndCredits, false); verifyNotInPendingDelete(add.getNameservers()); validateNameserversAllowedOnTld(tldStr, add.getNameserverHostNames()); diff --git a/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java b/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java index afeddc17490..a50d0158663 100644 --- a/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java +++ b/core/src/main/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java @@ -19,6 +19,7 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.pricing.PricingEngineProxy.isDomainPremium; import static google.registry.util.CollectionUtils.isNullOrEmpty; +import static google.registry.util.DateTimeUtils.toInstant; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; @@ -166,7 +167,8 @@ public static Domain maybeApplyBulkPricingRemovalToken( @VisibleForTesting static boolean tokenIsValidAgainstDomain( InternetDomainName domainName, AllocationToken token, CommandName commandName, DateTime now) { - if (discountTokenInvalidForPremiumName(token, isDomainPremium(domainName.toString(), now))) { + if (discountTokenInvalidForPremiumName( + token, isDomainPremium(domainName.toString(), toInstant(now)))) { return false; } if (!token.getAllowedEppActions().isEmpty() @@ -242,12 +244,13 @@ private static BigDecimal getSampleCostWithToken( case CREATE -> pricingLogic .getCreatePrice( - tld, domainName, now, yearsForAction, false, false, Optional.of(token)) + tld, domainName, toInstant(now), yearsForAction, false, false, Optional.of(token)) .getTotalCost() .getAmount(); case RENEW -> pricingLogic - .getRenewPrice(tld, domainName, now, yearsForAction, null, Optional.of(token)) + .getRenewPrice( + tld, domainName, toInstant(now), yearsForAction, null, Optional.of(token)) .getTotalCost() .getAmount(); default -> BigDecimal.ZERO; diff --git a/core/src/main/java/google/registry/flows/host/HostCreateFlow.java b/core/src/main/java/google/registry/flows/host/HostCreateFlow.java index 1644148bd86..8daca8ebd04 100644 --- a/core/src/main/java/google/registry/flows/host/HostCreateFlow.java +++ b/core/src/main/java/google/registry/flows/host/HostCreateFlow.java @@ -25,6 +25,7 @@ import static google.registry.model.reporting.HistoryEntry.Type.HOST_CREATE; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.util.CollectionUtils.isNullOrEmpty; +import static google.registry.util.DateTimeUtils.toInstant; import com.google.common.collect.ImmutableSet; import google.registry.config.RegistryConfig.Config; @@ -141,7 +142,7 @@ public EppResponse run() throws EppException { requestHostDnsRefresh(targetId); } tm().insertAll(entitiesToInsert); - return responseBuilder.setResData(HostCreateData.create(targetId, now)).build(); + return responseBuilder.setResData(HostCreateData.create(targetId, toInstant(now))).build(); } /** Subordinate hosts must have an ip address. */ diff --git a/core/src/main/java/google/registry/flows/host/HostInfoFlow.java b/core/src/main/java/google/registry/flows/host/HostInfoFlow.java index a8df0ae70af..60cb13bd93d 100644 --- a/core/src/main/java/google/registry/flows/host/HostInfoFlow.java +++ b/core/src/main/java/google/registry/flows/host/HostInfoFlow.java @@ -19,7 +19,6 @@ import static google.registry.flows.host.HostFlowUtils.validateHostName; import static google.registry.model.EppResourceUtils.isLinked; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; -import static google.registry.util.DateTimeUtils.toDateTime; import com.google.common.collect.ImmutableSet; import google.registry.flows.EppException; @@ -81,14 +80,14 @@ public EppResponse run() throws EppException { tm().loadByKey(host.getSuperordinateDomain()).cloneProjectedAtTime(now); hostInfoDataBuilder .setCurrentSponsorRegistrarId(superordinateDomain.getCurrentSponsorRegistrarId()) - .setLastTransferTime(toDateTime(host.computeLastTransferTime(superordinateDomain))); + .setLastTransferTime(host.computeLastTransferTime(superordinateDomain)); if (superordinateDomain.getStatusValues().contains(StatusValue.PENDING_TRANSFER)) { statusValues.add(StatusValue.PENDING_TRANSFER); } } else { hostInfoDataBuilder .setCurrentSponsorRegistrarId(host.getPersistedCurrentSponsorRegistrarId()) - .setLastTransferTime(host.getLastTransferTime()); + .setLastTransferTime(host.getLastTransferTimeInstant()); } return responseBuilder .setResData( @@ -98,9 +97,9 @@ public EppResponse run() throws EppException { .setStatusValues(statusValues.build()) .setInetAddresses(host.getInetAddresses()) .setCreationRegistrarId(host.getCreationRegistrarId()) - .setCreationTime(host.getCreationTime()) + .setCreationTime(host.getCreationTimeInstant()) .setLastEppUpdateRegistrarId(host.getLastEppUpdateRegistrarId()) - .setLastEppUpdateTime(host.getLastEppUpdateDateTime()) + .setLastEppUpdateTime(host.getLastEppUpdateTime()) .build()) .build(); } diff --git a/core/src/main/java/google/registry/flows/poll/PollRequestFlow.java b/core/src/main/java/google/registry/flows/poll/PollRequestFlow.java index d24e3637088..dd72ca0d532 100644 --- a/core/src/main/java/google/registry/flows/poll/PollRequestFlow.java +++ b/core/src/main/java/google/registry/flows/poll/PollRequestFlow.java @@ -77,7 +77,7 @@ public EppResponse run() throws EppException { .setResultFromCode(SUCCESS_WITH_ACK_MESSAGE) .setMessageQueueInfo( new MessageQueueInfo.Builder() - .setQueueDate(pollMessage.getEventTime()) + .setQueueDate(pollMessage.getEventTimeInstant()) .setMsg(pollMessage.getMsg()) .setQueueLength(getPollMessageCount(registrarId, now)) .setMessageId(makePollMessageExternalId(pollMessage)) diff --git a/core/src/main/java/google/registry/flows/session/HelloFlow.java b/core/src/main/java/google/registry/flows/session/HelloFlow.java index 5e17b1ea6a8..58f6e82e832 100644 --- a/core/src/main/java/google/registry/flows/session/HelloFlow.java +++ b/core/src/main/java/google/registry/flows/session/HelloFlow.java @@ -37,6 +37,6 @@ public final class HelloFlow implements Flow { @Override public Greeting run() throws EppException { extensionManager.validate(); // There are no legal extensions for this flow. - return Greeting.create(clock.nowUtc(), greetingServerId); + return Greeting.create(clock.now(), greetingServerId); } } diff --git a/core/src/main/java/google/registry/model/contact/ContactInfoData.java b/core/src/main/java/google/registry/model/contact/ContactInfoData.java index 2353ac82c9f..5ba69992f00 100644 --- a/core/src/main/java/google/registry/model/contact/ContactInfoData.java +++ b/core/src/main/java/google/registry/model/contact/ContactInfoData.java @@ -25,8 +25,8 @@ import jakarta.xml.bind.annotation.XmlType; import jakarta.xml.bind.annotation.adapters.CollapsedStringAdapter; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.time.Instant; import javax.annotation.Nullable; -import org.joda.time.DateTime; /** The {@link ResponseData} returned for an EPP info flow on a contact. */ @XmlRootElement(name = "infData") @@ -84,7 +84,7 @@ public abstract class ContactInfoData implements ResponseData { abstract String getCreationRegistrarId(); @XmlElement(name = "crDate") - abstract DateTime getCreationTime(); + abstract Instant getCreationTime(); @XmlElement(name = "upID") @Nullable @@ -92,11 +92,11 @@ public abstract class ContactInfoData implements ResponseData { @XmlElement(name = "upDate") @Nullable - abstract DateTime getLastEppUpdateTime(); + abstract Instant getLastEppUpdateTime(); @XmlElement(name = "trDate") @Nullable - abstract DateTime getLastTransferTime(); + abstract Instant getLastTransferTime(); @XmlElement(name = "authInfo") @Nullable @@ -121,12 +121,14 @@ public abstract static class Builder { public abstract Builder setCreationRegistrarId(String creationRegistrarId); - public abstract Builder setCreationTime(DateTime creationTime); + public abstract Builder setCreationTime(Instant creationTime); public abstract Builder setLastEppUpdateRegistrarId(@Nullable String lastEppUpdateRegistrarId); - public abstract Builder setLastEppUpdateTime(@Nullable DateTime lastEppUpdateTime); - public abstract Builder setLastTransferTime(@Nullable DateTime lastTransferTime); + public abstract Builder setLastEppUpdateTime(@Nullable Instant lastEppUpdateTime); + + public abstract Builder setLastTransferTime(@Nullable Instant lastTransferTime); + public abstract Builder setAuthInfo(@Nullable ContactAuthInfo authInfo); public abstract Builder setDisclose(@Nullable Disclose disclose); public abstract ContactInfoData build(); diff --git a/core/src/main/java/google/registry/model/contact/package-info.java b/core/src/main/java/google/registry/model/contact/package-info.java index 9be62c1dc65..2aa7eaff0a5 100644 --- a/core/src/main/java/google/registry/model/contact/package-info.java +++ b/core/src/main/java/google/registry/model/contact/package-info.java @@ -17,13 +17,18 @@ xmlns = @XmlNs(prefix = "contact", namespaceURI = "urn:ietf:params:xml:ns:contact-1.0"), elementFormDefault = XmlNsForm.QUALIFIED) @XmlAccessorType(XmlAccessType.FIELD) -@XmlJavaTypeAdapter(UtcDateTimeAdapter.class) +@XmlJavaTypeAdapters({ + @XmlJavaTypeAdapter(UtcDateTimeAdapter.class), + @XmlJavaTypeAdapter(UtcInstantAdapter.class) +}) package google.registry.model.contact; import google.registry.xml.UtcDateTimeAdapter; +import google.registry.xml.UtcInstantAdapter; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlNs; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapters; diff --git a/core/src/main/java/google/registry/model/domain/DomainInfoData.java b/core/src/main/java/google/registry/model/domain/DomainInfoData.java index 3a9112942f4..aa31583f771 100644 --- a/core/src/main/java/google/registry/model/domain/DomainInfoData.java +++ b/core/src/main/java/google/registry/model/domain/DomainInfoData.java @@ -25,8 +25,8 @@ import jakarta.xml.bind.annotation.XmlElementWrapper; import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlType; +import java.time.Instant; import javax.annotation.Nullable; -import org.joda.time.DateTime; /** The {@link ResponseData} returned for an EPP info flow on a domain. */ @XmlRootElement(name = "infData") @@ -88,7 +88,7 @@ public abstract class DomainInfoData implements ResponseData { @XmlElement(name = "crDate") @Nullable - abstract DateTime getCreationTime(); + abstract Instant getCreationTime(); @XmlElement(name = "upID") @Nullable @@ -96,15 +96,15 @@ public abstract class DomainInfoData implements ResponseData { @XmlElement(name = "upDate") @Nullable - abstract DateTime getLastEppUpdateTime(); + abstract Instant getLastEppUpdateTime(); @XmlElement(name = "exDate") @Nullable - abstract DateTime getRegistrationExpirationTime(); + abstract Instant getRegistrationExpirationTime(); @XmlElement(name = "trDate") @Nullable - abstract DateTime getLastTransferTime(); + abstract Instant getLastTransferTime(); @XmlElement(name = "authInfo") @Nullable @@ -127,14 +127,17 @@ public abstract Builder setContacts( public abstract Builder setCreationRegistrarId(@Nullable String creationRegistrarId); - public abstract Builder setCreationTime(@Nullable DateTime creationTime); + public abstract Builder setCreationTime(@Nullable Instant creationTime); public abstract Builder setLastEppUpdateRegistrarId(@Nullable String lastEppUpdateRegistrarId); - public abstract Builder setLastEppUpdateTime(@Nullable DateTime lastEppUpdateTime); + public abstract Builder setLastEppUpdateTime(@Nullable Instant lastEppUpdateTime); + public abstract Builder setRegistrationExpirationTime( - @Nullable DateTime registrationExpirationTime); - public abstract Builder setLastTransferTime(@Nullable DateTime lastTransferTime); + @Nullable Instant registrationExpirationTime); + + public abstract Builder setLastTransferTime(@Nullable Instant lastTransferTime); + public abstract Builder setAuthInfo(@Nullable DomainAuthInfo authInfo); /** Internal accessor for use in {@link #build}. */ diff --git a/core/src/main/java/google/registry/model/domain/fee/BaseFee.java b/core/src/main/java/google/registry/model/domain/fee/BaseFee.java index c70511237ec..bd530471956 100644 --- a/core/src/main/java/google/registry/model/domain/fee/BaseFee.java +++ b/core/src/main/java/google/registry/model/domain/fee/BaseFee.java @@ -32,7 +32,6 @@ import java.math.BigDecimal; import java.time.Instant; import java.util.stream.Stream; -import org.joda.time.DateTime; import org.joda.time.Period; /** Base class for the fee and credit types. */ @@ -104,9 +103,7 @@ boolean matchFormatString(String description) { @XmlTransient FeeType type; - @XmlTransient Range validDateRange; - - @XmlTransient Range validDateRangeInstant; + @XmlTransient Range validDateRange; @XmlTransient boolean isPremium; @@ -149,42 +146,13 @@ public FeeType getType() { @JsonIgnore public boolean hasValidDateRange() { - return validDateRange != null || validDateRangeInstant != null; - } - - @JsonIgnore - public Range getValidDateRange() { - checkState(hasValidDateRange()); - if (validDateRange != null) { - return validDateRange; - } - return convertRange(validDateRangeInstant, google.registry.util.DateTimeUtils::toDateTime); + return validDateRange != null; } @JsonIgnore - public Range getValidDateRangeInstant() { + public Range getValidDateRange() { checkState(hasValidDateRange()); - if (validDateRangeInstant != null) { - return validDateRangeInstant; - } - return convertRange(validDateRange, google.registry.util.DateTimeUtils::toInstant); - } - - private static , T extends Comparable> - Range convertRange(Range range, java.util.function.Function converter) { - if (range.hasLowerBound() && range.hasUpperBound()) { - return Range.range( - converter.apply(range.lowerEndpoint()), - range.lowerBoundType(), - converter.apply(range.upperEndpoint()), - range.upperBoundType()); - } else if (range.hasLowerBound()) { - return Range.downTo(converter.apply(range.lowerEndpoint()), range.lowerBoundType()); - } else if (range.hasUpperBound()) { - return Range.upTo(converter.apply(range.upperEndpoint()), range.upperBoundType()); - } else { - return Range.all(); - } + return validDateRange; } public boolean hasZeroCost() { diff --git a/core/src/main/java/google/registry/model/domain/fee/Fee.java b/core/src/main/java/google/registry/model/domain/fee/Fee.java index 508c48164b0..cefa86fccc3 100644 --- a/core/src/main/java/google/registry/model/domain/fee/Fee.java +++ b/core/src/main/java/google/registry/model/domain/fee/Fee.java @@ -23,7 +23,6 @@ import google.registry.model.eppcommon.ProtocolDefinition.ServiceExtension; import java.math.BigDecimal; import java.time.Instant; -import org.joda.time.DateTime; /** * A fee, in currency units specified elsewhere in the xml, with type of the fee an optional fee @@ -41,25 +40,13 @@ public static Fee create( /** Creates a Fee for the given cost, type, and valid date range with the default description. */ public static Fee create( - BigDecimal cost, - FeeType type, - boolean isPremium, - Range validDateRange, - Object... descriptionArgs) { - Fee instance = create(cost, type, isPremium, descriptionArgs); - instance.validDateRange = validDateRange; - return instance; - } - - /** Creates a Fee for the given cost, type, and valid date range with the default description. */ - public static Fee createInstant( BigDecimal cost, FeeType type, boolean isPremium, Range validDateRange, Object... descriptionArgs) { Fee instance = create(cost, type, isPremium, descriptionArgs); - instance.validDateRangeInstant = validDateRange; + instance.validDateRange = validDateRange; return instance; } diff --git a/core/src/main/java/google/registry/model/domain/fee/FeeQueryCommandExtensionItem.java b/core/src/main/java/google/registry/model/domain/fee/FeeQueryCommandExtensionItem.java index 03222958bec..18bce08ccbd 100644 --- a/core/src/main/java/google/registry/model/domain/fee/FeeQueryCommandExtensionItem.java +++ b/core/src/main/java/google/registry/model/domain/fee/FeeQueryCommandExtensionItem.java @@ -19,9 +19,9 @@ import google.registry.model.ImmutableObject; import google.registry.model.domain.Period; import jakarta.xml.bind.annotation.XmlTransient; +import java.time.Instant; import java.util.Optional; import org.joda.money.CurrencyUnit; -import org.joda.time.DateTime; /** * Abstract base class for the fee request query items used in Check and Info commands. It handles @@ -86,7 +86,7 @@ public boolean shouldLoadDomainForCheck() { public abstract CurrencyUnit getCurrency(); /** The as-of date for the fee extension to run. */ - public abstract Optional getEffectiveDate(); + public abstract Optional getEffectiveDate(); /** The name of the command being checked. */ public abstract CommandName getCommandName(); diff --git a/core/src/main/java/google/registry/model/domain/fee/FeeQueryResponseExtensionItem.java b/core/src/main/java/google/registry/model/domain/fee/FeeQueryResponseExtensionItem.java index 310b1406bf4..64f02da2e34 100644 --- a/core/src/main/java/google/registry/model/domain/fee/FeeQueryResponseExtensionItem.java +++ b/core/src/main/java/google/registry/model/domain/fee/FeeQueryResponseExtensionItem.java @@ -24,9 +24,9 @@ import google.registry.model.domain.fee.FeeQueryCommandExtensionItem.CommandName; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlTransient; +import java.time.Instant; import java.util.List; import org.joda.money.CurrencyUnit; -import org.joda.time.DateTime; /** * Abstract base class for the fee request query items used in Check and Info responses. It handles @@ -110,11 +110,11 @@ public B setReasonIfSupported(@SuppressWarnings("unused") String reason) { return thisCastToDerived(); // Default impl is a noop. } - public B setEffectiveDateIfSupported(@SuppressWarnings("unused") DateTime effectiveDate) { + public B setEffectiveDateIfSupported(@SuppressWarnings("unused") Instant effectiveDate) { return thisCastToDerived(); // Default impl is a noop. } - public B setNotAfterDateIfSupported(@SuppressWarnings("unused") DateTime notAfterDate) { + public B setNotAfterDateIfSupported(@SuppressWarnings("unused") Instant notAfterDate) { return thisCastToDerived(); // Default impl is a noop. } diff --git a/core/src/main/java/google/registry/model/domain/fee06/FeeCheckCommandExtensionItemV06.java b/core/src/main/java/google/registry/model/domain/fee06/FeeCheckCommandExtensionItemV06.java index 0c682b797d0..7719ce72444 100644 --- a/core/src/main/java/google/registry/model/domain/fee06/FeeCheckCommandExtensionItemV06.java +++ b/core/src/main/java/google/registry/model/domain/fee06/FeeCheckCommandExtensionItemV06.java @@ -17,9 +17,9 @@ import google.registry.model.domain.fee.FeeCheckCommandExtensionItem; import google.registry.model.domain.fee.FeeExtensionCommandDescriptor; import jakarta.xml.bind.annotation.XmlType; +import java.time.Instant; import java.util.Optional; import org.joda.money.CurrencyUnit; -import org.joda.time.DateTime; /** An individual price check item in version 0.6 of the fee extension on Check commands. */ @XmlType(propOrder = {"name", "currency", "command", "period"}) @@ -78,7 +78,7 @@ public FeeCheckResponseExtensionItemV06.Builder createResponseBuilder() { } @Override - public Optional getEffectiveDate() { + public Optional getEffectiveDate() { return Optional.empty(); } } diff --git a/core/src/main/java/google/registry/model/domain/fee06/FeeInfoCommandExtensionV06.java b/core/src/main/java/google/registry/model/domain/fee06/FeeInfoCommandExtensionV06.java index ba875b0d533..ccc6fe67fc8 100644 --- a/core/src/main/java/google/registry/model/domain/fee06/FeeInfoCommandExtensionV06.java +++ b/core/src/main/java/google/registry/model/domain/fee06/FeeInfoCommandExtensionV06.java @@ -19,9 +19,9 @@ import google.registry.model.eppinput.EppInput.CommandExtension; import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlType; +import java.time.Instant; import java.util.Optional; import org.joda.money.CurrencyUnit; -import org.joda.time.DateTime; /** A fee extension that may be present on domain info commands. */ @XmlRootElement(name = "info") @@ -65,7 +65,7 @@ public CurrencyUnit getCurrency() { } @Override - public Optional getEffectiveDate() { + public Optional getEffectiveDate() { return Optional.empty(); } } diff --git a/core/src/main/java/google/registry/model/domain/fee11/FeeCheckCommandExtensionV11.java b/core/src/main/java/google/registry/model/domain/fee11/FeeCheckCommandExtensionV11.java index e276544cab5..f8afd05fd4c 100644 --- a/core/src/main/java/google/registry/model/domain/fee11/FeeCheckCommandExtensionV11.java +++ b/core/src/main/java/google/registry/model/domain/fee11/FeeCheckCommandExtensionV11.java @@ -27,9 +27,9 @@ import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlType; +import java.time.Instant; import java.util.Optional; import org.joda.money.CurrencyUnit; -import org.joda.time.DateTime; /** * Version 0.11 of the fee extension that may be present on domain check commands. Unlike other @@ -138,7 +138,7 @@ public FeeCheckResponseExtensionItemV11.Builder createResponseBuilder() { } @Override - public Optional getEffectiveDate() { + public Optional getEffectiveDate() { return Optional.empty(); } } diff --git a/core/src/main/java/google/registry/model/domain/fee12/FeeCheckCommandExtensionItemV12.java b/core/src/main/java/google/registry/model/domain/fee12/FeeCheckCommandExtensionItemV12.java index eaf5ef562b1..22df170a15d 100644 --- a/core/src/main/java/google/registry/model/domain/fee12/FeeCheckCommandExtensionItemV12.java +++ b/core/src/main/java/google/registry/model/domain/fee12/FeeCheckCommandExtensionItemV12.java @@ -20,10 +20,10 @@ import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlType; +import java.time.Instant; import java.util.Locale; import java.util.Optional; import org.joda.money.CurrencyUnit; -import org.joda.time.DateTime; /** * An individual price check item in version 0.12 of the fee extension on domain check commands. @@ -59,7 +59,7 @@ public class FeeCheckCommandExtensionItemV12 extends FeeCheckCommandExtensionIte String feeClass; @XmlElement(name = "date") - DateTime feeDate; + Instant feeDate; /** Version .12 does not support domain name or currency in fee extension items. */ @Override @@ -111,7 +111,7 @@ public FeeCheckResponseExtensionItemV12.Builder createResponseBuilder() { } @Override - public Optional getEffectiveDate() { + public Optional getEffectiveDate() { return Optional.ofNullable(feeDate); } } diff --git a/core/src/main/java/google/registry/model/domain/fee12/FeeCheckResponseExtensionItemCommandV12.java b/core/src/main/java/google/registry/model/domain/fee12/FeeCheckResponseExtensionItemCommandV12.java index 6821365a6d6..41a03df7e1b 100644 --- a/core/src/main/java/google/registry/model/domain/fee12/FeeCheckResponseExtensionItemCommandV12.java +++ b/core/src/main/java/google/registry/model/domain/fee12/FeeCheckResponseExtensionItemCommandV12.java @@ -26,8 +26,8 @@ import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlType; +import java.time.Instant; import java.util.List; -import org.joda.time.DateTime; /** The version 0.12 response command entity for a domain check on a single resource. */ @XmlType(propOrder = {"period", "fee", "feeClass", "effectiveDate", "notAfterDate"}) @@ -65,12 +65,11 @@ public class FeeCheckResponseExtensionItemCommandV12 extends ImmutableObject { /** The effective date that the check is to be performed on (if specified in the query). */ @XmlElement(name = "date") - DateTime effectiveDate; + Instant effectiveDate; /** The date after which the quoted fee is no longer valid (if applicable). */ @XmlElement(name = "notAfter") - DateTime notAfterDate; - + Instant notAfterDate; public String getFeeClass() { return feeClass; @@ -99,12 +98,12 @@ public Builder setPeriod(Period period) { return this; } - public Builder setEffectiveDate(DateTime effectiveDate) { + public Builder setEffectiveDate(Instant effectiveDate) { getInstance().effectiveDate = effectiveDate; return this; } - public Builder setNotAfterDate(DateTime notAfterDate) { + public Builder setNotAfterDate(Instant notAfterDate) { getInstance().notAfterDate = notAfterDate; return this; } diff --git a/core/src/main/java/google/registry/model/domain/fee12/FeeCheckResponseExtensionItemV12.java b/core/src/main/java/google/registry/model/domain/fee12/FeeCheckResponseExtensionItemV12.java index 0071857d63e..bf147d19e8f 100644 --- a/core/src/main/java/google/registry/model/domain/fee12/FeeCheckResponseExtensionItemV12.java +++ b/core/src/main/java/google/registry/model/domain/fee12/FeeCheckResponseExtensionItemV12.java @@ -23,7 +23,7 @@ import google.registry.model.domain.fee.FeeCheckResponseExtensionItem; import google.registry.model.domain.fee.FeeQueryCommandExtensionItem.CommandName; import jakarta.xml.bind.annotation.XmlType; -import org.joda.time.DateTime; +import java.time.Instant; /** * The version 0.12 response for a domain check on a single resource. @@ -110,13 +110,13 @@ public FeeCheckResponseExtensionItemV12 build() { } @Override - public Builder setEffectiveDateIfSupported(DateTime effectiveDate) { + public Builder setEffectiveDateIfSupported(Instant effectiveDate) { commandBuilder.setEffectiveDate(effectiveDate); return this; } @Override - public Builder setNotAfterDateIfSupported(DateTime notAfterDate) { + public Builder setNotAfterDateIfSupported(Instant notAfterDate) { commandBuilder.setNotAfterDate(notAfterDate); return this; } diff --git a/core/src/main/java/google/registry/model/domain/fee12/package-info.java b/core/src/main/java/google/registry/model/domain/fee12/package-info.java index 9bf29e3ce3a..41eb78d761c 100644 --- a/core/src/main/java/google/registry/model/domain/fee12/package-info.java +++ b/core/src/main/java/google/registry/model/domain/fee12/package-info.java @@ -18,12 +18,13 @@ elementFormDefault = XmlNsForm.QUALIFIED) @XmlAccessorType(XmlAccessType.FIELD) @XmlJavaTypeAdapters({ - @XmlJavaTypeAdapter(CurrencyUnitAdapter.class), - @XmlJavaTypeAdapter(UtcDateTimeAdapter.class)}) + @XmlJavaTypeAdapter(CurrencyUnitAdapter.class), + @XmlJavaTypeAdapter(UtcInstantAdapter.class) +}) package google.registry.model.domain.fee12; import google.registry.model.adapters.CurrencyUnitAdapter; -import google.registry.xml.UtcDateTimeAdapter; +import google.registry.xml.UtcInstantAdapter; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlNs; diff --git a/core/src/main/java/google/registry/model/domain/feestdv1/FeeCheckCommandExtensionItemStdV1.java b/core/src/main/java/google/registry/model/domain/feestdv1/FeeCheckCommandExtensionItemStdV1.java index 0152b056e3c..4f600cec975 100644 --- a/core/src/main/java/google/registry/model/domain/feestdv1/FeeCheckCommandExtensionItemStdV1.java +++ b/core/src/main/java/google/registry/model/domain/feestdv1/FeeCheckCommandExtensionItemStdV1.java @@ -19,10 +19,10 @@ import google.registry.model.domain.fee.FeeCheckCommandExtensionItem; import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlType; +import java.time.Instant; import java.util.Locale; import java.util.Optional; import org.joda.money.CurrencyUnit; -import org.joda.time.DateTime; /** * An individual price check item in version 1.0 of the fee extension on domain check commands. @@ -100,7 +100,7 @@ public FeeCheckResponseExtensionItemStdV1.Builder createResponseBuilder() { } @Override - public Optional getEffectiveDate() { + public Optional getEffectiveDate() { return Optional.empty(); } } diff --git a/core/src/main/java/google/registry/model/domain/feestdv1/package-info.java b/core/src/main/java/google/registry/model/domain/feestdv1/package-info.java index b99a8baea6c..718c48a321a 100644 --- a/core/src/main/java/google/registry/model/domain/feestdv1/package-info.java +++ b/core/src/main/java/google/registry/model/domain/feestdv1/package-info.java @@ -19,12 +19,12 @@ @XmlAccessorType(XmlAccessType.FIELD) @XmlJavaTypeAdapters({ @XmlJavaTypeAdapter(CurrencyUnitAdapter.class), - @XmlJavaTypeAdapter(UtcDateTimeAdapter.class) + @XmlJavaTypeAdapter(UtcInstantAdapter.class) }) package google.registry.model.domain.feestdv1; import google.registry.model.adapters.CurrencyUnitAdapter; -import google.registry.xml.UtcDateTimeAdapter; +import google.registry.xml.UtcInstantAdapter; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlNs; diff --git a/core/src/main/java/google/registry/model/eppoutput/CreateData.java b/core/src/main/java/google/registry/model/eppoutput/CreateData.java index fd5daec3c35..45d3a4e4e2b 100644 --- a/core/src/main/java/google/registry/model/eppoutput/CreateData.java +++ b/core/src/main/java/google/registry/model/eppoutput/CreateData.java @@ -19,14 +19,14 @@ import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlTransient; import jakarta.xml.bind.annotation.XmlType; -import org.joda.time.DateTime; +import java.time.Instant; /** The {@link ResponseData} returned when creating a resource. */ @XmlTransient public abstract class CreateData implements ResponseData { @XmlElement(name = "crDate") - protected DateTime creationDate; + protected Instant creationDate; /** An acknowledgment message indicating that a contact was created. */ @XmlRootElement(name = "creData", namespace = "urn:ietf:params:xml:ns:contact-1.0") @@ -35,7 +35,7 @@ public static class ContactCreateData extends CreateData { String id; - public static ContactCreateData create(String id, DateTime creationDate) { + public static ContactCreateData create(String id, Instant creationDate) { ContactCreateData instance = new ContactCreateData(); instance.id = id; instance.creationDate = creationDate; @@ -53,10 +53,10 @@ public static class DomainCreateData extends CreateData { String name; @XmlElement(name = "exDate") - DateTime expirationDate; + Instant expirationDate; public static DomainCreateData create( - String name, DateTime creationDate, DateTime expirationDate) { + String name, Instant creationDate, Instant expirationDate) { DomainCreateData instance = new DomainCreateData(); instance.name = name; instance.creationDate = creationDate; @@ -68,11 +68,11 @@ public String name() { return name; } - public DateTime creationDate() { + public Instant creationDate() { return creationDate; } - public DateTime expirationDate() { + public Instant expirationDate() { return expirationDate; } } @@ -84,7 +84,7 @@ public static class HostCreateData extends CreateData { String name; - public static HostCreateData create(String name, DateTime creationDate) { + public static HostCreateData create(String name, Instant creationDate) { HostCreateData instance = new HostCreateData(); instance.name = name; instance.creationDate = creationDate; diff --git a/core/src/main/java/google/registry/model/eppoutput/Greeting.java b/core/src/main/java/google/registry/model/eppoutput/Greeting.java index 02aa71cd960..3d9e7834119 100644 --- a/core/src/main/java/google/registry/model/eppoutput/Greeting.java +++ b/core/src/main/java/google/registry/model/eppoutput/Greeting.java @@ -20,8 +20,8 @@ import google.registry.model.eppoutput.EppOutput.ResponseOrGreeting; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElementWrapper; +import java.time.Instant; import java.util.Set; -import org.joda.time.DateTime; /** * A greeting, defined in RFC5730. @@ -32,7 +32,7 @@ public class Greeting extends ImmutableObject implements ResponseOrGreeting { String svID; - DateTime svDate; + Instant svDate; /** This is never changed, so it might as well be static for efficiency. */ @XmlElement @@ -42,7 +42,7 @@ public class Greeting extends ImmutableObject implements ResponseOrGreeting { @XmlElement static Dcp dcp = new Dcp(); - public static Greeting create(DateTime svDate, String svID) { + public static Greeting create(Instant svDate, String svID) { Greeting instance = new Greeting(); instance.svID = svID; instance.svDate = svDate; diff --git a/core/src/main/java/google/registry/model/eppoutput/package-info.java b/core/src/main/java/google/registry/model/eppoutput/package-info.java index a00cab57a83..bd196cf1f62 100644 --- a/core/src/main/java/google/registry/model/eppoutput/package-info.java +++ b/core/src/main/java/google/registry/model/eppoutput/package-info.java @@ -17,13 +17,18 @@ xmlns = @XmlNs(prefix = "", namespaceURI = "urn:ietf:params:xml:ns:epp-1.0"), elementFormDefault = XmlNsForm.QUALIFIED) @XmlAccessorType(XmlAccessType.FIELD) -@XmlJavaTypeAdapter(UtcDateTimeAdapter.class) +@XmlJavaTypeAdapters({ + @XmlJavaTypeAdapter(UtcDateTimeAdapter.class), + @XmlJavaTypeAdapter(UtcInstantAdapter.class) +}) package google.registry.model.eppoutput; import google.registry.xml.UtcDateTimeAdapter; +import google.registry.xml.UtcInstantAdapter; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlNs; import jakarta.xml.bind.annotation.XmlNsForm; import jakarta.xml.bind.annotation.XmlSchema; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapters; diff --git a/core/src/main/java/google/registry/model/host/HostInfoData.java b/core/src/main/java/google/registry/model/host/HostInfoData.java index 2ae5027eda5..0739ea108e2 100644 --- a/core/src/main/java/google/registry/model/host/HostInfoData.java +++ b/core/src/main/java/google/registry/model/host/HostInfoData.java @@ -23,8 +23,8 @@ import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlType; import java.net.InetAddress; +import java.time.Instant; import javax.annotation.Nullable; -import org.joda.time.DateTime; /** The {@link ResponseData} returned for an EPP info flow on a host. */ @XmlRootElement(name = "infData") @@ -64,7 +64,7 @@ public abstract class HostInfoData implements ResponseData { abstract String getCreationRegistrarId(); @XmlElement(name = "crDate") - abstract DateTime getCreationTime(); + abstract Instant getCreationTime(); @XmlElement(name = "upID") @Nullable @@ -72,11 +72,11 @@ public abstract class HostInfoData implements ResponseData { @XmlElement(name = "upDate") @Nullable - abstract DateTime getLastEppUpdateTime(); + abstract Instant getLastEppUpdateTime(); @XmlElement(name = "trDate") @Nullable - abstract DateTime getLastTransferTime(); + abstract Instant getLastTransferTime(); /** Builder for {@link HostInfoData}. */ @AutoValue.Builder @@ -91,12 +91,14 @@ public abstract static class Builder { public abstract Builder setCreationRegistrarId(String creationRegistrarId); - public abstract Builder setCreationTime(DateTime creationTime); + public abstract Builder setCreationTime(Instant creationTime); public abstract Builder setLastEppUpdateRegistrarId(@Nullable String lastEppUpdateRegistrarId); - public abstract Builder setLastEppUpdateTime(@Nullable DateTime lastEppUpdateTime); - public abstract Builder setLastTransferTime(@Nullable DateTime lastTransferTime); + public abstract Builder setLastEppUpdateTime(@Nullable Instant lastEppUpdateTime); + + public abstract Builder setLastTransferTime(@Nullable Instant lastTransferTime); + public abstract HostInfoData build(); } diff --git a/core/src/main/java/google/registry/model/mark/ProtectedMark.java b/core/src/main/java/google/registry/model/mark/ProtectedMark.java index 097969a199d..1144d84d50e 100644 --- a/core/src/main/java/google/registry/model/mark/ProtectedMark.java +++ b/core/src/main/java/google/registry/model/mark/ProtectedMark.java @@ -16,14 +16,14 @@ import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlTransient; -import org.joda.time.DateTime; +import java.time.Instant; /** Common fields for {@link CourtMark} and {@link TreatyOrStatuteMark}. */ @XmlTransient public abstract class ProtectedMark extends CommonMarkFields { /** The date of protection of the mark. */ @XmlElement(name = "proDate") - DateTime protectionDate; + Instant protectionDate; /** * The reference number of the court's opinion for a court mark, or the number of the mark of the @@ -32,7 +32,7 @@ public abstract class ProtectedMark extends CommonMarkFields { @XmlElement(name = "refNum") String referenceNumber; - public DateTime getProtectionDate() { + public Instant getProtectionDate() { return protectionDate; } diff --git a/core/src/main/java/google/registry/model/mark/Trademark.java b/core/src/main/java/google/registry/model/mark/Trademark.java index 713b1a7cf90..eb53c44fa25 100644 --- a/core/src/main/java/google/registry/model/mark/Trademark.java +++ b/core/src/main/java/google/registry/model/mark/Trademark.java @@ -19,8 +19,8 @@ import com.google.common.collect.ImmutableList; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlType; +import java.time.Instant; import java.util.List; -import org.joda.time.DateTime; /** Holds information about a registered trademark. */ @XmlType(propOrder = { @@ -52,7 +52,7 @@ public class Trademark extends CommonMarkFields { /** The date that the trademark was applied for. */ @XmlElement(name = "apDate") - DateTime applicationDate; + Instant applicationDate; /** The trademark registration number registered in the trademark office. */ @XmlElement(name = "regNum") @@ -60,11 +60,11 @@ public class Trademark extends CommonMarkFields { /** The date the trademark was registered. */ @XmlElement(name = "regDate") - DateTime registrationDate; + Instant registrationDate; /** Expiration date of the trademark. */ @XmlElement(name = "exDate") - DateTime expirationDate; + Instant expirationDate; public String getJurisdiction() { return jurisdiction; @@ -78,7 +78,7 @@ public String getApplicationId() { return applicationId; } - public DateTime getApplicationDate() { + public Instant getApplicationDate() { return applicationDate; } @@ -86,11 +86,11 @@ public String getRegistrationNumber() { return registrationNumber; } - public DateTime getRegistrationDate() { + public Instant getRegistrationDate() { return registrationDate; } - public DateTime getExpirationDate() { + public Instant getExpirationDate() { return expirationDate; } } diff --git a/core/src/main/java/google/registry/model/mark/TreatyOrStatuteMark.java b/core/src/main/java/google/registry/model/mark/TreatyOrStatuteMark.java index 595c69d30b4..78e483f0cb7 100644 --- a/core/src/main/java/google/registry/model/mark/TreatyOrStatuteMark.java +++ b/core/src/main/java/google/registry/model/mark/TreatyOrStatuteMark.java @@ -19,8 +19,8 @@ import com.google.common.collect.ImmutableList; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlType; +import java.time.Instant; import java.util.List; -import org.joda.time.DateTime; /** Information about a mark derived from a treaty or statute. */ @XmlType(propOrder = { @@ -46,7 +46,7 @@ public class TreatyOrStatuteMark extends ProtectedMark { /** Execution date of the treaty or statute. */ @XmlElement(name = "execDate") - DateTime executionDate; + Instant executionDate; public ImmutableList getMarkProtections() { return nullToEmptyImmutableCopy(markProtections); @@ -56,7 +56,7 @@ public String getTitle() { return title; } - public DateTime getExecutionDate() { + public Instant getExecutionDate() { return executionDate; } } diff --git a/core/src/main/java/google/registry/model/mark/package-info.java b/core/src/main/java/google/registry/model/mark/package-info.java index bd382c3455a..ac9c56ee216 100644 --- a/core/src/main/java/google/registry/model/mark/package-info.java +++ b/core/src/main/java/google/registry/model/mark/package-info.java @@ -17,10 +17,10 @@ xmlns = @XmlNs(prefix = "mark", namespaceURI = "urn:ietf:params:xml:ns:mark-1.0"), elementFormDefault = XmlNsForm.QUALIFIED) @XmlAccessorType(XmlAccessType.FIELD) -@XmlJavaTypeAdapter(UtcDateTimeAdapter.class) +@XmlJavaTypeAdapter(UtcInstantAdapter.class) package google.registry.model.mark; -import google.registry.xml.UtcDateTimeAdapter; +import google.registry.xml.UtcInstantAdapter; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlNs; diff --git a/core/src/main/java/google/registry/model/poll/MessageQueueInfo.java b/core/src/main/java/google/registry/model/poll/MessageQueueInfo.java index bf40c36a060..d5b02671fb6 100644 --- a/core/src/main/java/google/registry/model/poll/MessageQueueInfo.java +++ b/core/src/main/java/google/registry/model/poll/MessageQueueInfo.java @@ -21,14 +21,14 @@ import google.registry.model.ImmutableObject; import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlElement; -import org.joda.time.DateTime; +import java.time.Instant; /** Information about the message queue for the currently logged in registrar. */ public class MessageQueueInfo extends ImmutableObject { /** The date and time that the current message was enqueued. */ @XmlElement(name = "qDate") - DateTime queueDate; + Instant queueDate; /** A human-readable message. */ String msg; @@ -43,7 +43,7 @@ public class MessageQueueInfo extends ImmutableObject { /** A builder for constructing a {@link MessageQueueInfo}, since it's immutable. */ public static class Builder extends Buildable.Builder { - public Builder setQueueDate(DateTime queueDate) { + public Builder setQueueDate(Instant queueDate) { getInstance().queueDate = queueDate; return this; } diff --git a/core/src/main/java/google/registry/model/pricing/PremiumPricingEngine.java b/core/src/main/java/google/registry/model/pricing/PremiumPricingEngine.java index 8e642b64f13..7a1de1fc5c7 100644 --- a/core/src/main/java/google/registry/model/pricing/PremiumPricingEngine.java +++ b/core/src/main/java/google/registry/model/pricing/PremiumPricingEngine.java @@ -14,8 +14,8 @@ package google.registry.model.pricing; +import java.time.Instant; import org.joda.money.Money; -import org.joda.time.DateTime; /** * A plugin interface for premium pricing engines. @@ -31,7 +31,7 @@ public interface PremiumPricingEngine { *

Note that the domainName must only contain a single part left of the TLD, i.e. subdomains * are not allowed, but multi-part TLDs are. */ - DomainPrices getDomainPrices(String domainName, DateTime priceTime); + DomainPrices getDomainPrices(String domainName, Instant priceTime); /** * A class containing information on premium prices for a specific domain name. diff --git a/core/src/main/java/google/registry/model/pricing/StaticPremiumListPricingEngine.java b/core/src/main/java/google/registry/model/pricing/StaticPremiumListPricingEngine.java index 8e27679a390..e56bf935da2 100644 --- a/core/src/main/java/google/registry/model/pricing/StaticPremiumListPricingEngine.java +++ b/core/src/main/java/google/registry/model/pricing/StaticPremiumListPricingEngine.java @@ -21,9 +21,9 @@ import google.registry.model.tld.Tld; import google.registry.model.tld.label.PremiumListDao; import jakarta.inject.Inject; +import java.time.Instant; import java.util.Optional; import org.joda.money.Money; -import org.joda.time.DateTime; /** A premium list pricing engine that stores static pricing information in database entities. */ public final class StaticPremiumListPricingEngine implements PremiumPricingEngine { @@ -34,7 +34,7 @@ public final class StaticPremiumListPricingEngine implements PremiumPricingEngin @Inject StaticPremiumListPricingEngine() {} @Override - public DomainPrices getDomainPrices(String domainName, DateTime priceTime) { + public DomainPrices getDomainPrices(String domainName, Instant priceTime) { String tldStr = getTldFromDomainName(domainName); String label = InternetDomainName.from(domainName).parts().get(0); Tld tld = Tld.get(checkNotNull(tldStr, "tld")); diff --git a/core/src/main/java/google/registry/model/smd/SignedMark.java b/core/src/main/java/google/registry/model/smd/SignedMark.java index ce80ccfcd93..d67a51027c2 100644 --- a/core/src/main/java/google/registry/model/smd/SignedMark.java +++ b/core/src/main/java/google/registry/model/smd/SignedMark.java @@ -20,7 +20,7 @@ import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElementRef; import jakarta.xml.bind.annotation.XmlRootElement; -import org.joda.time.DateTime; +import java.time.Instant; /** * Represents an XML fragment that is digitally signed by the TMCH to prove ownership over a mark. @@ -43,11 +43,11 @@ public class SignedMark extends ImmutableObject implements AbstractSignedMark { /** Creation time of this signed mark. */ @XmlElement(name = "notBefore") - DateTime creationTime; + Instant creationTime; /** Expiration time of this signed mark. */ @XmlElement(name = "notAfter") - DateTime expirationTime; + Instant expirationTime; /** Mark information. */ @XmlElementRef(type = Mark.class) @@ -66,11 +66,11 @@ public String getId() { return id; } - public DateTime getCreationTime() { + public Instant getCreationTime() { return creationTime; } - public DateTime getExpirationTime() { + public Instant getExpirationTime() { return expirationTime; } diff --git a/core/src/main/java/google/registry/model/smd/SignedMarkRevocationList.java b/core/src/main/java/google/registry/model/smd/SignedMarkRevocationList.java index 083882f343c..3709213f5aa 100644 --- a/core/src/main/java/google/registry/model/smd/SignedMarkRevocationList.java +++ b/core/src/main/java/google/registry/model/smd/SignedMarkRevocationList.java @@ -30,8 +30,8 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.MapKeyColumn; +import java.time.Instant; import java.util.Map; -import org.joda.time.DateTime; /** * Signed Mark Data Revocation List (SMDRL). @@ -52,7 +52,7 @@ public class SignedMarkRevocationList extends ImmutableObject { Long revisionId; /** Time when this list was last updated, as specified in the first line of the CSV file. */ - DateTime creationTime; + Instant creationTime; /** A map from SMD IDs to revocation time. */ @ElementCollection @@ -61,7 +61,7 @@ public class SignedMarkRevocationList extends ImmutableObject { joinColumns = @JoinColumn(name = "revisionId", referencedColumnName = "revisionId")) @MapKeyColumn(name = "smdId") @Column(name = "revocationTime", nullable = false) - Map revokes; + Map revokes; /** A cached supplier that fetches the {@link SignedMarkRevocationList} object. */ private static final Supplier CACHE = @@ -73,7 +73,7 @@ public static SignedMarkRevocationList get() { /** Create a new {@link SignedMarkRevocationList} without saving it. */ public static SignedMarkRevocationList create( - DateTime creationTime, ImmutableMap revokes) { + Instant creationTime, ImmutableMap revokes) { SignedMarkRevocationList instance = new SignedMarkRevocationList(); instance.creationTime = checkNotNull(creationTime, "creationTime"); instance.revokes = checkNotNull(revokes, "revokes"); @@ -81,13 +81,13 @@ public static SignedMarkRevocationList create( } /** Returns {@code true} if the SMD ID has been revoked at the given point in time. */ - public boolean isSmdRevoked(String smdId, DateTime now) { - DateTime revoked = revokes.get(checkNotNull(smdId, "smdId")); + public boolean isSmdRevoked(String smdId, Instant now) { + Instant revoked = revokes.get(checkNotNull(smdId, "smdId")); return revoked != null && isBeforeOrAt(revoked, now); } /** Returns the creation timestamp specified at the top of the SMDRL CSV file. */ - public DateTime getCreationTime() { + public Instant getCreationTime() { return creationTime; } diff --git a/core/src/main/java/google/registry/model/smd/SignedMarkRevocationListDao.java b/core/src/main/java/google/registry/model/smd/SignedMarkRevocationListDao.java index cf1f8df53a9..c39fee5a0f3 100644 --- a/core/src/main/java/google/registry/model/smd/SignedMarkRevocationListDao.java +++ b/core/src/main/java/google/registry/model/smd/SignedMarkRevocationListDao.java @@ -15,7 +15,7 @@ package google.registry.model.smd; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; -import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.START_INSTANT; import com.google.common.collect.ImmutableMap; import com.google.common.flogger.FluentLogger; @@ -41,7 +41,7 @@ static SignedMarkRevocationList load() { .getResultStream() .findFirst(); }); - return smdrl.orElseGet(() -> SignedMarkRevocationList.create(START_OF_TIME, ImmutableMap.of())); + return smdrl.orElseGet(() -> SignedMarkRevocationList.create(START_INSTANT, ImmutableMap.of())); } /** @@ -51,7 +51,7 @@ static SignedMarkRevocationList load() { * {@code revisionId} are needed. */ public static SignedMarkRevocationList save(SignedMarkRevocationList signedMarkRevocationList) { - var persisted = + SignedMarkRevocationList persisted = tm().transact( () -> { var entity = diff --git a/core/src/main/java/google/registry/model/smd/package-info.java b/core/src/main/java/google/registry/model/smd/package-info.java index 219bd574a8c..318cf93f0f7 100644 --- a/core/src/main/java/google/registry/model/smd/package-info.java +++ b/core/src/main/java/google/registry/model/smd/package-info.java @@ -17,10 +17,10 @@ xmlns = @XmlNs(prefix = "smd", namespaceURI = "urn:ietf:params:xml:ns:signedMark-1.0"), elementFormDefault = XmlNsForm.QUALIFIED) @XmlAccessorType(XmlAccessType.FIELD) -@XmlJavaTypeAdapter(UtcDateTimeAdapter.class) +@XmlJavaTypeAdapter(UtcInstantAdapter.class) package google.registry.model.smd; -import google.registry.xml.UtcDateTimeAdapter; +import google.registry.xml.UtcInstantAdapter; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlNs; diff --git a/core/src/main/java/google/registry/model/tld/Tld.java b/core/src/main/java/google/registry/model/tld/Tld.java index 625eb6a054d..35c6ecd58cb 100644 --- a/core/src/main/java/google/registry/model/tld/Tld.java +++ b/core/src/main/java/google/registry/model/tld/Tld.java @@ -806,7 +806,7 @@ public Fee getEapFeeFor(Instant now) { Range.closedOpen( periodStart != null ? periodStart : START_INSTANT, periodEnd != null ? periodEnd : END_INSTANT); - return Fee.createInstant( + return Fee.create( eapFeeSchedule.getValueAtTime(now).getAmount(), FeeType.EAP, // An EAP fee does not count as premium -- it's a separate one-time fee, independent of diff --git a/core/src/main/java/google/registry/model/tmch/ClaimsList.java b/core/src/main/java/google/registry/model/tmch/ClaimsList.java index 23808ea5463..f0497d63334 100644 --- a/core/src/main/java/google/registry/model/tmch/ClaimsList.java +++ b/core/src/main/java/google/registry/model/tmch/ClaimsList.java @@ -19,8 +19,6 @@ import static com.google.common.collect.ImmutableMap.toImmutableMap; import static google.registry.persistence.transaction.QueryComposer.Comparator.EQ; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; -import static google.registry.util.DateTimeUtils.toDateTime; -import static google.registry.util.DateTimeUtils.toInstant; import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.common.annotations.VisibleForTesting; @@ -43,7 +41,6 @@ import java.time.Instant; import java.util.Map; import java.util.Optional; -import org.joda.time.DateTime; /** * A list of TMCH claims labels and their associated claims keys. @@ -141,16 +138,8 @@ public Long getRevisionId() { * * @see DNL List * creation datetime - * @deprecated Use {@link #getTmdbGenerationTimeInstant()} */ - @Deprecated - @SuppressWarnings("InlineMeSuggester") - public DateTime getTmdbGenerationTime() { - return toDateTime(tmdbGenerationTime); - } - - /** Returns the time when the external TMDB service generated this revision of the claims list. */ - public Instant getTmdbGenerationTimeInstant() { + public Instant getTmdbGenerationTime() { return tmdbGenerationTime; } @@ -159,15 +148,6 @@ public Instant getCreationTime() { return creationTimestamp.getTimestamp(); } - /** - * @deprecated Use {@link #getCreationTime()} - */ - @Deprecated - @SuppressWarnings("InlineMeSuggester") - public DateTime getCreationDateTime() { - return toDateTime(creationTimestamp.getTimestamp()); - } - /** * Returns the claim key for a given domain if there is one, empty otherwise. * @@ -240,14 +220,4 @@ public static ClaimsList create( instance.labelsToKeys = checkNotNull(labelsToKeys); return instance; } - - /** - * @deprecated Use {@link #create(Instant, ImmutableMap)} - */ - @Deprecated - @SuppressWarnings("InlineMeSuggester") - public static ClaimsList create( - DateTime tmdbGenerationTime, ImmutableMap labelsToKeys) { - return create(toInstant(tmdbGenerationTime), labelsToKeys); - } } diff --git a/core/src/main/java/google/registry/model/tmch/ClaimsListDao.java b/core/src/main/java/google/registry/model/tmch/ClaimsListDao.java index 2e041794ed1..9409cab6e08 100644 --- a/core/src/main/java/google/registry/model/tmch/ClaimsListDao.java +++ b/core/src/main/java/google/registry/model/tmch/ClaimsListDao.java @@ -16,7 +16,7 @@ import static google.registry.config.RegistryConfig.getClaimsListCacheDuration; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; -import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.START_INSTANT; import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.common.annotations.VisibleForTesting; @@ -83,7 +83,7 @@ private static ClaimsList getUncached() { .setMaxResults(1) .getResultStream() .findFirst()) - .orElse(ClaimsList.create(START_OF_TIME, ImmutableMap.of())); + .orElse(ClaimsList.create(START_INSTANT, ImmutableMap.of())); } private ClaimsListDao() {} diff --git a/core/src/main/java/google/registry/model/tmch/TmchCrl.java b/core/src/main/java/google/registry/model/tmch/TmchCrl.java index 52d62e3ba2d..ce4b0e47e51 100644 --- a/core/src/main/java/google/registry/model/tmch/TmchCrl.java +++ b/core/src/main/java/google/registry/model/tmch/TmchCrl.java @@ -19,9 +19,9 @@ import google.registry.model.common.CrossTldSingleton; import jakarta.persistence.Column; +import java.time.Instant; import java.util.Optional; import javax.annotation.concurrent.Immutable; -import org.joda.time.DateTime; /** Singleton for ICANN's TMCH CA certificate revocation list (CRL). */ @jakarta.persistence.Entity @@ -32,7 +32,7 @@ public final class TmchCrl extends CrossTldSingleton { String crl; @Column(name = "updateTimestamp", nullable = false) - DateTime updated; + Instant updated; @Column(nullable = false) String url; @@ -53,7 +53,7 @@ public static void set(final String crl, final String url) { tm().transact( () -> { TmchCrl tmchCrl = new TmchCrl(); - tmchCrl.updated = tm().getTransactionTime(); + tmchCrl.updated = tm().getTxTime(); tmchCrl.crl = checkNotNull(crl, "crl"); tmchCrl.url = checkNotNull(url, "url"); tm().put(tmchCrl); @@ -71,7 +71,7 @@ public String getUrl() { } /** Time we last updated the Database with a newer ICANN CRL. */ - public DateTime getUpdated() { + public Instant getUpdated() { return updated; } } diff --git a/core/src/main/java/google/registry/module/ServletBase.java b/core/src/main/java/google/registry/module/ServletBase.java index b558d096a7a..2b8ba9539bc 100644 --- a/core/src/main/java/google/registry/module/ServletBase.java +++ b/core/src/main/java/google/registry/module/ServletBase.java @@ -24,6 +24,7 @@ import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.security.Security; +import java.time.Duration; import java.util.concurrent.TimeoutException; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.joda.time.DateTime; @@ -49,17 +50,14 @@ public void init() { // credential, etc.), we log the error but keep the main thread running. Also, the shutdown hook // will only be registered if the metric reporter starts up correctly. try { - metricReporter.get().startAsync().awaitRunning(java.time.Duration.ofSeconds(10)); + metricReporter.get().startAsync().awaitRunning(Duration.ofSeconds(10)); logger.atInfo().log("Started up MetricReporter."); Runtime.getRuntime() .addShutdownHook( new Thread( () -> { try { - metricReporter - .get() - .stopAsync() - .awaitTerminated(java.time.Duration.ofSeconds(10)); + metricReporter.get().stopAsync().awaitTerminated(Duration.ofSeconds(10)); logger.atInfo().log("Shut down MetricReporter."); } catch (TimeoutException e) { logger.atSevere().withCause(e).log("Failed to stop MetricReporter."); diff --git a/core/src/main/java/google/registry/pricing/PricingEngineProxy.java b/core/src/main/java/google/registry/pricing/PricingEngineProxy.java index f50a82e5a18..8a2c8db927a 100644 --- a/core/src/main/java/google/registry/pricing/PricingEngineProxy.java +++ b/core/src/main/java/google/registry/pricing/PricingEngineProxy.java @@ -21,9 +21,9 @@ import google.registry.model.pricing.PremiumPricingEngine; import google.registry.model.pricing.PremiumPricingEngine.DomainPrices; import google.registry.model.tld.Tld; +import java.time.Instant; import java.util.Map; import org.joda.money.Money; -import org.joda.time.DateTime; /** * A global proxy providing static methods for getting premium prices that dispatches requests @@ -35,19 +35,19 @@ public final class PricingEngineProxy { premiumPricingEngines = DaggerPricingComponent.create().premiumPricingEngines(); /** Returns the billing cost for registering the specified domain name for this many years. */ - public static Money getDomainCreateCost(String domainName, DateTime priceTime, int years) { + public static Money getDomainCreateCost(String domainName, Instant priceTime, int years) { checkArgument(years > 0, "Number of years must be positive"); return getPricesForDomainName(domainName, priceTime).getCreateCost().multipliedBy(years); } /** Returns the billing cost for renewing the specified domain name for this many years. */ - public static Money getDomainRenewCost(String domainName, DateTime priceTime, int years) { + public static Money getDomainRenewCost(String domainName, Instant priceTime, int years) { checkArgument(years > 0, "Number of years must be positive"); return getPricesForDomainName(domainName, priceTime).getRenewCost().multipliedBy(years); } /** Returns true if the specified domain name is premium. */ - public static boolean isDomainPremium(String domainName, DateTime priceTime) { + public static boolean isDomainPremium(String domainName, Instant priceTime) { return getPricesForDomainName(domainName, priceTime).isPremium(); } @@ -56,7 +56,7 @@ public static boolean isDomainPremium(String domainName, DateTime priceTime) { * appropriate {@link PremiumPricingEngine} based on what is configured for the TLD that the * domain is under. */ - public static DomainPrices getPricesForDomainName(String domainName, DateTime priceTime) { + public static DomainPrices getPricesForDomainName(String domainName, Instant priceTime) { String tld = getTldFromDomainName(domainName); String clazz = Tld.get(tld).getPricingEngineClassName(); PremiumPricingEngine engine = premiumPricingEngines.get(clazz); diff --git a/core/src/main/java/google/registry/tmch/ClaimsListParser.java b/core/src/main/java/google/registry/tmch/ClaimsListParser.java index adc7efe1f8d..aea6c6bdd50 100644 --- a/core/src/main/java/google/registry/tmch/ClaimsListParser.java +++ b/core/src/main/java/google/registry/tmch/ClaimsListParser.java @@ -18,15 +18,16 @@ import com.google.common.base.Joiner; import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import google.registry.model.tmch.ClaimsList; import java.io.IOException; import java.io.StringReader; +import java.time.Instant; import java.util.List; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVRecord; -import org.joda.time.DateTime; /** * Claims List (MarksDB DNL CSV) Parser. @@ -36,6 +37,9 @@ */ public class ClaimsListParser { + private static final ImmutableList EXPECTED_CSV_HEADERS = + ImmutableList.of("DNL", "lookup-key", "insertion-datetime"); + /** * Converts the lines from the DNL CSV file into a {@link ClaimsList} object. * @@ -50,7 +54,7 @@ public static ClaimsList parse(List lines) throws IOException { "Line 1: Expected 2 elements, found %d", firstLine.size())); int version = Integer.parseInt(firstLine.get(0)); - DateTime creationTime = DateTime.parse(firstLine.get(1)); + Instant creationTime = Instant.parse(firstLine.get(1)); checkArgument(version == 1, String.format( "Line 1: Expected version 1, found %d", version)); @@ -61,9 +65,18 @@ public static ClaimsList parse(List lines) throws IOException { .setSkipHeaderRecord(true) .build() .parse(new StringReader(Joiner.on('\n').join(lines.subList(1, lines.size())))); + + checkArgument( + csv.getHeaderNames().equals(EXPECTED_CSV_HEADERS), + "Expected CSV headers %s, found %s", + EXPECTED_CSV_HEADERS, + csv.getHeaderNames()); + for (CSVRecord record : csv) { + checkArgument(record.isConsistent(), "Inconsistent number of fields in record"); String label = record.get("DNL"); String lookupKey = record.get("lookup-key"); + Instant.parse(record.get("insertion-datetime")); // Validate the format builder.put(label, lookupKey); } diff --git a/core/src/main/java/google/registry/tmch/SmdrlCsvParser.java b/core/src/main/java/google/registry/tmch/SmdrlCsvParser.java index a370f1608b3..5596a5db551 100644 --- a/core/src/main/java/google/registry/tmch/SmdrlCsvParser.java +++ b/core/src/main/java/google/registry/tmch/SmdrlCsvParser.java @@ -15,7 +15,6 @@ package google.registry.tmch; import static com.google.common.base.Preconditions.checkArgument; -import static org.joda.time.DateTimeZone.UTC; import com.google.common.base.Joiner; import com.google.common.base.Splitter; @@ -23,11 +22,11 @@ import google.registry.model.smd.SignedMarkRevocationList; import java.io.IOException; import java.io.StringReader; +import java.time.Instant; import java.util.List; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVRecord; -import org.joda.time.DateTime; /** * Signed Mark Data Revocation List (SMDRL) CSV Parser @@ -39,7 +38,7 @@ public final class SmdrlCsvParser { /** Converts the lines from the DNL CSV file into a data structure. */ public static SignedMarkRevocationList parse(List lines) throws IOException { - ImmutableMap.Builder revokes = new ImmutableMap.Builder<>(); + ImmutableMap.Builder revokes = new ImmutableMap.Builder<>(); // First line: , List firstLine = Splitter.on(',').splitToList(lines.get(0)); @@ -48,7 +47,7 @@ public static SignedMarkRevocationList parse(List lines) throws IOExcept String.format("Line 1: Expected 2 elements, found %d", firstLine.size())); int version = Integer.parseInt(firstLine.get(0)); checkArgument(version == 1, String.format("Line 1: Expected version 1, found %d", version)); - DateTime creationTime = DateTime.parse(firstLine.get(1)).withZone(UTC); + Instant creationTime = Instant.parse(firstLine.get(1)); // Note: we have to skip the first line because it contains the version metadata CSVParser csv = @@ -60,7 +59,7 @@ public static SignedMarkRevocationList parse(List lines) throws IOExcept for (CSVRecord record : csv) { String smdId = record.get("smd-id"); - DateTime revokedTime = DateTime.parse(record.get("insertion-datetime")); + Instant revokedTime = Instant.parse(record.get("insertion-datetime")); revokes.put(smdId, revokedTime); } return SignedMarkRevocationList.create(creationTime, revokes.build()); diff --git a/core/src/main/java/google/registry/tools/CreateAnchorTenantCommand.java b/core/src/main/java/google/registry/tools/CreateAnchorTenantCommand.java index 4e38b534fb5..626e08f7a2c 100644 --- a/core/src/main/java/google/registry/tools/CreateAnchorTenantCommand.java +++ b/core/src/main/java/google/registry/tools/CreateAnchorTenantCommand.java @@ -84,7 +84,7 @@ protected void initMutatingEppToolCommand() { Money cost = null; if (fee) { - cost = getDomainCreateCost(domainName, clock.nowUtc(), DEFAULT_ANCHOR_TENANT_PERIOD_YEARS); + cost = getDomainCreateCost(domainName, clock.now(), DEFAULT_ANCHOR_TENANT_PERIOD_YEARS); } setSoyTemplate(CreateAnchorTenantSoyInfo.getInstance(), diff --git a/core/src/main/java/google/registry/tools/CreateDomainCommand.java b/core/src/main/java/google/registry/tools/CreateDomainCommand.java index ae0fd42abf2..af4af51219d 100644 --- a/core/src/main/java/google/registry/tools/CreateDomainCommand.java +++ b/core/src/main/java/google/registry/tools/CreateDomainCommand.java @@ -62,7 +62,7 @@ protected void initMutatingEppToolCommand() { for (String domain : domains) { String currency = null; String cost = null; - DomainPrices prices = getPricesForDomainName(domain, clock.nowUtc()); + DomainPrices prices = getPricesForDomainName(domain, clock.now()); // Check if the domain is premium and set the fee on the create command if so. if (prices.isPremium()) { diff --git a/core/src/main/java/google/registry/tools/GetHistoryEntriesCommand.java b/core/src/main/java/google/registry/tools/GetHistoryEntriesCommand.java index d8f000e3299..ebca62facd6 100644 --- a/core/src/main/java/google/registry/tools/GetHistoryEntriesCommand.java +++ b/core/src/main/java/google/registry/tools/GetHistoryEntriesCommand.java @@ -17,7 +17,6 @@ import static com.google.common.base.Preconditions.checkArgument; import static google.registry.util.DateTimeUtils.END_INSTANT; import static google.registry.util.DateTimeUtils.START_INSTANT; -import static google.registry.util.DateTimeUtils.toDateTime; import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; @@ -65,7 +64,7 @@ public void run() { checkArgument( type != null && uniqueId != null, "If either of 'type' or 'id' are set then both must be"); - VKey parentKey = type.getKey(uniqueId, toDateTime(clock.now())); + VKey parentKey = type.getKey(uniqueId, clock.nowUtc()); historyEntries = HistoryEntryDao.loadHistoryObjectsForResource(parentKey, after, before); } else { historyEntries = HistoryEntryDao.loadAllHistoryObjects(after, before); diff --git a/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java b/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java index 6399decde3e..20d5de91d36 100644 --- a/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java +++ b/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java @@ -28,7 +28,6 @@ import static google.registry.testing.DatabaseHelper.persistResource; import static google.registry.util.DateTimeUtils.END_INSTANT; import static google.registry.util.DateTimeUtils.minusYears; -import static google.registry.util.DateTimeUtils.toDateTime; import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.common.collect.ImmutableSet; @@ -49,6 +48,7 @@ import google.registry.testing.FakeClock; import google.registry.testing.SystemPropertyExtension; import google.registry.util.RegistryEnvironment; +import java.time.Duration; import java.time.Instant; import java.util.Optional; import java.util.Set; @@ -238,7 +238,7 @@ void test_recentlyCreatedDomain_isntDeletedYet() throws Exception { persistResource( DatabaseHelper.newDomain("blah.ib-any.test") .asBuilder() - .setCreationTimeForTest(clock.now().minus(java.time.Duration.ofSeconds(1))) + .setCreationTimeForTest(clock.now().minus(Duration.ofSeconds(1))) .build()); action.run(); Optional domain = @@ -263,15 +263,14 @@ void testDryRun_doesntSoftDeleteData() throws Exception { @Test void test_domainWithSubordinateHosts_isSkipped() throws Exception { persistActiveHost("ns1.blah.ib-any.test"); - Domain nakedDomain = - persistDeletedDomain("todelete.ib-any.test", toDateTime(minusYears(clock.now(), 1))); + Domain nakedDomain = persistDeletedDomain("todelete.ib-any.test", clock.nowUtc().minusYears(1)); Domain domainWithSubord = persistDomainAsDeleted( DatabaseHelper.newDomain("blah.ib-any.test") .asBuilder() .setSubordinateHosts(ImmutableSet.of("ns1.blah.ib-any.test")) .build(), - toDateTime(minusYears(clock.now(), 1))); + clock.nowUtc().minusYears(1)); action.run(); assertAllExist(ImmutableSet.of(domainWithSubord)); diff --git a/core/src/test/java/google/registry/bsa/BsaValidateActionTest.java b/core/src/test/java/google/registry/bsa/BsaValidateActionTest.java index 745f1126a8e..04ec41af007 100644 --- a/core/src/test/java/google/registry/bsa/BsaValidateActionTest.java +++ b/core/src/test/java/google/registry/bsa/BsaValidateActionTest.java @@ -25,8 +25,7 @@ import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.persistActiveDomain; import static google.registry.testing.DatabaseHelper.persistResource; -import static google.registry.util.DateTimeUtils.START_INSTANT; -import static google.registry.util.DateTimeUtils.toDateTime; +import static google.registry.util.DateTimeUtils.START_OF_TIME; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.startsWith; @@ -238,7 +237,7 @@ void checkBsaLabels_withErrors() throws Exception { @Test void isStalenessAllowed_newDomain_allowed() { persistBsaLabel("label"); - Domain domain = persistActiveDomain("label.app", toDateTime(fakeClock.now())); + Domain domain = persistActiveDomain("label.app", fakeClock.nowUtc()); fakeClock.advanceBy( org.joda.time.Duration.millis(MAX_STALENESS.minus(Duration.ofSeconds(1)).toMillis())); assertThat(action.isStalenessAllowed(domain)).isTrue(); @@ -247,7 +246,7 @@ void isStalenessAllowed_newDomain_allowed() { @Test void isStalenessAllowed_newDomain_notAllowed() { persistBsaLabel("label"); - Domain domain = persistActiveDomain("label.app", toDateTime(fakeClock.now())); + Domain domain = persistActiveDomain("label.app", fakeClock.nowUtc()); fakeClock.advanceBy(org.joda.time.Duration.millis(MAX_STALENESS.toMillis())); assertThat(action.isStalenessAllowed(domain)).isFalse(); } @@ -278,15 +277,9 @@ void checkUnblockableDomain_error() { @Test void checkForMissingReservedUnblockables_success() { persistResource( - createTld("app") - .asBuilder() - .setBsaEnrollStartTime(Optional.of(toDateTime(START_INSTANT))) - .build()); + createTld("app").asBuilder().setBsaEnrollStartTime(Optional.of(START_OF_TIME)).build()); persistResource( - createTld("dev") - .asBuilder() - .setBsaEnrollStartTime(Optional.of(toDateTime(START_INSTANT))) - .build()); + createTld("dev").asBuilder().setBsaEnrollStartTime(Optional.of(START_OF_TIME)).build()); persistBsaLabel("registered-reserved"); persistBsaLabel("reserved-only"); persistBsaLabel("reserved-missing"); @@ -310,15 +303,9 @@ void checkForMissingReservedUnblockables_success() { @Test void checkForMissingReservedUnblockablesInOneTld_success() { persistResource( - createTld("app") - .asBuilder() - .setBsaEnrollStartTime(Optional.of(toDateTime(START_INSTANT))) - .build()); + createTld("app").asBuilder().setBsaEnrollStartTime(Optional.of(START_OF_TIME)).build()); persistResource( - createTld("dev") - .asBuilder() - .setBsaEnrollStartTime(Optional.of(toDateTime(START_INSTANT))) - .build()); + createTld("dev").asBuilder().setBsaEnrollStartTime(Optional.of(START_OF_TIME)).build()); persistBsaLabel("reserved-missing-in-app"); persistUnblockableDomain( UnblockableDomain.of("reserved-missing-in-app", "dev", Reason.REGISTERED)); @@ -338,10 +325,7 @@ void checkForMissingReservedUnblockablesInOneTld_success() { @Test void checkForMissingReservedUnblockables_unblockedReservedNotReported() { persistResource( - createTld("app") - .asBuilder() - .setBsaEnrollStartTime(Optional.of(toDateTime(START_INSTANT))) - .build()); + createTld("app").asBuilder().setBsaEnrollStartTime(Optional.of(START_OF_TIME)).build()); createReservedList( "rl", @@ -356,10 +340,7 @@ void checkForMissingReservedUnblockables_unblockedReservedNotReported() { @Test void checkForMissingRegisteredUnblockables_success() { persistResource( - createTld("app") - .asBuilder() - .setBsaEnrollStartTime(Optional.of(toDateTime(START_INSTANT))) - .build()); + createTld("app").asBuilder().setBsaEnrollStartTime(Optional.of(START_OF_TIME)).build()); persistBsaLabel("registered"); persistBsaLabel("registered-missing"); persistUnblockableDomain(UnblockableDomain.of("registered", "app", Reason.REGISTERED)); diff --git a/core/src/test/java/google/registry/bsa/persistence/QueriesTest.java b/core/src/test/java/google/registry/bsa/persistence/QueriesTest.java index 3e32df5a510..d199c15b731 100644 --- a/core/src/test/java/google/registry/bsa/persistence/QueriesTest.java +++ b/core/src/test/java/google/registry/bsa/persistence/QueriesTest.java @@ -44,6 +44,7 @@ import google.registry.persistence.transaction.JpaTestExtensions; import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationWithCoverageExtension; import google.registry.testing.FakeClock; +import java.time.Duration; import java.time.Instant; import java.util.Optional; import org.junit.jupiter.api.BeforeEach; @@ -208,14 +209,14 @@ void queryNewlyCreatedDomains_onlyLiveDomainsReturned() { createTlds("tld"); persistNewRegistrar("TheRegistrar"); // time 0: - persistActiveDomain("d1.tld", toDateTime(fakeClock.now())); + persistActiveDomain("d1.tld", fakeClock.nowUtc()); // time 0, deletion time 1 persistDomainAsDeleted( newDomain("will-delete.tld").asBuilder().setCreationTimeForTest(fakeClock.now()).build(), - toDateTime(fakeClock.now().plusMillis(1))); + fakeClock.now().plusMillis(1)); fakeClock.advanceOneMilli(); // time 1 - persistActiveDomain("d2.tld", toDateTime(fakeClock.now())); + persistActiveDomain("d2.tld", fakeClock.nowUtc()); fakeClock.advanceOneMilli(); // Now is time 2 assertThat( @@ -232,14 +233,14 @@ void queryNewlyCreatedDomains_onlyDomainsAfterMinCreationTimeReturned() { createTlds("tld"); persistNewRegistrar("TheRegistrar"); // time 0: - persistActiveDomain("d1.tld", toDateTime(fakeClock.now())); + persistActiveDomain("d1.tld", fakeClock.nowUtc()); // time 0, deletion time 1 persistDomainAsDeleted( newDomain("will-delete.tld").asBuilder().setCreationTimeForTest(fakeClock.now()).build(), - toDateTime(fakeClock.now().plusMillis(1))); + fakeClock.now().plusMillis(1)); fakeClock.advanceOneMilli(); // time 1 - persistActiveDomain("d2.tld", toDateTime(fakeClock.now())); + persistActiveDomain("d2.tld", fakeClock.nowUtc()); fakeClock.advanceOneMilli(); // Now is time 2, ask for domains created since time 1 assertThat( @@ -255,8 +256,8 @@ void queryNewlyCreatedDomains_onlyDomainsInRequestedTldsReturned() { Instant testStartTime = fakeClock.now(); createTlds("tld", "tld2"); persistNewRegistrar("TheRegistrar"); - persistActiveDomain("d1.tld", toDateTime(fakeClock.now())); - persistActiveDomain("d2.tld2", toDateTime(fakeClock.now())); + persistActiveDomain("d1.tld", fakeClock.nowUtc()); + persistActiveDomain("d2.tld2", fakeClock.nowUtc()); fakeClock.advanceOneMilli(); assertThat( bsaQuery( @@ -271,19 +272,19 @@ void queryMissedRegisteredUnblockables_success() { createTlds("tld", "tld2"); persistNewRegistrar("TheRegistrar"); Instant time1 = fakeClock.now(); - persistActiveDomain("unblocked1.tld", toDateTime(fakeClock.now())); - persistActiveDomain("unblocked2.tld2", toDateTime(fakeClock.now())); - persistActiveDomain("label1.tld", toDateTime(fakeClock.now())); - persistActiveDomain("label2.tld2", toDateTime(fakeClock.now())); + persistActiveDomain("unblocked1.tld", fakeClock.nowUtc()); + persistActiveDomain("unblocked2.tld2", fakeClock.nowUtc()); + persistActiveDomain("label1.tld", fakeClock.nowUtc()); + persistActiveDomain("label2.tld2", fakeClock.nowUtc()); fakeClock.advanceOneMilli(); Instant time2 = fakeClock.now(); persistDomainAsDeleted( newDomain("label3.tld").asBuilder().setCreationTimeForTest(fakeClock.now()).build(), - toDateTime(fakeClock.now().plusMillis(1))); + fakeClock.now().plusMillis(1)); // Deleted in the future persistDomainAsDeleted( newDomain("label3.tld2").asBuilder().setCreationTimeForTest(fakeClock.now()).build(), - toDateTime(fakeClock.now().plus(java.time.Duration.ofHours(1)))); + toDateTime(fakeClock.now().plus(Duration.ofHours(1)))); fakeClock.advanceOneMilli(); assertThat( (ImmutableList) @@ -294,7 +295,7 @@ void queryMissedRegisteredUnblockables_success() { bsaQuery(() -> queryMissedRegisteredUnblockables("tld2", fakeClock.now()))) .containsExactly( new DomainLifeSpan("label2.tld2", time1, END_INSTANT), - new DomainLifeSpan("label3.tld2", time2, time2.plus(java.time.Duration.ofHours(1)))); + new DomainLifeSpan("label3.tld2", time2, time2.plus(Duration.ofHours(1)))); BsaTestingUtils.persistUnblockableDomain( UnblockableDomain.of("label2", "tld2", UnblockableDomain.Reason.REGISTERED)); @@ -303,8 +304,7 @@ void queryMissedRegisteredUnblockables_success() { assertThat( (ImmutableList) bsaQuery(() -> queryMissedRegisteredUnblockables("tld2", fakeClock.now()))) - .containsExactly( - new DomainLifeSpan("label3.tld2", time2, time2.plus(java.time.Duration.ofHours(1)))); + .containsExactly(new DomainLifeSpan("label3.tld2", time2, time2.plus(Duration.ofHours(1)))); } @Test diff --git a/core/src/test/java/google/registry/flows/ResourceFlowTestCase.java b/core/src/test/java/google/registry/flows/ResourceFlowTestCase.java index 03c1fac8c7a..105741f3870 100644 --- a/core/src/test/java/google/registry/flows/ResourceFlowTestCase.java +++ b/core/src/test/java/google/registry/flows/ResourceFlowTestCase.java @@ -101,7 +101,7 @@ private Class getResourceClass() { /** Persists a testing claims list to Cloud SQL. */ protected void persistClaimsList(ImmutableMap labelsToKeys) { - ClaimsListDao.save(ClaimsList.create(clock.nowUtc(), labelsToKeys)); + ClaimsListDao.save(ClaimsList.create(clock.now(), labelsToKeys)); } protected void assertClientIdFieldLogged(String registrarId) { 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 7baca4c9525..bbf6e1310c6 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainCheckFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainCheckFlowTest.java @@ -37,7 +37,9 @@ import static google.registry.testing.DatabaseHelper.persistReservedList; import static google.registry.testing.DatabaseHelper.persistResource; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; -import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.START_INSTANT; +import static google.registry.util.DateTimeUtils.minusDays; +import static google.registry.util.DateTimeUtils.plusDays; import static org.joda.money.CurrencyUnit.JPY; import static org.joda.money.CurrencyUnit.USD; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -93,9 +95,9 @@ import google.registry.model.tld.label.ReservedList; import google.registry.testing.DatabaseHelper; import java.math.BigDecimal; +import java.time.Instant; import java.util.Optional; 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.Test; @@ -105,7 +107,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCasenaturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); doCheckTest( @@ -350,11 +370,11 @@ void testSuccess_allocationTokenPromotion_singleYear_std_v1() throws Exception { .setAllowedEppActions(ImmutableSet.of(CommandName.CREATE)) .setDiscountFraction(0.5) .setDiscountYears(2) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_check_allocationtoken_fee_stdv1.xml"); @@ -373,11 +393,11 @@ void testSuccess_allocationTokenPromotion_doesNotUseValidDefaultToken_singleYear .setDiscountFraction(0.5) .setDiscountYears(2) .setAllowedEppActions(ImmutableSet.of(CommandName.CREATE)) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_check_allocationtoken_fee_stdv1.xml"); @@ -395,11 +415,11 @@ void testSuccess_allocationTokenPromotion_multiYearAndPremiums() throws Exceptio .setDiscountFraction(0.9) .setDiscountYears(3) .setDiscountPremiums(true) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput( @@ -453,11 +473,11 @@ void testSuccess_outOfDateToken_overridesOtherIssues() throws Exception { .setToken("abc123") .setTokenType(SINGLE_USE) .setDomainName("specificuse.tld") - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(2), TokenStatus.VALID) - .put(clock.nowUtc().minusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 2), TokenStatus.VALID) + .put(minusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); doCheckTest( @@ -515,11 +535,11 @@ void testSuccess_allocationTokenPromotion_multiYear_stdv1() throws Exception { .setDomainName("single.tld") .setDiscountFraction(0.444) .setDiscountYears(2) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput( @@ -548,11 +568,11 @@ void testSuccess_promotionNotActive_std_v1() throws Exception { .setToken("abc123") .setTokenType(UNLIMITED_USE) .setDiscountFraction(0.5) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().plusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(60), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(plusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 60), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_check_allocationtoken_fee_stdv1.xml"); @@ -572,11 +592,11 @@ void testSuccess_promoTokenNotValidForTld_std_v1() throws Exception { .setTokenType(UNLIMITED_USE) .setDiscountFraction(0.5) .setAllowedTlds(ImmutableSet.of("example")) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_check_allocationtoken_fee_stdv1.xml"); @@ -596,11 +616,11 @@ void testSuccess_promoTokenNotValidForRegistrar_std_v1() throws Exception { .setTokenType(UNLIMITED_USE) .setDiscountFraction(0.5) .setAllowedRegistrarIds(ImmutableSet.of("someOtherClient")) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_check_allocationtoken_fee_stdv1.xml"); @@ -781,11 +801,11 @@ void testFailure_missingBillingAccount() { Tld.get("tld") .asBuilder() .setCurrency(JPY) - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) - .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) - .setRenewBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) + .setEapFeeScheduleInstant(ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) + .setRenewBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) .setRegistryLockOrUnlockBillingCost(Money.ofMajor(JPY, 800)) .setServerStatusChangeBillingCost(Money.ofMajor(JPY, 800)) .setRestoreBillingCost(Money.ofMajor(JPY, 800)) @@ -1027,8 +1047,8 @@ void testFeeExtension_fractionalCost_std_v1() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 11.1))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(USD, 11.1))) .build()); setEppInput("domain_check_fee_fractional_stdv1.xml"); runFlowAssertResponse(loadFile("domain_check_fee_fractional_response_stdv1.xml")); @@ -1130,11 +1150,11 @@ void testFeeExtension_invalid_multipleCurrencies_std_v1() { createTld("example") .asBuilder() .setCurrency(JPY) - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) - .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) - .setRenewBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) + .setEapFeeScheduleInstant(ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) + .setRenewBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) .setRegistryLockOrUnlockBillingCost(Money.ofMajor(JPY, 800)) .setServerStatusChangeBillingCost(Money.ofMajor(JPY, 800)) .setRestoreBillingCost(Money.ofMajor(JPY, 800)) @@ -1198,11 +1218,11 @@ void testTieredPricingPromo_registrarIncluded_noTokenActive_std_v1() throws Exce persistResource( setUpDefaultToken("NewRegistrar") .asBuilder() - .setTokenStatusTransitions( + .setTokenStatusTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, TokenStatus.NOT_STARTED, - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), TokenStatus.VALID)) .build()); @@ -1303,16 +1323,16 @@ void testFeeExtension_existingPremiumDomain_withSpecifiedRenewalBehavior() throw void testFeeExtension_premium_eap_v06() throws Exception { createTld("example"); setEppInput("domain_check_fee_premium_v06.xml"); - clock.setTo(DateTime.parse("2010-01-01T10:00:00Z")); + clock.setTo(Instant.parse("2010-01-01T10:00:00Z")); persistResource( Tld.get("example") .asBuilder() - .setEapFeeSchedule( - new ImmutableSortedMap.Builder(Ordering.natural()) - .put(START_OF_TIME, Money.of(USD, 0)) - .put(clock.nowUtc().minusDays(1), Money.of(USD, 100)) - .put(clock.nowUtc().plusDays(1), Money.of(USD, 50)) - .put(clock.nowUtc().plusDays(2), Money.of(USD, 0)) + .setEapFeeScheduleInstant( + new ImmutableSortedMap.Builder(Ordering.natural()) + .put(START_INSTANT, Money.of(USD, 0)) + .put(minusDays(clock.now(), 1), Money.of(USD, 100)) + .put(plusDays(clock.now(), 1), Money.of(USD, 50)) + .put(plusDays(clock.now(), 2), Money.of(USD, 0)) .build()) .build()); @@ -1322,13 +1342,13 @@ void testFeeExtension_premium_eap_v06() throws Exception { @Test void testFeeExtension_premium_eap_v06_withRenewalOnRestore() throws Exception { createTld("example"); - DateTime startTime = DateTime.parse("2010-01-01T10:00:00Z"); + Instant startTime = Instant.parse("2010-01-01T10:00:00Z"); clock.setTo(startTime); persistResource( persistActiveDomain("rich.example") .asBuilder() - .setDeletionTime(clock.nowUtc().plusDays(25)) - .setRegistrationExpirationTime(clock.nowUtc().minusDays(1)) + .setDeletionTime(plusDays(clock.now(), 25)) + .setRegistrationExpirationTime(minusDays(clock.now(), 1)) .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) .build()); persistPendingDeleteDomain("rich.example"); @@ -1336,12 +1356,12 @@ void testFeeExtension_premium_eap_v06_withRenewalOnRestore() throws Exception { persistResource( Tld.get("example") .asBuilder() - .setEapFeeSchedule( - new ImmutableSortedMap.Builder(Ordering.natural()) - .put(START_OF_TIME, Money.of(USD, 0)) - .put(startTime.minusDays(1), Money.of(USD, 100)) - .put(startTime.plusDays(1), Money.of(USD, 50)) - .put(startTime.plusDays(2), Money.of(USD, 0)) + .setEapFeeScheduleInstant( + new ImmutableSortedMap.Builder(Ordering.natural()) + .put(START_INSTANT, Money.of(USD, 0)) + .put(minusDays(startTime, 1), Money.of(USD, 100)) + .put(plusDays(startTime, 1), Money.of(USD, 50)) + .put(plusDays(startTime, 2), Money.of(USD, 0)) .build()) .build()); runFlowAssertResponse(loadFile("domain_check_fee_premium_eap_response_v06_with_renewal.xml")); @@ -2053,11 +2073,11 @@ void testSuccess_multipleCurencies_v12() throws Exception { createTld("example") .asBuilder() .setCurrency(JPY) - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) - .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) - .setRenewBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) + .setEapFeeScheduleInstant(ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) + .setRenewBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) .setRegistryLockOrUnlockBillingCost(Money.ofMajor(JPY, 800)) .setServerStatusChangeBillingCost(Money.ofMajor(JPY, 800)) .setRestoreBillingCost(Money.ofMajor(JPY, 800)) @@ -2097,11 +2117,11 @@ void testTieredPricingPromo_registrarIncluded_noTokenActive_v12() throws Excepti persistResource( setUpDefaultToken("NewRegistrar") .asBuilder() - .setTokenStatusTransitions( + .setTokenStatusTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, TokenStatus.NOT_STARTED, - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), TokenStatus.VALID)) .build()); @@ -2117,8 +2137,8 @@ void testFeeExtension_fractionalCost_v06() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 11.1))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(USD, 11.1))) .build()); setEppInput("domain_check_fee_fractional_v06.xml"); runFlowAssertResponse(loadFile("domain_check_fee_fractional_response_v06.xml")); @@ -2136,11 +2156,11 @@ void testSuccess_allocationTokenPromotion_doesNotUseValidDefaultToken_singleYear .setDiscountFraction(0.5) .setDiscountYears(2) .setAllowedEppActions(ImmutableSet.of(CommandName.CREATE)) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_check_allocationtoken_fee_v06.xml"); @@ -2170,11 +2190,11 @@ void testSuccess_allocationTokenPromotion_multiYear_v06() throws Exception { .setDomainName("single.tld") .setDiscountFraction(0.444) .setDiscountYears(2) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput( @@ -2205,11 +2225,11 @@ void testSuccess_allocationTokenPromotion_multiYearAndPremiums_v06() throws Exce .setDiscountFraction(0.9) .setDiscountYears(3) .setDiscountPremiums(true) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput( @@ -2254,11 +2274,11 @@ void testSuccess_promotionNotActive_v06() throws Exception { .setToken("abc123") .setTokenType(UNLIMITED_USE) .setDiscountFraction(0.5) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().plusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(60), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(plusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 60), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_check_allocationtoken_fee_v06.xml"); @@ -2283,11 +2303,11 @@ void testSuccess_allocationTokenPromotion_singleYear_v06() throws Exception { .setAllowedEppActions(ImmutableSet.of(CommandName.CREATE)) .setDiscountFraction(0.5) .setDiscountYears(2) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_check_allocationtoken_fee_v06.xml"); @@ -2303,11 +2323,11 @@ void testSuccess_promoTokenNotValidForTld_v06() throws Exception { .setTokenType(UNLIMITED_USE) .setDiscountFraction(0.5) .setAllowedTlds(ImmutableSet.of("example")) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_check_allocationtoken_fee_v06.xml"); @@ -2331,11 +2351,11 @@ void testSuccess_promoTokenNotValidForRegistrar_v06() throws Exception { .setTokenType(UNLIMITED_USE) .setDiscountFraction(0.5) .setAllowedRegistrarIds(ImmutableSet.of("someOtherClient")) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_check_allocationtoken_fee_v06.xml"); @@ -2399,8 +2419,8 @@ private Domain persistPendingDeleteDomain(String domainName) { persistResource( DatabaseHelper.newDomain(domainName) .asBuilder() - .setDeletionTime(clock.nowUtc().plusDays(25)) - .setRegistrationExpirationTime(clock.nowUtc().minusDays(1)) + .setDeletionTime(plusDays(clock.now(), 25)) + .setRegistrationExpirationTime(minusDays(clock.now(), 1)) .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) .build()); DomainHistory historyEntry = @@ -2419,7 +2439,7 @@ private Domain persistPendingDeleteDomain(String domainName) { .setTargetId(existingDomain.getDomainName()) .setRegistrarId("TheRegistrar") .setEventTime(existingDomain.getCreationTime()) - .setRecurrenceEndTime(clock.nowUtc()) + .setRecurrenceEndTime(clock.now()) .setDomainHistory(historyEntry) .build()); return persistResource( @@ -2428,17 +2448,17 @@ private Domain persistPendingDeleteDomain(String domainName) { private void runEapFeeCheckTestWithXmlInputOutput(String inputXml, String outputXml) throws Exception { - clock.setTo(DateTime.parse("2010-01-01T10:00:00Z")); + clock.setTo(Instant.parse("2010-01-01T10:00:00Z")); persistActiveDomain("example1.tld"); persistResource( Tld.get("tld") .asBuilder() - .setEapFeeSchedule( - new ImmutableSortedMap.Builder(Ordering.natural()) - .put(START_OF_TIME, Money.of(USD, 0)) - .put(clock.nowUtc().minusDays(1), Money.of(USD, 100)) - .put(clock.nowUtc().plusDays(1), Money.of(USD, 50)) - .put(clock.nowUtc().plusDays(2), Money.of(USD, 0)) + .setEapFeeScheduleInstant( + new ImmutableSortedMap.Builder(Ordering.natural()) + .put(START_INSTANT, Money.of(USD, 0)) + .put(minusDays(clock.now(), 1), Money.of(USD, 100)) + .put(plusDays(clock.now(), 1), Money.of(USD, 50)) + .put(plusDays(clock.now(), 2), Money.of(USD, 0)) .build()) .build()); setEppInputXml(inputXml); diff --git a/core/src/test/java/google/registry/flows/domain/DomainClaimsCheckFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainClaimsCheckFlowTest.java index 2e0f9b19f53..f49664faa9d 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainClaimsCheckFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainClaimsCheckFlowTest.java @@ -181,7 +181,7 @@ void testFailure_allocationToken() { void testFailure_multipleTlds_oneHasEndedClaims() { createTlds("tld1", "tld2"); persistResource( - Tld.get("tld2").asBuilder().setClaimsPeriodEnd(clock.nowUtc().minusMillis(1)).build()); + Tld.get("tld2").asBuilder().setClaimsPeriodEndInstant(clock.now().minusMillis(1)).build()); setEppInput("domain_check_claims_multiple_tlds.xml"); EppException thrown = assertThrows(ClaimsPeriodEndedException.class, this::runFlow); assertAboutEppExceptions().that(thrown).marshalsToXml(); diff --git a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java index afb8dbe0cb4..c5d4c231619 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java @@ -57,7 +57,12 @@ import static google.registry.testing.DomainSubject.assertAboutDomains; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.util.DateTimeUtils.END_OF_TIME; -import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.START_INSTANT; +import static google.registry.util.DateTimeUtils.minusDays; +import static google.registry.util.DateTimeUtils.minusMonths; +import static google.registry.util.DateTimeUtils.minusYears; +import static google.registry.util.DateTimeUtils.plusDays; +import static google.registry.util.DateTimeUtils.plusYears; import static org.joda.money.CurrencyUnit.JPY; import static org.joda.money.CurrencyUnit.USD; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -184,7 +189,6 @@ import java.util.Optional; 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.Test; @@ -197,12 +201,12 @@ class DomainCreateFlowTest extends ResourceFlowTestCase autorenewVKey = domain.getAutorenewBillingEvent(); @@ -351,7 +357,7 @@ private void assertSuccessfulCreate( .setRegistrarId("TheRegistrar") .setCost(Money.of(USD, BigDecimal.valueOf(createCost))) .setPeriodYears(2) - .setEventTime(clock.nowUtc()) + .setEventTime(clock.now()) .setBillingTime(billingTime) .setFlags(expectedBillingFlags) .setDomainHistory(historyEntry) @@ -387,7 +393,7 @@ private void assertSuccessfulCreate( .setRegistrarId("TheRegistrar") .setPeriodYears(1) .setCost(eapFee) - .setEventTime(clock.nowUtc()) + .setEventTime(clock.now()) .setBillingTime(billingTime) .setFlags(expectedBillingFlags) .setDomainHistory(historyEntry) @@ -443,8 +449,8 @@ private void assertClaimsLordn() throws Exception { LaunchNotice.create( "370d0b7c9223372036854775807", "tmch", - DateTime.parse("2010-08-16T09:00:00.0Z"), - DateTime.parse("2009-08-16T09:00:00.0Z"))) + Instant.parse("2010-08-16T09:00:00.0Z"), + Instant.parse("2009-08-16T09:00:00.0Z"))) .and() .hasLordnPhase(LordnPhase.CLAIMS); } @@ -576,11 +582,11 @@ void testSuccess_validAllocationToken_multiUse() throws Exception { new AllocationToken.Builder() .setTokenType(UNLIMITED_USE) .setToken("abc123") - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); clock.advanceOneMilli(); @@ -628,7 +634,7 @@ void testFailure_domainNameExistsAsTld_uppercase() { @Test void testFailure_generalAvailability_withEncodedSignedMark() { createTld("tld", GENERAL_AVAILABILITY); - clock.setTo(DateTime.parse("2014-09-09T09:09:09Z")); + clock.setTo(Instant.parse("2014-09-09T09:09:09Z")); setEppInput( "domain_create_registration_encoded_signed_mark.xml", ImmutableMap.of("DOMAIN", "test-validate.tld", "PHASE", "open", "SMD", ENCODED_SMD)); @@ -726,13 +732,13 @@ void testSuccess_premiumAndEap_std_v1() throws Exception { persistResource( Tld.get("example") .asBuilder() - .setEapFeeSchedule( + .setEapFeeScheduleInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, Money.of(USD, 0), - clock.nowUtc().minusDays(1), + minusDays(clock.now(), 1), Money.of(USD, 100), - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), Money.of(USD, 0))) .build()); assertMutatingFlow(true); @@ -829,7 +835,7 @@ void testSuccess_periodNotSpecified() throws Exception { "epp.response.resData.creData.exDate"); // Ignore expiration date; we verify it below assertAboutDomains() .that(reloadResourceByForeignKey()) - .hasRegistrationExpirationTime(clock.nowUtc().plusYears(1)); + .hasRegistrationExpirationTime(plusYears(clock.now(), 1)); assertDomainDnsRequests("example.tld"); } @@ -843,7 +849,7 @@ void testFailure_periodInMonths() { @Test void testSuccess_claimsNotice() throws Exception { - clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z")); + clock.setTo(Instant.parse("2009-08-16T09:00:00.0Z")); setEppInput("domain_create_claim_notice.xml"); persistHosts(); runFlowAssertResponse(loadFile("domain_create_response_claims.xml")); @@ -864,15 +870,15 @@ void testSuccess_claimsNoticeInQuietPeriod() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setTldStateTransitions( + .setTldStateTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, PREDELEGATION, - DateTime.parse("1999-01-01T00:00:00Z"), + Instant.parse("1999-01-01T00:00:00Z"), QUIET_PERIOD)) .setReservedLists(persistReservedList("res1", "example-one,RESERVED_FOR_SPECIFIC_USE")) .build()); - clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z")); + clock.setTo(Instant.parse("2009-08-16T09:00:00.0Z")); setEppInput("domain_create_allocationtoken_claims.xml"); persistHosts(); runFlowAssertResponse(loadFile("domain_create_response_claims.xml")); @@ -886,7 +892,7 @@ void testSuccess_claimsNoticeInQuietPeriod() throws Exception { void testSuccess_noClaimsNotice_forClaimsListName_afterClaimsPeriodEnd() throws Exception { persistClaimsList(ImmutableMap.of("example", CLAIMS_KEY)); persistHosts(); - persistResource(Tld.get("tld").asBuilder().setClaimsPeriodEnd(clock.nowUtc()).build()); + persistResource(Tld.get("tld").asBuilder().setClaimsPeriodEndInstant(clock.now()).build()); runFlowAssertResponse( loadFile("domain_create_response.xml", ImmutableMap.of("DOMAIN", "example.tld"))); assertSuccessfulCreate("tld", ImmutableSet.of()); @@ -915,7 +921,7 @@ void testFailure_claimsNoticeProvided_claimsPeriodEnded() { setEppInput("domain_create_claim_notice.xml"); persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY)); persistHosts(); - persistResource(Tld.get("tld").asBuilder().setClaimsPeriodEnd(clock.nowUtc()).build()); + persistResource(Tld.get("tld").asBuilder().setClaimsPeriodEndInstant(clock.now()).build()); EppException thrown = assertThrows(ClaimsPeriodEndedException.class, this::runFlow); assertAboutEppExceptions().that(thrown).marshalsToXml(); } @@ -974,8 +980,8 @@ void testFailure_wrongFeeAmount_std_v1() { persistResource( Tld.get("tld") .asBuilder() - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(USD, 20))) .build()); persistHosts(); EppException thrown = assertThrows(FeesMismatchException.class, this::runFlow); @@ -988,7 +994,8 @@ void testSuccess_wrongFeeAmountTooHigh_defaultToken_std_v1() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setCreateBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 8))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(USD, 8))) .build()); // Expects fee of $24 setEppInput("domain_create_fee.xml", FEE_STD_1_0_MAP); @@ -1003,8 +1010,8 @@ void testFailure_wrongFeeAmountTooLow_defaultToken_std_v1() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 100))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(USD, 100))) .build()); // Expects fee of $24 setEppInput("domain_create_fee.xml", FEE_STD_1_0_MAP); @@ -1139,7 +1146,7 @@ void testSuccess_anchorTenant_withClaims() throws Exception { persistReservedList("anchor-with-claims", "example-one,RESERVED_FOR_ANCHOR_TENANT")) .build()); setEppInput("domain_create_allocationtoken_claims.xml"); - clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z")); + clock.setTo(Instant.parse("2009-08-16T09:00:00.0Z")); persistHosts(); runFlowAssertResponse(loadFile("domain_create_response_claims.xml")); assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken, 0); @@ -1189,7 +1196,7 @@ void testSuccess_anchorTenantInSunrise_withMetadataExtension_andSignedMark() thr "CREATE_TIME", SMD_VALID_TIME.toString(), "EXPIRATION_TIME", - SMD_VALID_TIME.plusYears(2).toString()))); + plusYears(SMD_VALID_TIME, 2).toString()))); assertSuccessfulCreate("tld", ImmutableSet.of(SUNRISE, ANCHOR_TENANT), 0); } @@ -1207,7 +1214,7 @@ void testSuccess_anchorTenantInSunrise_withSignedMark() throws Exception { .asBuilder() .setReservedLists( persistReservedList("anchor_tenants", "test-validate,RESERVED_FOR_ANCHOR_TENANT")) - .setTldStateTransitions(ImmutableSortedMap.of(START_OF_TIME, START_DATE_SUNRISE)) + .setTldStateTransitionsInstant(ImmutableSortedMap.of(START_INSTANT, START_DATE_SUNRISE)) .build()); setEppInput("domain_create_anchor_tenant_signed_mark.xml", ImmutableMap.of("SMD", ENCODED_SMD)); clock.setTo(SMD_VALID_TIME); @@ -1221,7 +1228,7 @@ void testSuccess_anchorTenantInSunrise_withSignedMark() throws Exception { "CREATE_TIME", SMD_VALID_TIME.toString(), "EXPIRATION_TIME", - SMD_VALID_TIME.plusYears(2).toString()))); + plusYears(SMD_VALID_TIME, 2).toString()))); assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT, SUNRISE), allocationToken, 0); assertDomainDnsRequests("test-validate.tld"); assertSunriseLordn(); @@ -1233,12 +1240,12 @@ void testSuccess_anchorTenant_duringQuietPeriodBeforeSunrise() throws Exception persistResource( Tld.get("tld") .asBuilder() - .setTldStateTransitions( - new ImmutableSortedMap.Builder(Ordering.natural()) - .put(START_OF_TIME, PREDELEGATION) - .put(DateTime.parse("1999-01-01T00:00:00Z"), QUIET_PERIOD) - .put(DateTime.parse("1999-07-01T00:00:00Z"), START_DATE_SUNRISE) - .put(DateTime.parse("2000-01-01T00:00:00Z"), GENERAL_AVAILABILITY) + .setTldStateTransitionsInstant( + new ImmutableSortedMap.Builder(Ordering.natural()) + .put(START_INSTANT, PREDELEGATION) + .put(Instant.parse("1999-01-01T00:00:00Z"), QUIET_PERIOD) + .put(Instant.parse("1999-07-01T00:00:00Z"), START_DATE_SUNRISE) + .put(Instant.parse("2000-01-01T00:00:00Z"), GENERAL_AVAILABILITY) .build()) .build()); // The anchor tenant is created during the quiet period, on 1999-04-03. @@ -1276,7 +1283,7 @@ void testSuccess_reservedDomain_viaAllocationTokenExtension_inQuietPeriod() thro persistResource( Tld.get("tld") .asBuilder() - .setTldStateTransitions(ImmutableSortedMap.of(START_OF_TIME, QUIET_PERIOD)) + .setTldStateTransitionsInstant(ImmutableSortedMap.of(START_INSTANT, QUIET_PERIOD)) .build()); allocationToken = persistResource( @@ -1319,11 +1326,11 @@ void testSuccess_allocationTokenPromotion() throws Exception { .setToken("abc123") .setTokenType(UNLIMITED_USE) .setDiscountFraction(0.5) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().plusMillis(1), TokenStatus.VALID) - .put(clock.nowUtc().plusSeconds(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(clock.now().plusMillis(1), TokenStatus.VALID) + .put(clock.now().plusSeconds(1), TokenStatus.ENDED) .build()) .build()); clock.advanceOneMilli(); @@ -1363,11 +1370,11 @@ void runTest_allocationToken_multiYearDiscount( .setDiscountFraction(discountFraction) .setDiscountYears(discountYears) .setDiscountPremiums(discountPremiums) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().plusMillis(1), TokenStatus.VALID) - .put(clock.nowUtc().plusSeconds(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(clock.now().plusMillis(1), TokenStatus.VALID) + .put(clock.now().plusSeconds(1), TokenStatus.ENDED) .build()) .build()); clock.advanceOneMilli(); @@ -1400,11 +1407,11 @@ void testSuccess_allocationToken_multiYearDiscount_worksForPremiums_std_v1() thr .setDiscountFraction(0.98) .setDiscountYears(2) .setDiscountPremiums(true) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().plusMillis(1), TokenStatus.VALID) - .put(clock.nowUtc().plusSeconds(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(clock.now().plusMillis(1), TokenStatus.VALID) + .put(clock.now().plusSeconds(1), TokenStatus.ENDED) .build()) .build()); clock.advanceOneMilli(); @@ -1439,11 +1446,11 @@ void testSuccess_allocationToken_singleYearDiscount_worksForPremiums_std_v1() th .setDomainName("rich.example") .setDiscountFraction(0.95555) .setDiscountPremiums(true) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().plusMillis(1), TokenStatus.VALID) - .put(clock.nowUtc().plusSeconds(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(clock.now().plusMillis(1), TokenStatus.VALID) + .put(clock.now().plusSeconds(1), TokenStatus.ENDED) .build()) .build()); clock.advanceOneMilli(); @@ -1496,11 +1503,11 @@ void testFailure_promotionNotActive() { .setToken("abc123") .setTokenType(UNLIMITED_USE) .setDiscountFraction(0.5) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().plusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(60), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(plusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 60), TokenStatus.ENDED) .build()) .build()); setEppInput( @@ -1520,11 +1527,11 @@ void testSuccess_promoTokenNotValidForRegistrar() { .setTokenType(UNLIMITED_USE) .setAllowedRegistrarIds(ImmutableSet.of("someClientId")) .setDiscountFraction(0.5) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput( @@ -1607,11 +1614,11 @@ void testSuccess_skipsOverExpiredDefaultToken() throws Exception { persistResource( setupDefaultTokenWithDiscount() .asBuilder() - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(2), TokenStatus.VALID) - .put(clock.nowUtc().minusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 2), TokenStatus.VALID) + .put(minusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); doSuccessfulTest(); @@ -1672,7 +1679,7 @@ void testSuccess_reservedNameCollisionDomain_inSunrise_setsServerHoldAndPollMess persistResource( Tld.get("tld") .asBuilder() - .setTldStateTransitions(ImmutableSortedMap.of(START_OF_TIME, START_DATE_SUNRISE)) + .setTldStateTransitionsInstant(ImmutableSortedMap.of(START_INSTANT, START_DATE_SUNRISE)) .build()); clock.setTo(SMD_VALID_TIME); setEppInput( @@ -1688,7 +1695,7 @@ void testSuccess_reservedNameCollisionDomain_inSunrise_setsServerHoldAndPollMess "CREATE_TIME", SMD_VALID_TIME.toString(), "EXPIRATION_TIME", - SMD_VALID_TIME.plusYears(2).toString()))); + plusYears(SMD_VALID_TIME, 2).toString()))); assertSunriseLordn(); @@ -1735,7 +1742,7 @@ private void assertPollMessagesWithCollisionOneTime(Domain domain) { .setResponseData( ImmutableList.of( DomainPendingActionNotificationResponse.create( - domain.getDomainName(), true, historyEntry.getTrid(), clock.nowUtc()))) + domain.getDomainName(), true, historyEntry.getTrid(), clock.now()))) .setId(1L) .build()); } @@ -1913,7 +1920,7 @@ void testFailure_codeMark() { @Test void testFailure_expiredClaim() { - clock.setTo(DateTime.parse("2010-08-17T09:00:00.0Z")); + clock.setTo(Instant.parse("2010-08-17T09:00:00.0Z")); setEppInput("domain_create_claim_notice.xml"); persistHosts(); EppException thrown = assertThrows(ExpiredClaimException.class, this::runFlow); @@ -1922,7 +1929,7 @@ void testFailure_expiredClaim() { @Test void testFailure_expiredAcceptance() { - clock.setTo(DateTime.parse("2009-09-16T09:00:00.0Z")); + clock.setTo(Instant.parse("2009-09-16T09:00:00.0Z")); setEppInput("domain_create_claim_notice.xml"); persistHosts(); EppException thrown = assertThrows(AcceptedTooLongAgoException.class, this::runFlow); @@ -1931,7 +1938,7 @@ void testFailure_expiredAcceptance() { @Test void testFailure_malformedTcnIdWrongLength() { - clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z")); + clock.setTo(Instant.parse("2009-08-16T09:00:00.0Z")); setEppInput("domain_create_malformed_claim_notice1.xml"); persistHosts(); EppException thrown = assertThrows(MalformedTcnIdException.class, this::runFlow); @@ -1940,7 +1947,7 @@ void testFailure_malformedTcnIdWrongLength() { @Test void testFailure_malformedTcnIdBadChar() { - clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z")); + clock.setTo(Instant.parse("2009-08-16T09:00:00.0Z")); setEppInput("domain_create_malformed_claim_notice2.xml"); persistHosts(); EppException thrown = assertThrows(MalformedTcnIdException.class, this::runFlow); @@ -1949,7 +1956,7 @@ void testFailure_malformedTcnIdBadChar() { @Test void testFailure_badTcnIdChecksum() { - clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z")); + clock.setTo(Instant.parse("2009-08-16T09:00:00.0Z")); setEppInput("domain_create_bad_checksum_claim_notice.xml"); persistHosts(); EppException thrown = assertThrows(InvalidTcnIdChecksumException.class, this::runFlow); @@ -2045,7 +2052,7 @@ void testSuccess_bsaLabelMatch_notEnrolledYet() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setBsaEnrollStartTime(Optional.of(clock.nowUtc().plusSeconds(1))) + .setBsaEnrollStartTimeInstant(Optional.of(clock.now().plusSeconds(1))) .build()); persistBsaLabel("example"); persistHosts(); @@ -2111,7 +2118,7 @@ void testSuccess_blockedByBsa_quietPeriod_skipTldStateCheckWithToken() throws Ex persistResource( Tld.get("tld") .asBuilder() - .setTldStateTransitions(ImmutableSortedMap.of(START_OF_TIME, QUIET_PERIOD)) + .setTldStateTransitionsInstant(ImmutableSortedMap.of(START_INSTANT, QUIET_PERIOD)) .build()); runFlow(); assertSuccessfulCreate("tld", ImmutableSet.of(), token); @@ -2296,7 +2303,7 @@ void testSuccess_startDateSunriseRegistration_withEncodedSignedMark() throws Exc "CREATE_TIME", SMD_VALID_TIME.toString(), "EXPIRATION_TIME", - SMD_VALID_TIME.plusYears(2).toString()))); + plusYears(SMD_VALID_TIME, 2).toString()))); assertSuccessfulCreate("tld", ImmutableSet.of(SUNRISE), 20.40); assertSunriseLordn(); } @@ -2319,7 +2326,7 @@ void testSuccess_startDateSunriseRegistration_withEncodedSignedMark_noType() thr "CREATE_TIME", SMD_VALID_TIME.toString(), "EXPIRATION_TIME", - SMD_VALID_TIME.plusYears(2).toString()))); + plusYears(SMD_VALID_TIME, 2).toString()))); assertSuccessfulCreate("tld", ImmutableSet.of(SUNRISE), 20.40); assertSunriseLordn(); } @@ -2409,7 +2416,7 @@ void testFail_startDateSunriseRegistration_markExpired() { @Test void testFailure_startDateSunriseRegistration_withClaimsNotice() { createTld("tld", START_DATE_SUNRISE); - clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z")); + clock.setTo(Instant.parse("2009-08-16T09:00:00.0Z")); setEppInput("domain_create_registration_start_date_sunrise_claims_notice.xml"); persistHosts(); EppException thrown = @@ -2437,11 +2444,11 @@ void testFailure_missingBillingAccountMap() { Tld.get("tld") .asBuilder() .setCurrency(JPY) - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) - .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) - .setRenewBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) + .setEapFeeScheduleInstant(ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) + .setRenewBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) .setRegistryLockOrUnlockBillingCost(Money.ofMajor(JPY, 800)) .setServerStatusChangeBillingCost(Money.ofMajor(JPY, 800)) .setRestoreBillingCost(Money.ofMajor(JPY, 800)) @@ -2628,13 +2635,13 @@ private void setEapForTld(String tld) { persistResource( Tld.get(tld) .asBuilder() - .setEapFeeSchedule( + .setEapFeeScheduleInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, Money.of(USD, 0), - clock.nowUtc().minusDays(1), + minusDays(clock.now(), 1), Money.of(USD, 100), - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), Money.of(USD, 0))) .build()); } @@ -2645,13 +2652,13 @@ void testSuccess_eapFee_beforeEntireSchedule() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setEapFeeSchedule( + .setEapFeeScheduleInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, Money.of(USD, 0), - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), Money.of(USD, 10), - clock.nowUtc().plusDays(2), + plusDays(clock.now(), 2), Money.of(USD, 0))) .build()); doSuccessfulTest("tld", "domain_create_response.xml", ImmutableMap.of("DOMAIN", "example.tld")); @@ -2663,13 +2670,13 @@ void testSuccess_eapFee_afterEntireSchedule() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setEapFeeSchedule( + .setEapFeeScheduleInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, Money.of(USD, 0), - clock.nowUtc().minusDays(2), + minusDays(clock.now(), 2), Money.of(USD, 100), - clock.nowUtc().minusDays(1), + minusDays(clock.now(), 1), Money.of(USD, 0))) .build()); doSuccessfulTest("tld", "domain_create_response.xml", ImmutableMap.of("DOMAIN", "example.tld")); @@ -2804,7 +2811,7 @@ void testSuccess_quietPeriod_skipTldStateCheckWithToken() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setTldStateTransitions(ImmutableSortedMap.of(START_OF_TIME, QUIET_PERIOD)) + .setTldStateTransitionsInstant(ImmutableSortedMap.of(START_INSTANT, QUIET_PERIOD)) .build()); runFlow(); assertSuccessfulCreate("tld", ImmutableSet.of(), token); @@ -2826,7 +2833,7 @@ void testSuccess_sunrise_skipTldCheckWithToken() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setTldStateTransitions(ImmutableSortedMap.of(START_OF_TIME, QUIET_PERIOD)) + .setTldStateTransitionsInstant(ImmutableSortedMap.of(START_INSTANT, QUIET_PERIOD)) .build()); runFlow(); assertSuccessfulCreate("tld", ImmutableSet.of(), token); @@ -2860,7 +2867,7 @@ void testFailure_quietPeriod_defaultTokenPresent() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setTldStateTransitions(ImmutableSortedMap.of(START_OF_TIME, QUIET_PERIOD)) + .setTldStateTransitionsInstant(ImmutableSortedMap.of(START_INSTANT, QUIET_PERIOD)) .build()); assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, this::runFlow); } @@ -2879,9 +2886,9 @@ void testFailure_quietPeriodBeforeSunrise_trademarkedDomain() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setTldStateTransitions( + .setTldStateTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, QUIET_PERIOD, clock.nowUtc().plusYears(1), START_DATE_SUNRISE)) + START_INSTANT, QUIET_PERIOD, plusYears(clock.now(), 1), START_DATE_SUNRISE)) .build()); persistHosts(); setEppInput("domain_create_allocationtoken_claims.xml"); @@ -2902,13 +2909,13 @@ void testSuccess_quietPeriodAfterSunrise_trademarkedDomain() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setTldStateTransitions( + .setTldStateTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, QUIET_PERIOD, - clock.nowUtc().minusYears(1), + minusYears(clock.now(), 1), START_DATE_SUNRISE, - clock.nowUtc().minusMonths(1), + minusMonths(clock.now(), 1), QUIET_PERIOD)) .build()); persistHosts(); @@ -3050,13 +3057,13 @@ void testSuccess_anchorTenant_quietPeriodAfterSunrise_nonTrademarked_viaToken() persistResource( Tld.get("tld") .asBuilder() - .setTldStateTransitions( + .setTldStateTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, QUIET_PERIOD, - clock.nowUtc().minusYears(1), + minusYears(clock.now(), 1), START_DATE_SUNRISE, - clock.nowUtc().minusMonths(1), + minusMonths(clock.now(), 1), QUIET_PERIOD)) .build()); AllocationToken token = @@ -3081,13 +3088,13 @@ void testSuccess_anchorTenant_quietPeriodAfterSunrise_trademarked_withClaims_via persistResource( Tld.get("tld") .asBuilder() - .setTldStateTransitions( + .setTldStateTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, QUIET_PERIOD, - clock.nowUtc().minusYears(1), + minusYears(clock.now(), 1), START_DATE_SUNRISE, - clock.nowUtc().minusMonths(1), + minusMonths(clock.now(), 1), QUIET_PERIOD)) .build()); persistResource( @@ -3107,13 +3114,13 @@ void testFailure_anchorTenant_quietPeriodAfterSunrise_trademarked_withoutClaims_ persistResource( Tld.get("tld") .asBuilder() - .setTldStateTransitions( + .setTldStateTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, QUIET_PERIOD, - clock.nowUtc().minusYears(1), + minusYears(clock.now(), 1), START_DATE_SUNRISE, - clock.nowUtc().minusMonths(1), + minusMonths(clock.now(), 1), QUIET_PERIOD)) .build()); persistResource( @@ -3279,11 +3286,11 @@ void testTieredPricingPromo_registrarIncluded_noTokenActive_std_v1() throws Exce persistResource( setupDefaultTokenWithDiscount("NewRegistrar") .asBuilder() - .setTokenStatusTransitions( + .setTokenStatusTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, TokenStatus.NOT_STARTED, - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), TokenStatus.VALID)) .build()); @@ -3305,8 +3312,8 @@ void testFailure_wrongFeeAmount_v06() { persistResource( Tld.get("tld") .asBuilder() - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(USD, 20))) .build()); persistHosts(); EppException thrown = assertThrows(FeesMismatchException.class, this::runFlow); @@ -3319,8 +3326,8 @@ void testFailure_wrongFeeAmount_v11() { persistResource( Tld.get("tld") .asBuilder() - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(USD, 20))) .build()); persistHosts(); EppException thrown = assertThrows(FeesMismatchException.class, this::runFlow); @@ -3333,8 +3340,8 @@ void testFailure_wrongFeeAmount_v12() { persistResource( Tld.get("tld") .asBuilder() - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(USD, 20))) .build()); persistHosts(); EppException thrown = assertThrows(FeesMismatchException.class, this::runFlow); @@ -3347,7 +3354,8 @@ void testSuccess_wrongFeeAmountTooHigh_defaultToken_v06() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setCreateBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 8))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(USD, 8))) .build()); // Expects fee of $24 setEppInput("domain_create_fee.xml", FEE_06_MAP); @@ -3362,7 +3370,8 @@ void testSuccess_wrongFeeAmountTooHigh_defaultToken_v11() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setCreateBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 8))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(USD, 8))) .build()); // Expects fee of $24 setEppInput("domain_create_fee.xml", FEE_11_MAP); @@ -3377,7 +3386,8 @@ void testSuccess_wrongFeeAmountTooHigh_defaultToken_v12() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setCreateBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 8))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(USD, 8))) .build()); // Expects fee of $24 setEppInput("domain_create_fee.xml", FEE_12_MAP); @@ -3518,8 +3528,8 @@ void testFailure_wrongFeeAmountTooLow_defaultToken_v06() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 100))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(USD, 100))) .build()); // Expects fee of $24 setEppInput("domain_create_fee.xml", FEE_06_MAP); @@ -3534,8 +3544,8 @@ void testFailure_wrongFeeAmountTooLow_defaultToken_v11() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 100))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(USD, 100))) .build()); // Expects fee of $24 setEppInput("domain_create_fee.xml", FEE_11_MAP); @@ -3550,8 +3560,8 @@ void testFailure_wrongFeeAmountTooLow_defaultToken_v12() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 100))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(USD, 100))) .build()); // Expects fee of $24 setEppInput("domain_create_fee.xml", FEE_12_MAP); @@ -3868,11 +3878,11 @@ void testSuccess_allocationToken_multiYearDiscount_worksForPremiums_v06() throws .setDiscountFraction(0.98) .setDiscountYears(2) .setDiscountPremiums(true) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().plusMillis(1), TokenStatus.VALID) - .put(clock.nowUtc().plusSeconds(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(clock.now().plusMillis(1), TokenStatus.VALID) + .put(clock.now().plusSeconds(1), TokenStatus.ENDED) .build()) .build()); clock.advanceOneMilli(); @@ -3937,13 +3947,13 @@ void testSuccess_premiumAndEap_v06() throws Exception { persistResource( Tld.get("example") .asBuilder() - .setEapFeeSchedule( + .setEapFeeScheduleInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, Money.of(USD, 0), - clock.nowUtc().minusDays(1), + minusDays(clock.now(), 1), Money.of(USD, 100), - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), Money.of(USD, 0))) .build()); assertMutatingFlow(true); @@ -3977,11 +3987,11 @@ void testSuccess_allocationToken_singleYearDiscount_worksForPremiums_v06() throw .setDomainName("rich.example") .setDiscountFraction(0.95555) .setDiscountPremiums(true) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().plusMillis(1), TokenStatus.VALID) - .put(clock.nowUtc().plusSeconds(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(clock.now().plusMillis(1), TokenStatus.VALID) + .put(clock.now().plusSeconds(1), TokenStatus.ENDED) .build()) .build()); clock.advanceOneMilli(); @@ -4008,11 +4018,11 @@ void testTieredPricingPromo_registrarIncluded_noTokenActive_v12() throws Excepti persistResource( setupDefaultTokenWithDiscount("NewRegistrar") .asBuilder() - .setTokenStatusTransitions( + .setTokenStatusTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, TokenStatus.NOT_STARTED, - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), TokenStatus.VALID)) .build()); diff --git a/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java index 9b3b2060b58..7b4b056ab7e 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainDeleteFlowTest.java @@ -51,7 +51,14 @@ import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.util.DateTimeUtils.END_OF_TIME; -import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.START_INSTANT; +import static google.registry.util.DateTimeUtils.minusDays; +import static google.registry.util.DateTimeUtils.minusMonths; +import static google.registry.util.DateTimeUtils.minusYears; +import static google.registry.util.DateTimeUtils.plusDays; +import static google.registry.util.DateTimeUtils.plusMonths; +import static google.registry.util.DateTimeUtils.plusYears; +import static google.registry.util.DateTimeUtils.toDateTime; import static org.joda.money.CurrencyUnit.USD; import static org.joda.time.Duration.standardDays; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -101,10 +108,10 @@ import google.registry.testing.CloudTasksHelper.TaskMatcher; import google.registry.testing.DatabaseHelper; import google.registry.testing.LogsSubject; +import java.time.Instant; import java.util.Map; import java.util.logging.Level; 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.Test; @@ -115,9 +122,9 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase FEE_06_MAP = ImmutableMap.of("FEE_VERSION", "fee-0.6", "FEE_NS", "fee"); @@ -156,7 +163,7 @@ private void setUpSuccessfulTest() throws Exception { assertMutatingFlow(true); } - private void createReferencedEntities(DateTime expirationTime) throws Exception { + private void createReferencedEntities(Instant expirationTime) throws Exception { domain = persistResource( DatabaseHelper.newDomain(getUniqueIdFromCommand()) @@ -169,7 +176,7 @@ private void createReferencedEntities(DateTime expirationTime) throws Exception new DomainHistory.Builder() .setType(DOMAIN_CREATE) .setDomain(domain) - .setModificationTime(clock.nowUtc()) + .setModificationTime(clock.now()) .setRegistrarId(domain.getCreationRegistrarId()) .build()); } @@ -193,7 +200,7 @@ private void setUpGracePeriodDurations() { } private void setUpAutorenewGracePeriod() throws Exception { - createReferencedEntities(A_MONTH_AGO.plusYears(1)); + createReferencedEntities(plusYears(A_MONTH_AGO, 1)); BillingRecurrence autorenewBillingEvent = persistResource( createAutorenewBillingEvent("TheRegistrar").setEventTime(A_MONTH_AGO).build()); @@ -209,7 +216,7 @@ private void setUpAutorenewGracePeriod() throws Exception { GracePeriod.createForRecurrence( GracePeriodStatus.AUTO_RENEW, domain.getRepoId(), - A_MONTH_AGO.plusDays(45), + plusDays(A_MONTH_AGO, 45), "TheRegistrar", autorenewBillingEvent.createVKey()))) .setAutorenewBillingEvent(autorenewBillingEvent.createVKey()) @@ -221,11 +228,11 @@ private void setUpAutorenewGracePeriod() throws Exception { private void assertAutorenewClosedAndCancellationCreatedFor( BillingEvent graceBillingEvent, DomainHistory historyEntryDomainDelete) { assertAutorenewClosedAndCancellationCreatedFor( - graceBillingEvent, historyEntryDomainDelete, clock.nowUtc()); + graceBillingEvent, historyEntryDomainDelete, clock.now()); } private void assertAutorenewClosedAndCancellationCreatedFor( - BillingEvent graceBillingEvent, DomainHistory historyEntryDomainDelete, DateTime eventTime) { + BillingEvent graceBillingEvent, DomainHistory historyEntryDomainDelete, Instant eventTime) { assertBillingEvents( createAutorenewBillingEvent("TheRegistrar").setRecurrenceEndTime(eventTime).build(), graceBillingEvent, @@ -234,7 +241,7 @@ private void assertAutorenewClosedAndCancellationCreatedFor( .setTargetId("example.tld") .setRegistrarId("TheRegistrar") .setEventTime(eventTime) - .setBillingTime(TIME_BEFORE_FLOW.plusDays(1)) + .setBillingTime(toDateTime(plusDays(TIME_BEFORE_FLOW, 1))) .setBillingEvent(graceBillingEvent.createVKey()) .setDomainHistory(historyEntryDomainDelete) .build()); @@ -244,7 +251,7 @@ private void assertOnlyBillingEventIsClosedAutorenew(String registrarId) { // There should be no billing events (even timed to when the transfer would have expired) except // for the now closed autorenew one. assertBillingEvents( - createAutorenewBillingEvent(registrarId).setRecurrenceEndTime(clock.nowUtc()).build()); + createAutorenewBillingEvent(registrarId).setRecurrenceEndTime(clock.now()).build()); } private BillingEvent createBillingEvent(Reason reason, Money cost) { @@ -254,8 +261,8 @@ private BillingEvent createBillingEvent(Reason reason, Money cost) { .setRegistrarId("TheRegistrar") .setCost(cost) .setPeriodYears(2) - .setEventTime(TIME_BEFORE_FLOW.minusDays(4)) - .setBillingTime(TIME_BEFORE_FLOW.plusDays(1)) + .setEventTime(minusDays(TIME_BEFORE_FLOW, 4)) + .setBillingTime(toDateTime(plusDays(TIME_BEFORE_FLOW, 1))) .setDomainHistory(earlierHistoryEntry) .build(); } @@ -298,7 +305,6 @@ void testSuccess_asyncActionsAreEnqueued() throws Exception { setUpSuccessfulTest(); clock.advanceOneMilli(); runFlowAssertResponse(loadFile("domain_delete_response_pending.xml")); - Duration when = standardDays(3); cloudTasksHelper.assertTasksEnqueued( QUEUE_ASYNC_ACTIONS, new TaskMatcher() @@ -307,9 +313,9 @@ void testSuccess_asyncActionsAreEnqueued() throws Exception { .service("backend") .header("content-type", "application/x-www-form-urlencoded") .param(PARAM_RESOURCE_KEY, domain.createVKey().stringify()) - .param(PARAM_REQUESTED_TIME, clock.nowUtc().toString()) - .param(PARAM_RESAVE_TIMES, clock.nowUtc().plusDays(5).toString()) - .scheduleTime(clock.nowUtc().plus(when))); + .param(PARAM_REQUESTED_TIME, clock.now().toString()) + .param(PARAM_RESAVE_TIMES, plusDays(clock.now(), 5).toString()) + .scheduleTime(clock.nowUtc().plus(standardDays(3)))); } @Test @@ -319,7 +325,7 @@ void testDryRun() throws Exception { GracePeriod.create( GracePeriodStatus.ADD, domain.getRepoId(), - TIME_BEFORE_FLOW.plusDays(1), + plusDays(TIME_BEFORE_FLOW, 1), "TheRegistrar", null)); dryRunFlowAssertResponse(loadFile("generic_success_response.xml")); @@ -376,8 +382,8 @@ void testSuccess_updatedEppUpdateTimeAfterPendingRedemption() throws Exception { runFlowAssertResponse(loadFile("domain_delete_response_pending.xml")); Domain domain = reloadResourceByForeignKey(); - DateTime redemptionEndTime = domain.getLastEppUpdateDateTime().plusDays(3); - Domain domainAtRedemptionTime = domain.cloneProjectedAtTime(redemptionEndTime); + Instant redemptionEndTime = plusDays(domain.getLastEppUpdateTime(), 3); + Domain domainAtRedemptionTime = domain.cloneProjectedAtInstant(redemptionEndTime); assertAboutDomains() .that(domainAtRedemptionTime) .hasLastEppUpdateRegistrarId("TheRegistrar") @@ -413,12 +419,12 @@ private void doSuccessfulTest_noAddGracePeriod( GracePeriod.create( GracePeriodStatus.TRANSFER, domain.getRepoId(), - TIME_BEFORE_FLOW.plusDays(1), + plusDays(TIME_BEFORE_FLOW, 1), "NewRegistrar", null)); // We should see exactly one poll message, which is for the autorenew 1 month in the future. assertPollMessages(createAutorenewPollMessage("TheRegistrar").build()); - DateTime expectedExpirationTime = domain.getRegistrationExpirationDateTime().minusYears(2); + Instant expectedExpirationTime = minusYears(domain.getRegistrationExpirationTime(), 2); clock.advanceOneMilli(); runFlowAssertResponse(loadFile(responseFilename, substitutions)); Domain resource = reloadResourceByForeignKey(); @@ -428,10 +434,11 @@ private void doSuccessfulTest_noAddGracePeriod( .hasStatusValue(StatusValue.PENDING_DELETE) .and() .hasDeletionTime( - clock - .nowUtc() - .plus(Tld.get("tld").getRedemptionGracePeriodLength()) - .plus(Tld.get("tld").getPendingDeleteLength())) + toDateTime( + clock + .now() + .plusMillis(Tld.get("tld").getRedemptionGracePeriodLength().getMillis()) + .plusMillis(Tld.get("tld").getPendingDeleteLength().getMillis()))) .and() .hasExactlyStatusValues(StatusValue.INACTIVE, StatusValue.PENDING_DELETE) .and() @@ -451,7 +458,7 @@ private void doSuccessfulTest_noAddGracePeriod( GracePeriod.create( GracePeriodStatus.REDEMPTION, domain.getRepoId(), - clock.nowUtc().plus(Tld.get("tld").getRedemptionGracePeriodLength()), + clock.now().plusMillis(Tld.get("tld").getRedemptionGracePeriodLength().getMillis()), "TheRegistrar", null, resource.getGracePeriods().iterator().next().getGracePeriodId())); @@ -462,8 +469,9 @@ private void assertDeletionPollMessageFor(Domain domain, String expectedMessage) // There should be a future poll message at the deletion time. The previous autorenew poll // message should now be deleted. assertAboutDomains().that(domain).hasDeletePollMessage(); - DateTime deletionTime = domain.getDeletionDateTime(); - assertThat(getPollMessages("TheRegistrar", deletionTime.minusMinutes(1))).isEmpty(); + Instant deletionTime = domain.getDeletionTime(); + assertThat(getPollMessages("TheRegistrar", deletionTime.minus(java.time.Duration.ofMinutes(1)))) + .isEmpty(); assertThat(getPollMessages("TheRegistrar", deletionTime)).hasSize(1); assertThat(domain.getDeletePollMessage()) .isEqualTo(getOnlyPollMessage("TheRegistrar").createVKey()); @@ -490,14 +498,15 @@ void testSuccess_autorenewPollMessageIsNotDeleted() throws Exception { persistResource( loadByKey(reloadResourceByForeignKey().getAutorenewPollMessage()) .asBuilder() - .setEventTime(A_MONTH_FROM_NOW.minusYears(3)) + .setEventTime(minusYears(A_MONTH_FROM_NOW, 3)) .build()); clock.advanceOneMilli(); runFlowAssertResponse(loadFile("domain_delete_response_pending.xml")); // There should now be two poll messages; one for the delete of the domain (in the future), and // another for the unacked autorenew messages. - DateTime deletionTime = reloadResourceByForeignKey().getDeletionDateTime(); - assertThat(getPollMessages("TheRegistrar", deletionTime.minusMinutes(1))).hasSize(1); + Instant deletionTime = reloadResourceByForeignKey().getDeletionTime(); + assertThat(getPollMessages("TheRegistrar", deletionTime.minus(java.time.Duration.ofMinutes(1)))) + .hasSize(1); assertThat(getPollMessages("TheRegistrar", deletionTime)).hasSize(2); } @@ -532,11 +541,11 @@ void testSuccess_autoRenewGracePeriod_priceChanges_std_v1() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setRenewBillingCostTransitions( + .setRenewBillingCostTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, Money.of(USD, 11), - TIME_BEFORE_FLOW.minusDays(5), + minusDays(TIME_BEFORE_FLOW, 5), Money.of(USD, 20))) .build()); setUpAutorenewGracePeriod(); @@ -571,10 +580,11 @@ void testSuccess_pendingTransfer() throws Exception { .hasExactlyStatusValues(StatusValue.INACTIVE, StatusValue.PENDING_DELETE) .and() .hasDeletionTime( - clock - .nowUtc() - .plus(Tld.get("tld").getRedemptionGracePeriodLength()) - .plus(Tld.get("tld").getPendingDeleteLength())) + toDateTime( + clock + .now() + .plusMillis(Tld.get("tld").getRedemptionGracePeriodLength().getMillis()) + .plusMillis(Tld.get("tld").getPendingDeleteLength().getMillis()))) .and() .hasOneHistoryEntryEachOfTypes(DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST, DOMAIN_DELETE); // All existing grace periods should be gone, and a new REDEMPTION one should be added. @@ -583,7 +593,7 @@ void testSuccess_pendingTransfer() throws Exception { GracePeriod.create( GracePeriodStatus.REDEMPTION, domain.getRepoId(), - clock.nowUtc().plus(Tld.get("tld").getRedemptionGracePeriodLength()), + clock.now().plusMillis(Tld.get("tld").getRedemptionGracePeriodLength().getMillis()), "TheRegistrar", null, domain.getGracePeriods().iterator().next().getGracePeriodId())); @@ -613,8 +623,9 @@ void testSuccess_pendingTransfer() throws Exception { .isEqualTo(Trid.create("transferClient-trid", "transferServer-trid")); assertThat(panData.getActionResult()).isFalse(); // There should be a future poll message to the losing registrar at the deletion time. - DateTime deletionTime = domain.getDeletionDateTime(); - assertThat(getPollMessages("TheRegistrar", deletionTime.minusMinutes(1))).isEmpty(); + Instant deletionTime = domain.getDeletionTime(); + assertThat(getPollMessages("TheRegistrar", deletionTime.minus(java.time.Duration.ofMinutes(1)))) + .isEmpty(); assertThat(getPollMessages("TheRegistrar", deletionTime)).hasSize(1); assertOnlyBillingEventIsClosedAutorenew("TheRegistrar"); // The domain TransferData should reflect the cancelled transfer as we expect, with @@ -624,7 +635,7 @@ void testSuccess_pendingTransfer() throws Exception { oldTransferData .copyConstantFieldsToBuilder() .setTransferStatus(TransferStatus.SERVER_CANCELLED) - .setPendingTransferExpirationTime(clock.nowUtc()) + .setPendingTransferExpirationTime(clock.now()) .build()); // The server-approve entities should all be deleted. assertThat(loadByKeyIfPresent(oldTransferData.getServerApproveBillingEvent())).isEmpty(); @@ -648,7 +659,7 @@ void testUnlinkingOfResources() throws Exception { // Add a nameserver. Host host = persistResource(newHost("ns1.example.tld")); persistResource( - ForeignKeyUtils.loadResource(Domain.class, getUniqueIdFromCommand(), clock.nowUtc()) + ForeignKeyUtils.loadResource(Domain.class, getUniqueIdFromCommand(), clock.now()) .get() .asBuilder() .setNameservers(ImmutableSet.of(host.createVKey())) @@ -658,9 +669,9 @@ void testUnlinkingOfResources() throws Exception { DatabaseHelper.newDomain("example1.tld") .asBuilder() .setNameservers(ImmutableSet.of(host.createVKey())) - .setDeletionTime(START_OF_TIME) + .setDeletionTime(START_INSTANT) .build()); - DateTime eventTime = clock.nowUtc(); + Instant eventTime = clock.now(); runFlowAssertResponse(loadFile("generic_success_response.xml")); assertDomainDnsRequests("example.tld"); assertAutorenewClosedAndCancellationCreatedFor( @@ -676,7 +687,7 @@ void testSuccess_deletedSubordinateDomain() throws Exception { newHost("ns1." + getUniqueIdFromCommand()) .asBuilder() .setSuperordinateDomain(reloadResourceByForeignKey().createVKey()) - .setDeletionTime(clock.nowUtc().minusDays(1)) + .setDeletionTime(minusDays(clock.now(), 1)) .build()); clock.advanceOneMilli(); runFlowAssertResponse(loadFile("domain_delete_response_pending.xml")); @@ -747,7 +758,7 @@ void testSuccess_superuserUnauthorizedClient() throws Exception { CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response_pending.xml")); HistoryEntry deleteHistoryEntry = getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE); - DateTime now = clock.nowUtc(); + Instant now = clock.now(); assertPollMessages( new PollMessage.OneTime.Builder() .setRegistrarId("TheRegistrar") @@ -764,7 +775,7 @@ void testSuccess_superuserUnauthorizedClient() throws Exception { new PollMessage.OneTime.Builder() .setRegistrarId("TheRegistrar") .setHistoryEntry(deleteHistoryEntry) - .setEventTime(DateTime.parse("2000-07-11T22:00:00.010Z")) + .setEventTime(Instant.parse("2000-07-11T22:00:00.010Z")) .setMsg("Deleted by registry administrator.") .setResponseData( ImmutableList.of( @@ -772,7 +783,7 @@ void testSuccess_superuserUnauthorizedClient() throws Exception { "example.tld", true, deleteHistoryEntry.getTrid(), - DateTime.parse("2000-07-11T22:00:00.010Z")))) + Instant.parse("2000-07-11T22:00:00.010Z")))) .build()); } @@ -888,7 +899,7 @@ void testSuccess_metadata() throws Exception { .that(reloadResourceByForeignKey()) .hasOneHistoryEntryEachOfTypes(DOMAIN_CREATE, DOMAIN_DELETE) .and() - .hasLastEppUpdateTime(clock.nowUtc()) + .hasLastEppUpdateTime(clock.now()) .and() .hasLastEppUpdateRegistrarId("TheRegistrar"); assertAboutHistoryEntries() @@ -928,11 +939,11 @@ void testIcannTransactionRecord_testTld_notStored() throws Exception { earlierHistoryEntry .asBuilder() .setType(DOMAIN_CREATE) - .setModificationTime(TIME_BEFORE_FLOW.minusDays(2)) + .setModificationTime(minusDays(TIME_BEFORE_FLOW, 2)) .setDomainTransactionRecords( ImmutableSet.of( DomainTransactionRecord.create( - "tld", TIME_BEFORE_FLOW.plusDays(1), NET_ADDS_1_YR, 1))) + "tld", plusDays(TIME_BEFORE_FLOW, 1), NET_ADDS_1_YR, 1))) .build()); runFlow(); DomainHistory persistedEntry = (DomainHistory) getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE); @@ -950,11 +961,11 @@ void testIcannTransactionRecord_noGrace_entryOutsideMaxGracePeriod() throws Exce earlierHistoryEntry .asBuilder() .setType(DOMAIN_CREATE) - .setModificationTime(TIME_BEFORE_FLOW.minusDays(4)) + .setModificationTime(minusDays(TIME_BEFORE_FLOW, 4)) .setDomainTransactionRecords( ImmutableSet.of( DomainTransactionRecord.create( - "tld", TIME_BEFORE_FLOW.plusDays(1), NET_ADDS_1_YR, 1))) + "tld", plusDays(TIME_BEFORE_FLOW, 1), NET_ADDS_1_YR, 1))) .build()); runFlow(); DomainHistory persistedEntry = (DomainHistory) getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE); @@ -962,7 +973,10 @@ void testIcannTransactionRecord_noGrace_entryOutsideMaxGracePeriod() throws Exce assertThat(persistedEntry.getDomainTransactionRecords()) .containsExactly( DomainTransactionRecord.create( - "tld", clock.nowUtc().plusHours(3), DELETED_DOMAINS_NOGRACE, 1)); + "tld", + clock.now().plus(java.time.Duration.ofHours(3)), + DELETED_DOMAINS_NOGRACE, + 1)); } @Test @@ -975,12 +989,12 @@ void testIcannTransactionRecord_noGrace_noAddOrRenewRecords() throws Exception { earlierHistoryEntry .asBuilder() .setType(DOMAIN_CREATE) - .setModificationTime(TIME_BEFORE_FLOW.minusDays(2)) + .setModificationTime(minusDays(TIME_BEFORE_FLOW, 2)) .setDomainTransactionRecords( ImmutableSet.of( // Only add or renew records counts should be cancelled DomainTransactionRecord.create( - "tld", TIME_BEFORE_FLOW.plusDays(1), RESTORED_DOMAINS, 1))) + "tld", plusDays(TIME_BEFORE_FLOW, 1), RESTORED_DOMAINS, 1))) .build()); runFlow(); DomainHistory persistedEntry = (DomainHistory) getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE); @@ -988,7 +1002,10 @@ void testIcannTransactionRecord_noGrace_noAddOrRenewRecords() throws Exception { assertThat(persistedEntry.getDomainTransactionRecords()) .containsExactly( DomainTransactionRecord.create( - "tld", clock.nowUtc().plusHours(3), DELETED_DOMAINS_NOGRACE, 1)); + "tld", + clock.now().plus(java.time.Duration.ofHours(3)), + DELETED_DOMAINS_NOGRACE, + 1)); } /** Verifies that if there's no add grace period, we still cancel out valid renew records */ @@ -998,16 +1015,16 @@ void testIcannTransactionRecord_noGrace_hasRenewRecord() throws Exception { setUpGracePeriodDurations(); clock.advanceOneMilli(); DomainTransactionRecord renewRecord = - DomainTransactionRecord.create("tld", TIME_BEFORE_FLOW.plusDays(1), NET_RENEWS_3_YR, 1); + DomainTransactionRecord.create("tld", plusDays(TIME_BEFORE_FLOW, 1), NET_RENEWS_3_YR, 1); // We don't want to cancel non-add or renew records DomainTransactionRecord notCancellableRecord = - DomainTransactionRecord.create("tld", TIME_BEFORE_FLOW.plusDays(1), RESTORED_DOMAINS, 5); + DomainTransactionRecord.create("tld", plusDays(TIME_BEFORE_FLOW, 1), RESTORED_DOMAINS, 5); earlierHistoryEntry = persistResource( earlierHistoryEntry .asBuilder() .setType(DOMAIN_CREATE) - .setModificationTime(TIME_BEFORE_FLOW.minusDays(2)) + .setModificationTime(minusDays(TIME_BEFORE_FLOW, 2)) .setDomainTransactionRecords(ImmutableSet.of(renewRecord, notCancellableRecord)) .build()); runFlow(); @@ -1016,7 +1033,7 @@ void testIcannTransactionRecord_noGrace_hasRenewRecord() throws Exception { assertThat(persistedEntry.getDomainTransactionRecords()) .containsExactly( DomainTransactionRecord.create( - "tld", clock.nowUtc().plusHours(3), DELETED_DOMAINS_NOGRACE, 1), + "tld", clock.now().plus(java.time.Duration.ofHours(3)), DELETED_DOMAINS_NOGRACE, 1), renewRecord.asBuilder().setReportAmount(-1).build()); } @@ -1027,7 +1044,7 @@ void testIcannTransactionRecord_inGrace_noRecords() throws Exception { GracePeriod.create( GracePeriodStatus.ADD, domain.getRepoId(), - TIME_BEFORE_FLOW.plusDays(1), + plusDays(TIME_BEFORE_FLOW, 1), "TheRegistrar", null)); setUpGracePeriodDurations(); @@ -1037,7 +1054,7 @@ void testIcannTransactionRecord_inGrace_noRecords() throws Exception { // Transaction record should just be the grace period delete assertThat(persistedEntry.getDomainTransactionRecords()) .containsExactly( - DomainTransactionRecord.create("tld", clock.nowUtc(), DELETED_DOMAINS_GRACE, 1)); + DomainTransactionRecord.create("tld", clock.now(), DELETED_DOMAINS_GRACE, 1)); } @Test @@ -1047,7 +1064,7 @@ void testIcannTransactionRecord_inGrace_multipleRecords() throws Exception { GracePeriod.create( GracePeriodStatus.ADD, domain.getRepoId(), - TIME_BEFORE_FLOW.plusDays(1), + plusDays(TIME_BEFORE_FLOW, 1), "TheRegistrar", null)); setUpGracePeriodDurations(); @@ -1057,20 +1074,20 @@ void testIcannTransactionRecord_inGrace_multipleRecords() throws Exception { earlierHistoryEntry .asBuilder() .setType(DOMAIN_CREATE) - .setModificationTime(TIME_BEFORE_FLOW.minusDays(2)) + .setModificationTime(minusDays(TIME_BEFORE_FLOW, 2)) .setDomainTransactionRecords( ImmutableSet.of( DomainTransactionRecord.create( - "tld", TIME_BEFORE_FLOW.plusDays(1), NET_ADDS_10_YR, 1))) + "tld", plusDays(TIME_BEFORE_FLOW, 1), NET_ADDS_10_YR, 1))) .build()); DomainTransactionRecord existingRecord = - DomainTransactionRecord.create("tld", TIME_BEFORE_FLOW.plusDays(2), NET_ADDS_10_YR, 1); + DomainTransactionRecord.create("tld", plusDays(TIME_BEFORE_FLOW, 2), NET_ADDS_10_YR, 1); // Create a HistoryEntry with a later modification time persistResource( new DomainHistory.Builder() .setType(DOMAIN_CREATE) .setDomain(domain) - .setModificationTime(TIME_BEFORE_FLOW.minusDays(1)) + .setModificationTime(minusDays(TIME_BEFORE_FLOW, 1)) .setRegistrarId("TheRegistrar") .setDomainTransactionRecords(ImmutableSet.of(existingRecord)) .build()); @@ -1079,7 +1096,7 @@ void testIcannTransactionRecord_inGrace_multipleRecords() throws Exception { // Transaction record should be the grace period delete, and the more recent cancellation record assertThat(persistedEntry.getDomainTransactionRecords()) .containsExactly( - DomainTransactionRecord.create("tld", clock.nowUtc(), DELETED_DOMAINS_GRACE, 1), + DomainTransactionRecord.create("tld", clock.now(), DELETED_DOMAINS_GRACE, 1), // The cancellation record is the same as the original, except with a -1 counter existingRecord.asBuilder().setReportAmount(-1).build()); } @@ -1099,13 +1116,13 @@ void testSuccess_superuserExtension_nonZeroDayGrace_nonZeroDayPendingDelete() th .that(resource) .hasExactlyStatusValues(StatusValue.INACTIVE, StatusValue.PENDING_DELETE) .and() - .hasDeletionTime(clock.nowUtc().plus(standardDays(19))); + .hasDeletionTime(clock.now().plusMillis(standardDays(19).getMillis())); assertThat(resource.getGracePeriods()) .containsExactly( GracePeriod.create( GracePeriodStatus.REDEMPTION, domain.getRepoId(), - clock.nowUtc().plus(standardDays(15)), + clock.now().plusMillis(standardDays(15).getMillis()), "TheRegistrar", null, resource.getGracePeriods().iterator().next().getGracePeriodId())); @@ -1127,7 +1144,7 @@ void testSuccess_superuserExtension_zeroDayGrace_nonZeroDayPendingDelete() throw .that(resource) .hasExactlyStatusValues(StatusValue.INACTIVE, StatusValue.PENDING_DELETE) .and() - .hasDeletionTime(clock.nowUtc().plus(standardDays(4))); + .hasDeletionTime(clock.now().plusMillis(standardDays(4).getMillis())); assertThat(resource.getGracePeriods()).isEmpty(); assertDeletionPollMessageFor(resource, "Deleted by registry administrator."); } @@ -1147,13 +1164,13 @@ void testSuccess_superuserExtension_nonZeroDayGrace_zeroDayPendingDelete() throw .that(resource) .hasExactlyStatusValues(StatusValue.INACTIVE, StatusValue.PENDING_DELETE) .and() - .hasDeletionTime(clock.nowUtc().plus(standardDays(15))); + .hasDeletionTime(clock.now().plusMillis(standardDays(15).getMillis())); assertThat(resource.getGracePeriods()) .containsExactly( GracePeriod.create( GracePeriodStatus.REDEMPTION, domain.getRepoId(), - clock.nowUtc().plus(standardDays(15)), + clock.now().plusMillis(standardDays(15).getMillis()), "TheRegistrar", null, resource.getGracePeriods().iterator().next().getGracePeriodId())); @@ -1312,11 +1329,11 @@ void testSuccess_autoRenewGracePeriod_priceChanges_v06() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setRenewBillingCostTransitions( + .setRenewBillingCostTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, Money.of(USD, 11), - TIME_BEFORE_FLOW.minusDays(5), + minusDays(TIME_BEFORE_FLOW, 5), Money.of(USD, 20))) .build()); setUpAutorenewGracePeriod(); @@ -1331,11 +1348,11 @@ void testSuccess_autoRenewGracePeriod_priceChanges_v11() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setRenewBillingCostTransitions( + .setRenewBillingCostTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, Money.of(USD, 11), - TIME_BEFORE_FLOW.minusDays(5), + minusDays(TIME_BEFORE_FLOW, 5), Money.of(USD, 20))) .build()); setUpAutorenewGracePeriod(); @@ -1349,11 +1366,11 @@ void testSuccess_autoRenewGracePeriod_priceChanges_v12() throws Exception { persistResource( Tld.get("tld") .asBuilder() - .setRenewBillingCostTransitions( + .setRenewBillingCostTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, + START_INSTANT, Money.of(USD, 11), - TIME_BEFORE_FLOW.minusDays(5), + minusDays(TIME_BEFORE_FLOW, 5), Money.of(USD, 20))) .build()); setUpAutorenewGracePeriod(); diff --git a/core/src/test/java/google/registry/flows/domain/DomainDeletionTimeCacheTest.java b/core/src/test/java/google/registry/flows/domain/DomainDeletionTimeCacheTest.java index b0df8ed901f..25da1daab13 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainDeletionTimeCacheTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainDeletionTimeCacheTest.java @@ -19,11 +19,13 @@ import static google.registry.testing.DatabaseHelper.persistActiveDomain; import static google.registry.testing.DatabaseHelper.persistDomainAsDeleted; import static google.registry.util.DateTimeUtils.END_OF_TIME; +import static google.registry.util.DateTimeUtils.toDateTime; import google.registry.model.domain.Domain; import google.registry.persistence.transaction.JpaTestExtensions; import google.registry.testing.DatabaseHelper; import google.registry.testing.FakeClock; +import java.time.Instant; import java.util.Optional; import org.joda.time.DateTime; import org.joda.time.Duration; @@ -34,7 +36,7 @@ /** Tests for {@link DomainDeletionTimeCache}. */ public class DomainDeletionTimeCacheTest { - private final FakeClock clock = new FakeClock(DateTime.parse("2025-10-01T00:00:00.000Z")); + private final FakeClock clock = new FakeClock(Instant.parse("2025-10-01T00:00:00.000Z")); private final DomainDeletionTimeCache cache = DomainDeletionTimeCache.create(); @RegisterExtension @@ -85,10 +87,10 @@ void testCache_returnsNewDataAfterDomainCreate() { void testCache_expires() { Domain domain = persistActiveDomain("domain.tld"); assertThat(getDeletionTimeFromCache("domain.tld")).hasValue(END_OF_TIME); - DateTime elevenMinutesFromNow = clock.nowUtc().plusMinutes(11); - persistDomainAsDeleted(domain, elevenMinutesFromNow); + Instant elevenMinutesFromNow = clock.now().plus(java.time.Duration.ofMinutes(11)); + persistDomainAsDeleted(domain, toDateTime(elevenMinutesFromNow)); clock.advanceBy(Duration.standardMinutes(30)); - assertThat(getDeletionTimeFromCache("domain.tld")).hasValue(elevenMinutesFromNow); + assertThat(getDeletionTimeFromCache("domain.tld")).hasValue(toDateTime(elevenMinutesFromNow)); } private Optional getDeletionTimeFromCache(String domainName) { diff --git a/core/src/test/java/google/registry/flows/domain/DomainInfoFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainInfoFlowTest.java index 4e68647e49c..8be64d0b595 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainInfoFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainInfoFlowTest.java @@ -31,6 +31,8 @@ import static google.registry.testing.TestDataHelper.updateSubstitutions; import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.minusDays; +import static google.registry.util.DateTimeUtils.plusDays; import static google.registry.xml.XmlTestUtils.assertXmlEquals; import static java.nio.charset.StandardCharsets.UTF_8; import static org.joda.money.CurrencyUnit.USD; @@ -77,7 +79,6 @@ import java.util.regex.Pattern; import javax.annotation.Nullable; import org.joda.money.Money; -import org.joda.time.DateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -106,7 +107,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase { @BeforeEach void setup() { setEppInput("domain_info.xml"); - clock.setTo(DateTime.parse("2005-03-03T22:00:00.000Z")); + clock.setTo(Instant.parse("2005-03-03T22:00:00.000Z")); sessionMetadata.setRegistrarId("NewRegistrar"); createTld("tld"); persistResource( @@ -127,10 +128,10 @@ private void persistTestEntities(String domainName, boolean inactive) { .setPersistedCurrentSponsorRegistrarId("NewRegistrar") .setCreationRegistrarId("TheRegistrar") .setLastEppUpdateRegistrarId("NewRegistrar") - .setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z")) - .setLastEppUpdateTime(DateTime.parse("1999-12-03T09:00:00.0Z")) - .setLastTransferTime(DateTime.parse("2000-04-08T09:00:00.0Z")) - .setRegistrationExpirationTime(DateTime.parse("2005-04-03T22:00:00.0Z")) + .setCreationTimeForTest(Instant.parse("1999-04-03T22:00:00.0Z")) + .setLastEppUpdateTime(Instant.parse("1999-12-03T09:00:00.0Z")) + .setLastTransferTime(Instant.parse("2000-04-08T09:00:00.0Z")) + .setRegistrationExpirationTime(Instant.parse("2005-04-03T22:00:00.0Z")) .setNameservers( inactive ? null : ImmutableSet.of(host1.createVKey(), host2.createVKey())) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("2fooBAR"))) @@ -331,12 +332,12 @@ private void doAddPeriodTest(GracePeriodStatus gracePeriodStatus) throws Excepti GracePeriod.create( gracePeriodStatus, domain.getRepoId(), - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), "TheRegistrar", null)) .setCreationRegistrarId("NewRegistrar") - .setCreationTimeForTest(DateTime.parse("2003-11-26T22:00:00.0Z")) - .setRegistrationExpirationTime(DateTime.parse("2005-11-26T22:00:00.0Z")) + .setCreationTimeForTest(Instant.parse("2003-11-26T22:00:00.0Z")) + .setRegistrationExpirationTime(Instant.parse("2005-11-26T22:00:00.0Z")) .setLastTransferTime((Instant) null) .setLastEppUpdateTime((Instant) null) .setLastEppUpdateRegistrarId(null) @@ -357,7 +358,7 @@ void testSuccess_autoRenewGracePeriod() throws Exception { new DomainHistory.Builder() .setDomain(domain) .setType(HistoryEntry.Type.DOMAIN_CREATE) - .setModificationTime(clock.nowUtc()) + .setModificationTime(clock.now()) .setRegistrarId(domain.getCreationRegistrarId()) .build()); BillingRecurrence renewEvent = @@ -367,7 +368,7 @@ void testSuccess_autoRenewGracePeriod() throws Exception { .setFlags(ImmutableSet.of(Flag.AUTO_RENEW)) .setTargetId(getUniqueIdFromCommand()) .setRegistrarId("TheRegistrar") - .setEventTime(clock.nowUtc()) + .setEventTime(clock.now()) .setRecurrenceEndTime(END_OF_TIME) .setDomainHistory(historyEntry) .build()); @@ -380,7 +381,7 @@ void testSuccess_autoRenewGracePeriod() throws Exception { GracePeriod.createForRecurrence( GracePeriodStatus.AUTO_RENEW, domain.getRepoId(), - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), "TheRegistrar", recurrenceVKey)) .build()); @@ -399,7 +400,7 @@ void testSuccess_redemptionGracePeriod() throws Exception { GracePeriod.create( GracePeriodStatus.REDEMPTION, domain.getRepoId(), - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), "TheRegistrar", null)) .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) @@ -418,7 +419,7 @@ void testSuccess_renewGracePeriod() throws Exception { GracePeriod.create( GracePeriodStatus.RENEW, domain.getRepoId(), - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), "TheRegistrar", null)) .build()); @@ -436,14 +437,14 @@ void testSuccess_multipleRenewGracePeriods() throws Exception { GracePeriod.create( GracePeriodStatus.RENEW, domain.getRepoId(), - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), "TheRegistrar", null)) .addGracePeriod( GracePeriod.create( GracePeriodStatus.RENEW, domain.getRepoId(), - clock.nowUtc().plusDays(2), + plusDays(clock.now(), 2), "TheRegistrar", null)) .build()); @@ -461,7 +462,7 @@ void testSuccess_transferGracePeriod() throws Exception { GracePeriod.create( GracePeriodStatus.TRANSFER, domain.getRepoId(), - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), "TheRegistrar", null)) .build()); @@ -489,14 +490,14 @@ void testSuccess_stackedAddRenewGracePeriods() throws Exception { GracePeriod.create( GracePeriodStatus.ADD, domain.getRepoId(), - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), "TheRegistrar", null)) .addGracePeriod( GracePeriod.create( GracePeriodStatus.RENEW, domain.getRepoId(), - clock.nowUtc().plusDays(2), + plusDays(clock.now(), 2), "TheRegistrar", null)) .build()); @@ -514,7 +515,7 @@ void testSuccess_secDnsAndAddGracePeriod() throws Exception { GracePeriod.create( GracePeriodStatus.ADD, domain.getRepoId(), - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), "TheRegistrar", null)) .setDsData( @@ -536,7 +537,7 @@ void testFailure_existedButWasDeleted() throws Exception { persistResource( DatabaseHelper.newDomain("example.tld") .asBuilder() - .setDeletionTime(clock.nowUtc().minusDays(1)) + .setDeletionTime(minusDays(clock.now(), 1)) .build()); ResourceDoesNotExistException thrown = assertThrows(ResourceDoesNotExistException.class, this::runFlow); @@ -588,7 +589,7 @@ void testBulkInfoExtension_returnsBulkInfo() throws Exception { new AllocationToken.Builder() .setToken("abc123") .setTokenType(TokenType.BULK_PRICING) - .setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z")) + .setCreationTimeForTest(Instant.parse("2010-11-12T05:00:00Z")) .setAllowedTlds(ImmutableSet.of("foo")) .setAllowedRegistrarIds(ImmutableSet.of("NewRegistrar")) .setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED) @@ -610,7 +611,7 @@ void testBulkInfoExtension_returnsBulkInfoForSuperUser() throws Exception { new AllocationToken.Builder() .setToken("abc123") .setTokenType(TokenType.BULK_PRICING) - .setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z")) + .setCreationTimeForTest(Instant.parse("2010-11-12T05:00:00Z")) .setAllowedTlds(ImmutableSet.of("foo")) .setAllowedRegistrarIds(ImmutableSet.of("NewRegistrar")) .setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED) @@ -644,7 +645,7 @@ void testBulkInfoExtension_notCurrentSponsorRegistrar() throws Exception { new AllocationToken.Builder() .setToken("abc123") .setTokenType(TokenType.BULK_PRICING) - .setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z")) + .setCreationTimeForTest(Instant.parse("2010-11-12T05:00:00Z")) .setAllowedTlds(ImmutableSet.of("foo")) .setAllowedRegistrarIds(ImmutableSet.of("NewRegistrar")) .setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED) @@ -673,8 +674,8 @@ void testFeeExtension_restoreCommand_pendingDelete_withRenewal() throws Exceptio persistResource( domain .asBuilder() - .setDeletionTime(clock.nowUtc().plusDays(25)) - .setRegistrationExpirationTime(clock.nowUtc().minusDays(1)) + .setDeletionTime(plusDays(clock.now(), 25)) + .setRegistrationExpirationTime(minusDays(clock.now(), 1)) .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) .build()); doSuccessfulTest( @@ -762,7 +763,7 @@ void testFeeExtension_restoreCommand_pendingDelete_noRenewal() throws Exception persistResource( domain .asBuilder() - .setDeletionTime(clock.nowUtc().plusDays(25)) + .setDeletionTime(plusDays(clock.now(), 25)) .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) .build()); doSuccessfulTest( diff --git a/core/src/test/java/google/registry/flows/domain/DomainPricingLogicTest.java b/core/src/test/java/google/registry/flows/domain/DomainPricingLogicTest.java index 194f3a39704..58c0322c530 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainPricingLogicTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainPricingLogicTest.java @@ -27,7 +27,7 @@ import static google.registry.testing.DatabaseHelper.persistPremiumList; import static google.registry.testing.DatabaseHelper.persistResource; import static google.registry.util.DateTimeUtils.END_OF_TIME; -import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.START_INSTANT; import static org.joda.money.CurrencyUnit.USD; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -56,9 +56,10 @@ import google.registry.testing.FakeHttpSession; import google.registry.util.Clock; import java.math.BigDecimal; +import java.time.Duration; +import java.time.Instant; import java.util.Optional; import org.joda.money.Money; -import org.joda.time.DateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -72,7 +73,7 @@ public class DomainPricingLogicTest { final JpaIntegrationTestExtension jpa = new JpaTestExtensions.Builder().buildIntegrationTestExtension(); - Clock clock = new FakeClock(DateTime.parse("2023-05-13T00:00:00.000Z")); + Clock clock = new FakeClock(Instant.parse("2023-05-13T00:00:00.000Z")); @Mock EppInput eppInput; SessionMetadata sessionMetadata; Tld tld; @@ -88,9 +89,9 @@ void beforeEach() throws Exception { persistResource( Tld.get("example") .asBuilder() - .setRenewBillingCostTransitions( + .setRenewBillingCostTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, Money.of(USD, 1), clock.nowUtc(), Money.of(USD, 10))) + START_INSTANT, Money.of(USD, 1), clock.now(), Money.of(USD, 10))) .setPremiumList(persistPremiumList("tld2", USD, "premium,USD 100")) .build()); } @@ -102,14 +103,14 @@ private BillingRecurrence persistDomainAndSetRecurrence( persistResource( DatabaseHelper.newDomain(domainName) .asBuilder() - .setCreationTimeForTest(DateTime.parse("1999-01-05T00:00:00Z")) + .setCreationTimeForTest(Instant.parse("1999-01-05T00:00:00Z")) .build()); DomainHistory historyEntry = persistResource( new DomainHistory.Builder() .setRegistrarId(domain.getCreationRegistrarId()) .setType(DOMAIN_CREATE) - .setModificationTime(DateTime.parse("1999-01-05T00:00:00Z")) + .setModificationTime(Instant.parse("1999-01-05T00:00:00Z")) .setDomain(domain) .build()); BillingRecurrence billingRecurrence = @@ -117,7 +118,7 @@ private BillingRecurrence persistDomainAndSetRecurrence( new BillingRecurrence.Builder() .setDomainHistory(historyEntry) .setRegistrarId(domain.getCreationRegistrarId()) - .setEventTime(DateTime.parse("1999-01-05T00:00:00Z")) + .setEventTime(Instant.parse("1999-01-05T00:00:00Z")) .setFlags(ImmutableSet.of(AUTO_RENEW)) .setId(2L) .setReason(Reason.RENEW) @@ -133,16 +134,19 @@ private BillingRecurrence persistDomainAndSetRecurrence( @Test void testGetDomainCreatePrice_sunrise_appliesDiscount() throws EppException { - ImmutableSortedMap transitions = - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TldState.PREDELEGATION) - .put(clock.nowUtc().minusHours(1), TldState.START_DATE_SUNRISE) - .put(clock.nowUtc().plusHours(1), TldState.GENERAL_AVAILABILITY) + ImmutableSortedMap transitions = + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TldState.PREDELEGATION) + .put(clock.now().minus(Duration.ofHours(1)), TldState.START_DATE_SUNRISE) + .put(clock.now().plus(Duration.ofHours(1)), TldState.GENERAL_AVAILABILITY) .build(); - Tld sunriseTld = createTld("sunrise", transitions); + createTld("sunrise"); + Tld sunriseTld = + persistResource( + Tld.get("sunrise").asBuilder().setTldStateTransitionsInstant(transitions).build()); assertThat( domainPricingLogic.getCreatePrice( - sunriseTld, "domain.sunrise", clock.nowUtc(), 2, false, true, Optional.empty())) + sunriseTld, "domain.sunrise", clock.now(), 2, false, true, Optional.empty())) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -166,13 +170,7 @@ void testGetDomainCreatePrice_discountPriceAllocationToken_oneYearCreate_applies .build()); assertThat( domainPricingLogic.getCreatePrice( - tld, - "default.example", - clock.nowUtc(), - 1, - false, - false, - Optional.of(allocationToken))) + tld, "default.example", clock.now(), 1, false, false, Optional.of(allocationToken))) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -197,13 +195,7 @@ void testGetDomainCreatePrice_discountPriceAllocationToken_multiYearCreate_appli // 3 year create should be 5 (discount price) + 10*2 (regular price) = 25. assertThat( domainPricingLogic.getCreatePrice( - tld, - "default.example", - clock.nowUtc(), - 3, - false, - false, - Optional.of(allocationToken))) + tld, "default.example", clock.now(), 3, false, false, Optional.of(allocationToken))) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -216,7 +208,7 @@ void testGetDomainRenewPrice_oneYear_standardDomain_noBilling_isStandardPrice() throws EppException { assertThat( domainPricingLogic.getRenewPrice( - tld, "standard.example", clock.nowUtc(), 1, null, Optional.empty())) + tld, "standard.example", clock.now(), 1, null, Optional.empty())) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -229,7 +221,7 @@ void testGetDomainRenewPrice_multiYear_standardDomain_noBilling_isStandardPrice( throws EppException { assertThat( domainPricingLogic.getRenewPrice( - tld, "standard.example", clock.nowUtc(), 5, null, Optional.empty())) + tld, "standard.example", clock.now(), 5, null, Optional.empty())) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -242,7 +234,7 @@ void testGetDomainRenewPrice_oneYear_premiumDomain_noBilling_isPremiumPrice() throws EppException { assertThat( domainPricingLogic.getRenewPrice( - tld, "premium.example", clock.nowUtc(), 1, null, Optional.empty())) + tld, "premium.example", clock.now(), 1, null, Optional.empty())) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -255,7 +247,7 @@ void testGetDomainRenewPrice_multiYear_premiumDomain_noBilling_isPremiumPrice() throws EppException { assertThat( domainPricingLogic.getRenewPrice( - tld, "premium.example", clock.nowUtc(), 5, null, Optional.empty())) + tld, "premium.example", clock.now(), 5, null, Optional.empty())) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -269,7 +261,7 @@ void testGetDomainRenewPrice_oneYear_premiumDomain_default_isPremiumPrice() thro domainPricingLogic.getRenewPrice( tld, "premium.example", - clock.nowUtc(), + clock.now(), 1, persistDomainAndSetRecurrence("premium.example", DEFAULT, Optional.empty()), Optional.empty())) @@ -295,7 +287,7 @@ void testGetDomainRenewPrice_oneYear_premiumDomain_default_withToken_isPremiumPr domainPricingLogic.getRenewPrice( tld, "premium.example", - clock.nowUtc(), + clock.now(), 1, persistDomainAndSetRecurrence("premium.example", DEFAULT, Optional.empty()), Optional.of(allocationToken))) @@ -312,7 +304,7 @@ void testGetDomainRenewPrice_multiYear_premiumDomain_default_isPremiumCost() thr domainPricingLogic.getRenewPrice( tld, "premium.example", - clock.nowUtc(), + clock.now(), 5, persistDomainAndSetRecurrence("premium.example", DEFAULT, Optional.empty()), Optional.empty())) @@ -339,7 +331,7 @@ void testGetDomainRenewPrice_multiYear_premiumDomain_default_withToken_isPremium domainPricingLogic.getRenewPrice( tld, "premium.example", - clock.nowUtc(), + clock.now(), 5, persistDomainAndSetRecurrence("premium.example", DEFAULT, Optional.empty()), Optional.of(allocationToken))) @@ -357,7 +349,7 @@ void testGetDomainRenewPrice_oneYear_standardDomain_default_isNonPremiumPrice() domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 1, persistDomainAndSetRecurrence("standard.example", DEFAULT, Optional.empty()), Optional.empty())) @@ -383,7 +375,7 @@ void testGetDomainRenewPrice_oneYear_standardDomain_default_withToken_isDiscount domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 1, persistDomainAndSetRecurrence("standard.example", DEFAULT, Optional.empty()), Optional.of(allocationToken))) @@ -410,7 +402,7 @@ void testGetDomainRenewPrice_oneYear_standardDomain_default_withToken_isDiscount domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 1, persistDomainAndSetRecurrence("standard.example", DEFAULT, Optional.empty()), Optional.of(allocationToken))) @@ -428,7 +420,7 @@ void testGetDomainRenewPrice_multiYear_standardDomain_default_isNonPremiumCost() domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 5, persistDomainAndSetRecurrence("standard.example", DEFAULT, Optional.empty()), Optional.empty())) @@ -455,7 +447,7 @@ void testGetDomainRenewPrice_multiYear_standardDomain_default_withToken_isDiscou domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 5, persistDomainAndSetRecurrence("standard.example", DEFAULT, Optional.empty()), Optional.of(allocationToken))) @@ -485,7 +477,7 @@ void testGetDomainRenewPrice_multiYear_standardDomain_default_withToken_isDiscou domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 5, persistDomainAndSetRecurrence("standard.example", DEFAULT, Optional.empty()), Optional.of(allocationToken))) @@ -503,7 +495,7 @@ void testGetDomainRenewPrice_oneYear_premiumDomain_anchorTenant_isNonPremiumPric domainPricingLogic.getRenewPrice( tld, "premium.example", - clock.nowUtc(), + clock.now(), 1, persistDomainAndSetRecurrence("premium.example", NONPREMIUM, Optional.empty()), Optional.empty())) @@ -530,7 +522,7 @@ void testGetDomainRenewPrice_oneYear_premiumDomain_anchorTenant_isNonPremiumPric domainPricingLogic.getRenewPrice( tld, "premium.example", - clock.nowUtc(), + clock.now(), 1, persistDomainAndSetRecurrence("premium.example", NONPREMIUM, Optional.empty()), Optional.of(allocationToken))) @@ -548,7 +540,7 @@ void testGetDomainRenewPrice_multiYear_premiumDomain_anchorTenant_isNonPremiumCo domainPricingLogic.getRenewPrice( tld, "premium.example", - clock.nowUtc(), + clock.now(), 5, persistDomainAndSetRecurrence("premium.example", NONPREMIUM, Optional.empty()), Optional.empty())) @@ -576,7 +568,7 @@ void testGetDomainRenewPrice_multiYear_premiumDomain_anchorTenant_isNonPremiumCo domainPricingLogic.getRenewPrice( tld, "premium.example", - clock.nowUtc(), + clock.now(), 5, persistDomainAndSetRecurrence("premium.example", NONPREMIUM, Optional.empty()), Optional.of(allocationToken))) @@ -594,7 +586,7 @@ void testGetDomainRenewPrice_oneYear_standardDomain_anchorTenant_isNonPremiumPri domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 1, persistDomainAndSetRecurrence("standard.example", NONPREMIUM, Optional.empty()), Optional.empty())) @@ -612,7 +604,7 @@ void testGetDomainRenewPrice_multiYear_standardDomain_anchorTenant_isNonPremiumC domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 5, persistDomainAndSetRecurrence("standard.example", NONPREMIUM, Optional.empty()), Optional.empty())) @@ -630,7 +622,7 @@ void testGetDomainRenewPrice_oneYear_standardDomain_internalRegistration_isSpeci domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 1, persistDomainAndSetRecurrence( "standard.example", SPECIFIED, Optional.of(Money.of(USD, 1))), @@ -658,7 +650,7 @@ void testGetDomainRenewPrice_oneYear_standardDomain_internalRegistration_isSpeci domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 1, persistDomainAndSetRecurrence( "standard.example", SPECIFIED, Optional.of(Money.of(USD, 1))), @@ -688,7 +680,7 @@ void testGetDomainRenewPrice_oneYear_standardDomain_internalRegistration_isSpeci domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 1, persistDomainAndSetRecurrence( "standard.example", SPECIFIED, Optional.of(Money.of(USD, 1))), @@ -719,7 +711,7 @@ void testGetDomainRenewPrice_oneYear_standardDomain_internalRegistration_isSpeci domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 1, persistDomainAndSetRecurrence( "standard.example", SPECIFIED, Optional.of(Money.of(USD, 1))), @@ -744,7 +736,7 @@ void testGetDomainRenewPrice_multiYear_standardDomain_internalRegistration_isSpe domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 5, persistDomainAndSetRecurrence( "standard.example", SPECIFIED, Optional.of(Money.of(USD, 1))), @@ -772,7 +764,7 @@ void testGetDomainRenewPrice_multiYear_standardDomain_internalRegistration_isSpe domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 5, persistDomainAndSetRecurrence( "standard.example", SPECIFIED, Optional.of(Money.of(USD, 1))), @@ -800,7 +792,7 @@ void testGetDomainRenewPrice_multiYear_standardDomain_internalRegistration_isSpe domainPricingLogic.getRenewPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), 5, persistDomainAndSetRecurrence( "standard.example", SPECIFIED, Optional.of(Money.of(USD, 1))), @@ -819,7 +811,7 @@ void testGetDomainRenewPrice_oneYear_premiumDomain_internalRegistration_isSpecif domainPricingLogic.getRenewPrice( tld, "premium.example", - clock.nowUtc(), + clock.now(), 1, persistDomainAndSetRecurrence( "premium.example", SPECIFIED, Optional.of(Money.of(USD, 17))), @@ -838,7 +830,7 @@ void testGetDomainRenewPrice_multiYear_premiumDomain_internalRegistration_isSpec domainPricingLogic.getRenewPrice( tld, "premium.example", - clock.nowUtc(), + clock.now(), 5, persistDomainAndSetRecurrence( "premium.example", SPECIFIED, Optional.of(Money.of(USD, 17))), @@ -857,14 +849,14 @@ void testGetDomainRenewPrice_negativeYear_throwsException() { IllegalArgumentException.class, () -> domainPricingLogic.getRenewPrice( - tld, "standard.example", clock.nowUtc(), -1, null, Optional.empty())); + tld, "standard.example", clock.now(), -1, null, Optional.empty())); assertThat(thrown).hasMessageThat().isEqualTo("Number of years must be positive"); } @Test void testGetDomainTransferPrice_standardDomain_default_noBilling_defaultRenewalPrice() throws EppException { - assertThat(domainPricingLogic.getTransferPrice(tld, "standard.example", clock.nowUtc(), null)) + assertThat(domainPricingLogic.getTransferPrice(tld, "standard.example", clock.now(), null)) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -875,7 +867,7 @@ void testGetDomainTransferPrice_standardDomain_default_noBilling_defaultRenewalP @Test void testGetDomainTransferPrice_premiumDomain_default_noBilling_premiumRenewalPrice() throws EppException { - assertThat(domainPricingLogic.getTransferPrice(tld, "premium.example", clock.nowUtc(), null)) + assertThat(domainPricingLogic.getTransferPrice(tld, "premium.example", clock.now(), null)) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -889,7 +881,7 @@ void testGetDomainTransferPrice_standardDomain_default_defaultRenewalPrice() thr domainPricingLogic.getTransferPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), persistDomainAndSetRecurrence("standard.example", DEFAULT, Optional.empty()))) .isEqualTo( new FeesAndCredits.Builder() @@ -904,7 +896,7 @@ void testGetDomainTransferPrice_premiumDomain_default_premiumRenewalPrice() thro domainPricingLogic.getTransferPrice( tld, "premium.example", - clock.nowUtc(), + clock.now(), persistDomainAndSetRecurrence("premium.example", DEFAULT, Optional.empty()))) .isEqualTo( new FeesAndCredits.Builder() @@ -920,7 +912,7 @@ void testGetDomainTransferPrice_standardDomain_nonPremium_nonPremiumRenewalPrice domainPricingLogic.getTransferPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), persistDomainAndSetRecurrence("standard.example", NONPREMIUM, Optional.empty()))) .isEqualTo( new FeesAndCredits.Builder() @@ -936,7 +928,7 @@ void testGetDomainTransferPrice_premiumDomain_nonPremium_nonPremiumRenewalPrice( domainPricingLogic.getTransferPrice( tld, "premium.example", - clock.nowUtc(), + clock.now(), persistDomainAndSetRecurrence("premium.example", NONPREMIUM, Optional.empty()))) .isEqualTo( new FeesAndCredits.Builder() @@ -952,7 +944,7 @@ void testGetDomainTransferPrice_standardDomain_specified_specifiedRenewalPrice() domainPricingLogic.getTransferPrice( tld, "standard.example", - clock.nowUtc(), + clock.now(), persistDomainAndSetRecurrence( "standard.example", SPECIFIED, Optional.of(Money.of(USD, 1.23))))) .isEqualTo( @@ -969,7 +961,7 @@ void testGetDomainTransferPrice_premiumDomain_specified_specifiedRenewalPrice() domainPricingLogic.getTransferPrice( tld, "premium.example", - clock.nowUtc(), + clock.now(), persistDomainAndSetRecurrence( "premium.example", SPECIFIED, Optional.of(Money.of(USD, 1.23))))) .isEqualTo( @@ -991,13 +983,7 @@ void testGetDomainCreatePrice_nonPremiumCreate_unaffectedRenewal() throws EppExc .build()); assertThat( domainPricingLogic.getCreatePrice( - tld, - "premium.example", - clock.nowUtc(), - 1, - false, - false, - Optional.of(allocationToken))) + tld, "premium.example", clock.now(), 1, false, false, Optional.of(allocationToken))) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -1006,13 +992,7 @@ void testGetDomainCreatePrice_nonPremiumCreate_unaffectedRenewal() throws EppExc // Two-year create should be 13 (standard price) + 100 (premium price), and it's premium assertThat( domainPricingLogic.getCreatePrice( - tld, - "premium.example", - clock.nowUtc(), - 2, - false, - false, - Optional.of(allocationToken))) + tld, "premium.example", clock.now(), 2, false, false, Optional.of(allocationToken))) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -1022,7 +1002,7 @@ void testGetDomainCreatePrice_nonPremiumCreate_unaffectedRenewal() throws EppExc domainPricingLogic.getRenewPrice( tld, "premium.example", - clock.nowUtc(), + clock.now(), 1, persistDomainAndSetRecurrence("premium.example", DEFAULT, Optional.empty()), Optional.of(allocationToken))) @@ -1048,13 +1028,7 @@ void testGetDomainCreatePrice_premium_multiYear_nonpremiumCreateAndRenewal() thr // are standard assertThat( domainPricingLogic.getCreatePrice( - tld, - "premium.example", - clock.nowUtc(), - 2, - false, - false, - Optional.of(allocationToken))) + tld, "premium.example", clock.now(), 2, false, false, Optional.of(allocationToken))) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -1063,13 +1037,7 @@ void testGetDomainCreatePrice_premium_multiYear_nonpremiumCreateAndRenewal() thr // Similarly, 3 years should be 13 + 10 + 10 assertThat( domainPricingLogic.getCreatePrice( - tld, - "premium.example", - clock.nowUtc(), - 3, - false, - false, - Optional.of(allocationToken))) + tld, "premium.example", clock.now(), 3, false, false, Optional.of(allocationToken))) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -1090,13 +1058,7 @@ void testGetDomainCreatePrice_premium_multiYear_onlyNonpremiumRenewal() throws E // Two-year create should be 100 (premium 1st year) plus 10 (nonpremium 2nd year) assertThat( domainPricingLogic.getCreatePrice( - tld, - "premium.example", - clock.nowUtc(), - 2, - false, - false, - Optional.of(allocationToken))) + tld, "premium.example", clock.now(), 2, false, false, Optional.of(allocationToken))) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -1105,13 +1067,7 @@ void testGetDomainCreatePrice_premium_multiYear_onlyNonpremiumRenewal() throws E // Similarly, 3 years should be 100 + 10 + 10 assertThat( domainPricingLogic.getCreatePrice( - tld, - "premium.example", - clock.nowUtc(), - 3, - false, - false, - Optional.of(allocationToken))) + tld, "premium.example", clock.now(), 3, false, false, Optional.of(allocationToken))) .isEqualTo( new FeesAndCredits.Builder() .setCurrency(USD) @@ -1133,7 +1089,7 @@ void testDomainRenewPrice_specifiedToken() throws Exception { assertThat( domainPricingLogic .getRenewPrice( - tld, "premium.example", clock.nowUtc(), 1, null, Optional.of(allocationToken)) + tld, "premium.example", clock.now(), 1, null, Optional.of(allocationToken)) .getRenewCost()) .isEqualTo(Money.of(USD, 5)); } 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 cdbb9e478fd..1d32183b40c 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainRenewFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainRenewFlowTest.java @@ -40,7 +40,13 @@ import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.TestDataHelper.updateSubstitutions; import static google.registry.util.DateTimeUtils.END_OF_TIME; +import static google.registry.util.DateTimeUtils.START_INSTANT; import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.minusDays; +import static google.registry.util.DateTimeUtils.minusYears; +import static google.registry.util.DateTimeUtils.plusDays; +import static google.registry.util.DateTimeUtils.plusYears; +import static google.registry.util.DateTimeUtils.toDateTime; import static org.joda.money.CurrencyUnit.EUR; import static org.joda.money.CurrencyUnit.JPY; import static org.joda.money.CurrencyUnit.USD; @@ -100,10 +106,10 @@ import google.registry.model.tld.Tld; import google.registry.persistence.VKey; import google.registry.testing.DatabaseHelper; +import java.time.Instant; 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.Test; @@ -128,7 +134,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase private static final ImmutableMap FEE_STD_1_0_MAP = updateSubstitutions(FEE_BASE_MAP, "FEE_VERSION", "epp:fee-1.0", "FEE_NS", "fee1_00"); - private final DateTime expirationTime = DateTime.parse("2000-04-03T22:00:00.0Z"); + private final Instant expirationTime = Instant.parse("2000-04-03T22:00:00.0Z"); @BeforeEach void initDomainTest() { @@ -157,7 +163,7 @@ private void persistDomain( new DomainHistory.Builder() .setDomain(domain) .setType(HistoryEntry.Type.DOMAIN_CREATE) - .setModificationTime(clock.nowUtc()) + .setModificationTime(clock.now()) .setRegistrarId(domain.getCreationRegistrarId()) .build(); BillingRecurrence autorenewEvent = @@ -247,8 +253,8 @@ private void doSuccessfulTest( @Nullable Money renewalPrice) throws Exception { assertMutatingFlow(true); - DateTime currentExpiration = reloadResourceByForeignKey().getRegistrationExpirationDateTime(); - DateTime newExpiration = currentExpiration.plusYears(renewalYears); + Instant currentExpiration = reloadResourceByForeignKey().getRegistrationExpirationTime(); + Instant newExpiration = plusYears(currentExpiration, renewalYears); runFlowAssertResponse( CommitMode.LIVE, userPrivileges, loadFile(responseFilename, substitutions)); Domain domain = reloadResourceByForeignKey(); @@ -256,17 +262,17 @@ private void doSuccessfulTest( DomainHistory historyEntryDomainRenew = getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RENEW, DomainHistory.class); assertThat(loadByKey(domain.getAutorenewBillingEvent()).getEventTime()) - .isEqualTo(newExpiration); + .isEqualTo(toDateTime(newExpiration)); assertAboutDomains() .that(domain) - .isActiveAt(clock.nowUtc()) + .isActiveAt(clock.now()) .and() .hasRegistrationExpirationTime(newExpiration) .and() .hasOneHistoryEntryEachOfTypes( HistoryEntry.Type.DOMAIN_CREATE, HistoryEntry.Type.DOMAIN_RENEW) .and() - .hasLastEppUpdateTime(clock.nowUtc()) + .hasLastEppUpdateTime(clock.now()) .and() .hasLastEppUpdateRegistrarId(renewalClientId); assertAboutHistoryEntries().that(historyEntryDomainRenew).hasPeriodYears(renewalYears); @@ -277,8 +283,10 @@ private void doSuccessfulTest( .setRegistrarId(renewalClientId) .setCost(totalRenewCost) .setPeriodYears(renewalYears) - .setEventTime(clock.nowUtc()) - .setBillingTime(clock.nowUtc().plus(Tld.get("tld").getRenewGracePeriodLength())) + .setEventTime(clock.now()) + .setBillingTime( + toDateTime( + clock.now().plusMillis(Tld.get("tld").getRenewGracePeriodLength().getMillis()))) .setDomainHistory(historyEntryDomainRenew) .build(); assertBillingEvents( @@ -291,7 +299,7 @@ private void doSuccessfulTest( .setTargetId(getUniqueIdFromCommand()) .setRegistrarId("TheRegistrar") .setEventTime(expirationTime) - .setRecurrenceEndTime(clock.nowUtc()) + .setRecurrenceEndTime(clock.now()) .setDomainHistory( getOnlyHistoryEntryOfType( domain, HistoryEntry.Type.DOMAIN_CREATE, DomainHistory.class)) @@ -324,7 +332,8 @@ private void doSuccessfulTest( GracePeriod.create( GracePeriodStatus.RENEW, domain.getRepoId(), - clock.nowUtc().plus(Tld.get("tld").getRenewGracePeriodLength()), + toDateTime( + clock.now().plusMillis(Tld.get("tld").getRenewGracePeriodLength().getMillis())), renewalClientId, null), renewBillingEvent)); @@ -659,11 +668,11 @@ void testFailure_promotionNotActive() throws Exception { .setToken("abc123") .setTokenType(UNLIMITED_USE) .setDiscountFraction(0.5) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().plusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(60), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(plusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 60), TokenStatus.ENDED) .build()) .build()); assertAboutEppExceptions() @@ -683,11 +692,11 @@ void testFailure_promoTokenNotValidForRegistrar() throws Exception { .setTokenType(UNLIMITED_USE) .setAllowedRegistrarIds(ImmutableSet.of("someClientId")) .setDiscountFraction(0.5) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); assertAboutEppExceptions() @@ -708,11 +717,11 @@ void testFailure_promoTokenNotValidForTld() throws Exception { .setTokenType(UNLIMITED_USE) .setAllowedTlds(ImmutableSet.of("example")) .setDiscountFraction(0.5) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); runFlowAssertResponse( @@ -795,7 +804,7 @@ void testSuccess_autorenewPollMessageIsNotDeleted() throws Exception { persistResource( loadByKey(reloadResourceByForeignKey().getAutorenewPollMessage()) .asBuilder() - .setEventTime(expirationTime.minusYears(1)) + .setEventTime(minusYears(expirationTime, 1)) .build()); runFlowAssertResponse( loadFile( @@ -807,8 +816,8 @@ void testSuccess_autorenewPollMessageIsNotDeleted() throws Exception { new PollMessage.Autorenew.Builder() .setTargetId(getUniqueIdFromCommand()) .setRegistrarId("TheRegistrar") - .setEventTime(expirationTime.minusYears(1)) - .setAutorenewEndTime(clock.nowUtc()) + .setEventTime(minusYears(expirationTime, 1)) + .setAutorenewEndTime(clock.now()) .setMsg("Domain was auto-renewed.") .setHistoryEntry( getOnlyHistoryEntryOfType( @@ -817,7 +826,7 @@ void testSuccess_autorenewPollMessageIsNotDeleted() throws Exception { new PollMessage.Autorenew.Builder() .setTargetId(getUniqueIdFromCommand()) .setRegistrarId("TheRegistrar") - .setEventTime(reloadResourceByForeignKey().getRegistrationExpirationDateTime()) + .setEventTime(reloadResourceByForeignKey().getRegistrationExpirationTime()) .setAutorenewEndTime(END_OF_TIME) .setMsg("Domain was auto-renewed.") .setHistoryEntry(historyEntryDomainRenew) @@ -910,7 +919,7 @@ void testFailure_pendingDelete() throws Exception { DatabaseHelper.newDomain(getUniqueIdFromCommand()) .asBuilder() .setRegistrationExpirationTime(expirationTime) - .setDeletionTime(clock.nowUtc().plusDays(1)) + .setDeletionTime(plusDays(clock.now(), 1)) .addStatusValue(StatusValue.PENDING_DELETE) .build()); ResourceStatusProhibitsOperationException thrown = @@ -985,7 +994,7 @@ void testFailure_pendingTransfer() throws Exception { persistWithPendingTransfer( reloadResourceByForeignKey() .asBuilder() - .setRegistrationExpirationTime(DateTime.parse("2001-09-08T22:00:00.0Z")) + .setRegistrationExpirationTime(Instant.parse("2001-09-08T22:00:00.0Z")) .build()); ResourceStatusProhibitsOperationException thrown = assertThrows(ResourceStatusProhibitsOperationException.class, this::runFlow); @@ -1015,7 +1024,7 @@ void testFailure_curExpDateMustMatch() throws Exception { persistResource( reloadResourceByForeignKey() .asBuilder() - .setRegistrationExpirationTime(DateTime.parse("2000-04-04T22:00:00.0Z")) + .setRegistrationExpirationTime(Instant.parse("2000-04-04T22:00:00.0Z")) .build()); EppException thrown = assertThrows(IncorrectCurrentExpirationDateException.class, this::runFlow); diff --git a/core/src/test/java/google/registry/flows/domain/DomainRestoreRequestFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainRestoreRequestFlowTest.java index 35eeb139945..51b4fc3d4c8 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainRestoreRequestFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainRestoreRequestFlowTest.java @@ -29,8 +29,14 @@ import static google.registry.testing.DatabaseHelper.persistResource; import static google.registry.testing.DomainSubject.assertAboutDomains; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; +import static google.registry.util.DateTimeUtils.END_INSTANT; import static google.registry.util.DateTimeUtils.END_OF_TIME; -import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.START_INSTANT; +import static google.registry.util.DateTimeUtils.minusDays; +import static google.registry.util.DateTimeUtils.plusDays; +import static google.registry.util.DateTimeUtils.plusMonths; +import static google.registry.util.DateTimeUtils.plusYears; +import static google.registry.util.DateTimeUtils.toDateTime; import static org.joda.money.CurrencyUnit.EUR; import static org.joda.money.CurrencyUnit.JPY; import static org.joda.money.CurrencyUnit.USD; @@ -76,10 +82,11 @@ import google.registry.model.tld.Tld; import google.registry.persistence.VKey; import google.registry.testing.DatabaseHelper; +import java.time.Duration; +import java.time.Instant; import java.util.Map; import java.util.Optional; import org.joda.money.Money; -import org.joda.time.DateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -108,16 +115,16 @@ void initDomainTest() { Domain persistPendingDeleteDomain() throws Exception { // The domain is now past what had been its expiration date at the time of deletion. - return persistPendingDeleteDomain(clock.nowUtc().minusDays(5)); + return persistPendingDeleteDomain(minusDays(clock.now(), 5)); } - Domain persistPendingDeleteDomain(DateTime expirationTime) throws Exception { + Domain persistPendingDeleteDomain(Instant expirationTime) throws Exception { Domain domain = persistResource(DatabaseHelper.newDomain(getUniqueIdFromCommand())); HistoryEntry historyEntry = persistResource( new DomainHistory.Builder() .setType(HistoryEntry.Type.DOMAIN_DELETE) - .setModificationTime(clock.nowUtc()) + .setModificationTime(clock.now()) .setRegistrarId(domain.getCurrentSponsorRegistrarId()) .setDomain(domain) .build()); @@ -126,12 +133,12 @@ Domain persistPendingDeleteDomain(DateTime expirationTime) throws Exception { domain .asBuilder() .setRegistrationExpirationTime(expirationTime) - .setDeletionTime(clock.nowUtc().plusDays(35)) + .setDeletionTime(plusDays(clock.now(), 35)) .addGracePeriod( GracePeriod.create( GracePeriodStatus.REDEMPTION, domain.getRepoId(), - clock.nowUtc().plusDays(1), + plusDays(clock.now(), 1), "TheRegistrar", null)) .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) @@ -139,7 +146,7 @@ Domain persistPendingDeleteDomain(DateTime expirationTime) throws Exception { persistResource( new PollMessage.OneTime.Builder() .setRegistrarId("TheRegistrar") - .setEventTime(clock.nowUtc().plusDays(5)) + .setEventTime(plusDays(clock.now(), 5)) .setHistoryEntry(historyEntry) .build()) .createVKey()) @@ -165,7 +172,7 @@ void testDryRun() throws Exception { @Test void testSuccess_expiryStillInFuture_notExtended() throws Exception { setEppInput("domain_update_restore_request.xml", ImmutableMap.of("DOMAIN", "example.tld")); - DateTime expirationTime = clock.nowUtc().plusYears(5).plusDays(45); + Instant expirationTime = plusYears(clock.now(), 5).plus(Duration.ofDays(45)); persistPendingDeleteDomain(expirationTime); assertMutatingFlow(true); // Double check that we see a poll message in the future for when the delete happens. @@ -176,7 +183,7 @@ void testSuccess_expiryStillInFuture_notExtended() throws Exception { getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RESTORE, DomainHistory.class); assertLastHistoryContainsResource(domain); assertThat(loadByKey(domain.getAutorenewBillingEvent()).getEventTime()) - .isEqualTo(expirationTime); + .isEqualTo(toDateTime(expirationTime)); assertAboutDomains() .that(domain) // New expiration time should be the same as from before the deletion. @@ -184,12 +191,12 @@ void testSuccess_expiryStillInFuture_notExtended() throws Exception { .and() .doesNotHaveStatusValue(StatusValue.PENDING_DELETE) .and() - .hasDeletionTime(END_OF_TIME) + .hasDeletionTime(END_INSTANT) .and() .hasOneHistoryEntryEachOfTypes( HistoryEntry.Type.DOMAIN_DELETE, HistoryEntry.Type.DOMAIN_RESTORE) .and() - .hasLastEppUpdateTime(clock.nowUtc()) + .hasLastEppUpdateTime(clock.now()) .and() .hasLastEppUpdateRegistrarId("TheRegistrar"); assertThat(domain.getGracePeriods()).isEmpty(); @@ -214,7 +221,7 @@ void testSuccess_expiryStillInFuture_notExtended() throws Exception { .setTargetId("example.tld") .setRegistrarId("TheRegistrar") .setEventTime(expirationTime) - .setRecurrenceEndTime(END_OF_TIME) + .setRecurrenceEndTime(END_INSTANT) .setDomainHistory(historyEntryDomainRestore) .build(), new BillingEvent.Builder() @@ -223,8 +230,8 @@ void testSuccess_expiryStillInFuture_notExtended() throws Exception { .setRegistrarId("TheRegistrar") .setCost(Money.of(USD, 17)) .setPeriodYears(1) - .setEventTime(clock.nowUtc()) - .setBillingTime(clock.nowUtc()) + .setEventTime(clock.now()) + .setBillingTime(clock.now()) .setDomainHistory(historyEntryDomainRestore) .build()); } @@ -232,8 +239,8 @@ void testSuccess_expiryStillInFuture_notExtended() throws Exception { @Test void testSuccess_expiryInPast_extendedByOneYear() throws Exception { setEppInput("domain_update_restore_request.xml", ImmutableMap.of("DOMAIN", "example.tld")); - DateTime expirationTime = clock.nowUtc().minusDays(20); - DateTime newExpirationTime = expirationTime.plusYears(1); + Instant expirationTime = minusDays(clock.now(), 20); + Instant newExpirationTime = plusYears(expirationTime, 1); persistPendingDeleteDomain(expirationTime); assertMutatingFlow(true); // Double check that we see a poll message in the future for when the delete happens. @@ -244,7 +251,7 @@ void testSuccess_expiryInPast_extendedByOneYear() throws Exception { getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RESTORE, DomainHistory.class); assertLastHistoryContainsResource(domain); assertThat(loadByKey(domain.getAutorenewBillingEvent()).getEventTime()) - .isEqualTo(newExpirationTime); + .isEqualTo(toDateTime(newExpirationTime)); assertAboutDomains() .that(domain) // New expiration time should be exactly a year from now. @@ -252,12 +259,12 @@ void testSuccess_expiryInPast_extendedByOneYear() throws Exception { .and() .doesNotHaveStatusValue(StatusValue.PENDING_DELETE) .and() - .hasDeletionTime(END_OF_TIME) + .hasDeletionTime(END_INSTANT) .and() .hasOneHistoryEntryEachOfTypes( HistoryEntry.Type.DOMAIN_DELETE, HistoryEntry.Type.DOMAIN_RESTORE) .and() - .hasLastEppUpdateTime(clock.nowUtc()) + .hasLastEppUpdateTime(clock.now()) .and() .hasLastEppUpdateRegistrarId("TheRegistrar"); assertThat(domain.getGracePeriods()).isEmpty(); @@ -283,7 +290,7 @@ void testSuccess_expiryInPast_extendedByOneYear() throws Exception { .setTargetId("example.tld") .setRegistrarId("TheRegistrar") .setEventTime(newExpirationTime) - .setRecurrenceEndTime(END_OF_TIME) + .setRecurrenceEndTime(END_INSTANT) .setDomainHistory(historyEntryDomainRestore) .build(), new BillingEvent.Builder() @@ -292,8 +299,8 @@ void testSuccess_expiryInPast_extendedByOneYear() throws Exception { .setRegistrarId("TheRegistrar") .setCost(Money.of(USD, 17)) .setPeriodYears(1) - .setEventTime(clock.nowUtc()) - .setBillingTime(clock.nowUtc()) + .setEventTime(clock.now()) + .setBillingTime(clock.now()) .setDomainHistory(historyEntryDomainRestore) .build(), new BillingEvent.Builder() @@ -302,8 +309,8 @@ void testSuccess_expiryInPast_extendedByOneYear() throws Exception { .setRegistrarId("TheRegistrar") .setCost(Money.of(USD, 11)) .setPeriodYears(1) - .setEventTime(clock.nowUtc()) - .setBillingTime(clock.nowUtc()) + .setEventTime(clock.now()) + .setBillingTime(clock.now()) .setDomainHistory(historyEntryDomainRestore) .build()); } @@ -315,7 +322,7 @@ void testSuccess_autorenewEndTimeIsCleared() throws Exception { persistResource( reloadResourceByForeignKey() .asBuilder() - .setAutorenewEndTime(Optional.of(clock.nowUtc().plusYears(2))) + .setAutorenewEndTimeInstant(Optional.of(plusYears(clock.now(), 2))) .build()); assertThat(reloadResourceByForeignKey().getAutorenewEndTime()).isPresent(); runFlowAssertResponse( @@ -386,7 +393,7 @@ void testSuccess_premiumNotBlocked() throws Exception { void testSuccess_premiumNotBlocked_andNoRenewal_std_v1() throws Exception { createTld("example"); setEppInput("domain_update_restore_request_premium_no_renewal.xml", FEE_STD_1_0_MAP); - persistPendingDeleteDomain(clock.nowUtc().plusYears(2)); + persistPendingDeleteDomain(plusYears(clock.now(), 2)); runFlowAssertResponse( loadFile("domain_update_restore_request_response_fee_no_renewal.xml", FEE_STD_1_0_MAP)); } @@ -475,11 +482,12 @@ private void runWrongCurrencyTest(Map substitutions) throws Exce Tld.get("tld") .asBuilder() .setCurrency(EUR) - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 13))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(EUR, 13))) .setRestoreBillingCost(Money.of(EUR, 11)) - .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7))) - .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) + .setRenewBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.of(EUR, 7))) + .setEapFeeScheduleInstant(ImmutableSortedMap.of(START_INSTANT, Money.zero(EUR))) .setServerStatusChangeBillingCost(Money.of(EUR, 19)) .setRegistryLockOrUnlockBillingCost(Money.of(EUR, 0)) .build()); @@ -505,7 +513,7 @@ void testFailure_notInRedemptionPeriod() throws Exception { persistResource( DatabaseHelper.newDomain(getUniqueIdFromCommand()) .asBuilder() - .setDeletionTime(clock.nowUtc().plusDays(4)) + .setDeletionTime(plusDays(clock.now(), 4)) .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) .build()); EppException thrown = assertThrows(DomainNotEligibleForRestoreException.class, this::runFlow); @@ -593,11 +601,11 @@ void testFailure_missingBillingAccount() throws Exception { Tld.get("tld") .asBuilder() .setCurrency(JPY) - .setCreateBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) - .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) - .setRenewBillingCostTransitions( - ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 800))) + .setCreateBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) + .setEapFeeScheduleInstant(ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) + .setRenewBillingCostTransitionsInstant( + ImmutableSortedMap.of(START_INSTANT, Money.ofMajor(JPY, 800))) .setRegistryLockOrUnlockBillingCost(Money.ofMajor(JPY, 800)) .setServerStatusChangeBillingCost(Money.ofMajor(JPY, 800)) .setRestoreBillingCost(Money.ofMajor(JPY, 800)) @@ -790,7 +798,7 @@ void testSuccess_fee_v06() throws Exception { @Test void testSuccess_fee_v06_noRenewal() throws Exception { setEppInput("domain_update_restore_request_fee_no_renewal.xml", FEE_06_MAP); - persistPendingDeleteDomain(clock.nowUtc().plusMonths(6)); + persistPendingDeleteDomain(plusMonths(clock.now(), 6)); runFlowAssertResponse( loadFile("domain_update_restore_request_response_fee_no_renewal.xml", FEE_06_MAP)); } @@ -887,7 +895,7 @@ void testFailure_premiumBlocked_v12() throws Exception { void testSuccess_premiumNotBlocked_andNoRenewal_v12() throws Exception { createTld("example"); setEppInput("domain_update_restore_request_premium_no_renewal.xml", FEE_12_MAP); - persistPendingDeleteDomain(clock.nowUtc().plusYears(2)); + persistPendingDeleteDomain(plusYears(clock.now(), 2)); runFlowAssertResponse( loadFile("domain_update_restore_request_response_fee_no_renewal.xml", FEE_12_MAP)); } diff --git a/core/src/test/java/google/registry/flows/domain/DomainTransferApproveFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainTransferApproveFlowTest.java index f8a92a82b61..fad8b64342b 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainTransferApproveFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainTransferApproveFlowTest.java @@ -38,7 +38,12 @@ import static google.registry.testing.DomainSubject.assertAboutDomains; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; -import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.START_INSTANT; +import static google.registry.util.DateTimeUtils.minusDays; +import static google.registry.util.DateTimeUtils.minusYears; +import static google.registry.util.DateTimeUtils.plusDays; +import static google.registry.util.DateTimeUtils.plusYears; +import static google.registry.util.DateTimeUtils.toDateTime; import static org.joda.money.CurrencyUnit.USD; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -92,10 +97,10 @@ import google.registry.persistence.VKey; import google.registry.testing.DatabaseHelper; import java.math.BigDecimal; +import java.time.Instant; import java.util.Arrays; import java.util.stream.Stream; 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.Test; @@ -116,10 +121,10 @@ void beforeEach() { persistResource( Tld.get("tld") .asBuilder() - .setRenewBillingCostTransitions( - new ImmutableSortedMap.Builder(Ordering.natural()) - .put(START_OF_TIME, Money.of(USD, 1)) - .put(clock.nowUtc().minusDays(1).plusMillis(1), Money.of(USD, 22)) + .setRenewBillingCostTransitionsInstant( + new ImmutableSortedMap.Builder(Ordering.natural()) + .put(START_INSTANT, Money.of(USD, 1)) + .put(minusDays(clock.now(), 1).plusMillis(1), Money.of(USD, 22)) .put(TRANSFER_REQUEST_TIME.plusMillis(1), Money.of(USD, 333)) .build()) .build()); @@ -134,11 +139,11 @@ private void assertTransferApproved(Domain domain, DomainTransferData oldTransfe .that(domain) .hasCurrentSponsorRegistrarId("NewRegistrar") .and() - .hasLastTransferTime(clock.nowUtc()) + .hasLastTransferTime(clock.now()) .and() .doesNotHaveStatusValue(StatusValue.PENDING_TRANSFER) .and() - .hasLastEppUpdateTime(clock.nowUtc()) + .hasLastEppUpdateTime(clock.now()) .and() .hasLastEppUpdateRegistrarId("TheRegistrar"); // The domain TransferData should reflect the approved transfer as we expect, with @@ -148,9 +153,8 @@ private void assertTransferApproved(Domain domain, DomainTransferData oldTransfe oldTransferData .copyConstantFieldsToBuilder() .setTransferStatus(TransferStatus.CLIENT_APPROVED) - .setPendingTransferExpirationTime(clock.nowUtc()) - .setTransferredRegistrationExpirationTime( - domain.getRegistrationExpirationDateTime()) + .setPendingTransferExpirationTime(clock.now()) + .setTransferredRegistrationExpirationTime(domain.getRegistrationExpirationTime()) .build()); } @@ -163,7 +167,7 @@ private void doSuccessfulTest( String tld, String commandFilename, String expectedXmlFilename, - DateTime expectedExpirationTime, + Instant expectedExpirationTime, int expectedYearsToCharge, BillingCancellation.Builder... expectedCancellationBillingEvents) throws Exception { @@ -177,7 +181,7 @@ private void runSuccessfulFlowWithAssertions( String tld, String commandFilename, String expectedXmlFilename, - DateTime expectedExpirationTime) + Instant expectedExpirationTime) throws Exception { setEppInput(commandFilename); Tld registry = Tld.get(tld); @@ -210,7 +214,7 @@ private void runSuccessfulFlowWithAssertions( assertTransferApproved(domain, originalTransferData); assertAboutDomains().that(domain).hasRegistrationExpirationTime(expectedExpirationTime); assertThat(loadByKey(domain.getAutorenewBillingEvent()).getEventTime()) - .isEqualTo(expectedExpirationTime); + .isEqualTo(toDateTime(expectedExpirationTime)); // The poll message (in the future) to the losing registrar for implicit ack should be gone. assertThat(getPollMessages(domain, "TheRegistrar", clock.nowUtc().plusMonths(1))).isEmpty(); @@ -218,7 +222,9 @@ private void runSuccessfulFlowWithAssertions( // should be one at the current time to the gaining registrar, as well as one at the domain's // autorenew time. assertThat(getPollMessages(domain, "NewRegistrar", clock.nowUtc().plusMonths(1))).hasSize(1); - assertThat(getPollMessages(domain, "NewRegistrar", domain.getRegistrationExpirationDateTime())) + assertThat( + getPollMessages( + domain, "NewRegistrar", toDateTime(domain.getRegistrationExpirationTime()))) .hasSize(2); PollMessage gainingTransferPollMessage = @@ -227,11 +233,11 @@ private void runSuccessfulFlowWithAssertions( getOnlyPollMessage( domain, "NewRegistrar", - domain.getRegistrationExpirationDateTime(), + toDateTime(domain.getRegistrationExpirationTime()), PollMessage.Autorenew.class); assertThat(gainingTransferPollMessage.getEventTime()).isEqualTo(clock.nowUtc()); assertThat(gainingAutorenewPollMessage.getEventTime()) - .isEqualTo(domain.getRegistrationExpirationDateTime()); + .isEqualTo(toDateTime(domain.getRegistrationExpirationTime())); DomainTransferResponse transferResponse = gainingTransferPollMessage .getResponseData() @@ -256,7 +262,8 @@ private void runSuccessfulFlowWithAssertions( // After the expected grace time, the grace period should be gone. assertThat( domain - .cloneProjectedAtTime(clock.nowUtc().plus(registry.getTransferGracePeriodLength())) + .cloneProjectedAtInstant( + clock.now().plusMillis(registry.getTransferGracePeriodLength().getMillis())) .getGracePeriods()) .isEmpty(); } @@ -276,8 +283,10 @@ private void assertHistoryEntriesContainBillingEventsAndGracePeriods( new BillingEvent.Builder() .setReason(Reason.TRANSFER) .setTargetId(domain.getDomainName()) - .setEventTime(clock.nowUtc()) - .setBillingTime(clock.nowUtc().plus(registry.getTransferGracePeriodLength())) + .setEventTime(clock.now()) + .setBillingTime( + toDateTime( + clock.now().plusMillis(registry.getTransferGracePeriodLength().getMillis()))) .setRegistrarId("NewRegistrar") .setCost(Money.of(USD, 11).multipliedBy(expectedYearsToCharge)) .setPeriodYears(expectedYearsToCharge) @@ -292,13 +301,13 @@ private void assertHistoryEntriesContainBillingEventsAndGracePeriods( transferBillingEvent, getLosingClientAutorenewEvent() .asBuilder() - .setRecurrenceEndTime(clock.nowUtc()) + .setRecurrenceEndTime(clock.now()) .build(), getGainingClientAutorenewEvent() .asBuilder() - .setEventTime(domain.getRegistrationExpirationDateTime()) + .setEventTime(domain.getRegistrationExpirationTime()) .setRecurrenceLastExpansion( - domain.getRegistrationExpirationDateTime().minusYears(1)) + minusYears(domain.getRegistrationExpirationTime(), 1)) .setDomainHistory(historyEntryTransferApproved) .build())) .toArray(BillingBase[]::new)); @@ -309,7 +318,8 @@ private void assertHistoryEntriesContainBillingEventsAndGracePeriods( GracePeriod.create( GracePeriodStatus.TRANSFER, domain.getRepoId(), - clock.nowUtc().plus(registry.getTransferGracePeriodLength()), + toDateTime( + clock.now().plusMillis(registry.getTransferGracePeriodLength().getMillis())), "NewRegistrar", null), transferBillingEvent)); @@ -330,13 +340,13 @@ private void assertHistoryEntriesDoNotContainTransferBillingEventsOrGracePeriods Stream.of( getLosingClientAutorenewEvent() .asBuilder() - .setRecurrenceEndTime(clock.nowUtc()) + .setRecurrenceEndTime(clock.now()) .build(), getGainingClientAutorenewEvent() .asBuilder() - .setEventTime(domain.getRegistrationExpirationDateTime()) + .setEventTime(domain.getRegistrationExpirationTime()) .setRecurrenceLastExpansion( - domain.getRegistrationExpirationDateTime().minusYears(1)) + minusYears(domain.getRegistrationExpirationTime(), 1)) .setDomainHistory(historyEntryTransferApproved) .build())) .toArray(BillingBase[]::new)); @@ -351,7 +361,7 @@ private void doSuccessfulTest(String tld, String commandFilename, String expecte tld, commandFilename, expectedXmlFilename, - domain.getRegistrationExpirationDateTime().plusYears(1), + plusYears(domain.getRegistrationExpirationTime(), 1), 1); } @@ -429,7 +439,7 @@ void testSuccess_removesBulkToken() throws Exception { persistResource(domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build()); clock.advanceOneMilli(); setEppInput("domain_transfer_approve_wildcard.xml", ImmutableMap.of("DOMAIN", "example.tld")); - DateTime now = clock.nowUtc(); + Instant now = clock.now(); runFlowAssertResponse(loadFile("domain_transfer_approve_response.xml")); domain = reloadResourceByForeignKey(); DomainHistory acceptHistory = @@ -437,7 +447,7 @@ void testSuccess_removesBulkToken() throws Exception { assertBillingEventsForResource( domain, new BillingEvent.Builder() - .setBillingTime(now.plusDays(5)) + .setBillingTime(plusDays(now, 5)) .setEventTime(now) .setRegistrarId("NewRegistrar") .setCost(Money.of(USD, new BigDecimal("11.00"))) @@ -490,7 +500,7 @@ void testSuccess_domainAuthInfo() throws Exception { @Test void testSuccess_autorenewBeforeTransfer() throws Exception { domain = reloadResourceByForeignKey(); - DateTime oldExpirationTime = clock.nowUtc().minusDays(1); + Instant oldExpirationTime = minusDays(clock.now(), 1); persistResource(domain.asBuilder().setRegistrationExpirationTime(oldExpirationTime).build()); // The autorenew should be subsumed into the transfer resulting in 1 year of renewal in total. clock.advanceOneMilli(); @@ -498,15 +508,18 @@ void testSuccess_autorenewBeforeTransfer() throws Exception { "tld", "domain_transfer_approve_domain_authinfo.xml", "domain_transfer_approve_response_autorenew.xml", - oldExpirationTime.plusYears(1), + plusYears(oldExpirationTime, 1), 1, // Expect the grace period for autorenew to be cancelled. new BillingCancellation.Builder() .setReason(Reason.RENEW) .setTargetId("example.tld") .setRegistrarId("TheRegistrar") - .setEventTime(clock.nowUtc()) // The cancellation happens at the moment of transfer. - .setBillingTime(oldExpirationTime.plus(Tld.get("tld").getAutoRenewGracePeriodLength())) + .setEventTime(clock.now()) // The cancellation happens at the moment of transfer. + .setBillingTime( + toDateTime( + oldExpirationTime.plusMillis( + Tld.get("tld").getAutoRenewGracePeriodLength().getMillis()))) .setBillingRecurrence(domain.getAutorenewBillingEvent())); } @@ -529,7 +542,7 @@ void testSuccess_nonpremiumPriceRenewalBehavior_carriesOver() throws Exception { .setRenewalPriceBehavior(RenewalPriceBehavior.NONPREMIUM) .build()); setEppInput("domain_transfer_approve_wildcard.xml", ImmutableMap.of("DOMAIN", "example.tld")); - DateTime now = clock.nowUtc(); + Instant now = clock.now(); runFlowAssertResponse(loadFile("domain_transfer_approve_response.xml")); domain = reloadResourceByForeignKey(); DomainHistory acceptHistory = @@ -537,7 +550,7 @@ void testSuccess_nonpremiumPriceRenewalBehavior_carriesOver() throws Exception { assertBillingEventsForResource( domain, new BillingEvent.Builder() - .setBillingTime(now.plusDays(5)) + .setBillingTime(plusDays(now, 5)) .setEventTime(now) .setRegistrarId("NewRegistrar") .setCost(Money.of(USD, new BigDecimal("11.00"))) @@ -578,7 +591,7 @@ void testSuccess_specifiedPriceRenewalBehavior_carriesOver() throws Exception { .setRenewalPrice(Money.of(USD, new BigDecimal("43.10"))) .build()); setEppInput("domain_transfer_approve_wildcard.xml", ImmutableMap.of("DOMAIN", "example.tld")); - DateTime now = clock.nowUtc(); + Instant now = clock.now(); runFlowAssertResponse(loadFile("domain_transfer_approve_response.xml")); domain = reloadResourceByForeignKey(); DomainHistory acceptHistory = @@ -586,7 +599,7 @@ void testSuccess_specifiedPriceRenewalBehavior_carriesOver() throws Exception { assertBillingEventsForResource( domain, new BillingEvent.Builder() - .setBillingTime(now.plusDays(5)) + .setBillingTime(plusDays(now, 5)) .setEventTime(now) .setRegistrarId("NewRegistrar") .setCost(Money.of(USD, new BigDecimal("43.10"))) @@ -708,7 +721,7 @@ void testFailure_unrelatedClient() { @Test void testFailure_deletedDomain() throws Exception { - persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); + persistResource(domain.asBuilder().setDeletionTime(minusDays(clock.now(), 1)).build()); ResourceDoesNotExistException thrown = assertThrows( ResourceDoesNotExistException.class, @@ -779,7 +792,7 @@ void testIcannTransactionRecord_noRecordsToCancel() throws Exception { assertThat(persistedEntry.getDomainTransactionRecords()) .containsExactly( DomainTransactionRecord.create( - "tld", clock.nowUtc().plusDays(3), TRANSFER_SUCCESSFUL, 1)); + "tld", plusDays(clock.now(), 3), TRANSFER_SUCCESSFUL, 1)); } @Test @@ -787,15 +800,15 @@ void testIcannTransactionRecord_cancelsPreviousRecords() throws Exception { clock.advanceOneMilli(); setUpGracePeriodDurations(); DomainTransactionRecord previousSuccessRecord = - DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), TRANSFER_SUCCESSFUL, 1); + DomainTransactionRecord.create("tld", plusDays(clock.now(), 1), TRANSFER_SUCCESSFUL, 1); // We only want to cancel TRANSFER_SUCCESSFUL records DomainTransactionRecord notCancellableRecord = - DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), NET_ADDS_4_YR, 5); + DomainTransactionRecord.create("tld", plusDays(clock.now(), 1), NET_ADDS_4_YR, 5); persistResource( new DomainHistory.Builder() .setType(DOMAIN_TRANSFER_REQUEST) .setDomain(domain) - .setModificationTime(clock.nowUtc().minusDays(4)) + .setModificationTime(minusDays(clock.now(), 4)) .setRegistrarId("TheRegistrar") .setDomainTransactionRecords( ImmutableSet.of(previousSuccessRecord, notCancellableRecord)) @@ -809,7 +822,7 @@ void testIcannTransactionRecord_cancelsPreviousRecords() throws Exception { .containsExactly( previousSuccessRecord.asBuilder().setReportAmount(-1).build(), DomainTransactionRecord.create( - "tld", clock.nowUtc().plusDays(3), TRANSFER_SUCCESSFUL, 1)); + "tld", plusDays(clock.now(), 3), TRANSFER_SUCCESSFUL, 1)); } @Test @@ -827,7 +840,7 @@ void testSuccess_superuserExtension_transferPeriodZero() throws Exception { "tld", "domain_transfer_approve.xml", "domain_transfer_approve_response_zero_period.xml", - domain.getRegistrationExpirationDateTime()); + domain.getRegistrationExpirationTime()); assertHistoryEntriesDoNotContainTransferBillingEventsOrGracePeriods(); } @@ -837,8 +850,8 @@ void testSuccess_superuserExtension_transferPeriodZero_autorenewGraceActive() th VKey existingAutorenewEvent = domain.getAutorenewBillingEvent(); // Set domain to have auto-renewed just before the transfer request, so that it will have an // active autorenew grace period spanning the entire transfer window. - DateTime autorenewTime = clock.nowUtc().minusDays(1); - DateTime expirationTime = autorenewTime.plusYears(1); + Instant autorenewTime = minusDays(clock.now(), 1); + Instant expirationTime = plusYears(autorenewTime, 1); DomainTransferData.Builder transferDataBuilder = domain.getTransferData().asBuilder(); domain = persistResource( @@ -851,7 +864,8 @@ void testSuccess_superuserExtension_transferPeriodZero_autorenewGraceActive() th GracePeriod.createForRecurrence( GracePeriodStatus.AUTO_RENEW, domain.getRepoId(), - autorenewTime.plus(Tld.get("tld").getAutoRenewGracePeriodLength()), + autorenewTime.plusMillis( + Tld.get("tld").getAutoRenewGracePeriodLength().getMillis()), "TheRegistrar", existingAutorenewEvent)) .build()); @@ -860,7 +874,7 @@ void testSuccess_superuserExtension_transferPeriodZero_autorenewGraceActive() th "tld", "domain_transfer_approve.xml", "domain_transfer_approve_response_zero_period_autorenew_grace.xml", - domain.getRegistrationExpirationDateTime()); + domain.getRegistrationExpirationTime()); assertHistoryEntriesDoNotContainTransferBillingEventsOrGracePeriods(); } @@ -909,11 +923,11 @@ void testFailure_allocationTokenNotActive() throws Exception { .setToken("abc123") .setTokenType(UNLIMITED_USE) .setDiscountFraction(0.5) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().plusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(60), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(plusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 60), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_transfer_approve_allocation_token.xml"); @@ -929,11 +943,11 @@ void testFailure_allocationTokenNotValidForRegistrar() throws Exception { .setTokenType(UNLIMITED_USE) .setAllowedRegistrarIds(ImmutableSet.of("someClientId")) .setDiscountFraction(0.5) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_transfer_approve_allocation_token.xml"); @@ -950,11 +964,11 @@ void testFailure_allocationTokenNotValidForTld() throws Exception { .setTokenType(UNLIMITED_USE) .setAllowedTlds(ImmutableSet.of("example")) .setDiscountFraction(0.5) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_transfer_approve_allocation_token.xml"); diff --git a/core/src/test/java/google/registry/flows/domain/DomainTransferCancelFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainTransferCancelFlowTest.java index ea5ff9e16c3..95aed1e8041 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainTransferCancelFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainTransferCancelFlowTest.java @@ -32,6 +32,8 @@ import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.util.DateTimeUtils.END_OF_TIME; +import static google.registry.util.DateTimeUtils.minusDays; +import static google.registry.util.DateTimeUtils.plusDays; import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.common.collect.ImmutableList; @@ -55,7 +57,7 @@ import google.registry.model.transfer.DomainTransferData; import google.registry.model.transfer.TransferResponse.DomainTransferResponse; import google.registry.model.transfer.TransferStatus; -import org.joda.time.DateTime; +import java.time.Instant; import org.joda.time.Duration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -114,7 +116,7 @@ private void doSuccessfulTest(String commandFilename) throws Exception { // Setup done; run the test. assertMutatingFlow(true); - DateTime originalExpirationTime = domain.getRegistrationExpirationDateTime(); + Instant originalExpirationTime = domain.getRegistrationExpirationTime(); ImmutableSet originalGracePeriods = domain.getGracePeriods(); DomainTransferData originalTransferData = domain.getTransferData(); runFlowAssertResponse(loadFile("domain_transfer_cancel_response.xml")); @@ -127,13 +129,13 @@ private void doSuccessfulTest(String commandFilename) throws Exception { .that(domain) .hasRegistrationExpirationTime(originalExpirationTime) .and() - .hasLastTransferTimeNotEqualTo(clock.nowUtc()); + .hasLastTransferTimeNotEqualTo(clock.now()); assertAboutDomains() .that(domain) .hasOneHistoryEntryEachOfTypes( DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST, DOMAIN_TRANSFER_CANCEL) .and() - .hasLastEppUpdateTime(clock.nowUtc()) + .hasLastEppUpdateTime(clock.now()) .and() .hasLastEppUpdateRegistrarId("NewRegistrar"); final HistoryEntry historyEntryTransferCancel = @@ -163,7 +165,7 @@ private void doSuccessfulTest(String commandFilename) throws Exception { .build(), new PollMessage.OneTime.Builder() .setRegistrarId("TheRegistrar") - .setEventTime(clock.nowUtc()) + .setEventTime(clock.now()) .setResponseData( ImmutableList.of( new DomainTransferResponse.Builder() @@ -172,7 +174,7 @@ private void doSuccessfulTest(String commandFilename) throws Exception { .setTransferRequestTime(TRANSFER_REQUEST_TIME) .setGainingRegistrarId("NewRegistrar") .setLosingRegistrarId("TheRegistrar") - .setPendingTransferExpirationTime(clock.nowUtc()) + .setPendingTransferExpirationTime(clock.now()) .build())) .setMsg("Transfer cancelled.") .setHistoryEntry(getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_CANCEL)) @@ -312,8 +314,7 @@ void testFailure_unrelatedClient() { @Test void testFailure_deletedDomain() throws Exception { - domain = - persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); + domain = persistResource(domain.asBuilder().setDeletionTime(minusDays(clock.now(), 1)).build()); ResourceDoesNotExistException thrown = assertThrows( ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_cancel.xml")); @@ -380,15 +381,15 @@ void testIcannTransactionRecord_cancelsPreviousRecords() throws Exception { .setTransferGracePeriodLength(Duration.standardDays(3)) .build()); DomainTransactionRecord previousSuccessRecord = - DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), TRANSFER_SUCCESSFUL, 1); + DomainTransactionRecord.create("tld", plusDays(clock.now(), 1), TRANSFER_SUCCESSFUL, 1); // We only want to cancel TRANSFER_SUCCESSFUL records DomainTransactionRecord notCancellableRecord = - DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), RESTORED_DOMAINS, 5); + DomainTransactionRecord.create("tld", plusDays(clock.now(), 1), RESTORED_DOMAINS, 5); persistResource( new DomainHistory.Builder() .setType(DOMAIN_TRANSFER_REQUEST) .setDomain(domain) - .setModificationTime(clock.nowUtc().minusDays(4)) + .setModificationTime(minusDays(clock.now(), 4)) .setRegistrarId("TheRegistrar") .setDomainTransactionRecords( ImmutableSet.of(previousSuccessRecord, notCancellableRecord)) diff --git a/core/src/test/java/google/registry/flows/domain/DomainTransferFlowTestCase.java b/core/src/test/java/google/registry/flows/domain/DomainTransferFlowTestCase.java index 29a0f234a24..597841a34c8 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainTransferFlowTestCase.java +++ b/core/src/test/java/google/registry/flows/domain/DomainTransferFlowTestCase.java @@ -11,7 +11,6 @@ // 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.flows.domain; import static com.google.common.base.Preconditions.checkState; @@ -25,6 +24,7 @@ import static google.registry.testing.DatabaseHelper.persistResource; import static google.registry.testing.DomainSubject.assertAboutDomains; import static google.registry.util.DateTimeUtils.END_OF_TIME; +import static google.registry.util.DateTimeUtils.plusYears; import com.google.common.base.Ascii; import com.google.common.collect.ImmutableSet; @@ -44,7 +44,7 @@ import google.registry.model.transfer.DomainTransferData; import google.registry.model.transfer.TransferStatus; import google.registry.persistence.transaction.JpaTransactionManagerExtension; -import org.joda.time.DateTime; +import java.time.Instant; import org.joda.time.Duration; import org.junit.jupiter.api.BeforeEach; @@ -60,15 +60,15 @@ abstract class DomainTransferFlowTestCase // Transfer is requested on the 6th and expires on the 11th. // The "now" of this flow is on the 9th, 3 days in. - static final DateTime TRANSFER_REQUEST_TIME = DateTime.parse("2000-06-06T22:00:00.0Z"); - static final DateTime TRANSFER_EXPIRATION_TIME = - TRANSFER_REQUEST_TIME.plus(Tld.DEFAULT_AUTOMATIC_TRANSFER_LENGTH); + static final Instant TRANSFER_REQUEST_TIME = Instant.parse("2000-06-06T22:00:00.0Z"); + static final Instant TRANSFER_EXPIRATION_TIME = + TRANSFER_REQUEST_TIME.plusMillis(Tld.DEFAULT_AUTOMATIC_TRANSFER_LENGTH.getMillis()); private static final Duration TIME_SINCE_REQUEST = Duration.standardDays(3); private static final int EXTENDED_REGISTRATION_YEARS = 1; - private static final DateTime REGISTRATION_EXPIRATION_TIME = - DateTime.parse("2001-09-08T22:00:00.0Z"); - static final DateTime EXTENDED_REGISTRATION_EXPIRATION_TIME = - REGISTRATION_EXPIRATION_TIME.plusYears(EXTENDED_REGISTRATION_YEARS); + private static final Instant REGISTRATION_EXPIRATION_TIME = + Instant.parse("2001-09-08T22:00:00.0Z"); + static final Instant EXTENDED_REGISTRATION_EXPIRATION_TIME = + plusYears(REGISTRATION_EXPIRATION_TIME, EXTENDED_REGISTRATION_YEARS); protected Domain domain; Host subordinateHost; @@ -76,7 +76,7 @@ abstract class DomainTransferFlowTestCase DomainTransferFlowTestCase() { checkState(!Tld.DEFAULT_TRANSFER_GRACE_PERIOD.isShorterThan(TIME_SINCE_REQUEST)); - clock.setTo(TRANSFER_REQUEST_TIME.plus(TIME_SINCE_REQUEST)); + clock.setTo(TRANSFER_REQUEST_TIME.plusMillis(TIME_SINCE_REQUEST.getMillis())); } @BeforeEach @@ -105,8 +105,8 @@ void setupDomain(String label, String tld) { persistDomainWithDependentResources( label, tld, - clock.nowUtc(), - DateTime.parse("1999-04-03T22:00:00.0Z"), + clock.now(), + Instant.parse("1999-04-03T22:00:00.0Z"), REGISTRATION_EXPIRATION_TIME); subordinateHost = persistResource( @@ -115,7 +115,7 @@ void setupDomain(String label, String tld) { .setHostName("ns1." + label + "." + tld) .setPersistedCurrentSponsorRegistrarId("TheRegistrar") .setCreationRegistrarId("TheRegistrar") - .setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z")) + .setCreationTimeForTest(Instant.parse("1999-04-03T22:00:00.0Z")) .setSuperordinateDomain(domain.createVKey()) .build()); domain = @@ -172,9 +172,10 @@ void assertTransferFailed( // all the speculative server-approve fields nulled out. assertThat(domain.getTransferData()) .isEqualTo( - oldTransferData.copyConstantFieldsToBuilder() + oldTransferData + .copyConstantFieldsToBuilder() .setTransferStatus(status) - .setPendingTransferExpirationTime(clock.nowUtc()) + .setPendingTransferExpirationTime(clock.now()) .build()); } diff --git a/core/src/test/java/google/registry/flows/domain/DomainTransferQueryFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainTransferQueryFlowTest.java index b96a4f41223..e6fbb3ee35d 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainTransferQueryFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainTransferQueryFlowTest.java @@ -21,6 +21,9 @@ import static google.registry.testing.DatabaseHelper.persistResource; import static google.registry.testing.DomainSubject.assertAboutDomains; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; +import static google.registry.util.DateTimeUtils.minusDays; +import static google.registry.util.DateTimeUtils.plusDays; +import static google.registry.util.DateTimeUtils.plusYears; import static org.junit.jupiter.api.Assertions.assertThrows; import google.registry.flows.EppException; @@ -152,8 +155,7 @@ void testSuccess_tenYears() throws Exception { @Test void testFailure_pendingDeleteDomain() throws Exception { changeTransferStatus(TransferStatus.SERVER_CANCELLED); - domain = - persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().plusDays(1)).build()); + domain = persistResource(domain.asBuilder().setDeletionTime(plusDays(clock.now(), 1)).build()); doSuccessfulTest( "domain_transfer_query.xml", "domain_transfer_query_response_server_cancelled.xml", 1); } @@ -205,8 +207,7 @@ void testFailure_unrelatedClient() { @Test void testFailure_deletedDomain() throws Exception { - domain = - persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); + domain = persistResource(domain.asBuilder().setDeletionTime(minusDays(clock.now(), 1)).build()); ResourceDoesNotExistException thrown = assertThrows( ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_query.xml")); @@ -234,8 +235,8 @@ void testSuccess_serverApproved_afterAutorenews() throws Exception { // Set the clock to just past the extended registration time. We'd expect the domain to have // auto-renewed once, but the transfer query response should be the same. clock.setTo(EXTENDED_REGISTRATION_EXPIRATION_TIME.plusMillis(1)); - assertThat(domain.cloneProjectedAtTime(clock.nowUtc()).getRegistrationExpirationDateTime()) - .isEqualTo(EXTENDED_REGISTRATION_EXPIRATION_TIME.plusYears(1)); + assertThat(domain.cloneProjectedAtInstant(clock.now()).getRegistrationExpirationTime()) + .isEqualTo(plusYears(EXTENDED_REGISTRATION_EXPIRATION_TIME, 1)); doSuccessfulTest( "domain_transfer_query.xml", "domain_transfer_query_response_server_approved.xml", 2); } diff --git a/core/src/test/java/google/registry/flows/domain/DomainTransferRejectFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainTransferRejectFlowTest.java index e3bac621677..55bb46057bc 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainTransferRejectFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainTransferRejectFlowTest.java @@ -33,6 +33,8 @@ import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.util.DateTimeUtils.END_OF_TIME; +import static google.registry.util.DateTimeUtils.minusDays; +import static google.registry.util.DateTimeUtils.plusDays; import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.common.collect.ImmutableSet; @@ -57,7 +59,7 @@ import google.registry.model.transfer.DomainTransferData; import google.registry.model.transfer.TransferResponse; import google.registry.model.transfer.TransferStatus; -import org.joda.time.DateTime; +import java.time.Instant; import org.joda.time.Duration; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -88,7 +90,7 @@ private void doSuccessfulTest(String commandFilename, String expectedXmlFilename assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1))).hasSize(1); // Setup done; run the test. assertMutatingFlow(true); - DateTime originalExpirationTime = domain.getRegistrationExpirationDateTime(); + Instant originalExpirationTime = domain.getRegistrationExpirationTime(); ImmutableSet originalGracePeriods = domain.getGracePeriods(); DomainTransferData originalTransferData = domain.getTransferData(); runFlowAssertResponse(loadFile(expectedXmlFilename)); @@ -99,12 +101,12 @@ private void doSuccessfulTest(String commandFilename, String expectedXmlFilename .that(domain) .hasRegistrationExpirationTime(originalExpirationTime) .and() - .hasLastTransferTimeNotEqualTo(clock.nowUtc()) + .hasLastTransferTimeNotEqualTo(clock.now()) .and() .hasOneHistoryEntryEachOfTypes( DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST, DOMAIN_TRANSFER_REJECT) .and() - .hasLastEppUpdateTime(clock.nowUtc()) + .hasLastEppUpdateTime(clock.now()) .and() .hasLastEppUpdateRegistrarId("TheRegistrar"); final HistoryEntry historyEntryTransferRejected = @@ -297,8 +299,7 @@ void testFailure_unrelatedClient() { @Test void testFailure_deletedDomain() throws Exception { - domain = - persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); + domain = persistResource(domain.asBuilder().setDeletionTime(minusDays(clock.now(), 1)).build()); ResourceDoesNotExistException thrown = assertThrows( ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_reject.xml")); @@ -341,22 +342,22 @@ void testIcannTransactionRecord_noRecordsToCancel() throws Exception { (DomainHistory) getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REJECT); // We should only produce transfer nacked records, reported now assertThat(persistedEntry.getDomainTransactionRecords()) - .containsExactly(DomainTransactionRecord.create("tld", clock.nowUtc(), TRANSFER_NACKED, 1)); + .containsExactly(DomainTransactionRecord.create("tld", clock.now(), TRANSFER_NACKED, 1)); } @Test void testIcannTransactionRecord_cancelsPreviousRecords() throws Exception { setUpGracePeriodDurations(); DomainTransactionRecord previousSuccessRecord = - DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), TRANSFER_SUCCESSFUL, 1); + DomainTransactionRecord.create("tld", plusDays(clock.now(), 1), TRANSFER_SUCCESSFUL, 1); // We only want to cancel TRANSFER_SUCCESSFUL records DomainTransactionRecord notCancellableRecord = - DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), NET_RENEWS_3_YR, 5); + DomainTransactionRecord.create("tld", plusDays(clock.now(), 1), NET_RENEWS_3_YR, 5); persistResource( new DomainHistory.Builder() .setType(DOMAIN_TRANSFER_REQUEST) .setDomain(domain) - .setModificationTime(clock.nowUtc().minusDays(4)) + .setModificationTime(minusDays(clock.now(), 4)) .setRegistrarId("TheRegistrar") .setDomainTransactionRecords( ImmutableSet.of(previousSuccessRecord, notCancellableRecord)) @@ -368,6 +369,6 @@ void testIcannTransactionRecord_cancelsPreviousRecords() throws Exception { assertThat(persistedEntry.getDomainTransactionRecords()) .containsExactly( previousSuccessRecord.asBuilder().setReportAmount(-1).build(), - DomainTransactionRecord.create("tld", clock.nowUtc(), TRANSFER_NACKED, 1)); + DomainTransactionRecord.create("tld", clock.now(), TRANSFER_NACKED, 1)); } } diff --git a/core/src/test/java/google/registry/flows/domain/DomainTransferRequestFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainTransferRequestFlowTest.java index 57eebb83a16..02711108759 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainTransferRequestFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainTransferRequestFlowTest.java @@ -46,7 +46,13 @@ import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HostSubject.assertAboutHosts; import static google.registry.testing.TestDataHelper.updateSubstitutions; +import static google.registry.util.DateTimeUtils.START_INSTANT; import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.minusDays; +import static google.registry.util.DateTimeUtils.minusYears; +import static google.registry.util.DateTimeUtils.plusDays; +import static google.registry.util.DateTimeUtils.plusYears; +import static google.registry.util.DateTimeUtils.toDateTime; import static org.joda.money.CurrencyUnit.JPY; import static org.joda.money.CurrencyUnit.USD; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -125,11 +131,11 @@ import google.registry.testing.CloudTasksHelper.TaskMatcher; import google.registry.testing.DatabaseHelper; import java.math.BigDecimal; +import java.time.Instant; import java.util.Map; import java.util.Optional; import java.util.stream.Stream; 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.Test; @@ -183,9 +189,9 @@ void beforeEach() { private void assertTransferRequested( Domain domain, - DateTime automaticTransferTime, + Instant automaticTransferTime, Period expectedPeriod, - DateTime expectedExpirationTime) + Instant expectedExpirationTime) throws Exception { assertAboutDomains() .that(domain) @@ -193,7 +199,7 @@ private void assertTransferRequested( .and() .hasStatusValue(StatusValue.PENDING_TRANSFER) .and() - .hasLastEppUpdateTime(clock.nowUtc()) + .hasLastEppUpdateTime(clock.now()) .and() .hasLastEppUpdateRegistrarId("NewRegistrar"); Trid expectedTrid = @@ -211,7 +217,7 @@ private void assertTransferRequested( .setGainingRegistrarId("NewRegistrar") .setLosingRegistrarId("TheRegistrar") .setTransferRequestTrid(expectedTrid) - .setTransferRequestTime(clock.nowUtc()) + .setTransferRequestTime(clock.now()) .setTransferPeriod(expectedPeriod) .setTransferStatus(TransferStatus.PENDING) .setPendingTransferExpirationTime(automaticTransferTime) @@ -222,7 +228,7 @@ private void assertTransferRequested( } private void assertTransferApproved( - Domain domain, DateTime automaticTransferTime, Period expectedPeriod) throws Exception { + Domain domain, Instant automaticTransferTime, Period expectedPeriod) throws Exception { assertAboutDomains() .that(domain) .hasCurrentSponsorRegistrarId("NewRegistrar") @@ -240,7 +246,7 @@ private void assertTransferApproved( .setGainingRegistrarId("NewRegistrar") .setLosingRegistrarId("TheRegistrar") .setTransferRequestTrid(expectedTrid) - .setTransferRequestTime(clock.nowUtc()) + .setTransferRequestTime(clock.now()) .setTransferPeriod(expectedPeriod) .setTransferStatus(TransferStatus.SERVER_APPROVED) .setPendingTransferExpirationTime(automaticTransferTime) @@ -251,8 +257,8 @@ private void assertTransferApproved( } private void assertHistoryEntriesContainBillingEventsAndGracePeriods( - DateTime expectedExpirationTime, - DateTime implicitTransferTime, + Instant expectedExpirationTime, + Instant implicitTransferTime, Optional transferCost, ImmutableSet originalGracePeriods, boolean expectTransferBillingEvent, @@ -274,7 +280,8 @@ private void assertHistoryEntriesContainBillingEventsAndGracePeriods( .setTargetId(domain.getDomainName()) .setEventTime(implicitTransferTime) .setBillingTime( - implicitTransferTime.plus(registry.getTransferGracePeriodLength())) + implicitTransferTime.plusMillis( + registry.getTransferGracePeriodLength().getMillis())) .setRegistrarId("NewRegistrar") .setCost(transferCost.orElse(Money.of(USD, 11))) .setPeriodYears(1) @@ -297,7 +304,7 @@ private void assertHistoryEntriesContainBillingEventsAndGracePeriods( getGainingClientAutorenewEvent() .asBuilder() .setEventTime(expectedExpirationTime) - .setRecurrenceLastExpansion(expectedExpirationTime.minusYears(1)) + .setRecurrenceLastExpansion(minusYears(expectedExpirationTime, 1)) .build(); // Construct extra billing events expected by the specific test. ImmutableSet extraBillingBases = @@ -334,12 +341,12 @@ private void assertHistoryEntriesContainBillingEventsAndGracePeriods( // The domain's autorenew billing event should still point to the losing client's event. BillingRecurrence domainAutorenewEvent = loadByKey(domain.getAutorenewBillingEvent()); assertThat(domainAutorenewEvent.getRegistrarId()).isEqualTo("TheRegistrar"); - assertThat(domainAutorenewEvent.getRecurrenceEndTime()).isEqualTo(implicitTransferTime); + assertThat(domainAutorenewEvent.getRecurrenceEndTimeInstant()).isEqualTo(implicitTransferTime); // The original grace periods should remain untouched. assertThat(domain.getGracePeriods()).containsExactlyElementsIn(originalGracePeriods); // If we fast forward AUTOMATIC_TRANSFER_DAYS, the transfer should have cleared out all other // grace periods, but expect a transfer grace period (if there was a transfer billing event). - Domain domainAfterAutomaticTransfer = domain.cloneProjectedAtTime(implicitTransferTime); + Domain domainAfterAutomaticTransfer = domain.cloneProjectedAtInstant(implicitTransferTime); if (expectTransferBillingEvent) { assertGracePeriods( domainAfterAutomaticTransfer.getGracePeriods(), @@ -347,7 +354,8 @@ private void assertHistoryEntriesContainBillingEventsAndGracePeriods( GracePeriod.create( GracePeriodStatus.TRANSFER, domain.getRepoId(), - implicitTransferTime.plus(registry.getTransferGracePeriodLength()), + implicitTransferTime.plusMillis( + registry.getTransferGracePeriodLength().getMillis()), "NewRegistrar", null), optionalTransferBillingEvent.get())); @@ -357,12 +365,12 @@ private void assertHistoryEntriesContainBillingEventsAndGracePeriods( } private void assertPollMessagesEmitted( - DateTime expectedExpirationTime, DateTime implicitTransferTime) { + Instant expectedExpirationTime, Instant implicitTransferTime) { // Assert that there exists a poll message to notify the losing registrar that a transfer was // requested. If the implicit transfer time is now (i.e. the automatic transfer length is zero) // then also expect a server approved poll message. assertThat(getPollMessages("TheRegistrar", clock.nowUtc())) - .hasSize(implicitTransferTime.equals(clock.nowUtc()) ? 2 : 1); + .hasSize(implicitTransferTime.equals(clock.now()) ? 2 : 1); // Two poll messages on the gaining registrar's side at the expected expiration time: a // (OneTime) transfer approved message, and an Autorenew poll message. @@ -371,8 +379,8 @@ private void assertPollMessagesEmitted( getOnlyPollMessage("NewRegistrar", implicitTransferTime, PollMessage.OneTime.class); PollMessage autorenewPollMessage = getOnlyPollMessage("NewRegistrar", expectedExpirationTime, PollMessage.Autorenew.class); - assertThat(transferApprovedPollMessage.getEventTime()).isEqualTo(implicitTransferTime); - assertThat(autorenewPollMessage.getEventTime()).isEqualTo(expectedExpirationTime); + assertThat(transferApprovedPollMessage.getEventTimeInstant()).isEqualTo(implicitTransferTime); + assertThat(autorenewPollMessage.getEventTimeInstant()).isEqualTo(expectedExpirationTime); assertThat( transferApprovedPollMessage.getResponseData().stream() .filter(TransferResponse.class::isInstance) @@ -399,8 +407,9 @@ private void assertPollMessagesEmitted( getPollMessages("TheRegistrar", implicitTransferTime).stream() .filter(Predicates.not(Predicates.equalTo(losingTransferPendingPollMessage))) .collect(onlyElement()); - assertThat(losingTransferPendingPollMessage.getEventTime()).isEqualTo(clock.nowUtc()); - assertThat(losingTransferApprovedPollMessage.getEventTime()).isEqualTo(implicitTransferTime); + assertThat(losingTransferPendingPollMessage.getEventTimeInstant()).isEqualTo(clock.now()); + assertThat(losingTransferApprovedPollMessage.getEventTimeInstant()) + .isEqualTo(implicitTransferTime); assertThat( losingTransferPendingPollMessage.getResponseData().stream() .filter(TransferResponse.class::isInstance) @@ -430,10 +439,10 @@ private void assertPollMessagesEmitted( } private void assertAboutDomainAfterAutomaticTransfer( - DateTime expectedExpirationTime, DateTime implicitTransferTime, Period expectedPeriod) + Instant expectedExpirationTime, Instant implicitTransferTime, Period expectedPeriod) throws Exception { Tld registry = Tld.get(domain.getTld()); - Domain domainAfterAutomaticTransfer = domain.cloneProjectedAtTime(implicitTransferTime); + Domain domainAfterAutomaticTransfer = domain.cloneProjectedAtInstant(implicitTransferTime); assertTransferApproved(domainAfterAutomaticTransfer, implicitTransferTime, expectedPeriod); assertAboutDomains() .that(domainAfterAutomaticTransfer) @@ -442,15 +451,17 @@ private void assertAboutDomainAfterAutomaticTransfer( .hasLastEppUpdateTime(implicitTransferTime) .and() .hasLastEppUpdateRegistrarId("NewRegistrar"); - assertThat(loadByKey(domainAfterAutomaticTransfer.getAutorenewBillingEvent()).getEventTime()) + assertThat( + loadByKey(domainAfterAutomaticTransfer.getAutorenewBillingEvent()) + .getEventTimeInstant()) .isEqualTo(expectedExpirationTime); // And after the expected grace time, the grace period should be gone. Domain afterGracePeriod = - domain.cloneProjectedAtTime( + domain.cloneProjectedAtInstant( clock - .nowUtc() - .plus(registry.getAutomaticTransferLength()) - .plus(registry.getTransferGracePeriodLength())); + .now() + .plusMillis(registry.getAutomaticTransferLength().getMillis()) + .plusMillis(registry.getTransferGracePeriodLength().getMillis())); assertThat(afterGracePeriod.getGracePeriods()).isEmpty(); } @@ -462,7 +473,7 @@ private void assertAboutDomainAfterAutomaticTransfer( private void doSuccessfulTest( String commandFilename, String expectedXmlFilename, - DateTime expectedExpirationTime, + Instant expectedExpirationTime, Map substitutions, Optional transferCost, BillingCancellation.Builder... extraExpectedBillingEvents) @@ -473,7 +484,8 @@ private void doSuccessfulTest( // for the request test we want that same 'now' to be the initial request time, so we shift // the transfer timeline 3 days later by adjusting the implicit transfer time here. Tld registry = Tld.get(domain.getTld()); - DateTime implicitTransferTime = clock.nowUtc().plus(registry.getAutomaticTransferLength()); + Instant implicitTransferTime = + clock.now().plusMillis(registry.getAutomaticTransferLength().getMillis()); // Setup done; run the test. assertMutatingFlow(true); runFlowAssertResponse(loadFile(expectedXmlFilename, substitutions)); @@ -517,14 +529,16 @@ private void doSuccessfulTest( .service("backend") .header("content-type", "application/x-www-form-urlencoded") .param(PARAM_RESOURCE_KEY, domain.createVKey().stringify()) - .param(PARAM_REQUESTED_TIME, clock.nowUtc().toString()) - .scheduleTime(clock.nowUtc().plus(registry.getAutomaticTransferLength()))); + .param(PARAM_REQUESTED_TIME, clock.now().toString()) + .scheduleTime( + toDateTime( + clock.now().plusMillis(registry.getAutomaticTransferLength().getMillis())))); } private void doSuccessfulTest( String commandFilename, String expectedXmlFilename, - DateTime expectedExpirationTime, + Instant expectedExpirationTime, BillingCancellation.Builder... extraExpectedBillingEvents) throws Exception { doSuccessfulTest( @@ -543,7 +557,7 @@ private void doSuccessfulTest( doSuccessfulTest( commandFilename, expectedXmlFilename, - domain.getRegistrationExpirationDateTime().plusYears(1), + plusYears(domain.getRegistrationExpirationTime(), 1), substitutions, Optional.empty()); } @@ -552,15 +566,13 @@ private void doSuccessfulTest(String commandFilename, String expectedXmlFilename throws Exception { clock.advanceOneMilli(); doSuccessfulTest( - commandFilename, - expectedXmlFilename, - domain.getRegistrationExpirationDateTime().plusYears(1)); + commandFilename, expectedXmlFilename, plusYears(domain.getRegistrationExpirationTime(), 1)); } private void doSuccessfulSuperuserExtensionTest( String commandFilename, String expectedXmlFilename, - DateTime expectedExpirationTime, + Instant expectedExpirationTime, Map substitutions, Optional transferCost, Period expectedPeriod, @@ -573,7 +585,8 @@ private void doSuccessfulSuperuserExtensionTest( // For all of the other transfer flow tests, 'now' corresponds to day 3 of the transfer, but // for the request test we want that same 'now' to be the initial request time, so we shift // the transfer timeline 3 days later by adjusting the implicit transfer time here. - DateTime implicitTransferTime = clock.nowUtc().plus(expectedAutomaticTransferLength); + Instant implicitTransferTime = + clock.now().plusMillis(expectedAutomaticTransferLength.getMillis()); // Setup done; run the test. assertMutatingFlow(true); runFlowAssertResponse( @@ -815,7 +828,7 @@ void testSuccess_superuserExtension_zeroPeriod_nonZeroAutomaticTransferLength() doSuccessfulSuperuserExtensionTest( "domain_transfer_request_superuser_extension.xml", "domain_transfer_request_response_su_ext_zero_period_nonzero_transfer_length.xml", - domain.getRegistrationExpirationDateTime().plusYears(0), + plusYears(domain.getRegistrationExpirationTime(), 0), ImmutableMap.of("PERIOD", "0", "AUTOMATIC_TRANSFER_LENGTH", "5"), Optional.empty(), Period.create(0, Unit.YEARS), @@ -829,7 +842,7 @@ void testSuccess_superuserExtension_zeroPeriod_zeroAutomaticTransferLength() thr doSuccessfulSuperuserExtensionTest( "domain_transfer_request_superuser_extension.xml", "domain_transfer_request_response_su_ext_zero_period_zero_transfer_length.xml", - domain.getRegistrationExpirationDateTime().plusYears(0), + plusYears(domain.getRegistrationExpirationTime(), 0), ImmutableMap.of("PERIOD", "0", "AUTOMATIC_TRANSFER_LENGTH", "0"), Optional.empty(), Period.create(0, Unit.YEARS), @@ -844,7 +857,7 @@ void testSuccess_superuserExtension_nonZeroPeriod_nonZeroAutomaticTransferLength doSuccessfulSuperuserExtensionTest( "domain_transfer_request_superuser_extension.xml", "domain_transfer_request_response_su_ext_one_year_period_nonzero_transfer_length.xml", - domain.getRegistrationExpirationDateTime().plusYears(1), + plusYears(domain.getRegistrationExpirationTime(), 1), ImmutableMap.of("PERIOD", "1", "AUTOMATIC_TRANSFER_LENGTH", "5"), Optional.empty(), Period.create(1, Unit.YEARS), @@ -857,8 +870,8 @@ void testSuccess_superuserExtension_zeroPeriod_autorenewGraceActive() throws Exc VKey existingAutorenewEvent = domain.getAutorenewBillingEvent(); // Set domain to have auto-renewed just before the transfer request, so that it will have an // active autorenew grace period spanning the entire transfer window. - DateTime autorenewTime = clock.nowUtc().minusDays(1); - DateTime expirationTime = autorenewTime.plusYears(1); + Instant autorenewTime = minusDays(clock.now(), 1); + Instant expirationTime = plusYears(autorenewTime, 1); domain = persistResource( domain @@ -868,7 +881,8 @@ void testSuccess_superuserExtension_zeroPeriod_autorenewGraceActive() throws Exc GracePeriod.createForRecurrence( GracePeriodStatus.AUTO_RENEW, domain.getRepoId(), - autorenewTime.plus(Tld.get("tld").getAutoRenewGracePeriodLength()), + autorenewTime.plusMillis( + Tld.get("tld").getAutoRenewGracePeriodLength().getMillis()), "TheRegistrar", existingAutorenewEvent)) .build()); @@ -876,7 +890,7 @@ void testSuccess_superuserExtension_zeroPeriod_autorenewGraceActive() throws Exc doSuccessfulSuperuserExtensionTest( "domain_transfer_request_superuser_extension.xml", "domain_transfer_request_response_su_ext_zero_period_autorenew_grace.xml", - domain.getRegistrationExpirationDateTime(), + domain.getRegistrationExpirationTime(), ImmutableMap.of("PERIOD", "0", "AUTOMATIC_TRANSFER_LENGTH", "0"), Optional.empty(), Period.create(0, Unit.YEARS), @@ -925,7 +939,7 @@ void testSuccess_superuserExtension_clientTransferProhibited() throws Exception doSuccessfulSuperuserExtensionTest( "domain_transfer_request_superuser_extension.xml", "domain_transfer_request_response_su_ext_zero_period_zero_transfer_length.xml", - domain.getRegistrationExpirationDateTime().plusYears(0), + plusYears(domain.getRegistrationExpirationTime(), 0), ImmutableMap.of("PERIOD", "0", "AUTOMATIC_TRANSFER_LENGTH", "0"), Optional.empty(), Period.create(0, Unit.YEARS), @@ -942,7 +956,7 @@ void testSuccess_superuserExtension_serverTransferProhibited() throws Exception doSuccessfulSuperuserExtensionTest( "domain_transfer_request_superuser_extension.xml", "domain_transfer_request_response_su_ext_zero_period_zero_transfer_length.xml", - domain.getRegistrationExpirationDateTime().plusYears(0), + plusYears(domain.getRegistrationExpirationTime(), 0), ImmutableMap.of("PERIOD", "0", "AUTOMATIC_TRANSFER_LENGTH", "0"), Optional.empty(), Period.create(0, Unit.YEARS), @@ -955,7 +969,7 @@ void testSuccess_cappedExpiration() throws Exception { // Set the domain to expire 10 years from now (as if it were just created with a 10-year term). domain = persistResource( - domain.asBuilder().setRegistrationExpirationTime(clock.nowUtc().plusYears(10)).build()); + domain.asBuilder().setRegistrationExpirationTime(plusYears(clock.now(), 10)).build()); // New expiration time should be capped at exactly 10 years from the transfer server-approve // time, so the domain only ends up gaining the 5-day transfer window's worth of extra // registration time. @@ -963,7 +977,8 @@ void testSuccess_cappedExpiration() throws Exception { doSuccessfulTest( "domain_transfer_request.xml", "domain_transfer_request_response_10_year_cap.xml", - clock.nowUtc().plus(Tld.get("tld").getAutomaticTransferLength()).plusYears(10)); + plusYears( + clock.now().plusMillis(Tld.get("tld").getAutomaticTransferLength().getMillis()), 10)); } @Test @@ -980,7 +995,7 @@ void testSuccess_customLogicFee_std_v1() throws Exception { doSuccessfulTest( "domain_transfer_request_separate_fees.xml", "domain_transfer_request_response_fees.xml", - domain.getRegistrationExpirationDateTime().plusYears(1), + plusYears(domain.getRegistrationExpirationTime(), 1), new ImmutableMap.Builder() .put("DOMAIN", "expensive-domain.foo") .put("YEARS", "1") @@ -1046,9 +1061,12 @@ void testSuccess_autorenewGraceActive_onlyAtTransferRequestTime() throws Excepti setupDomain("example", "tld"); // Set the domain to have auto-renewed long enough ago that it is still in the autorenew grace // period at the transfer request time, but will have exited it by the automatic transfer time. - DateTime autorenewTime = - clock.nowUtc().minus(Tld.get("tld").getAutoRenewGracePeriodLength()).plusDays(1); - DateTime expirationTime = autorenewTime.plusYears(1); + Instant autorenewTime = + clock + .now() + .minusMillis(Tld.get("tld").getAutoRenewGracePeriodLength().getMillis()) + .plus(java.time.Duration.ofDays(1)); + Instant expirationTime = plusYears(autorenewTime, 1); domain = persistResource( domain @@ -1058,7 +1076,8 @@ void testSuccess_autorenewGraceActive_onlyAtTransferRequestTime() throws Excepti GracePeriod.createForRecurrence( GracePeriodStatus.AUTO_RENEW, domain.getRepoId(), - autorenewTime.plus(Tld.get("tld").getAutoRenewGracePeriodLength()), + autorenewTime.plusMillis( + Tld.get("tld").getAutoRenewGracePeriodLength().getMillis()), "TheRegistrar", domain.getAutorenewBillingEvent())) .build()); @@ -1068,7 +1087,7 @@ void testSuccess_autorenewGraceActive_onlyAtTransferRequestTime() throws Excepti doSuccessfulTest( "domain_transfer_request.xml", "domain_transfer_request_response_autorenew_grace_at_request_only.xml", - expirationTime.plusYears(1)); + plusYears(expirationTime, 1)); } @Test @@ -1077,8 +1096,8 @@ void testSuccess_autorenewGraceActive_throughoutTransferWindow() throws Exceptio VKey existingAutorenewEvent = domain.getAutorenewBillingEvent(); // Set domain to have auto-renewed just before the transfer request, so that it will have an // active autorenew grace period spanning the entire transfer window. - DateTime autorenewTime = clock.nowUtc().minusDays(1); - DateTime expirationTime = autorenewTime.plusYears(1); + Instant autorenewTime = minusDays(clock.now(), 1); + Instant expirationTime = plusYears(autorenewTime, 1); domain = persistResource( domain @@ -1088,7 +1107,8 @@ void testSuccess_autorenewGraceActive_throughoutTransferWindow() throws Exceptio GracePeriod.createForRecurrence( GracePeriodStatus.AUTO_RENEW, domain.getRepoId(), - autorenewTime.plus(Tld.get("tld").getAutoRenewGracePeriodLength()), + autorenewTime.plusMillis( + Tld.get("tld").getAutoRenewGracePeriodLength().getMillis()), "TheRegistrar", existingAutorenewEvent)) .build()); @@ -1104,8 +1124,15 @@ void testSuccess_autorenewGraceActive_throughoutTransferWindow() throws Exceptio .setTargetId("example.tld") .setRegistrarId("TheRegistrar") // The cancellation happens at the moment of transfer. - .setEventTime(clock.nowUtc().plus(Tld.get("tld").getAutomaticTransferLength())) - .setBillingTime(autorenewTime.plus(Tld.get("tld").getAutoRenewGracePeriodLength())) + .setEventTime( + toDateTime( + clock + .now() + .plusMillis(Tld.get("tld").getAutomaticTransferLength().getMillis()))) + .setBillingTime( + toDateTime( + autorenewTime.plusMillis( + Tld.get("tld").getAutoRenewGracePeriodLength().getMillis()))) // The cancellation should refer to the old autorenew billing event. .setBillingRecurrence(existingAutorenewEvent)); } @@ -1116,7 +1143,7 @@ void testSuccess_autorenewGraceActive_onlyAtAutomaticTransferTime() throws Excep VKey existingAutorenewEvent = domain.getAutorenewBillingEvent(); // Set domain to expire in 1 day, so that it will be in the autorenew grace period by the // automatic transfer time, even though it isn't yet. - DateTime expirationTime = clock.nowUtc().plusDays(1); + Instant expirationTime = plusDays(clock.now(), 1); domain = persistResource(domain.asBuilder().setRegistrationExpirationTime(expirationTime).build()); clock.advanceOneMilli(); @@ -1125,14 +1152,21 @@ void testSuccess_autorenewGraceActive_onlyAtAutomaticTransferTime() throws Excep doSuccessfulTest( "domain_transfer_request.xml", "domain_transfer_request_response_autorenew_grace_at_transfer_only.xml", - expirationTime.plusYears(1), + plusYears(expirationTime, 1), new BillingCancellation.Builder() .setReason(Reason.RENEW) .setTargetId("example.tld") .setRegistrarId("TheRegistrar") // The cancellation happens at the moment of transfer. - .setEventTime(clock.nowUtc().plus(Tld.get("tld").getAutomaticTransferLength())) - .setBillingTime(expirationTime.plus(Tld.get("tld").getAutoRenewGracePeriodLength())) + .setEventTime( + toDateTime( + clock + .now() + .plusMillis(Tld.get("tld").getAutomaticTransferLength().getMillis()))) + .setBillingTime( + toDateTime( + expirationTime.plusMillis( + Tld.get("tld").getAutoRenewGracePeriodLength().getMillis()))) // The cancellation should refer to the old autorenew billing event. .setBillingRecurrence(existingAutorenewEvent)); } @@ -1175,7 +1209,7 @@ void testSuccess_nonPremiumRenewalPrice_isReflectedInTransferCostAndCarriesOver( .asBuilder() .setRenewalPriceBehavior(RenewalPriceBehavior.NONPREMIUM) .build()); - DateTime now = clock.nowUtc(); + Instant now = clock.now(); // This ensures that the transfer has non-premium cost, as otherwise, the fee extension would be // required to ack the premium price. @@ -1190,8 +1224,10 @@ void testSuccess_nonPremiumRenewalPrice_isReflectedInTransferCostAndCarriesOver( assertBillingEventsForResource( domain, new BillingEvent.Builder() - .setBillingTime(now.plusDays(10)) // 5 day pending transfer + 5 day billing grace period - .setEventTime(now.plusDays(5)) + .setBillingTime( + toDateTime( + plusDays(now, 10))) // 5 day pending transfer + 5 day billing grace period + .setEventTime(plusDays(now, 5)) .setRegistrarId("NewRegistrar") .setCost(Money.of(USD, new BigDecimal("11.00"))) .setDomainHistory(requestHistory) @@ -1206,7 +1242,7 @@ void testSuccess_nonPremiumRenewalPrice_isReflectedInTransferCostAndCarriesOver( .build(), getLosingClientAutorenewEvent() .asBuilder() - .setRecurrenceEndTime(now.plusDays(5)) + .setRecurrenceEndTime(plusDays(now, 5)) .setRenewalPriceBehavior(RenewalPriceBehavior.NONPREMIUM) .build()); } @@ -1232,7 +1268,7 @@ void testSuccess_specifiedRenewalPrice_isReflectedInTransferCostAndCarriesOver() .setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED) .setRenewalPrice(Money.of(USD, new BigDecimal("18.79"))) .build()); - DateTime now = clock.nowUtc(); + Instant now = clock.now(); setEppInput("domain_transfer_request.xml"); runFlowAssertResponse(loadFile("domain_transfer_request_response.xml")); @@ -1245,8 +1281,10 @@ void testSuccess_specifiedRenewalPrice_isReflectedInTransferCostAndCarriesOver() assertBillingEventsForResource( domain, new BillingEvent.Builder() - .setBillingTime(now.plusDays(10)) // 5 day pending transfer + 5 day billing grace period - .setEventTime(now.plusDays(5)) + .setBillingTime( + toDateTime( + plusDays(now, 10))) // 5 day pending transfer + 5 day billing grace period + .setEventTime(plusDays(now, 5)) .setRegistrarId("NewRegistrar") .setCost(Money.of(USD, new BigDecimal("18.79"))) .setDomainHistory(requestHistory) @@ -1262,7 +1300,7 @@ void testSuccess_specifiedRenewalPrice_isReflectedInTransferCostAndCarriesOver() .build(), getLosingClientAutorenewEvent() .asBuilder() - .setRecurrenceEndTime(now.plusDays(5)) + .setRecurrenceEndTime(plusDays(now, 5)) .setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED) .setRenewalPrice(Money.of(USD, new BigDecimal("18.79"))) .build()); @@ -1293,7 +1331,7 @@ void testSuccess_specifiedRenewalPrice_notCarriedOverForBulkPricingName() throws domain = persistResource( domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build()); - DateTime now = clock.nowUtc(); + Instant now = clock.now(); setEppInput("domain_transfer_request.xml"); runFlowAssertResponse(loadFile("domain_transfer_request_response.xml")); @@ -1306,8 +1344,10 @@ void testSuccess_specifiedRenewalPrice_notCarriedOverForBulkPricingName() throws assertBillingEventsForResource( domain, new BillingEvent.Builder() - .setBillingTime(now.plusDays(10)) // 5 day pending transfer + 5 day billing grace period - .setEventTime(now.plusDays(5)) + .setBillingTime( + toDateTime( + plusDays(now, 10))) // 5 day pending transfer + 5 day billing grace period + .setEventTime(plusDays(now, 5)) .setRegistrarId("NewRegistrar") .setCost(Money.of(USD, new BigDecimal("11.00"))) .setDomainHistory(requestHistory) @@ -1323,7 +1363,7 @@ void testSuccess_specifiedRenewalPrice_notCarriedOverForBulkPricingName() throws .build(), getLosingClientAutorenewEvent() .asBuilder() - .setRecurrenceEndTime(now.plusDays(5)) + .setRecurrenceEndTime(plusDays(now, 5)) .setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED) .setRenewalPrice(Money.of(USD, new BigDecimal("18.79"))) .build()); @@ -1353,7 +1393,7 @@ void testSuccess_defaultRenewalPrice_carriedOverForBulkPricingName() throws Exce domain = persistResource( domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build()); - DateTime now = clock.nowUtc(); + Instant now = clock.now(); setEppInput("domain_transfer_request.xml"); runFlowAssertResponse(loadFile("domain_transfer_request_response.xml")); @@ -1366,8 +1406,10 @@ void testSuccess_defaultRenewalPrice_carriedOverForBulkPricingName() throws Exce assertBillingEventsForResource( domain, new BillingEvent.Builder() - .setBillingTime(now.plusDays(10)) // 5 day pending transfer + 5 day billing grace period - .setEventTime(now.plusDays(5)) + .setBillingTime( + toDateTime( + plusDays(now, 10))) // 5 day pending transfer + 5 day billing grace period + .setEventTime(plusDays(now, 5)) .setRegistrarId("NewRegistrar") .setCost(Money.of(USD, new BigDecimal("11.00"))) .setDomainHistory(requestHistory) @@ -1383,7 +1425,7 @@ void testSuccess_defaultRenewalPrice_carriedOverForBulkPricingName() throws Exce .build(), getLosingClientAutorenewEvent() .asBuilder() - .setRecurrenceEndTime(now.plusDays(5)) + .setRecurrenceEndTime(plusDays(now, 5)) .setRenewalPriceBehavior(RenewalPriceBehavior.DEFAULT) .build()); } @@ -1416,7 +1458,7 @@ void testSuccess_bulkPricingName_zeroPeriod() throws Exception { doSuccessfulSuperuserExtensionTest( "domain_transfer_request_superuser_extension.xml", "domain_transfer_request_response_su_ext_zero_period_zero_transfer_length.xml", - domain.getRegistrationExpirationDateTime().plusYears(0), + plusYears(domain.getRegistrationExpirationTime(), 0), ImmutableMap.of("PERIOD", "0", "AUTOMATIC_TRANSFER_LENGTH", "0"), Optional.empty(), Period.create(0, Unit.YEARS), @@ -1559,7 +1601,7 @@ void testFailure_pending() { .getTransferData() .asBuilder() .setTransferStatus(TransferStatus.PENDING) - .setPendingTransferExpirationTime(clock.nowUtc().plusDays(1)) + .setPendingTransferExpirationTime(plusDays(clock.now(), 1)) .build()) .build()); EppException thrown = @@ -1600,8 +1642,7 @@ void testFailure_sponsoringClient() { @Test void testFailure_deletedDomain() throws Exception { setupDomain("example", "tld"); - domain = - persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); + domain = persistResource(domain.asBuilder().setDeletionTime(minusDays(clock.now(), 1)).build()); ResourceDoesNotExistException thrown = assertThrows( ResourceDoesNotExistException.class, @@ -1738,7 +1779,7 @@ void testIcannTransactionRecord_getsStored() throws Exception { assertThat(persistedEntry.getDomainTransactionRecords()) .containsExactly( DomainTransactionRecord.create( - "tld", clock.nowUtc().plusDays(5), TRANSFER_SUCCESSFUL, 1)); + "tld", plusDays(clock.now(), 5), TRANSFER_SUCCESSFUL, 1)); } @Test @@ -1772,11 +1813,11 @@ void testFailure_allocationTokenNotActive() throws Exception { .setToken("abc123") .setTokenType(UNLIMITED_USE) .setDiscountFraction(0.5) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().plusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(60), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(plusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 60), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_transfer_request_allocation_token.xml", ImmutableMap.of("TOKEN", "abc123")); @@ -1793,11 +1834,11 @@ void testFailure_allocationTokenNotValidForRegistrar() throws Exception { .setTokenType(UNLIMITED_USE) .setAllowedRegistrarIds(ImmutableSet.of("someClientId")) .setDiscountFraction(0.5) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, TokenStatus.NOT_STARTED) - .put(clock.nowUtc().minusDays(1), TokenStatus.VALID) - .put(clock.nowUtc().plusDays(1), TokenStatus.ENDED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, TokenStatus.NOT_STARTED) + .put(minusDays(clock.now(), 1), TokenStatus.VALID) + .put(plusDays(clock.now(), 1), TokenStatus.ENDED) .build()) .build()); setEppInput("domain_transfer_request_allocation_token.xml", ImmutableMap.of("TOKEN", "abc123")); @@ -2031,7 +2072,7 @@ void testSuccess_customLogicFee_v06() throws Exception { doSuccessfulTest( "domain_transfer_request_separate_fees.xml", "domain_transfer_request_response_fees.xml", - domain.getRegistrationExpirationDateTime().plusYears(1), + plusYears(domain.getRegistrationExpirationTime(), 1), new ImmutableMap.Builder() .put("DOMAIN", "expensive-domain.foo") .put("YEARS", "1") diff --git a/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java index ca0a26e0528..8dd38bf5e5a 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainUpdateFlowTest.java @@ -51,6 +51,9 @@ import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.plusDays; +import static google.registry.util.DateTimeUtils.plusYears; +import static google.registry.util.DateTimeUtils.toDateTime; import static org.joda.money.CurrencyUnit.USD; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -103,9 +106,9 @@ import google.registry.model.tld.Tld; import google.registry.persistence.VKey; import google.registry.testing.DatabaseHelper; +import java.time.Instant; import java.util.Optional; import org.joda.money.Money; -import org.joda.time.DateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -138,7 +141,7 @@ private void persistReferencedEntities() { } private Domain persistDomain() throws Exception { - Host host = loadResource(Host.class, "ns1.example.foo", clock.nowUtc()).get(); + Host host = loadResource(Host.class, "ns1.example.foo", clock.now()).get(); Domain domain = persistResource( DatabaseHelper.newDomain(getUniqueIdFromCommand()) @@ -148,7 +151,7 @@ private Domain persistDomain() throws Exception { persistResource( new DomainHistory.Builder() .setType(DOMAIN_CREATE) - .setModificationTime(clock.nowUtc()) + .setModificationTime(clock.now()) .setRegistrarId(domain.getCreationRegistrarId()) .setDomain(domain) .build()); @@ -173,7 +176,7 @@ private void doSuccessfulTest(String expectedXmlFilename) throws Exception { .and() .hasOneHistoryEntryEachOfTypes(DOMAIN_CREATE, DOMAIN_UPDATE) .and() - .hasLastEppUpdateTime(clock.nowUtc()) + .hasLastEppUpdateTime(clock.now()) .and() .hasLastEppUpdateRegistrarId("TheRegistrar") .and() @@ -234,7 +237,7 @@ void testSuccess_noExistingAuthData() throws Exception { .and() .hasOneHistoryEntryEachOfTypes(DOMAIN_CREATE, DOMAIN_UPDATE) .and() - .hasLastEppUpdateTime(clock.nowUtc()) + .hasLastEppUpdateTime(clock.now()) .and() .hasLastEppUpdateRegistrarId("TheRegistrar") .and() @@ -286,7 +289,7 @@ private void modifyDomainToHave13Nameservers() throws Exception { for (int i = 1; i < 15; i++) { if (i != 2) { // Skip 2 since that's the one that the tests will add. nameservers.add( - loadResource(Host.class, String.format("ns%d.example.foo", i), clock.nowUtc()) + loadResource(Host.class, String.format("ns%d.example.foo", i), clock.now()) .get() .createVKey()); } @@ -378,7 +381,7 @@ void testSuccess_addAndRemoveSubordinateHostNameservers() throws Exception { .addSubordinateHost("ns2.example.tld") .setNameservers( ImmutableSet.of( - loadResource(Host.class, "ns1.example.tld", clock.nowUtc()).get().createVKey())) + loadResource(Host.class, "ns1.example.tld", clock.now()).get().createVKey())) .build()); clock.advanceOneMilli(); assertMutatingFlow(true); @@ -386,8 +389,8 @@ void testSuccess_addAndRemoveSubordinateHostNameservers() throws Exception { domain = reloadResourceByForeignKey(); assertThat(domain.getNameservers()).containsExactly(addedHost.createVKey()); assertThat(domain.getSubordinateHosts()).containsExactly("ns1.example.tld", "ns2.example.tld"); - Host existingHost = loadResource(Host.class, "ns1.example.tld", clock.nowUtc()).get(); - addedHost = loadResource(Host.class, "ns2.example.tld", clock.nowUtc()).get(); + Host existingHost = loadResource(Host.class, "ns1.example.tld", clock.now()).get(); + addedHost = loadResource(Host.class, "ns2.example.tld", clock.now()).get(); assertThat(existingHost.getSuperordinateDomain()).isEqualTo(domain.createVKey()); assertThat(addedHost.getSuperordinateDomain()).isEqualTo(domain.createVKey()); } @@ -797,8 +800,8 @@ void doServerStatusBillingTest(String xmlFilename, boolean isBillable) throws Ex .setTargetId("example.tld") .setRegistrarId("TheRegistrar") .setCost(Money.of(USD, 19)) - .setEventTime(clock.nowUtc()) - .setBillingTime(clock.nowUtc()) + .setEventTime(clock.now()) + .setBillingTime(clock.now()) .setDomainHistory( getOnlyHistoryEntryOfType( reloadResourceByForeignKey(), DOMAIN_UPDATE, DomainHistory.class)) @@ -1095,17 +1098,14 @@ void testSuccess_addingServerStatusValue_sendsPollMessage() throws Exception { assertPollMessagesForResource( updatedDomain, new PollMessage.OneTime.Builder() - .setEventTime(clock.nowUtc()) + .setEventTime(clock.now()) .setHistoryEntry(getOnlyHistoryEntryOfType(updatedDomain, DOMAIN_UPDATE)) .setRegistrarId("NewRegistrar") .setMsg("The registry administrator has added the status(es) [serverHold].") .setResponseData( ImmutableList.of( DomainPendingActionNotificationResponse.create( - "example.tld", - true, - Trid.create("ABC-12345", "server-trid"), - clock.nowUtc()))) + "example.tld", true, Trid.create("ABC-12345", "server-trid"), clock.now()))) .build()); } @@ -1134,7 +1134,7 @@ void testSuccess_removingServerStatusValue_sendsPollMessage() throws Exception { assertPollMessagesForResource( updatedDomain, new PollMessage.OneTime.Builder() - .setEventTime(clock.nowUtc()) + .setEventTime(clock.now()) .setHistoryEntry(getOnlyHistoryEntryOfType(updatedDomain, DOMAIN_UPDATE)) .setRegistrarId("NewRegistrar") .setMsg( @@ -1143,10 +1143,7 @@ void testSuccess_removingServerStatusValue_sendsPollMessage() throws Exception { .setResponseData( ImmutableList.of( DomainPendingActionNotificationResponse.create( - "example.tld", - true, - Trid.create("ABC-12345", "server-trid"), - clock.nowUtc()))) + "example.tld", true, Trid.create("ABC-12345", "server-trid"), clock.now()))) .build()); } @@ -1172,7 +1169,7 @@ void testSuccess_addingAndRemovingServerStatusValues_sendsPollMessage() throws E assertPollMessagesForResource( updatedDomain, new PollMessage.OneTime.Builder() - .setEventTime(clock.nowUtc()) + .setEventTime(clock.now()) .setHistoryEntry(getOnlyHistoryEntryOfType(updatedDomain, DOMAIN_UPDATE)) .setRegistrarId("NewRegistrar") .setMsg( @@ -1182,10 +1179,7 @@ void testSuccess_addingAndRemovingServerStatusValues_sendsPollMessage() throws E .setResponseData( ImmutableList.of( DomainPendingActionNotificationResponse.create( - "example.tld", - true, - Trid.create("ABC-12345", "server-trid"), - clock.nowUtc()))) + "example.tld", true, Trid.create("ABC-12345", "server-trid"), clock.now()))) .build()); } @@ -1262,7 +1256,7 @@ void testFailure_pendingDelete() throws Exception { persistResource( DatabaseHelper.newDomain(getUniqueIdFromCommand()) .asBuilder() - .setDeletionTime(clock.nowUtc().plusDays(1)) + .setDeletionTime(plusDays(clock.now(), 1)) .addStatusValue(PENDING_DELETE) .build()); ResourceStatusProhibitsOperationException thrown = @@ -1319,7 +1313,7 @@ void testFailure_sameNameserverAddedAndRemoved() throws Exception { .asBuilder() .setNameservers( ImmutableSet.of( - loadResource(Host.class, "ns1.example.foo", clock.nowUtc()).get().createVKey())) + loadResource(Host.class, "ns1.example.foo", clock.now()).get().createVKey())) .build()); EppException thrown = assertThrows(AddRemoveSameValueException.class, this::runFlow); assertAboutEppExceptions().that(thrown).marshalsToXml(); @@ -1387,7 +1381,7 @@ void testFailure_addPendingDeleteHost() throws Exception { persistReferencedEntities(); persistDomain(); persistResource( - loadResource(Host.class, "ns2.example.foo", clock.nowUtc()) + loadResource(Host.class, "ns2.example.foo", clock.now()) .get() .asBuilder() .addStatusValue(PENDING_DELETE) @@ -1422,7 +1416,7 @@ void testSuccess_tldWithNameserverAllowList_removeNameserver() throws Exception reloadResourceByForeignKey() .asBuilder() .addNameserver( - loadResource(Host.class, "ns2.example.foo", clock.nowUtc()).get().createVKey()) + loadResource(Host.class, "ns2.example.foo", clock.now()).get().createVKey()) .build()); persistResource( Tld.get("tld") @@ -1431,12 +1425,12 @@ void testSuccess_tldWithNameserverAllowList_removeNameserver() throws Exception ImmutableSet.of("ns1.example.foo", "ns2.example.foo")) .build()); assertThat(reloadResourceByForeignKey().getNameservers()) - .contains(loadResource(Host.class, "ns1.example.foo", clock.nowUtc()).get().createVKey()); + .contains(loadResource(Host.class, "ns1.example.foo", clock.now()).get().createVKey()); clock.advanceOneMilli(); runFlow(); assertThat(reloadResourceByForeignKey().getNameservers()) .doesNotContain( - loadResource(Host.class, "ns1.example.foo", clock.nowUtc()) + loadResource(Host.class, "ns1.example.foo", clock.now()) .map(ImmutableObject::createVKey) .get()); } @@ -1491,7 +1485,7 @@ void testIcannActivityReportField_getsLogged() throws Exception { void testSuperuserExtension_turnsOffAutorenew() throws Exception { eppRequestSource = EppRequestSource.TOOL; setEppInput("domain_update_superuser_extension.xml", ImmutableMap.of("AUTORENEWS", "false")); - DateTime expirationTime = clock.nowUtc().plusYears(3); + Instant expirationTime = plusYears(clock.now(), 3); persistReferencedEntities(); persistResource( persistDomain().asBuilder().setRegistrationExpirationTime(expirationTime).build()); @@ -1504,12 +1498,12 @@ void testSuperuserExtension_turnsOffAutorenew() throws Exception { void testSuperuserExtension_turnsOnAutorenew() throws Exception { eppRequestSource = EppRequestSource.TOOL; setEppInput("domain_update_superuser_extension.xml", ImmutableMap.of("AUTORENEWS", "true")); - DateTime expirationTime = clock.nowUtc().plusYears(3); + Instant expirationTime = plusYears(clock.now(), 3); persistReferencedEntities(); persistResource( persistDomain() .asBuilder() - .setAutorenewEndTime(Optional.of(expirationTime)) + .setAutorenewEndTime(Optional.of(toDateTime(expirationTime))) .setRegistrationExpirationTime(expirationTime) .build()); clock.advanceOneMilli(); diff --git a/core/src/test/java/google/registry/flows/domain/ProductionSimulatingFeeExtensionsTest.java b/core/src/test/java/google/registry/flows/domain/ProductionSimulatingFeeExtensionsTest.java index c6b78057acb..93ef4a707fe 100644 --- a/core/src/test/java/google/registry/flows/domain/ProductionSimulatingFeeExtensionsTest.java +++ b/core/src/test/java/google/registry/flows/domain/ProductionSimulatingFeeExtensionsTest.java @@ -86,7 +86,7 @@ void testProdEnvironment_feeExtensionFeatureActiveInTheFuture() throws Exception FEE_EXTENSION_1_DOT_0_IN_PROD.name(), "--force", "--status_map", - String.format("%s=INACTIVE,%s=ACTIVE", START_OF_TIME, fakeClock.nowUtc().plusMillis(1))); + String.format("%s=INACTIVE,%s=ACTIVE", START_OF_TIME, fakeClock.now().plusMillis(1))); RegistryEnvironment.PRODUCTION.setup(); ProtocolDefinition.reloadServiceExtensionUris(); // prod shouldn't have the fee extension version 1.0 @@ -107,7 +107,7 @@ void testProdEnvironment_feeExtensionFeatureActiveInThePast() throws Exception { FEE_EXTENSION_1_DOT_0_IN_PROD.name(), "--force", "--status_map", - String.format("%s=INACTIVE,%s=ACTIVE", START_OF_TIME, fakeClock.nowUtc().minusMillis(1))); + String.format("%s=INACTIVE,%s=ACTIVE", START_OF_TIME, fakeClock.now().minusMillis(1))); RegistryEnvironment.PRODUCTION.setup(); ProtocolDefinition.reloadServiceExtensionUris(); // prod should have the fee extension version 1.0 diff --git a/core/src/test/java/google/registry/flows/domain/token/AllocationTokenFlowUtilsTest.java b/core/src/test/java/google/registry/flows/domain/token/AllocationTokenFlowUtilsTest.java index 8c60f92581a..4d55639dbb9 100644 --- a/core/src/test/java/google/registry/flows/domain/token/AllocationTokenFlowUtilsTest.java +++ b/core/src/test/java/google/registry/flows/domain/token/AllocationTokenFlowUtilsTest.java @@ -25,7 +25,11 @@ import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.persistResource; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; -import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.START_INSTANT; +import static google.registry.util.DateTimeUtils.minusDays; +import static google.registry.util.DateTimeUtils.minusMonths; +import static google.registry.util.DateTimeUtils.plusDays; +import static google.registry.util.DateTimeUtils.plusMonths; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -49,8 +53,9 @@ import google.registry.persistence.transaction.JpaTestExtensions; import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension; import google.registry.testing.FakeClock; +import java.time.Duration; +import java.time.Instant; import java.util.Optional; -import org.joda.time.DateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -58,7 +63,7 @@ /** Unit tests for {@link AllocationTokenFlowUtils}. */ class AllocationTokenFlowUtilsTest { - private final FakeClock clock = new FakeClock(DateTime.parse("2025-01-10T01:00:00.000Z")); + private final FakeClock clock = new FakeClock(Instant.parse("2025-01-10T01:00:00.000Z")); @RegisterExtension final JpaIntegrationTestExtension jpa = @@ -247,7 +252,7 @@ void testFailure_redeemToken_nonSingleUse() { IllegalArgumentException.class, () -> AllocationTokenFlowUtils.redeemToken( - createOneMonthPromoTokenBuilder(clock.nowUtc()).build(), + createOneMonthPromoTokenBuilder(clock.now()).build(), new HistoryEntryId("repoId", 10L))); } @@ -265,7 +270,7 @@ void testFailure_loadFromExtension_nullToken() { @Test void testFailure_tokenInvalidForRegistrar() { persistResource( - createOneMonthPromoTokenBuilder(clock.nowUtc().minusDays(1)) + createOneMonthPromoTokenBuilder(minusDays(clock.now(), 1)) .setAllowedRegistrarIds(ImmutableSet.of("NewRegistrar")) .build()); assertLoadTokenFromExtensionThrowsException(AllocationTokenNotValidForRegistrarException.class); @@ -273,13 +278,13 @@ void testFailure_tokenInvalidForRegistrar() { @Test void testFailure_beforePromoStart() { - persistResource(createOneMonthPromoTokenBuilder(clock.nowUtc().plusDays(1)).build()); + persistResource(createOneMonthPromoTokenBuilder(plusDays(clock.now(), 1)).build()); assertLoadTokenFromExtensionThrowsException(AllocationTokenNotInPromotionException.class); } @Test void testFailure_afterPromoEnd() { - persistResource(createOneMonthPromoTokenBuilder(clock.nowUtc().minusMonths(2)).build()); + persistResource(createOneMonthPromoTokenBuilder(minusMonths(clock.now(), 2)).build()); assertLoadTokenFromExtensionThrowsException(AllocationTokenNotInPromotionException.class); } @@ -287,12 +292,12 @@ void testFailure_afterPromoEnd() { void testFailure_promoCancelled() { // the promo would be valid, but it was cancelled 12 hours ago persistResource( - createOneMonthPromoTokenBuilder(clock.nowUtc().minusDays(1)) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, NOT_STARTED) - .put(clock.nowUtc().minusMonths(1), VALID) - .put(clock.nowUtc().minusHours(12), CANCELLED) + createOneMonthPromoTokenBuilder(minusDays(clock.now(), 1)) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, NOT_STARTED) + .put(minusMonths(clock.now(), 1), VALID) + .put(clock.now().minus(Duration.ofHours(12)), CANCELLED) .build()) .build()); assertLoadTokenFromExtensionThrowsException(AllocationTokenNotInPromotionException.class); @@ -475,16 +480,16 @@ private AllocationToken.Builder singleUseTokenBuilder() { .setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar")); } - private AllocationToken.Builder createOneMonthPromoTokenBuilder(DateTime promoStart) { + private AllocationToken.Builder createOneMonthPromoTokenBuilder(Instant promoStart) { when(allocationTokenExtension.getAllocationToken()).thenReturn("tokeN"); return new AllocationToken.Builder() .setToken("tokeN") .setTokenType(UNLIMITED_USE) - .setTokenStatusTransitions( - ImmutableSortedMap.naturalOrder() - .put(START_OF_TIME, NOT_STARTED) + .setTokenStatusTransitionsInstant( + ImmutableSortedMap.naturalOrder() + .put(START_INSTANT, NOT_STARTED) .put(promoStart, VALID) - .put(promoStart.plusMonths(1), ENDED) + .put(plusMonths(promoStart, 1), ENDED) .build()); } } diff --git a/core/src/test/java/google/registry/flows/host/HostDeleteFlowTest.java b/core/src/test/java/google/registry/flows/host/HostDeleteFlowTest.java index 187a04965c1..1c0af852600 100644 --- a/core/src/test/java/google/registry/flows/host/HostDeleteFlowTest.java +++ b/core/src/test/java/google/registry/flows/host/HostDeleteFlowTest.java @@ -345,7 +345,7 @@ private void assertSqlDeleteSuccess(boolean isSubordinate) throws Exception { Host deletedHost = reloadResourceByForeignKey(clock.nowUtc().minusMillis(1)); assertAboutHosts() .that(deletedHost) - .isNotActiveAt(clock.nowUtc()) + .isNotActiveAt(clock.now()) .and() .hasExactlyStatusValues(StatusValue.OK) .and() diff --git a/core/src/test/java/google/registry/flows/host/HostUpdateFlowTest.java b/core/src/test/java/google/registry/flows/host/HostUpdateFlowTest.java index c7e1ea7e537..2fcc3d7a2e7 100644 --- a/core/src/test/java/google/registry/flows/host/HostUpdateFlowTest.java +++ b/core/src/test/java/google/registry/flows/host/HostUpdateFlowTest.java @@ -408,7 +408,7 @@ void testSuccess_internalToExternal() throws Exception { .and() .hasLastSuperordinateChange(clock.nowUtc()); assertThat(renamedHost.getLastTransferTime()).isEqualTo(oneDayAgo); - Domain reloadedDomain = loadByEntity(domain).cloneProjectedAtTime(clock.nowUtc()); + Domain reloadedDomain = loadByEntity(domain).cloneProjectedAtInstant(clock.now()); assertThat(reloadedDomain.getSubordinateHosts()).isEmpty(); assertHostDnsRequests("ns1.example.foo"); } diff --git a/core/src/test/java/google/registry/model/CreateAutoTimestampTest.java b/core/src/test/java/google/registry/model/CreateAutoTimestampTest.java index 9f7dd5dff1a..d6fda01b468 100644 --- a/core/src/test/java/google/registry/model/CreateAutoTimestampTest.java +++ b/core/src/test/java/google/registry/model/CreateAutoTimestampTest.java @@ -17,6 +17,7 @@ import static com.google.common.truth.Truth.assertThat; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.testing.DatabaseHelper.loadByEntity; +import static google.registry.util.DateTimeUtils.minusDays; import google.registry.model.common.CrossTldSingleton; import google.registry.persistence.transaction.JpaTestExtensions; @@ -24,7 +25,6 @@ import google.registry.testing.FakeClock; import jakarta.persistence.Entity; import jakarta.persistence.Id; -import java.time.Duration; import java.time.Instant; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -67,7 +67,7 @@ void testSaveSetsTime() { @Test void testResavingRespectsOriginalTime() { - final Instant oldCreateTime = clock.now().minus(Duration.ofDays(1)); + final Instant oldCreateTime = minusDays(clock.now(), 1); tm().transact( () -> { CreateAutoTimestampTestObject object = new CreateAutoTimestampTestObject(); diff --git a/core/src/test/java/google/registry/model/UpdateAutoTimestampTest.java b/core/src/test/java/google/registry/model/UpdateAutoTimestampTest.java index 3fc66e2093f..31c073d5aef 100644 --- a/core/src/test/java/google/registry/model/UpdateAutoTimestampTest.java +++ b/core/src/test/java/google/registry/model/UpdateAutoTimestampTest.java @@ -17,6 +17,7 @@ import static com.google.common.truth.Truth.assertThat; import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.util.DateTimeUtils.START_INSTANT; +import static google.registry.util.DateTimeUtils.minusDays; import google.registry.model.common.CrossTldSingleton; import google.registry.persistence.VKey; @@ -25,7 +26,6 @@ import google.registry.testing.FakeClock; import jakarta.persistence.Entity; import jakarta.persistence.Id; -import java.time.Duration; import java.time.Instant; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -75,8 +75,7 @@ void testResavingOverwritesOriginalTime() { () -> { clock.advanceOneMilli(); UpdateAutoTimestampTestObject object = new UpdateAutoTimestampTestObject(); - object.updateTime = - UpdateAutoTimestamp.create(clock.now().minus(Duration.ofDays(1))); + object.updateTime = UpdateAutoTimestamp.create(minusDays(clock.now(), 1)); tm().insert(object); return tm().getTxTime(); }); diff --git a/core/src/test/java/google/registry/model/adapters/StatusValueAdapterTest.java b/core/src/test/java/google/registry/model/adapters/StatusValueAdapterTest.java index c5de47c4be6..f6961f74c31 100644 --- a/core/src/test/java/google/registry/model/adapters/StatusValueAdapterTest.java +++ b/core/src/test/java/google/registry/model/adapters/StatusValueAdapterTest.java @@ -15,7 +15,7 @@ package google.registry.model.adapters; import static com.google.common.truth.Truth.assertThat; -import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.START_INSTANT; import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.collect.ImmutableMap; @@ -46,7 +46,7 @@ void testMarshalling() throws Exception { .setResData( HostInfoData.newBuilder() .setCreationRegistrarId("") - .setCreationTime(START_OF_TIME) + .setCreationTime(START_INSTANT) .setCurrentSponsorRegistrarId("") .setHostName("") .setInetAddresses(ImmutableSet.of()) diff --git a/core/src/test/java/google/registry/model/domain/DomainSqlTest.java b/core/src/test/java/google/registry/model/domain/DomainSqlTest.java index 0c26a523002..a6eec201ea4 100644 --- a/core/src/test/java/google/registry/model/domain/DomainSqlTest.java +++ b/core/src/test/java/google/registry/model/domain/DomainSqlTest.java @@ -28,6 +28,7 @@ import static google.registry.testing.SqlHelper.saveRegistrar; import static google.registry.util.DateTimeUtils.END_INSTANT; import static google.registry.util.DateTimeUtils.START_INSTANT; +import static google.registry.util.DateTimeUtils.plusDays; import static google.registry.util.DateTimeUtils.plusYears; import com.google.common.collect.ImmutableList; @@ -131,7 +132,7 @@ void setUp() { ImmutableSortedMap.naturalOrder() .put(START_INSTANT, NOT_STARTED) .put(fakeClock.now(), TokenStatus.VALID) - .put(fakeClock.now().plus(java.time.Duration.ofDays(56)), TokenStatus.ENDED) + .put(plusDays(fakeClock.now(), 56), TokenStatus.ENDED) .build()) .build(); } diff --git a/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java b/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java index 9399dfd2cc8..c73a98e9c9a 100644 --- a/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java +++ b/core/src/test/java/google/registry/model/domain/token/AllocationTokenTest.java @@ -28,6 +28,7 @@ import static google.registry.testing.DatabaseHelper.persistActiveDomain; import static google.registry.testing.DatabaseHelper.persistResource; import static google.registry.util.DateTimeUtils.START_INSTANT; +import static google.registry.util.DateTimeUtils.plusDays; import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.common.collect.ImmutableSet; @@ -77,7 +78,7 @@ void testPersistence() { ImmutableSortedMap.naturalOrder() .put(START_INSTANT, NOT_STARTED) .put(fakeClock.now(), TokenStatus.VALID) - .put(fakeClock.now().plus(java.time.Duration.ofDays(56)), TokenStatus.ENDED) + .put(plusDays(fakeClock.now(), 56), TokenStatus.ENDED) .build()) .setAllowedEppActions(ImmutableSet.of(CommandName.CREATE, CommandName.RENEW)) .build()); @@ -114,7 +115,7 @@ void testSerializable() { ImmutableSortedMap.naturalOrder() .put(START_INSTANT, NOT_STARTED) .put(fakeClock.now(), TokenStatus.VALID) - .put(fakeClock.now().plus(java.time.Duration.ofDays(56)), TokenStatus.ENDED) + .put(plusDays(fakeClock.now(), 56), TokenStatus.ENDED) .build()) .setAllowedEppActions(ImmutableSet.of(CommandName.CREATE, CommandName.RENEW)) .build()); @@ -422,12 +423,8 @@ void testSetTransitions_notStartOfTime() { .setTokenStatusTransitionsInstant( ImmutableSortedMap.naturalOrder() .put(fakeClock.now(), NOT_STARTED) - .put( - fakeClock.now().plus(java.time.Duration.ofDays(1)), - TokenStatus.VALID) - .put( - fakeClock.now().plus(java.time.Duration.ofDays(2)), - TokenStatus.ENDED) + .put(plusDays(fakeClock.now(), 1), TokenStatus.VALID) + .put(plusDays(fakeClock.now(), 2), TokenStatus.ENDED) .build())); assertThat(thrown) .hasMessageThat() @@ -465,7 +462,7 @@ void testSetTransitions_badTransitionsFromValid() { ImmutableSortedMap.naturalOrder() .put(START_INSTANT, NOT_STARTED) .put(fakeClock.now(), VALID) - .put(fakeClock.now().plus(java.time.Duration.ofDays(1)), VALID) + .put(plusDays(fakeClock.now(), 1), VALID) .build(), VALID, VALID); @@ -473,7 +470,7 @@ void testSetTransitions_badTransitionsFromValid() { ImmutableSortedMap.naturalOrder() .put(START_INSTANT, NOT_STARTED) .put(fakeClock.now(), VALID) - .put(fakeClock.now().plus(java.time.Duration.ofDays(1)), NOT_STARTED) + .put(plusDays(fakeClock.now(), 1), NOT_STARTED) .build(), VALID, NOT_STARTED); @@ -741,8 +738,8 @@ private void assertTerminal(TokenStatus status) { ImmutableSortedMap.naturalOrder() .put(START_INSTANT, NOT_STARTED) .put(fakeClock.now(), VALID) - .put(fakeClock.now().plus(java.time.Duration.ofDays(1)), status) - .put(fakeClock.now().plus(java.time.Duration.ofDays(2)), CANCELLED) + .put(plusDays(fakeClock.now(), 1), status) + .put(plusDays(fakeClock.now(), 2), CANCELLED) .build())); assertThat(thrown) .hasMessageThat() diff --git a/core/src/test/java/google/registry/model/smd/SignedMarkRevocationListDaoTest.java b/core/src/test/java/google/registry/model/smd/SignedMarkRevocationListDaoTest.java index 337a7e54f75..b86ea81208e 100644 --- a/core/src/test/java/google/registry/model/smd/SignedMarkRevocationListDaoTest.java +++ b/core/src/test/java/google/registry/model/smd/SignedMarkRevocationListDaoTest.java @@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableMap; import google.registry.model.EntityTestCase; import jakarta.persistence.OptimisticLockException; +import java.time.Duration; import java.util.concurrent.atomic.AtomicBoolean; import org.junit.jupiter.api.Test; @@ -34,7 +35,7 @@ public SignedMarkRevocationListDaoTest() { void testSave_success() { SignedMarkRevocationList list = SignedMarkRevocationList.create( - fakeClock.nowUtc(), ImmutableMap.of("mark", fakeClock.nowUtc().minusHours(1))); + fakeClock.now(), ImmutableMap.of("mark", fakeClock.now().minus(Duration.ofHours(1)))); list = SignedMarkRevocationListDao.save(list); SignedMarkRevocationList fromDb = SignedMarkRevocationListDao.load(); assertAboutImmutableObjects().that(fromDb).isEqualExceptFields(list); @@ -44,7 +45,7 @@ void testSave_success() { void testSave_retrySuccess() { SignedMarkRevocationList list = SignedMarkRevocationList.create( - fakeClock.nowUtc(), ImmutableMap.of("mark", fakeClock.nowUtc().minusHours(1))); + fakeClock.now(), ImmutableMap.of("mark", fakeClock.now().minus(Duration.ofHours(1)))); AtomicBoolean isFirstAttempt = new AtomicBoolean(true); tm().transact( () -> { @@ -61,7 +62,7 @@ void testSave_retrySuccess() { @Test void testSaveAndLoad_emptyList() { SignedMarkRevocationList list = - SignedMarkRevocationList.create(fakeClock.nowUtc(), ImmutableMap.of()); + SignedMarkRevocationList.create(fakeClock.now(), ImmutableMap.of()); SignedMarkRevocationListDao.save(list); SignedMarkRevocationList fromDb = SignedMarkRevocationListDao.load(); assertAboutImmutableObjects().that(fromDb).isEqualExceptFields(list, "revisionId"); @@ -71,17 +72,14 @@ void testSaveAndLoad_emptyList() { void testSave_multipleVersions() { SignedMarkRevocationList list = SignedMarkRevocationList.create( - fakeClock.nowUtc(), ImmutableMap.of("mark", fakeClock.nowUtc().minusHours(1))); + fakeClock.now(), ImmutableMap.of("mark", fakeClock.now().minus(Duration.ofHours(1)))); SignedMarkRevocationListDao.save(list); - assertThat(SignedMarkRevocationListDao.load().isSmdRevoked("mark", fakeClock.nowUtc())) - .isTrue(); + assertThat(SignedMarkRevocationListDao.load().isSmdRevoked("mark", fakeClock.now())).isTrue(); // Now remove the revocation SignedMarkRevocationList secondList = - SignedMarkRevocationList.create(fakeClock.nowUtc(), ImmutableMap.of()); + SignedMarkRevocationList.create(fakeClock.now(), ImmutableMap.of()); SignedMarkRevocationListDao.save(secondList); - assertThat(SignedMarkRevocationListDao.load().isSmdRevoked("mark", fakeClock.nowUtc())) - .isFalse(); + assertThat(SignedMarkRevocationListDao.load().isSmdRevoked("mark", fakeClock.now())).isFalse(); } - } diff --git a/core/src/test/java/google/registry/model/smd/SignedMarkRevocationListTest.java b/core/src/test/java/google/registry/model/smd/SignedMarkRevocationListTest.java index cc4881600eb..1342f293217 100644 --- a/core/src/test/java/google/registry/model/smd/SignedMarkRevocationListTest.java +++ b/core/src/test/java/google/registry/model/smd/SignedMarkRevocationListTest.java @@ -15,7 +15,7 @@ package google.registry.model.smd; import static com.google.common.truth.Truth.assertThat; -import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.START_INSTANT; import static org.joda.time.Duration.standardDays; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -23,7 +23,7 @@ import google.registry.persistence.transaction.JpaTestExtensions; import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension; import google.registry.testing.FakeClock; -import org.joda.time.DateTime; +import java.time.Instant; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -34,22 +34,21 @@ public class SignedMarkRevocationListTest { final JpaIntegrationTestExtension jpa = new JpaTestExtensions.Builder().buildIntegrationTestExtension(); - private final FakeClock clock = new FakeClock(DateTime.parse("2013-01-01T00:00:00Z")); + private final FakeClock clock = new FakeClock(Instant.parse("2013-01-01T00:00:00Z")); @Test void testEmpty() { // When Cloud SQL is empty, it should give us an empty thing. assertThat(SignedMarkRevocationList.get()) - .isEqualTo(SignedMarkRevocationList.create(START_OF_TIME, ImmutableMap.of())); + .isEqualTo(SignedMarkRevocationList.create(START_INSTANT, ImmutableMap.of())); } private SignedMarkRevocationList createSaveGetHelper(int rows) { - ImmutableMap.Builder revokes = new ImmutableMap.Builder<>(); + ImmutableMap.Builder revokes = new ImmutableMap.Builder<>(); for (int i = 0; i < rows; i++) { - revokes.put(Integer.toString(i), clock.nowUtc()); + revokes.put(Integer.toString(i), clock.now()); } - SignedMarkRevocationListDao.save( - SignedMarkRevocationList.create(clock.nowUtc(), revokes.build())); + SignedMarkRevocationListDao.save(SignedMarkRevocationList.create(clock.now(), revokes.build())); SignedMarkRevocationList res = SignedMarkRevocationList.get(); assertThat(res.size()).isEqualTo(rows); return res; @@ -60,36 +59,36 @@ void test_isSmdRevoked_null() { assertThrows( NullPointerException.class, () -> - SignedMarkRevocationList.create(START_OF_TIME, ImmutableMap.of()) - .isSmdRevoked(null, clock.nowUtc())); + SignedMarkRevocationList.create(START_INSTANT, ImmutableMap.of()) + .isSmdRevoked(null, clock.now())); } @Test void test_isSmdRevoked_garbage() { SignedMarkRevocationList smdrl = createSaveGetHelper(100); - assertThat(smdrl.getCreationTime()).isEqualTo(clock.nowUtc()); - assertThat(smdrl.isSmdRevoked("rofl", clock.nowUtc())).isFalse(); - assertThat(smdrl.isSmdRevoked("31337", clock.nowUtc())).isFalse(); + assertThat(smdrl.getCreationTime()).isEqualTo(clock.now()); + assertThat(smdrl.isSmdRevoked("rofl", clock.now())).isFalse(); + assertThat(smdrl.isSmdRevoked("31337", clock.now())).isFalse(); } @Test void test_getCreationTime() { - clock.setTo(DateTime.parse("2000-01-01T00:00:00Z")); + clock.setTo(Instant.parse("2000-01-01T00:00:00Z")); createSaveGetHelper(5); assertThat(SignedMarkRevocationList.get().getCreationTime()) - .isEqualTo(DateTime.parse("2000-01-01T00:00:00Z")); + .isEqualTo(Instant.parse("2000-01-01T00:00:00Z")); clock.advanceBy(standardDays(1)); assertThat(SignedMarkRevocationList.get().getCreationTime()) - .isEqualTo(DateTime.parse("2000-01-01T00:00:00Z")); + .isEqualTo(Instant.parse("2000-01-01T00:00:00Z")); } @Test void test_isSmdRevoked_present() { final int rows = 100; SignedMarkRevocationList smdrl = createSaveGetHelper(rows); - assertThat(smdrl.isSmdRevoked("0", clock.nowUtc())).isTrue(); - assertThat(smdrl.isSmdRevoked(Integer.toString(rows - 1), clock.nowUtc())).isTrue(); - assertThat(smdrl.isSmdRevoked(Integer.toString(rows), clock.nowUtc())).isFalse(); + assertThat(smdrl.isSmdRevoked("0", clock.now())).isTrue(); + assertThat(smdrl.isSmdRevoked(Integer.toString(rows - 1), clock.now())).isTrue(); + assertThat(smdrl.isSmdRevoked(Integer.toString(rows), clock.now())).isFalse(); } @Test @@ -97,18 +96,18 @@ void test_isSmdRevoked_future() { final int rows = 100; SignedMarkRevocationList smdrl = createSaveGetHelper(rows); clock.advanceOneMilli(); - assertThat(smdrl.isSmdRevoked("0", clock.nowUtc())).isTrue(); - assertThat(smdrl.isSmdRevoked(Integer.toString(rows - 1), clock.nowUtc())).isTrue(); - assertThat(smdrl.isSmdRevoked(Integer.toString(rows), clock.nowUtc())).isFalse(); + assertThat(smdrl.isSmdRevoked("0", clock.now())).isTrue(); + assertThat(smdrl.isSmdRevoked(Integer.toString(rows - 1), clock.now())).isTrue(); + assertThat(smdrl.isSmdRevoked(Integer.toString(rows), clock.now())).isFalse(); } @Test void test_isSmdRevoked_past() { final int rows = 100; SignedMarkRevocationList smdrl = createSaveGetHelper(rows); - clock.setTo(clock.nowUtc().minusMillis(1)); - assertThat(smdrl.isSmdRevoked("0", clock.nowUtc())).isFalse(); - assertThat(smdrl.isSmdRevoked(Integer.toString(rows - 1), clock.nowUtc())).isFalse(); - assertThat(smdrl.isSmdRevoked(Integer.toString(rows), clock.nowUtc())).isFalse(); + clock.setTo(clock.now().minusMillis(1)); + assertThat(smdrl.isSmdRevoked("0", clock.now())).isFalse(); + assertThat(smdrl.isSmdRevoked(Integer.toString(rows - 1), clock.now())).isFalse(); + assertThat(smdrl.isSmdRevoked(Integer.toString(rows), clock.now())).isFalse(); } } diff --git a/core/src/test/java/google/registry/model/tmch/ClaimsListDaoTest.java b/core/src/test/java/google/registry/model/tmch/ClaimsListDaoTest.java index 560df6ee435..340b4a362b3 100644 --- a/core/src/test/java/google/registry/model/tmch/ClaimsListDaoTest.java +++ b/core/src/test/java/google/registry/model/tmch/ClaimsListDaoTest.java @@ -69,8 +69,8 @@ void save_insertsClaimsListSuccessfully_withRetries() { } }); ClaimsList insertedClaimsList = ClaimsListDao.get(); - assertThat(insertedClaimsList.getTmdbGenerationTimeInstant()) - .isEqualTo(claimsList.getTmdbGenerationTimeInstant()); + assertThat(insertedClaimsList.getTmdbGenerationTime()) + .isEqualTo(claimsList.getTmdbGenerationTime()); assertThat(insertedClaimsList.getLabelsToKeys()).isEqualTo(claimsList.getLabelsToKeys()); assertThat(insertedClaimsList.getCreationTime()).isEqualTo(fakeClock.now()); } @@ -140,7 +140,7 @@ void testEntryCaching_savesAndUpdates() { private void assertClaimsListEquals(ClaimsList left, ClaimsList right) { assertThat(left.getRevisionId()).isEqualTo(right.getRevisionId()); - assertThat(left.getTmdbGenerationTimeInstant()).isEqualTo(right.getTmdbGenerationTimeInstant()); + assertThat(left.getTmdbGenerationTime()).isEqualTo(right.getTmdbGenerationTime()); assertThat(left.getLabelsToKeys()).isEqualTo(right.getLabelsToKeys()); } } diff --git a/core/src/test/java/google/registry/pricing/PricingEngineProxyTest.java b/core/src/test/java/google/registry/pricing/PricingEngineProxyTest.java index f008fc7244d..881d2a57f50 100644 --- a/core/src/test/java/google/registry/pricing/PricingEngineProxyTest.java +++ b/core/src/test/java/google/registry/pricing/PricingEngineProxyTest.java @@ -21,7 +21,7 @@ import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.persistPremiumList; import static google.registry.testing.DatabaseHelper.persistResource; -import static google.registry.util.DateTimeUtils.START_OF_TIME; +import static google.registry.util.DateTimeUtils.START_INSTANT; import static org.joda.money.CurrencyUnit.USD; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -32,8 +32,8 @@ import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension; import google.registry.testing.FakeClock; import google.registry.util.Clock; +import java.time.Instant; import org.joda.money.Money; -import org.joda.time.DateTime; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -54,39 +54,39 @@ void beforeEach() { "premium list", USD, "rich,USD 100", "richer,USD 999", "fraction,USD 20.50"); createTld("moka"); persistResource(Tld.get("moka").asBuilder().setPremiumList(premiumList).build()); - clock = new FakeClock(DateTime.parse("2016-03-17T12:01:00Z")); + clock = new FakeClock(Instant.parse("2016-03-17T12:01:00Z")); } @Test void test_getDomainCreateCost_multipleYears() { - assertThat(getDomainCreateCost("espresso.moka", clock.nowUtc(), 1)) + assertThat(getDomainCreateCost("espresso.moka", clock.now(), 1)) .isEqualTo(Money.parse("USD 13")); - assertThat(getDomainCreateCost("espresso.moka", clock.nowUtc(), 5)) + assertThat(getDomainCreateCost("espresso.moka", clock.now(), 5)) .isEqualTo(Money.parse("USD 65")); - assertThat(getDomainCreateCost("fraction.moka", clock.nowUtc(), 1)) + assertThat(getDomainCreateCost("fraction.moka", clock.now(), 1)) .isEqualTo(Money.parse("USD 20.50")); - assertThat(getDomainCreateCost("fraction.moka", clock.nowUtc(), 3)) + assertThat(getDomainCreateCost("fraction.moka", clock.now(), 3)) .isEqualTo(Money.parse("USD 61.50")); } @Test void test_getDomainRenewCost_multipleYears() { - assertThat(getDomainRenewCost("espresso.moka", clock.nowUtc(), 1)) + assertThat(getDomainRenewCost("espresso.moka", clock.now(), 1)) .isEqualTo(Money.parse("USD 11")); - assertThat(getDomainRenewCost("espresso.moka", clock.nowUtc(), 5)) + assertThat(getDomainRenewCost("espresso.moka", clock.now(), 5)) .isEqualTo(Money.parse("USD 55")); - assertThat(getDomainRenewCost("fraction.moka", clock.nowUtc(), 1)) + assertThat(getDomainRenewCost("fraction.moka", clock.now(), 1)) .isEqualTo(Money.parse("USD 20.50")); - assertThat(getDomainRenewCost("fraction.moka", clock.nowUtc(), 3)) + assertThat(getDomainRenewCost("fraction.moka", clock.now(), 3)) .isEqualTo(Money.parse("USD 61.50")); } @Test void testIsPremiumDomain() { createTld("example"); - assertThat(isDomainPremium("poor.example", clock.nowUtc())).isFalse(); - assertThat(isDomainPremium("rich.example", clock.nowUtc())).isTrue(); - assertThat(isDomainPremium("richer.example", clock.nowUtc())).isTrue(); + assertThat(isDomainPremium("poor.example", clock.now())).isFalse(); + assertThat(isDomainPremium("rich.example", clock.now())).isTrue(); + assertThat(isDomainPremium("richer.example", clock.now())).isTrue(); } @Test @@ -94,12 +94,10 @@ void testGetDomainCreateCost() { // The example tld has a premium price for "rich". createTld("example"); // The default value of 17 is set in createTld(). - assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), 1)).isEqualTo(Money.of(USD, 13)); - assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), 2)).isEqualTo(Money.of(USD, 26)); - assertThat(getDomainCreateCost("rich.example", clock.nowUtc(), 1)) - .isEqualTo(Money.of(USD, 100)); - assertThat(getDomainCreateCost("rich.example", clock.nowUtc(), 2)) - .isEqualTo(Money.of(USD, 200)); + assertThat(getDomainCreateCost("poor.example", clock.now(), 1)).isEqualTo(Money.of(USD, 13)); + assertThat(getDomainCreateCost("poor.example", clock.now(), 2)).isEqualTo(Money.of(USD, 26)); + assertThat(getDomainCreateCost("rich.example", clock.now(), 1)).isEqualTo(Money.of(USD, 100)); + assertThat(getDomainCreateCost("rich.example", clock.now(), 2)).isEqualTo(Money.of(USD, 200)); } @Test @@ -109,18 +107,18 @@ void testGetDomainRenewCost() { persistResource( Tld.get("example") .asBuilder() - .setRenewBillingCostTransitions( + .setRenewBillingCostTransitionsInstant( ImmutableSortedMap.of( - START_OF_TIME, Money.of(USD, 8), clock.nowUtc(), Money.of(USD, 10))) + START_INSTANT, Money.of(USD, 8), clock.now(), Money.of(USD, 10))) .build()); - assertThat(getDomainRenewCost("poor.example", START_OF_TIME, 1)).isEqualTo(Money.of(USD, 8)); - assertThat(getDomainRenewCost("poor.example", START_OF_TIME, 2)).isEqualTo(Money.of(USD, 16)); - assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), 1)).isEqualTo(Money.of(USD, 10)); - assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), 2)).isEqualTo(Money.of(USD, 20)); - assertThat(getDomainRenewCost("rich.example", START_OF_TIME, 1)).isEqualTo(Money.of(USD, 100)); - assertThat(getDomainRenewCost("rich.example", START_OF_TIME, 2)).isEqualTo(Money.of(USD, 200)); - assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), 1)).isEqualTo(Money.of(USD, 100)); - assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), 2)).isEqualTo(Money.of(USD, 200)); + assertThat(getDomainRenewCost("poor.example", START_INSTANT, 1)).isEqualTo(Money.of(USD, 8)); + assertThat(getDomainRenewCost("poor.example", START_INSTANT, 2)).isEqualTo(Money.of(USD, 16)); + assertThat(getDomainRenewCost("poor.example", clock.now(), 1)).isEqualTo(Money.of(USD, 10)); + assertThat(getDomainRenewCost("poor.example", clock.now(), 2)).isEqualTo(Money.of(USD, 20)); + assertThat(getDomainRenewCost("rich.example", START_INSTANT, 1)).isEqualTo(Money.of(USD, 100)); + assertThat(getDomainRenewCost("rich.example", START_INSTANT, 2)).isEqualTo(Money.of(USD, 200)); + assertThat(getDomainRenewCost("rich.example", clock.now(), 1)).isEqualTo(Money.of(USD, 100)); + assertThat(getDomainRenewCost("rich.example", clock.now(), 2)).isEqualTo(Money.of(USD, 200)); } @Test @@ -129,8 +127,7 @@ void testFailure_cantLoadPricingEngine() { persistResource(Tld.get("example").asBuilder().setPremiumPricingEngine("fake").build()); IllegalStateException thrown = assertThrows( - IllegalStateException.class, - () -> getDomainCreateCost("bad.example", clock.nowUtc(), 1)); + IllegalStateException.class, () -> getDomainCreateCost("bad.example", clock.now(), 1)); assertThat(thrown) .hasMessageThat() .contains("Could not load pricing engine fake for TLD example"); diff --git a/core/src/test/java/google/registry/rdap/RdapJsonFormatterTest.java b/core/src/test/java/google/registry/rdap/RdapJsonFormatterTest.java index 97dc0c9b8c3..7e89ef06fc6 100644 --- a/core/src/test/java/google/registry/rdap/RdapJsonFormatterTest.java +++ b/core/src/test/java/google/registry/rdap/RdapJsonFormatterTest.java @@ -151,7 +151,7 @@ void beforeEach() { makeDomain("fish.みんな", null, null, registrar) .asBuilder() .setCreationTimeForTest(clock.nowUtc()) - .setLastEppUpdateTime((java.time.Instant) null) + .setLastEppUpdateTime((Instant) null) .build()); // history entries diff --git a/core/src/test/java/google/registry/testing/AbstractEppResourceSubject.java b/core/src/test/java/google/registry/testing/AbstractEppResourceSubject.java index dbb4bfc6b18..b45d4d32385 100644 --- a/core/src/test/java/google/registry/testing/AbstractEppResourceSubject.java +++ b/core/src/test/java/google/registry/testing/AbstractEppResourceSubject.java @@ -32,6 +32,7 @@ import google.registry.model.reporting.HistoryEntry; import google.registry.testing.TruthChainer.And; import google.registry.testing.TruthChainer.Which; +import java.time.Instant; import java.util.List; import java.util.Optional; import javax.annotation.Nullable; @@ -153,16 +154,30 @@ public And hasDeletionTime(DateTime deletionTime) { return hasValue(deletionTime, actual.getDeletionDateTime(), "getDeletionTime()"); } + public And hasDeletionTime(Instant deletionTime) { + return hasValue(deletionTime, actual.getDeletionTime(), "getDeletionTime()"); + } + public And hasLastEppUpdateTime(DateTime lastUpdateTime) { return hasValue(lastUpdateTime, actual.getLastEppUpdateDateTime(), "has lastEppUpdateTime"); } + public And hasLastEppUpdateTime(Instant lastUpdateTime) { + return hasValue(lastUpdateTime, actual.getLastEppUpdateTime(), "has lastEppUpdateTime"); + } + public And hasLastEppUpdateTimeAtLeast(DateTime before) { DateTime lastEppUpdateTime = actual.getLastEppUpdateDateTime(); check("getLastEppUpdateTime()").that(lastEppUpdateTime).isAtLeast(before); return andChainer(); } + public And hasLastEppUpdateTimeAtLeast(Instant before) { + Instant lastEppUpdateTime = actual.getLastEppUpdateTime(); + check("getLastEppUpdateTime()").that(lastEppUpdateTime).isAtLeast(before); + return andChainer(); + } + public And hasLastEppUpdateRegistrarId(String registrarId) { return hasValue( registrarId, actual.getLastEppUpdateRegistrarId(), "getLastEppUpdateRegistrarId()"); @@ -182,9 +197,23 @@ public And isActiveAt(DateTime time) { return andChainer(); } + public And isActiveAt(Instant time) { + if (!isActive(actual, DateTime.parse(time.toString()))) { + failWithActual("expected to be active at", time); + } + return andChainer(); + } + public And isNotActiveAt(DateTime time) { if (isActive(actual, time)) { - failWithActual("expected not to be active at", time); + failWithActual("expected to not be active at", time); + } + return andChainer(); + } + + public And isNotActiveAt(Instant time) { + if (isActive(actual, DateTime.parse(time.toString()))) { + failWithActual("expected to not be active at", time); } return andChainer(); } diff --git a/core/src/test/java/google/registry/testing/DatabaseHelper.java b/core/src/test/java/google/registry/testing/DatabaseHelper.java index c78fb15581c..bc930796c8c 100644 --- a/core/src/test/java/google/registry/testing/DatabaseHelper.java +++ b/core/src/test/java/google/registry/testing/DatabaseHelper.java @@ -38,7 +38,8 @@ import static google.registry.util.CollectionUtils.union; import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME; -import static google.registry.util.DateTimeUtils.isBeforeOrAt; +import static google.registry.util.DateTimeUtils.toDateTime; +import static google.registry.util.DateTimeUtils.toInstant; import static google.registry.util.DomainNameUtils.ACE_PREFIX_REGEX; import static google.registry.util.DomainNameUtils.getTldFromDomainName; import static google.registry.util.PreconditionsUtils.checkArgumentPresent; @@ -102,6 +103,7 @@ import google.registry.model.transfer.DomainTransferData; import google.registry.model.transfer.TransferStatus; import google.registry.persistence.VKey; +import java.time.Instant; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -267,6 +269,10 @@ public static Domain persistDeletedDomain(String domainName, DateTime deletionTi * Returns a persisted domain that is the passed-in domain modified to be deleted at the specified * time. */ + public static Domain persistDomainAsDeleted(Domain domain, Instant deletionTime) { + return persistResource(domain.asBuilder().setDeletionTime(deletionTime).build()); + } + public static Domain persistDomainAsDeleted(Domain domain, DateTime deletionTime) { return persistResource(domain.asBuilder().setDeletionTime(deletionTime).build()); } @@ -446,6 +452,24 @@ private static DomainTransferData.Builder createDomainTransferDataBuilder( .setPendingTransferExpirationTime(expirationTime); } + public static PollMessage.OneTime createPollMessageForImplicitTransfer( + Domain domain, + HistoryEntry historyEntry, + String registrarId, + Instant requestTime, + Instant expirationTime, + @Nullable Instant extendedRegistrationExpirationTime) { + return createPollMessageForImplicitTransfer( + domain, + historyEntry, + registrarId, + toDateTime(requestTime), + toDateTime(expirationTime), + extendedRegistrationExpirationTime != null + ? toDateTime(extendedRegistrationExpirationTime) + : null); + } + public static PollMessage.OneTime createPollMessageForImplicitTransfer( Domain domain, HistoryEntry historyEntry, @@ -466,6 +490,12 @@ public static PollMessage.OneTime createPollMessageForImplicitTransfer( .build(); } + public static BillingEvent createBillingEventForTransfer( + Domain domain, DomainHistory historyEntry, Instant costLookupTime, Instant eventTime) { + return createBillingEventForTransfer( + domain, historyEntry, toDateTime(costLookupTime), toDateTime(eventTime)); + } + public static BillingEvent createBillingEventForTransfer( Domain domain, DomainHistory historyEntry, DateTime costLookupTime, DateTime eventTime) { return new BillingEvent.Builder() @@ -475,11 +505,17 @@ public static BillingEvent createBillingEventForTransfer( .setBillingTime(eventTime.plus(Tld.get(domain.getTld()).getTransferGracePeriodLength())) .setRegistrarId("NewRegistrar") .setPeriodYears(1) - .setCost(getDomainRenewCost(domain.getDomainName(), costLookupTime, 1)) + .setCost(getDomainRenewCost(domain.getDomainName(), toInstant(costLookupTime), 1)) .setDomainHistory(historyEntry) .build(); } + public static Domain persistDomainWithDependentResources( + String label, String tld, Instant now, Instant creationTime, Instant expirationTime) { + return persistDomainWithDependentResources( + label, tld, toDateTime(now), toDateTime(creationTime), toDateTime(expirationTime)); + } + public static Domain persistDomainWithDependentResources( String label, String tld, @@ -545,6 +581,18 @@ public static Domain persistDomainWithDependentResources( .build()); } + public static Domain persistDomainWithPendingTransfer( + Domain domain, + Instant requestTime, + Instant expirationTime, + Instant extendedRegistrationExpirationTime) { + return persistDomainWithPendingTransfer( + domain, + toDateTime(requestTime), + toDateTime(expirationTime), + toDateTime(extendedRegistrationExpirationTime)); + } + public static Domain persistDomainWithPendingTransfer( Domain domain, DateTime requestTime, @@ -801,27 +849,33 @@ public static ImmutableList getPollMessages(DomainBase domain) { public static ImmutableList getPollMessages( String registrarId, DateTime beforeOrAt) { + return getPollMessages(registrarId, toInstant(beforeOrAt)); + } + + public static ImmutableList getPollMessages(String registrarId, Instant beforeOrAt) { return tm().transact( () -> tm().loadAllOf(PollMessage.class).stream() .filter(pollMessage -> pollMessage.getRegistrarId().equals(registrarId)) - .filter(pollMessage -> isBeforeOrAt(pollMessage.getEventTime(), beforeOrAt)) + .filter(pollMessage -> !pollMessage.getEventTimeInstant().isAfter(beforeOrAt)) .collect(toImmutableList())); } /** Gets all PollMessages associated with the given EppResource. */ public static ImmutableList getPollMessages( EppResource resource, String registrarId, DateTime now) { + return getPollMessages(resource, registrarId, toInstant(now)); + } + + public static ImmutableList getPollMessages( + EppResource resource, String registrarId, Instant now) { return tm().transact( () -> tm().loadAllOf(PollMessage.class).stream() .filter( pollMessage -> pollMessage.getDomainRepoId().equals(resource.getRepoId())) .filter(pollMessage -> pollMessage.getRegistrarId().equals(registrarId)) - .filter( - pollMessage -> - pollMessage.getEventTime().isEqual(now) - || pollMessage.getEventTime().isBefore(now)) + .filter(pollMessage -> !pollMessage.getEventTimeInstant().isAfter(now)) .collect(toImmutableList())); } @@ -830,11 +884,20 @@ public static PollMessage getOnlyPollMessage(String registrarId) { } public static PollMessage getOnlyPollMessage(String registrarId, DateTime now) { + return getOnlyPollMessage(registrarId, toInstant(now)); + } + + public static PollMessage getOnlyPollMessage(String registrarId, Instant now) { return Iterables.getOnlyElement(getPollMessages(registrarId, now)); } public static PollMessage getOnlyPollMessage( String registrarId, DateTime now, Class subType) { + return getOnlyPollMessage(registrarId, toInstant(now), subType); + } + + public static PollMessage getOnlyPollMessage( + String registrarId, Instant now, Class subType) { return getPollMessages(registrarId, now).stream() .filter(subType::isInstance) .map(subType::cast) @@ -843,6 +906,11 @@ public static PollMessage getOnlyPollMessage( public static PollMessage getOnlyPollMessage( DomainBase domain, String registrarId, DateTime now, Class subType) { + return getOnlyPollMessage(domain, registrarId, toInstant(now), subType); + } + + public static PollMessage getOnlyPollMessage( + DomainBase domain, String registrarId, Instant now, Class subType) { return getPollMessages(domain, registrarId, now).stream() .filter(subType::isInstance) .map(subType::cast) diff --git a/core/src/test/java/google/registry/tmch/SmdrlCsvParserTest.java b/core/src/test/java/google/registry/tmch/SmdrlCsvParserTest.java index 68a768defab..1e1d390ae90 100644 --- a/core/src/test/java/google/registry/tmch/SmdrlCsvParserTest.java +++ b/core/src/test/java/google/registry/tmch/SmdrlCsvParserTest.java @@ -24,7 +24,8 @@ import com.google.common.io.CharSource; import google.registry.model.smd.SignedMarkRevocationList; import google.registry.testing.FakeClock; -import org.joda.time.DateTime; +import java.time.Instant; +import java.time.format.DateTimeParseException; import org.junit.jupiter.api.Test; /** Unit tests for {@link SmdrlCsvParser}. */ @@ -39,38 +40,38 @@ class SmdrlCsvParserTest { void testParse() throws Exception { SignedMarkRevocationList smdrl = SmdrlCsvParser.parse(SMDRL_LATEST_CSV.readLines()); assertThat(smdrl.size()).isEqualTo(150); - assertThat(smdrl.getCreationTime()).isEqualTo(DateTime.parse("2013-11-24T23:30:04.3Z")); + assertThat(smdrl.getCreationTime()).isEqualTo(Instant.parse("2013-11-24T23:30:04.3Z")); } @Test void testFirstRow() throws Exception { SignedMarkRevocationList smdrl = SmdrlCsvParser.parse(SMDRL_LATEST_CSV.readLines()); - clock.setTo(DateTime.parse("2013-08-09T12:00:00.0Z")); - assertThat(smdrl.isSmdRevoked("0000001681375789102250-65535", clock.nowUtc())).isTrue(); - clock.setTo(clock.nowUtc().minusMillis(1)); - assertThat(smdrl.isSmdRevoked("0000001681375789102250-65535", clock.nowUtc())).isFalse(); + clock.setTo(Instant.parse("2013-08-09T12:00:00.0Z")); + assertThat(smdrl.isSmdRevoked("0000001681375789102250-65535", clock.now())).isTrue(); + clock.setTo(clock.now().minusMillis(1)); + assertThat(smdrl.isSmdRevoked("0000001681375789102250-65535", clock.now())).isFalse(); clock.advanceBy(millis(2)); - assertThat(smdrl.isSmdRevoked("0000001681375789102250-65535", clock.nowUtc())).isTrue(); + assertThat(smdrl.isSmdRevoked("0000001681375789102250-65535", clock.now())).isTrue(); } @Test void testLastRow() throws Exception { SignedMarkRevocationList smdrl = SmdrlCsvParser.parse(SMDRL_LATEST_CSV.readLines()); - clock.setTo(DateTime.parse("2013-08-09T12:00:00.0Z")); - assertThat(smdrl.isSmdRevoked("0000002211373633641407-65535", clock.nowUtc())).isTrue(); - clock.setTo(clock.nowUtc().minusMillis(1)); - assertThat(smdrl.isSmdRevoked("0000002211373633641407-65535", clock.nowUtc())).isFalse(); + clock.setTo(Instant.parse("2013-08-09T12:00:00.0Z")); + assertThat(smdrl.isSmdRevoked("0000002211373633641407-65535", clock.now())).isTrue(); + clock.setTo(clock.now().minusMillis(1)); + assertThat(smdrl.isSmdRevoked("0000002211373633641407-65535", clock.now())).isFalse(); clock.advanceBy(millis(2)); - assertThat(smdrl.isSmdRevoked("0000002211373633641407-65535", clock.nowUtc())).isTrue(); + assertThat(smdrl.isSmdRevoked("0000002211373633641407-65535", clock.now())).isTrue(); } @Test void testRowWithDifferentDate() throws Exception { SignedMarkRevocationList smdrl = SmdrlCsvParser.parse(SMDRL_LATEST_CSV.readLines()); - clock.setTo(DateTime.parse("2013-08-09T12:00:00.0Z")); - assertThat(smdrl.isSmdRevoked("0000002101376042766438-65535", clock.nowUtc())).isFalse(); + clock.setTo(Instant.parse("2013-08-09T12:00:00.0Z")); + assertThat(smdrl.isSmdRevoked("0000002101376042766438-65535", clock.now())).isFalse(); clock.advanceBy(standardDays(1)); - assertThat(smdrl.isSmdRevoked("0000002101376042766438-65535", clock.nowUtc())).isTrue(); + assertThat(smdrl.isSmdRevoked("0000002101376042766438-65535", clock.now())).isTrue(); } @Test @@ -82,9 +83,9 @@ void testOneRow() throws Exception { "smd-id,insertion-datetime", "0000001681375789102250-65535,2013-08-09T12:00:00.0Z")); assertThat(smdrl.size()).isEqualTo(1); - assertThat(smdrl.getCreationTime()).isEqualTo(DateTime.parse("2013-11-24T23:30:04.3Z")); - clock.setTo(DateTime.parse("2020-08-09T12:00:00.0Z")); - assertThat(smdrl.isSmdRevoked("0000001681375789102250-65535", clock.nowUtc())).isTrue(); + assertThat(smdrl.getCreationTime()).isEqualTo(Instant.parse("2013-11-24T23:30:04.3Z")); + clock.setTo(Instant.parse("2020-08-09T12:00:00.0Z")); + assertThat(smdrl.isSmdRevoked("0000001681375789102250-65535", clock.now())).isTrue(); } @Test @@ -93,9 +94,9 @@ void testEmpty() throws Exception { SmdrlCsvParser.parse( ImmutableList.of("1,2014-11-24T23:30:04.3Z", "smd-id,insertion-datetime")); assertThat(smdrl.size()).isEqualTo(0); - assertThat(smdrl.getCreationTime()).isEqualTo(DateTime.parse("2014-11-24T23:30:04.3Z")); - clock.setTo(DateTime.parse("2020-08-09T12:00:00.0Z")); - assertThat(smdrl.isSmdRevoked("0000001681375789102250-65535", clock.nowUtc())).isFalse(); + assertThat(smdrl.getCreationTime()).isEqualTo(Instant.parse("2014-11-24T23:30:04.3Z")); + clock.setTo(Instant.parse("2020-08-09T12:00:00.0Z")); + assertThat(smdrl.isSmdRevoked("0000001681375789102250-65535", clock.now())).isFalse(); } @Test @@ -130,15 +131,15 @@ void testFail_badHeader() { @Test void testFail_tooManyColumns() { - IllegalArgumentException thrown = + DateTimeParseException thrown = assertThrows( - IllegalArgumentException.class, + DateTimeParseException.class, () -> SmdrlCsvParser.parse( ImmutableList.of( "1,2013-11-24T23:30:04.3Z", "smd-id,insertion-datetime", "0000001681375789102250-65535,haha,2013-08-09T12:00:00.0Z"))); - assertThat(thrown).hasMessageThat().isEqualTo("Invalid format: \"haha\""); + assertThat(thrown).hasMessageThat().contains("Text 'haha' could not be parsed at index 0"); } } diff --git a/core/src/test/java/google/registry/tmch/TmchDnlActionTest.java b/core/src/test/java/google/registry/tmch/TmchDnlActionTest.java index 40a474d06e1..4a85582f91f 100644 --- a/core/src/test/java/google/registry/tmch/TmchDnlActionTest.java +++ b/core/src/test/java/google/registry/tmch/TmchDnlActionTest.java @@ -25,8 +25,8 @@ import google.registry.model.tmch.ClaimsListDao; import java.io.ByteArrayInputStream; import java.net.URL; +import java.time.Instant; import java.util.Optional; -import org.joda.time.DateTime; import org.junit.jupiter.api.Test; /** Unit tests for {@link TmchDnlAction}. */ @@ -57,7 +57,7 @@ void testDnl() throws Exception { // Make sure the contents of testdata/dnl-latest.csv got inserted into the database. ClaimsList claimsList = ClaimsListDao.get(); assertThat(claimsList.getTmdbGenerationTime()) - .isEqualTo(DateTime.parse("2013-11-24T23:15:37.4Z")); + .isEqualTo(Instant.parse("2013-11-24T23:15:37.4Z")); assertThat(tm().transact(() -> claimsList.getClaimKey("xn----7sbejwbn3axu3d"))) .hasValue("2013112500/7/4/8/dIHW0DiuybvhdP8kIz"); assertThat(tm().transact(() -> claimsList.getClaimKey("lolcat"))).isEmpty(); diff --git a/core/src/test/java/google/registry/tmch/TmchSmdrlActionTest.java b/core/src/test/java/google/registry/tmch/TmchSmdrlActionTest.java index 85c87517d38..1e5992b80ca 100644 --- a/core/src/test/java/google/registry/tmch/TmchSmdrlActionTest.java +++ b/core/src/test/java/google/registry/tmch/TmchSmdrlActionTest.java @@ -24,14 +24,14 @@ import google.registry.model.smd.SignedMarkRevocationList; import java.io.ByteArrayInputStream; import java.net.URL; +import java.time.Instant; import java.util.Optional; -import org.joda.time.DateTime; import org.junit.jupiter.api.Test; /** Unit tests for {@link TmchSmdrlAction}. */ class TmchSmdrlActionTest extends TmchActionTestCase { - private static final DateTime now = DateTime.parse("2014-01-01T00:00:00Z"); + private static final Instant now = Instant.parse("2014-01-01T00:00:00Z"); private TmchSmdrlAction newTmchSmdrlAction() { TmchSmdrlAction action = new TmchSmdrlAction(); diff --git a/core/src/test/java/google/registry/tmch/TmchTestDataExpirationTest.java b/core/src/test/java/google/registry/tmch/TmchTestDataExpirationTest.java index a5448eb0900..1018e5a9887 100644 --- a/core/src/test/java/google/registry/tmch/TmchTestDataExpirationTest.java +++ b/core/src/test/java/google/registry/tmch/TmchTestDataExpirationTest.java @@ -15,7 +15,6 @@ package google.registry.tmch; import static google.registry.testing.TestDataHelper.loadFile; -import static org.joda.time.DateTimeZone.UTC; import google.registry.config.RegistryConfig.ConfigModule.TmchCaMode; import google.registry.flows.EppException; @@ -24,7 +23,7 @@ import google.registry.persistence.transaction.JpaTestExtensions; import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension; import google.registry.util.SystemClock; -import org.joda.time.DateTime; +import java.time.Instant; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -57,7 +56,7 @@ void testActiveSignedMarkFiles_areValidAndNotExpired() throws Exception { String tmchData = loadFile(TmchTestDataExpirationTest.class, filePath); EncodedSignedMark smd = TmchData.readEncodedSignedMark(tmchData); try { - tmchUtils.verifyEncodedSignedMark(smd, DateTime.now(UTC)); + tmchUtils.verifyEncodedSignedMark(smd, Instant.now()); } catch (EppException e) { throw new AssertionError("Error verifying signed mark " + filePath, e); } diff --git a/core/src/test/java/google/registry/tools/CreateRegistrarCommandTest.java b/core/src/test/java/google/registry/tools/CreateRegistrarCommandTest.java index de8b3a7bebf..8f129e65da2 100644 --- a/core/src/test/java/google/registry/tools/CreateRegistrarCommandTest.java +++ b/core/src/test/java/google/registry/tools/CreateRegistrarCommandTest.java @@ -23,7 +23,7 @@ import static google.registry.testing.DatabaseHelper.persistNewRegistrar; import static google.registry.testing.DatabaseHelper.persistResource; import static google.registry.util.DateTimeUtils.START_INSTANT; -import static google.registry.util.DateTimeUtils.toDateTime; +import static google.registry.util.DateTimeUtils.START_OF_TIME; import static org.joda.money.CurrencyUnit.JPY; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.eq; @@ -64,11 +64,7 @@ void beforeEach() { command.setConnection(connection); command.certificateChecker = new CertificateChecker( - ImmutableSortedMap.of( - toDateTime(START_INSTANT), - 825, - toDateTime(Instant.parse("2020-09-01T00:00:00Z")), - 398), + ImmutableSortedMap.of(START_OF_TIME, 825, DateTime.parse("2020-09-01T00:00:00Z"), 398), 30, 15, 2048, diff --git a/core/src/test/java/google/registry/tools/GetClaimsListCommandTest.java b/core/src/test/java/google/registry/tools/GetClaimsListCommandTest.java index 6bd4408e5b4..35b3f918c93 100644 --- a/core/src/test/java/google/registry/tools/GetClaimsListCommandTest.java +++ b/core/src/test/java/google/registry/tools/GetClaimsListCommandTest.java @@ -17,7 +17,6 @@ import static com.google.common.truth.Truth.assertThat; import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.file.Files.readAllLines; -import static org.joda.time.DateTimeZone.UTC; import com.google.common.collect.ImmutableMap; import google.registry.model.tmch.ClaimsList; @@ -25,7 +24,7 @@ import google.registry.testing.TestCacheExtension; import java.io.File; import java.nio.file.Files; -import org.joda.time.DateTime; +import java.time.Duration; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -34,11 +33,11 @@ class GetClaimsListCommandTest extends CommandTestCase { @RegisterExtension public final TestCacheExtension testCacheExtension = - new TestCacheExtension.Builder().withClaimsListCache(java.time.Duration.ofHours(6)).build(); + new TestCacheExtension.Builder().withClaimsListCache(Duration.ofHours(6)).build(); @Test void testSuccess_getWorks() throws Exception { - ClaimsListDao.save(ClaimsList.create(DateTime.now(UTC), ImmutableMap.of("a", "1", "b", "2"))); + ClaimsListDao.save(ClaimsList.create(fakeClock.now(), ImmutableMap.of("a", "1", "b", "2"))); File output = tmpDir.resolve("claims.txt").toFile(); runCommand("--output=" + output.getAbsolutePath()); assertThat(readAllLines(output.toPath(), UTF_8)).containsExactly("a,1", "b,2"); @@ -46,7 +45,7 @@ void testSuccess_getWorks() throws Exception { @Test void testSuccess_endsWithNewline() throws Exception { - ClaimsListDao.save(ClaimsList.create(DateTime.now(UTC), ImmutableMap.of("a", "1"))); + ClaimsListDao.save(ClaimsList.create(fakeClock.now(), ImmutableMap.of("a", "1"))); File output = tmpDir.resolve("claims.txt").toFile(); runCommand("--output=" + output.getAbsolutePath()); assertThat(Files.readString(output.toPath())).endsWith("\n"); diff --git a/core/src/test/java/google/registry/tools/UploadClaimsListCommandTest.java b/core/src/test/java/google/registry/tools/UploadClaimsListCommandTest.java index 53d390d089e..88b75d768e4 100644 --- a/core/src/test/java/google/registry/tools/UploadClaimsListCommandTest.java +++ b/core/src/test/java/google/registry/tools/UploadClaimsListCommandTest.java @@ -22,7 +22,9 @@ import google.registry.model.tmch.ClaimsListDao; import google.registry.testing.TestCacheExtension; import java.io.FileNotFoundException; -import org.joda.time.DateTime; +import java.time.Duration; +import java.time.Instant; +import java.time.format.DateTimeParseException; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -31,7 +33,7 @@ class UploadClaimsListCommandTest extends CommandTestCase claimsList.getClaimKey("example"))) .hasValue("2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001"); assertThat(tm().transact(() -> claimsList.getClaimKey("another-example"))) @@ -84,73 +86,79 @@ void testFailure_badCreationTime() throws Exception { "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); - assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename)); + assertThrows(DateTimeParseException.class, () -> runCommand("--force", filename)); } @Test void testFailure_badFirstHeader() throws Exception { - String filename = writeToTmpFile( - "1,foo", - "SNL,lookup-key,insertion-datetime", - "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", - "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", - "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); + String filename = + writeToTmpFile( + "1,2010-01-01T00:00:00.0Z", + "SNL,lookup-key,insertion-datetime", + "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", + "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", + "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename)); } @Test void testFailure_badSecondHeader() throws Exception { - String filename = writeToTmpFile( - "1,foo", - "DNL,lookup-keys,insertion-datetime", - "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", - "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", - "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); + String filename = + writeToTmpFile( + "1,2010-01-01T00:00:00.0Z", + "DNL,lookup-keys,insertion-datetime", + "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", + "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", + "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename)); } @Test void testFailure_badThirdHeader() throws Exception { - String filename = writeToTmpFile( - "1,foo", - "DNL,lookup-key,insertion-datetimes", - "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", - "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", - "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); + String filename = + writeToTmpFile( + "1,2010-01-01T00:00:00.0Z", + "DNL,lookup-key,insertion-datetimes", + "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", + "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", + "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename)); } @Test void testFailure_wrongNumberOfHeaders() throws Exception { - String filename = writeToTmpFile( - "1,foo", - "DNL,lookup-key,insertion-datetime,extra-field", - "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", - "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", - "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); + String filename = + writeToTmpFile( + "1,2010-01-01T00:00:00.0Z", + "DNL,lookup-key,insertion-datetime,extra-field", + "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", + "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", + "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename)); } @Test void testFailure_wrongNumberOfFields() throws Exception { - String filename = writeToTmpFile( - "1,foo", - "DNL,lookup-key,insertion-datetime", - "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z,extra", - "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", - "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); + String filename = + writeToTmpFile( + "1,2010-01-01T00:00:00.0Z", + "DNL,lookup-key,insertion-datetime", + "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z,extra", + "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", + "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename)); } @Test void testFailure_badInsertionTime() throws Exception { - String filename = writeToTmpFile( - "1,foo", - "DNL,lookup-key,insertion-datetime", - "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", - "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,foo", - "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); - assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename)); + String filename = + writeToTmpFile( + "1,2010-01-01T00:00:00.0Z", + "DNL,lookup-key,insertion-datetime", + "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", + "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,foo", + "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); + assertThrows(DateTimeParseException.class, () -> runCommand("--force", filename)); } @Test diff --git a/proxy/src/main/java/google/registry/proxy/ProxyServer.java b/proxy/src/main/java/google/registry/proxy/ProxyServer.java index bf5266e0c79..323a7e55bbf 100644 --- a/proxy/src/main/java/google/registry/proxy/ProxyServer.java +++ b/proxy/src/main/java/google/registry/proxy/ProxyServer.java @@ -44,6 +44,7 @@ import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.JdkLoggerFactory; import jakarta.inject.Provider; +import java.time.Duration; import java.util.ArrayDeque; import java.util.HashMap; import java.util.Queue; @@ -314,7 +315,7 @@ public static void main(String[] args) { if (proxyModule.provideEnvironment() != Environment.LOCAL) { MetricReporter metricReporter = proxyComponent.metricReporter(); try { - metricReporter.startAsync().awaitRunning(java.time.Duration.ofSeconds(10)); + metricReporter.startAsync().awaitRunning(Duration.ofSeconds(10)); logger.atInfo().log("Started up MetricReporter."); } catch (TimeoutException timeoutException) { logger.atSevere().withCause(timeoutException).log( @@ -325,7 +326,7 @@ public static void main(String[] args) { new Thread( () -> { try { - metricReporter.stopAsync().awaitTerminated(java.time.Duration.ofSeconds(10)); + metricReporter.stopAsync().awaitTerminated(Duration.ofSeconds(10)); logger.atInfo().log("Shut down MetricReporter."); } catch (TimeoutException timeoutException) { logger.atWarning().withCause(timeoutException).log( diff --git a/util/src/test/java/google/registry/util/DateTimeUtilsTest.java b/util/src/test/java/google/registry/util/DateTimeUtilsTest.java index a0a9dea6519..f62f6221b4c 100644 --- a/util/src/test/java/google/registry/util/DateTimeUtilsTest.java +++ b/util/src/test/java/google/registry/util/DateTimeUtilsTest.java @@ -23,7 +23,9 @@ import static google.registry.util.DateTimeUtils.isAtOrAfter; import static google.registry.util.DateTimeUtils.isBeforeOrAt; import static google.registry.util.DateTimeUtils.latestOf; +import static google.registry.util.DateTimeUtils.minusMonths; import static google.registry.util.DateTimeUtils.minusYears; +import static google.registry.util.DateTimeUtils.plusMonths; import static google.registry.util.DateTimeUtils.plusYears; import static google.registry.util.DateTimeUtils.toDateTime; import static google.registry.util.DateTimeUtils.toInstant; @@ -108,6 +110,24 @@ void test_minusYears_worksWithInstants() { assertThat(minusYears(startDate, 4)).isEqualTo(Instant.parse("2008-02-28T00:00:00Z")); } + @Test + void test_plusMonths_worksWithInstants() { + Instant startDate = Instant.parse("2012-02-29T00:00:00Z"); + assertThat(plusMonths(startDate, 4)).isEqualTo(Instant.parse("2012-06-29T00:00:00Z")); + + Instant startLeapYear = Instant.parse("2012-01-31T00:00:00Z"); + assertThat(plusMonths(startLeapYear, 1)).isEqualTo(Instant.parse("2012-02-29T00:00:00Z")); + } + + @Test + void test_minusMonths_worksWithInstants() { + Instant startDate = Instant.parse("2012-06-29T00:00:00Z"); + assertThat(minusMonths(startDate, 4)).isEqualTo(Instant.parse("2012-02-29T00:00:00Z")); + + Instant startLeapYear = Instant.parse("2012-03-31T00:00:00Z"); + assertThat(minusMonths(startLeapYear, 1)).isEqualTo(Instant.parse("2012-02-29T00:00:00Z")); + } + @Test void testSuccess_minusYears_zeroYears() { DateTime leapDay = DateTime.parse("2012-02-29T00:00:00Z");