Complete Joda-Time to java.time migration (#3039)

This completes the exhaustive refactoring of foundational temporal types from Joda-Time to the native java.time API across the entire codebase.

- Replaced org.joda.time.DateTime, Instant, LocalDate, and Duration with java.time equivalents.
- Audited and updated Clock implementations (FakeClock, SystemClock). Added nowMillis(), nowDate(), and nowDateTime() to eliminate repetitive conversions and maintain parallel naming.
- Replaced ZonedDateTime with OffsetDateTime globally per go/avoid-zdt. OffsetDateTime is a better fit as we use a hardcoded ZoneOffset.UTC throughout the system, making geographical time zone rules (like daylight saving time) irrelevant and preventing serialization ambiguities. Added a presubmit check.
- Completely removed all transitional bridge methods from DateTimeUtils and deleted obsolete converters (e.g., DateTimeConverter).
- Updated testing infrastructure, Apache Beam pipelines, custom JCommander parameters, and networking modules to solely rely on java.time primitives.
- Retained the lone necessary org.joda.time.Instant usage in SafeBrowsingTransforms required by the Apache Beam API.
- Cleared Gradle lockfiles and removed the joda-time dependency entirely from the build configuration.
This commit is contained in:
Ben McIlwain
2026-05-13 16:07:19 +00:00
committed by GitHub
parent b33c2f4874
commit 56fe588b56
218 changed files with 589 additions and 1390 deletions
@@ -216,8 +216,8 @@ public class CloudTasksUtilsTest {
assertThat(task.getScheduleTime().getSeconds()).isNotEqualTo(0);
Instant scheduleTime = Instant.ofEpochSecond(task.getScheduleTime().getSeconds());
Instant lowerBoundTime = Instant.ofEpochMilli(clock.now().toEpochMilli());
Instant upperBound = Instant.ofEpochMilli(clock.now().plusSeconds(100).toEpochMilli());
Instant lowerBoundTime = clock.now();
Instant upperBound = clock.now().plusSeconds(100);
assertThat(scheduleTime.isBefore(lowerBoundTime)).isFalse();
assertThat(upperBound.isBefore(scheduleTime)).isFalse();
@@ -253,7 +253,7 @@ public class CloudTasksUtilsTest {
.isEqualTo("https://backend.registry.test/the/path?key1=val1&key2=val2&key1=val3");
verifyOidcToken(task);
assertThat(Instant.ofEpochSecond(task.getScheduleTime().getSeconds()))
.isEqualTo(Instant.ofEpochMilli(clock.now().plus(Duration.ofMinutes(10)).toEpochMilli()));
.isEqualTo(clock.now().plus(Duration.ofMinutes(10)));
}
@Test
@@ -25,7 +25,6 @@ import static google.registry.testing.DatabaseHelper.persistDomainWithDependentR
import static google.registry.testing.DatabaseHelper.persistDomainWithPendingTransfer;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.util.DateTimeUtils.plusDays;
import static org.joda.time.Duration.standardDays;
import static org.mockito.Mockito.verify;
import com.google.cloud.tasks.v2.HttpMethod;
@@ -41,6 +40,7 @@ import google.registry.request.Response;
import google.registry.testing.CloudTasksHelper;
import google.registry.testing.CloudTasksHelper.TaskMatcher;
import google.registry.testing.FakeClock;
import java.time.Duration;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -121,7 +121,7 @@ public class ResaveEntityActionTest {
plusDays(clock.now(), 30),
"TheRegistrar")))
.build());
clock.advanceBy(standardDays(30));
clock.advanceBy(Duration.ofDays(30));
Instant requestedTime = clock.now();
assertThat(domain.getGracePeriods()).isNotEmpty();
@@ -44,10 +44,10 @@ import google.registry.persistence.transaction.CriteriaQueryBuilder;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.testing.FakeClock;
import java.time.Instant;
import org.apache.beam.sdk.coders.StringUtf8Coder;
import org.apache.beam.sdk.testing.PAssert;
import org.apache.beam.sdk.values.PCollection;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -55,7 +55,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link RegistryJpaIO.Read}. */
public class RegistryJpaReadTest {
private static final DateTime START_TIME = DateTime.parse("2000-01-01T00:00:00.0Z");
private static final Instant START_TIME = Instant.parse("2000-01-01T00:00:00.0Z");
private final FakeClock fakeClock = new FakeClock(START_TIME);
@@ -28,15 +28,15 @@ import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationT
import google.registry.persistence.transaction.JpaTransactionManagerExtension;
import google.registry.testing.FakeClock;
import java.io.Serializable;
import java.time.Instant;
import org.apache.beam.sdk.transforms.Create;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit test for {@link RegistryJpaIO.Write}. */
class RegistryJpaWriteTest implements Serializable {
private final FakeClock fakeClock = new FakeClock(DateTime.parse("2000-01-01T00:00:00.0Z"));
private final FakeClock fakeClock = new FakeClock(Instant.parse("2000-01-01T00:00:00.0Z"));
@RegisterExtension
final transient JpaIntegrationTestExtension jpa =
@@ -96,7 +96,6 @@ import org.apache.beam.sdk.values.KV;
import org.apache.beam.sdk.values.PCollection;
import org.bouncycastle.openpgp.PGPPrivateKey;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -113,9 +112,9 @@ public class RdePipelineTest {
private static final String HOST_NAME_PATTERN = "<rdeHost:name>(.*)</rdeHost:name>";
// This is the default creation time for test data.
private final FakeClock clock = new FakeClock(DateTime.parse("1999-12-31TZ"));
private final FakeClock clock = new FakeClock(Instant.parse("1999-12-31T00:00:00Z"));
// This is teh default as-of time the RDE/BRDA job.
// This is the default as-of time the RDE/BRDA job.
private final Instant now = Instant.parse("2000-01-01T00:00:00.000Z");
private final ImmutableSet<PendingDeposit> pendings =
@@ -352,8 +351,8 @@ public class RdePipelineTest {
</rdeDomain:ns>
<rdeDomain:clID>TheRegistrar</rdeDomain:clID>
<rdeDomain:crRr>TheRegistrar</rdeDomain:crRr>
<rdeDomain:crDate>1970-01-01T00:00:00Z</rdeDomain:crDate>
<rdeDomain:exDate>294247-01-10T04:00:54Z</rdeDomain:exDate>
<rdeDomain:crDate>1970-01-01T00:00:00.000Z</rdeDomain:crDate>
<rdeDomain:exDate>294247-01-10T04:00:54.775Z</rdeDomain:exDate>
</rdeDomain:domain>\
""");
}
@@ -381,8 +380,8 @@ public class RdePipelineTest {
</rdeDomain:ns>
<rdeDomain:clID>TheRegistrar</rdeDomain:clID>
<rdeDomain:crRr>TheRegistrar</rdeDomain:crRr>
<rdeDomain:crDate>1970-01-01T00:00:00Z</rdeDomain:crDate>
<rdeDomain:exDate>294247-01-10T04:00:54Z</rdeDomain:exDate>
<rdeDomain:crDate>1970-01-01T00:00:00.000Z</rdeDomain:crDate>
<rdeDomain:exDate>294247-01-10T04:00:54.775Z</rdeDomain:exDate>
</rdeDomain:domain>\
""");
} else {
@@ -415,8 +414,8 @@ public class RdePipelineTest {
</rdeDomain:ns>
<rdeDomain:clID>TheRegistrar</rdeDomain:clID>
<rdeDomain:crRr>TheRegistrar</rdeDomain:crRr>
<rdeDomain:crDate>1970-01-01T00:00:00Z</rdeDomain:crDate>
<rdeDomain:exDate>294247-01-10T04:00:54Z</rdeDomain:exDate>
<rdeDomain:crDate>1970-01-01T00:00:00.000Z</rdeDomain:crDate>
<rdeDomain:exDate>294247-01-10T04:00:54.775Z</rdeDomain:exDate>
</rdeDomain:domain>\
""");
}
@@ -53,6 +53,7 @@ import google.registry.util.Retrier;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.time.LocalDate;
import org.apache.beam.sdk.coders.KvCoder;
import org.apache.beam.sdk.coders.SerializableCoder;
@@ -64,7 +65,6 @@ import org.apache.beam.sdk.values.PCollection;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.joda.time.DateTime;
import org.json.JSONObject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -80,7 +80,7 @@ import org.junit.jupiter.api.io.TempDir;
*/
class Spec11PipelineTest {
private static final DateTime START_TIME = DateTime.parse("2020-01-27T00:00:00.0Z");
private static final Instant START_TIME = Instant.parse("2020-01-27T00:00:00.0Z");
private final FakeClock fakeClock = new FakeClock(START_TIME);
private static final String DATE = "2020-01-27";
@@ -28,7 +28,6 @@ import static google.registry.util.DateTimeUtils.minusHours;
import static google.registry.util.DateTimeUtils.plusHours;
import static org.joda.money.CurrencyUnit.JPY;
import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.Duration.standardMinutes;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
@@ -43,6 +42,7 @@ import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.testing.DatabaseHelper;
import google.registry.testing.FakeClock;
import java.time.Duration;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -182,7 +182,7 @@ public class SyncRegistrarsSheetTest {
Instant registrarCreationTime = persistResource(registrar).getCreationTime();
persistResources(contacts);
clock.advanceBy(standardMinutes(1));
clock.advanceBy(Duration.ofMinutes(1));
newSyncRegistrarsSheet().run("foobar");
verify(sheetSynchronizer).synchronize(eq("foobar"), rowsCaptor.capture());
@@ -45,11 +45,11 @@ import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationT
import google.registry.testing.FakeClock;
import google.registry.util.Clock;
import google.registry.xml.ValidationMode;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import org.joda.time.DateTime;
import org.json.simple.JSONValue;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -81,7 +81,7 @@ class EppControllerTest {
@Mock EppResponse eppResponse;
@Mock Result result;
private static final DateTime START_TIME = DateTime.parse("2016-09-01T00:00:00Z");
private static final Instant START_TIME = Instant.parse("2016-09-01T00:00:00Z");
private final Clock clock = new FakeClock(START_TIME);
private final TestLogHandler logHandler = new TestLogHandler();
@@ -14,7 +14,6 @@
package google.registry.flows;
import com.google.common.collect.ImmutableMap;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
@@ -150,4 +150,3 @@ public interface EppTestComponent {
FlowComponent.Builder flowComponentBuilder();
}
}
@@ -27,7 +27,6 @@ import static google.registry.util.DateTimeUtils.END_INSTANT;
import static google.registry.util.DateTimeUtils.START_INSTANT;
import static google.registry.xml.XmlTestUtils.assertXmlEquals;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -53,12 +52,12 @@ import google.registry.testing.FakeHttpSession;
import google.registry.testing.TestDataHelper;
import google.registry.util.TypeUtils.TypeInstantiator;
import google.registry.xml.ValidationMode;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -83,7 +82,7 @@ public abstract class FlowTestCase<F extends Flow> {
protected EppLoader eppLoader;
protected SessionMetadata sessionMetadata;
protected FakeClock clock = new FakeClock(DateTime.now(UTC));
protected FakeClock clock = new FakeClock(Instant.now());
protected TransportCredentials credentials = new PasswordOnlyTransportCredentials();
protected EppRequestSource eppRequestSource = EppRequestSource.UNIT_TEST;
protected CloudTasksHelper cloudTasksHelper;
@@ -1437,4 +1437,3 @@ class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Host> {
assertIcannReportingActivityFieldLogged("srs-host-update");
}
}
@@ -13,13 +13,12 @@
// limitations under the License.
package google.registry.model;
import static org.joda.time.DateTimeZone.UTC;
import google.registry.persistence.transaction.JpaEntityCoverageExtension;
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.Order;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -37,7 +36,7 @@ public abstract class EntityTestCase {
DISABLED
}
protected FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
protected FakeClock fakeClock = new FakeClock(Instant.now());
@Order(Order.DEFAULT)
@RegisterExtension
@@ -32,7 +32,7 @@ import google.registry.model.domain.Period;
import google.registry.model.eppcommon.Trid;
import google.registry.model.reporting.DomainTransactionRecord.TransactionReportField;
import google.registry.testing.DatabaseHelper;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -43,7 +43,7 @@ class HistoryEntryDaoTest extends EntityTestCase {
@BeforeEach
void beforeEach() {
fakeClock.setTo(DateTime.parse("2020-10-01T00:00:00Z"));
fakeClock.setTo(Instant.parse("2020-10-01T00:00:00Z"));
createTld("foobar");
domain = persistActiveDomain("foo.foobar");
DomainTransactionRecord transactionRecord =
@@ -16,13 +16,13 @@ package google.registry.model.smd;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.util.DateTimeUtils.START_INSTANT;
import static org.joda.time.Duration.standardDays;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableMap;
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 org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -77,7 +77,7 @@ public class SignedMarkRevocationListTest {
createSaveGetHelper(5);
assertThat(SignedMarkRevocationList.get().getCreationTime())
.isEqualTo(Instant.parse("2000-01-01T00:00:00Z"));
clock.advanceBy(standardDays(1));
clock.advanceBy(Duration.ofDays(1));
assertThat(SignedMarkRevocationList.get().getCreationTime())
.isEqualTo(Instant.parse("2000-01-01T00:00:00Z"));
}
@@ -37,7 +37,7 @@ import google.registry.model.tld.Tld;
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.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -45,7 +45,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link ReservedList}. */
class ReservedListTest {
private FakeClock clock = new FakeClock(DateTime.parse("2010-01-01T10:00:00Z"));
private FakeClock clock = new FakeClock(Instant.parse("2010-01-01T10:00:00Z"));
@RegisterExtension
final JpaIntegrationTestExtension jpa =
@@ -15,8 +15,6 @@
package google.registry.model.transfer;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.util.DateTimeUtils.toInstant;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.collect.ImmutableSet;
import google.registry.model.billing.BillingCancellation;
@@ -26,14 +24,14 @@ import google.registry.model.domain.Period;
import google.registry.model.eppcommon.Trid;
import google.registry.model.poll.PollMessage;
import google.registry.persistence.VKey;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link DomainTransferData}. */
public class DomainTransferDataTest {
private final DateTime now = DateTime.now(UTC);
private final Instant now = Instant.parse("2024-03-27T10:15:30.105Z");
private VKey<BillingEvent> transferBillingEventKey;
private VKey<BillingCancellation> otherServerApproveBillingEventKey;
@@ -55,7 +53,7 @@ public class DomainTransferDataTest {
DomainTransferData constantTransferData =
new DomainTransferData.Builder()
.setTransferRequestTrid(Trid.create("server-trid", "client-trid"))
.setTransferRequestTime(toInstant(now))
.setTransferRequestTime(now)
.setGainingRegistrarId("NewRegistrar")
.setLosingRegistrarId("TheRegistrar")
// Test must use a non-1-year period, since that's the default value.
@@ -64,7 +62,7 @@ public class DomainTransferDataTest {
DomainTransferData fullTransferData =
constantTransferData
.asBuilder()
.setPendingTransferExpirationTime(toInstant(now))
.setPendingTransferExpirationTime(now)
.setTransferStatus(TransferStatus.PENDING)
.setServerApproveEntities(
"4-TLD",
@@ -34,10 +34,10 @@ import google.registry.mosapi.MosApiModels.TldServiceState;
import google.registry.request.lock.LockHandler;
import google.registry.testing.FakeClock;
import java.io.IOException;
import java.time.Instant;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.stream.IntStream;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
@@ -61,7 +61,7 @@ public class MosApiMetricsTest {
mock(Monitoring.Projects.MetricDescriptors.Create.class);
// Fixed Clock for deterministic testing
private final FakeClock clock = new FakeClock(DateTime.parse("2026-01-01T12:00:00Z"));
private final FakeClock clock = new FakeClock(Instant.parse("2026-01-01T12:00:00Z"));
private MosApiMetrics mosApiMetrics;
@BeforeEach
@@ -1,109 +0,0 @@
// Copyright 2019 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.persistResource;
import static java.time.ZoneOffset.UTC;
import google.registry.model.ImmutableObject;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaUnitTestExtension;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import java.time.Instant;
import java.time.ZonedDateTime;
import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link DateTimeConverter}. */
public class DateTimeConverterTest {
@RegisterExtension
public final JpaUnitTestExtension jpaExtension =
new JpaTestExtensions.Builder().withEntityClass(TestEntity.class).buildUnitTestExtension();
private final DateTimeConverter converter = new DateTimeConverter();
@Test
void convertToDatabaseColumn_returnsNullIfInputIsNull() {
assertThat(converter.convertToDatabaseColumn(null)).isNull();
}
@Test
void convertToDatabaseColumn_convertsCorrectly() {
DateTime dateTime = DateTime.parse("2019-09-01T01:01:01");
assertThat(converter.convertToDatabaseColumn(dateTime).toInstant().toEpochMilli())
.isEqualTo(dateTime.getMillis());
}
@Test
void convertToEntityAttribute_returnsNullIfInputIsNull() {
assertThat(converter.convertToEntityAttribute(null)).isNull();
}
@Test
void convertToEntityAttribute_convertsCorrectly() {
DateTime dateTime = DateTime.parse("2019-09-01T01:01:01Z");
long millis = dateTime.getMillis();
assertThat(
converter.convertToEntityAttribute(
ZonedDateTime.ofInstant(Instant.ofEpochMilli(millis), UTC)))
.isEqualTo(dateTime);
}
static DateTime parseDateTime(String value) {
return ISODateTimeFormat.dateTimeNoMillis().withOffsetParsed().parseDateTime(value);
}
@Test
void converter_generatesTimestampWithNormalizedZone() {
DateTime dt = parseDateTime("2019-09-01T01:01:01Z");
TestEntity entity = new TestEntity("normalized_utc_time", dt);
persistResource(entity);
TestEntity retrievedEntity =
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "normalized_utc_time"));
assertThat(retrievedEntity.dt.toString()).isEqualTo("2019-09-01T01:01:01.000Z");
}
@Test
void converter_convertsNonUtcZoneCorrectly() {
DateTime dt = parseDateTime("2019-09-01T01:01:01-05:00");
TestEntity entity = new TestEntity("new_york_time", dt);
persistResource(entity);
TestEntity retrievedEntity =
tm().transact(() -> tm().getEntityManager().find(TestEntity.class, "new_york_time"));
assertThat(retrievedEntity.dt.toString()).isEqualTo("2019-09-01T06:01:01.000Z");
}
@Entity(name = "TestEntity") // Override entity name to avoid the nested class reference.
private static class TestEntity extends ImmutableObject {
@Id String name;
DateTime dt;
TestEntity() {}
TestEntity(String name, DateTime dt) {
this.name = name;
this.dt = dt;
}
}
}
@@ -24,8 +24,7 @@ import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaUnitTestExtension;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.joda.time.LocalDate;
import org.joda.time.format.ISODateTimeFormat;
import java.time.LocalDate;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -38,7 +37,7 @@ public class LocalDateConverterTest {
.withEntityClass(LocalDateConverterTestEntity.class)
.buildUnitTestExtension();
private final LocalDate exampleDate = LocalDate.parse("2020-06-10", ISODateTimeFormat.date());
private final LocalDate exampleDate = LocalDate.parse("2020-06-10");
@Test
void testNullInput() {
@@ -15,13 +15,13 @@
package google.registry.persistence.transaction;
import static com.google.common.base.Preconditions.checkState;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import google.registry.testing.FakeClock;
import google.registry.util.Clock;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -29,7 +29,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.hibernate.cfg.Environment;
import org.joda.time.DateTime;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
@@ -166,7 +165,7 @@ public class JpaTestExtensions {
/** Builds a {@link JpaIntegrationTestExtension} instance. */
public JpaIntegrationTestExtension buildIntegrationTestExtension() {
return new JpaIntegrationTestExtension(
clock == null ? new FakeClock(DateTime.now(UTC)) : clock,
clock == null ? new FakeClock(Instant.now()) : clock,
ImmutableList.copyOf(extraEntityClasses),
ImmutableMap.copyOf(userProperties),
!withoutCannedData);
@@ -190,7 +189,7 @@ public class JpaTestExtensions {
!Objects.equals(GOLDEN_SCHEMA_SQL_PATH, initScript),
"Unit tests must not depend on the Nomulus schema.");
return new JpaUnitTestExtension(
clock == null ? new FakeClock(DateTime.now(UTC)) : clock,
clock == null ? new FakeClock(Instant.now()) : clock,
// Use the hstore extension by default so we can save the migration schedule
Optional.of(initScript == null ? HSTORE_EXTENSION_SQL_PATH : initScript),
ImmutableList.copyOf(extraEntityClasses),
@@ -24,8 +24,8 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import google.registry.rdap.AbstractJsonableObject.JsonableException;
import google.registry.rdap.AbstractJsonableObject.RestrictJsonNames;
import java.time.Instant;
import java.util.Optional;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link AbstractJsonableObject}. */
@@ -53,9 +53,10 @@ final class AbstractJsonableObjectTest {
@Test
void testDateTime() {
Jsonable jsonable = new AbstractJsonableObject() {
@JsonableElement DateTime dateTime = DateTime.parse("2019-01-02T13:53Z");
};
Jsonable jsonable =
new AbstractJsonableObject() {
@JsonableElement Instant dateTime = Instant.parse("2019-01-02T13:53:00Z");
};
assertThat(jsonable.toJson()).isEqualTo(createJson("{'dateTime':'2019-01-02T13:53:00.000Z'}"));
}
@@ -21,7 +21,6 @@ import static google.registry.rdap.RdapTestHelper.parseJsonObject;
import static google.registry.request.Action.Method.GET;
import static google.registry.request.Action.Method.HEAD;
import static google.registry.testing.DatabaseHelper.createTld;
import static org.joda.time.Duration.millis;
import static org.mockito.Mockito.verify;
import google.registry.rdap.RdapMetrics.EndpointType;
@@ -33,6 +32,7 @@ import google.registry.rdap.RdapSearchResults.IncompletenessWarningType;
import google.registry.request.Action;
import google.registry.request.auth.Auth;
import google.registry.testing.FakeClock;
import java.time.Duration;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -66,7 +66,7 @@ class RdapActionBaseTest extends RdapActionBaseTestCase<RdapActionBaseTest.RdapT
throw new RuntimeException();
}
if (pathSearchString.equals("advanceClock")) {
((FakeClock) clock).advanceBy(millis(50));
((FakeClock) clock).advanceBy(Duration.ofMillis(50));
}
return new ReplyPayloadBase(BoilerplateType.OTHER) {
@JsonableElement String key = "value";
@@ -40,17 +40,17 @@ import google.registry.testing.FakeClock;
import google.registry.testing.FakeResponse;
import google.registry.util.Idn;
import google.registry.util.TypeUtils;
import java.time.Instant;
import java.util.HashMap;
import java.util.Optional;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Common unit test code for actions inheriting {@link RdapActionBase}. */
abstract class RdapActionBaseTestCase<A extends RdapActionBase> {
protected final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
protected final FakeClock clock = new FakeClock(Instant.parse("2000-01-01T00:00:00Z"));
static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
@RegisterExtension
@@ -96,7 +96,7 @@ abstract class RdapActionBaseTestCase<A extends RdapActionBase> {
action.requestMethod = GET;
action.domainCache =
(domainName) -> ForeignKeyUtils.loadResourceByCache(Domain.class, domainName, clock.now());
action.clock = new FakeClock(DateTime.parse("2025-01-01T00:00:00.000Z"));
action.clock = new FakeClock(Instant.parse("2025-01-01T00:00:00.000Z"));
logout();
}
@@ -24,7 +24,6 @@ import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.loadByKey;
import static google.registry.testing.DatabaseHelper.loadByKeyIfPresent;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.joda.time.DateTimeConstants.TUESDAY;
import com.google.common.collect.ImmutableSetMultimap;
import google.registry.model.common.Cursor;
@@ -33,6 +32,7 @@ import google.registry.model.tld.Tld;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.testing.FakeClock;
import java.time.DayOfWeek;
import java.time.Duration;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
@@ -51,7 +51,7 @@ public class PendingDepositCheckerTest {
@BeforeEach
void beforeEach() {
checker.brdaDayOfWeek = TUESDAY;
checker.brdaDayOfWeek = DayOfWeek.TUESDAY.getValue();
checker.brdaInterval = Duration.ofDays(7);
checker.clock = clock;
checker.rdeInterval = Duration.ofDays(1);
@@ -198,4 +198,3 @@ public class PendingDepositCheckerTest {
persistResource(Tld.get(tld).asBuilder().setEscrowEnabled(true).build());
}
}
@@ -15,12 +15,17 @@
package google.registry.rde;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.loadRegistrar;
import static google.registry.testing.DatabaseHelper.newDomain;
import static google.registry.xml.ValidationMode.STRICT;
import google.registry.model.domain.Domain;
import google.registry.model.rde.RdeMode;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.xml.XmlTestUtils;
import java.time.Instant;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -86,4 +91,20 @@ public class RdeMarshallerTest {
new RdeMarshaller(STRICT).marshalRegistrar(loadRegistrar("TheRegistrar"));
assertThat(fragment.xml()).contains("123 Example Bőulevard");
}
@Test
void testMarshalDomain_largeYear_validatesAgainstXsd() throws Exception {
createTld("tld");
Domain initialDomain = newDomain("example.tld");
Domain domain =
initialDomain
.asBuilder()
.setRegistrationExpirationTime(Instant.parse("+294247-01-10T04:00:54Z"))
.build();
DepositFragment fragment = new RdeMarshaller(STRICT).marshalDomain(domain, RdeMode.FULL);
assertThat(fragment.error()).isEmpty();
assertThat(fragment.xml())
.contains("<rdeDomain:exDate>294247-01-10T04:00:54.000Z</rdeDomain:exDate>");
}
}
@@ -67,5 +67,3 @@ class TransactionsReportingQueryBuilderTest {
}
}
}
@@ -15,7 +15,6 @@
package google.registry.reporting.spec11;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.util.DateTimeUtils.toLocalDate;
import static jakarta.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static org.apache.http.HttpStatus.SC_OK;
import static org.mockito.Mockito.when;
@@ -50,7 +49,7 @@ class GenerateSpec11ReportActionTest extends BeamActionTestBase {
"gs://staging-project/staging-bucket/",
"gs://reporting-project/reporting-bucket/",
"api_key/a",
toLocalDate(clock.now()),
clock.nowDate(),
true,
clock,
response,
@@ -73,7 +72,7 @@ class GenerateSpec11ReportActionTest extends BeamActionTestBase {
"gs://staging-project/staging-bucket/",
"gs://reporting-project/reporting-bucket/",
"api_key/a",
toLocalDate(clock.now()),
clock.nowDate(),
true,
clock,
response,
@@ -104,7 +103,7 @@ class GenerateSpec11ReportActionTest extends BeamActionTestBase {
"gs://staging-project/staging-bucket/",
"gs://reporting-project/reporting-bucket/",
"api_key/a",
toLocalDate(clock.now()),
clock.nowDate(),
false,
clock,
response,
@@ -17,10 +17,10 @@ package google.registry.request;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.request.RequestParameters.extractBooleanParameter;
import static google.registry.request.RequestParameters.extractEnumParameter;
import static google.registry.request.RequestParameters.extractOptionalDatetimeParameter;
import static google.registry.request.RequestParameters.extractOptionalEnumParameter;
import static google.registry.request.RequestParameters.extractOptionalInstantParameter;
import static google.registry.request.RequestParameters.extractOptionalParameter;
import static google.registry.request.RequestParameters.extractRequiredDatetimeParameter;
import static google.registry.request.RequestParameters.extractRequiredInstantParameter;
import static google.registry.request.RequestParameters.extractRequiredParameter;
import static google.registry.request.RequestParameters.extractSetOfEnumParameters;
import static google.registry.request.RequestParameters.extractSetOfParameters;
@@ -31,7 +31,7 @@ import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableMap;
import google.registry.request.HttpException.BadRequestException;
import jakarta.servlet.http.HttpServletRequest;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link RequestParameters}. */
@@ -257,8 +257,8 @@ class RequestParametersTest {
@Test
void testExtractRequiredDatetimeParameter_correctValue_works() {
when(req.getParameter("timeParam")).thenReturn("2015-08-27T13:25:34.123Z");
assertThat(extractRequiredDatetimeParameter(req, "timeParam"))
.isEqualTo(DateTime.parse("2015-08-27T13:25:34.123Z"));
assertThat(extractRequiredInstantParameter(req, "timeParam"))
.isEqualTo(Instant.parse("2015-08-27T13:25:34.123Z"));
}
@Test
@@ -266,15 +266,15 @@ class RequestParametersTest {
when(req.getParameter("timeParam")).thenReturn("Tuesday at three o'clock");
BadRequestException thrown =
assertThrows(
BadRequestException.class, () -> extractRequiredDatetimeParameter(req, "timeParam"));
BadRequestException.class, () -> extractRequiredInstantParameter(req, "timeParam"));
assertThat(thrown).hasMessageThat().contains("timeParam");
}
@Test
void testExtractOptionalDatetimeParameter_correctValue_works() {
when(req.getParameter("timeParam")).thenReturn("2015-08-27T13:25:34.123Z");
assertThat(extractOptionalDatetimeParameter(req, "timeParam"))
.hasValue(DateTime.parse("2015-08-27T13:25:34.123Z"));
assertThat(extractOptionalInstantParameter(req, "timeParam"))
.hasValue(Instant.parse("2015-08-27T13:25:34.123Z"));
}
@Test
@@ -282,21 +282,21 @@ class RequestParametersTest {
when(req.getParameter("timeParam")).thenReturn("Tuesday at three o'clock");
BadRequestException thrown =
assertThrows(
BadRequestException.class, () -> extractOptionalDatetimeParameter(req, "timeParam"));
BadRequestException.class, () -> extractOptionalInstantParameter(req, "timeParam"));
assertThat(thrown).hasMessageThat().contains("timeParam");
}
@Test
void testExtractOptionalDatetimeParameter_empty_returnsEmpty() {
when(req.getParameter("timeParam")).thenReturn("");
assertThat(extractOptionalDatetimeParameter(req, "timeParam")).isEmpty();
assertThat(extractOptionalInstantParameter(req, "timeParam")).isEmpty();
}
@Test
void testExtractRequiredDatetimeParameter_noValue_throwsBadRequest() {
BadRequestException thrown =
assertThrows(
BadRequestException.class, () -> extractRequiredDatetimeParameter(req, "timeParam"));
BadRequestException.class, () -> extractRequiredInstantParameter(req, "timeParam"));
assertThat(thrown).hasMessageThat().contains("timeParam");
}
}
@@ -18,7 +18,6 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatabaseHelper.existsInDb;
import static google.registry.testing.DatabaseHelper.loadByKey;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.collect.ImmutableList;
import google.registry.model.registrar.Registrar;
@@ -27,7 +26,7 @@ import google.registry.persistence.VKey;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationWithCoverageExtension;
import google.registry.testing.FakeClock;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -35,7 +34,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for persisting {@link Registrar} entities. */
public class RegistrarDaoTest {
protected FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
protected FakeClock fakeClock = new FakeClock(Instant.now());
@RegisterExtension
JpaIntegrationWithCoverageExtension jpa =
@@ -70,7 +70,6 @@ import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import org.joda.time.DateTime;
/**
* Static utility functions for testing task queues.
@@ -361,10 +360,6 @@ public class CloudTasksHelper implements Serializable {
return scheduleTime(Timestamps.fromMillis(scheduleTime.toEpochMilli()));
}
public TaskMatcher scheduleTime(DateTime scheduleTime) {
return scheduleTime(Timestamps.fromMillis(scheduleTime.getMillis()));
}
public TaskMatcher param(String key, String value) {
checkNotNull(value, "Test error: A param can never have a null value, so don't assert it");
expected.params.put(key, value);
@@ -27,7 +27,7 @@ import google.registry.ui.server.SendEmailUtils;
import google.registry.ui.server.console.ConsoleApiParams;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import org.joda.time.DateTime;
import java.time.Instant;
public final class ConsoleApiParamsUtils {
@@ -37,7 +37,7 @@ public final class ConsoleApiParamsUtils {
SendEmailUtils sendEmailUtils =
new SendEmailUtils(ImmutableList.of("notification@test.example"), gmailClient);
XsrfTokenManager xsrfTokenManager =
new XsrfTokenManager(new FakeClock(DateTime.parse("2020-02-02T01:23:45Z")));
new XsrfTokenManager(new FakeClock(Instant.parse("2020-02-02T01:23:45Z")));
when(request.getCookies())
.thenReturn(
new Cookie[] {
@@ -17,7 +17,6 @@ package google.registry.testing;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.Fact.simpleFact;
import static com.google.common.truth.Truth.assertAbout;
import static google.registry.util.DateTimeUtils.toInstant;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import com.google.common.collect.ImmutableSet;
@@ -32,7 +31,6 @@ import google.registry.tmch.LordnTaskUtils.LordnPhase;
import java.time.Instant;
import java.util.Set;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
/** Truth subject for asserting things about {@link Domain} instances. */
public final class DomainSubject extends AbstractEppResourceSubject<Domain, DomainSubject> {
@@ -78,27 +76,15 @@ public final class DomainSubject extends AbstractEppResourceSubject<Domain, Doma
registrarId, actual.getCurrentSponsorRegistrarId(), "currentSponsorRegistrarId");
}
public And<DomainSubject> hasRegistrationExpirationTime(DateTime expiration) {
return hasRegistrationExpirationTime(toInstant(expiration));
}
public And<DomainSubject> hasRegistrationExpirationTime(Instant expiration) {
return hasValue(
expiration, actual.getRegistrationExpirationTime(), "getRegistrationExpirationTime()");
}
public And<DomainSubject> hasLastTransferTime(DateTime lastTransferTime) {
return hasLastTransferTime(toInstant(lastTransferTime));
}
public And<DomainSubject> hasLastTransferTime(Instant lastTransferTime) {
return hasValue(lastTransferTime, actual.getLastTransferTime(), "getLastTransferTime()");
}
public And<DomainSubject> hasLastTransferTimeNotEqualTo(DateTime lastTransferTime) {
return hasLastTransferTimeNotEqualTo(toInstant(lastTransferTime));
}
public And<DomainSubject> hasLastTransferTimeNotEqualTo(Instant lastTransferTime) {
return doesNotHaveValue(
lastTransferTime, actual.getLastTransferTime(), "getLastTransferTime()");
@@ -122,10 +108,6 @@ public final class DomainSubject extends AbstractEppResourceSubject<Domain, Doma
return hasValue(smdId, actual.getSmdId(), "getSmdId()");
}
public And<DomainSubject> hasAutorenewEndTime(DateTime autorenewEndTime) {
return hasAutorenewEndTime(toInstant(autorenewEndTime));
}
public And<DomainSubject> hasAutorenewEndTime(Instant autorenewEndTime) {
checkArgumentNotNull(autorenewEndTime, "Use hasNoAutorenewEndTime() instead");
return hasValue(
@@ -16,7 +16,6 @@ package google.registry.testing;
import static com.google.common.truth.Fact.simpleFact;
import static com.google.common.truth.Truth.assertAbout;
import static google.registry.util.DateTimeUtils.toInstant;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.SimpleSubjectBuilder;
@@ -27,7 +26,6 @@ import google.registry.model.reporting.HistoryEntry;
import google.registry.testing.TruthChainer.And;
import java.time.Instant;
import java.util.Optional;
import org.joda.time.DateTime;
/** Utility methods for asserting things about {@link HistoryEntry} instances. */
public class HistoryEntrySubject extends Subject {
@@ -66,11 +64,6 @@ public class HistoryEntrySubject extends Subject {
otherRegistrarId, ((DomainHistory) actual).getOtherRegistrarId(), "getOtherRegistrarId()");
}
public And<HistoryEntrySubject> hasModificationTime(DateTime modificationTime) {
return hasValue(
toInstant(modificationTime), actual.getModificationTime(), "getModificationTime()");
}
public And<HistoryEntrySubject> hasModificationTime(Instant modificationTime) {
return hasValue(modificationTime, actual.getModificationTime(), "getModificationTime()");
}
@@ -127,7 +120,7 @@ public class HistoryEntrySubject extends Subject {
return assertAbout(historyEntries());
}
public static Factory<HistoryEntrySubject, HistoryEntry> historyEntries() {
public static Subject.Factory<HistoryEntrySubject, HistoryEntry> historyEntries() {
return HistoryEntrySubject::new;
}
}
@@ -16,14 +16,13 @@ package google.registry.tmch;
import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.US_ASCII;
import static org.joda.time.Duration.millis;
import static org.joda.time.Duration.standardDays;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableList;
import com.google.common.io.CharSource;
import google.registry.model.smd.SignedMarkRevocationList;
import google.registry.testing.FakeClock;
import java.time.Duration;
import java.time.Instant;
import java.time.format.DateTimeParseException;
import org.junit.jupiter.api.Test;
@@ -50,7 +49,7 @@ class SmdrlCsvParserTest {
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));
clock.advanceBy(Duration.ofMillis(2));
assertThat(smdrl.isSmdRevoked("0000001681375789102250-65535", clock.now())).isTrue();
}
@@ -61,7 +60,7 @@ class SmdrlCsvParserTest {
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));
clock.advanceBy(Duration.ofMillis(2));
assertThat(smdrl.isSmdRevoked("0000002211373633641407-65535", clock.now())).isTrue();
}
@@ -70,7 +69,7 @@ class SmdrlCsvParserTest {
SignedMarkRevocationList smdrl = SmdrlCsvParser.parse(SMDRL_LATEST_CSV.readLines());
clock.setTo(Instant.parse("2013-08-09T12:00:00.0Z"));
assertThat(smdrl.isSmdRevoked("0000002101376042766438-65535", clock.now())).isFalse();
clock.advanceBy(standardDays(1));
clock.advanceBy(Duration.ofDays(1));
assertThat(smdrl.isSmdRevoked("0000002101376042766438-65535", clock.now())).isTrue();
}
@@ -41,8 +41,8 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.file.Path;
import java.time.Instant;
import java.util.List;
import org.joda.time.DateTime;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -64,7 +64,7 @@ public abstract class CommandTestCase<C extends Command> {
protected C command;
protected final FakeClock fakeClock = new FakeClock(DateTime.parse("2022-09-01T00:00:00.000Z"));
protected final FakeClock fakeClock = new FakeClock(Instant.parse("2022-09-01T00:00:00.000Z"));
@RegisterExtension
final JpaIntegrationTestExtension jpa =
@@ -25,9 +25,7 @@ import static google.registry.testing.DatabaseHelper.createTlds;
import static google.registry.testing.DatabaseHelper.loadAllOf;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.util.DateTimeUtils.START_INSTANT;
import static google.registry.util.DateTimeUtils.toInstant;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.DateTimeZone.UTC;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.beust.jcommander.ParameterException;
@@ -47,11 +45,11 @@ import google.registry.util.StringGenerator.Alphabets;
import java.io.File;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneOffset;
import java.util.Collection;
import javax.annotation.Nullable;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -136,8 +134,8 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
@Test
void testSuccess_promotionToken() throws Exception {
DateTime promoStart = DateTime.now(UTC);
DateTime promoEnd = promoStart.plusMonths(1);
Instant promoStart = fakeClock.now();
Instant promoEnd = promoStart.atZone(ZoneOffset.UTC).plusMonths(1).toInstant();
runCommand(
"--number", "1",
"--prefix", "promo",
@@ -163,16 +161,16 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
.setTokenStatusTransitions(
ImmutableSortedMap.<Instant, TokenStatus>naturalOrder()
.put(START_INSTANT, TokenStatus.NOT_STARTED)
.put(toInstant(promoStart), TokenStatus.VALID)
.put(toInstant(promoEnd), TokenStatus.ENDED)
.put(promoStart, TokenStatus.VALID)
.put(promoEnd, TokenStatus.ENDED)
.build())
.build());
}
@Test
void testSuccess_promotionToken_withDiscountPrice() throws Exception {
DateTime promoStart = DateTime.now(UTC);
DateTime promoEnd = promoStart.plusMonths(1);
Instant promoStart = fakeClock.now();
Instant promoEnd = promoStart.atZone(ZoneOffset.UTC).plusMonths(1).toInstant();
runCommand(
"--number",
"1",
@@ -205,8 +203,8 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
.setTokenStatusTransitions(
ImmutableSortedMap.<Instant, TokenStatus>naturalOrder()
.put(START_INSTANT, TokenStatus.NOT_STARTED)
.put(toInstant(promoStart), TokenStatus.VALID)
.put(toInstant(promoEnd), TokenStatus.ENDED)
.put(promoStart, TokenStatus.VALID)
.put(promoEnd, TokenStatus.ENDED)
.build())
.build());
}
@@ -479,7 +477,7 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
"--number",
"999",
String.format(
"--token_status_transitions=\"%s=INVALID_STATUS\"", START_INSTANT))))
"--token_status_transitions=%s=INVALID_STATUS", START_INSTANT))))
.hasCauseThat()
.isInstanceOf(IllegalArgumentException.class);
}
@@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import com.beust.jcommander.ParameterException;
import google.registry.testing.CloudTasksHelper;
import google.registry.testing.CloudTasksHelper.TaskMatcher;
import java.time.format.DateTimeParseException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.junit.jupiter.MockitoSettings;
@@ -103,11 +104,11 @@ public class GenerateEscrowDepositCommandTest
@Test
void testCommand_malformedWatermark() {
IllegalArgumentException thrown =
DateTimeParseException thrown =
assertThrows(
IllegalArgumentException.class,
DateTimeParseException.class,
() -> runCommand("--tld=tld", "--watermark=blah", "--mode=full", "-r 42", "-o test"));
assertThat(thrown).hasMessageThat().contains("Invalid format: \"blah\"");
assertThat(thrown).hasMessageThat().contains("could not be parsed");
}
@Test
@@ -24,7 +24,7 @@ import google.registry.model.domain.launch.LaunchNotice;
import google.registry.testing.DatabaseHelper;
import java.nio.file.Files;
import java.nio.file.Path;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -35,7 +35,7 @@ class GenerateLordnCommandTest extends CommandTestCase<GenerateLordnCommand> {
@BeforeEach
void beforeEach() {
fakeClock.setTo(DateTime.parse("2021-04-16T10:04:00.000Z"));
fakeClock.setTo(Instant.parse("2021-04-16T10:04:00.000Z"));
command.clock = fakeClock;
}
@@ -137,4 +137,3 @@ class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
assertInStdout("Websafe key: kind:Domain@sql:rO0ABXQABTMtVExE");
}
}
@@ -14,7 +14,6 @@
package google.registry.tools;
import com.google.common.collect.ImmutableMap;
import google.registry.model.console.GlobalRole;
import google.registry.model.console.RegistrarRole;
@@ -33,6 +33,8 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -41,8 +43,6 @@ import org.jline.reader.LineReaderBuilder;
import org.jline.reader.impl.DefaultParser;
import org.jline.terminal.Terminal;
import org.jline.terminal.impl.DumbTerminal;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -55,7 +55,7 @@ class ShellCommandTest {
final SystemPropertyExtension systemPropertyExtension = new SystemPropertyExtension();
CommandRunner cli = mock(CommandRunner.class);
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
private final FakeClock clock = new FakeClock(Instant.parse("2000-01-01T00:00:00Z"));
private final DelayingByteArrayInputStream input = new DelayingByteArrayInputStream(clock);
private PrintStream orgStdout;
@@ -112,7 +112,7 @@ class ShellCommandTest {
RegistryToolEnvironment.ALPHA.setup(systemPropertyExtension);
FakeCli cli = new FakeCli();
ShellCommand shellCommand =
createShellCommand(cli, Duration.standardDays(1), "test1 foo bar", "test2 foo bar");
createShellCommand(cli, Duration.ofDays(1), "test1 foo bar", "test2 foo bar");
shellCommand.run();
}
@@ -121,7 +121,7 @@ class ShellCommandTest {
RegistryToolEnvironment.SANDBOX.setup(systemPropertyExtension);
FakeCli cli = new FakeCli();
ShellCommand shellCommand =
createShellCommand(cli, Duration.standardDays(1), "test1 foo bar", "test2 foo bar");
createShellCommand(cli, Duration.ofDays(1), "test1 foo bar", "test2 foo bar");
shellCommand.run();
}
@@ -130,7 +130,7 @@ class ShellCommandTest {
RegistryToolEnvironment.PRODUCTION.setup(systemPropertyExtension);
FakeCli cli = new FakeCli();
ShellCommand shellCommand =
createShellCommand(cli, Duration.standardMinutes(61), "test1 foo bar", "test2 foo bar");
createShellCommand(cli, Duration.ofMinutes(61), "test1 foo bar", "test2 foo bar");
RuntimeException exception = assertThrows(RuntimeException.class, shellCommand::run);
assertThat(exception).hasMessageThat().contains("Been idle for too long");
}
@@ -140,7 +140,7 @@ class ShellCommandTest {
RegistryToolEnvironment.PRODUCTION.setup(systemPropertyExtension);
FakeCli cli = new FakeCli();
ShellCommand shellCommand =
createShellCommand(cli, Duration.standardMinutes(59), "test1 foo bar", "test2 foo bar");
createShellCommand(cli, Duration.ofMinutes(59), "test1 foo bar", "test2 foo bar");
shellCommand.run();
}
@@ -276,13 +276,13 @@ class ShellCommandTest {
assertThat(stdout.toString(US_ASCII))
.isEqualTo(
"""
RUNNING "command1"
out: first line
err: second line
err: surprise!
out: fragmented line
SUCCESS
""");
RUNNING "command1"
out: first line
err: second line
err: surprise!
out: fragmented line
SUCCESS
""");
}
@Test
@@ -302,10 +302,10 @@ class ShellCommandTest {
assertThat(stdout.toString(US_ASCII))
.isEqualTo(
"""
RUNNING "command1"
out: first line
FAILURE java.lang.Exception some error!
""");
RUNNING "command1"
out: first line
FAILURE java.lang.Exception some error!
""");
}
@Test
@@ -14,7 +14,6 @@
package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.domain.rgp.GracePeriodStatus.AUTO_RENEW;
import static google.registry.model.eppcommon.StatusValue.PENDING_DELETE;
@@ -44,7 +44,6 @@ 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.Test;
@@ -255,7 +254,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
@Test
void testSuccess_certFile() throws Exception {
fakeClock.setTo(DateTime.parse("2020-11-01T00:00:00Z"));
fakeClock.setTo(Instant.parse("2020-11-01T00:00:00Z"));
Registrar registrar = loadRegistrar("NewRegistrar");
assertThat(registrar.getClientCertificate()).isEmpty();
assertThat(registrar.getClientCertificateHash()).isEmpty();
@@ -271,7 +270,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
@Test
void testSuccess_rotatePrimaryCert() throws Exception {
fakeClock.setTo(DateTime.parse("2020-11-01T00:00:00Z"));
fakeClock.setTo(Instant.parse("2020-11-01T00:00:00Z"));
persistResource(
loadRegistrar("NewRegistrar")
.asBuilder()
@@ -295,7 +294,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
@Test
void test_rotatePrimaryCert_noPrimaryCert() throws Exception {
fakeClock.setTo(DateTime.parse("2020-11-01T00:00:00Z"));
fakeClock.setTo(Instant.parse("2020-11-01T00:00:00Z"));
Registrar registrar = loadRegistrar("NewRegistrar");
assertThat(registrar.getClientCertificate()).isEmpty();
assertThat(registrar.getClientCertificateHash()).isEmpty();
@@ -327,7 +326,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
@Test
void testFail_certFileWithViolation() throws Exception {
fakeClock.setTo(DateTime.parse("2020-11-01T00:00:00Z"));
fakeClock.setTo(Instant.parse("2020-11-01T00:00:00Z"));
Registrar registrar = loadRegistrar("NewRegistrar");
assertThat(registrar.getClientCertificate()).isEmpty();
assertThat(registrar.getClientCertificateHash()).isEmpty();
@@ -344,7 +343,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
@Test
void testFail_certFileWithMultipleViolations() throws Exception {
fakeClock.setTo(DateTime.parse("2055-10-01T00:00:00Z"));
fakeClock.setTo(Instant.parse("2055-10-01T00:00:00Z"));
Registrar registrar = loadRegistrar("NewRegistrar");
assertThat(registrar.getClientCertificate()).isEmpty();
assertThat(registrar.getClientCertificateHash()).isEmpty();
@@ -361,7 +360,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
@Test
void testFail_failoverCertFileWithViolation() throws Exception {
fakeClock.setTo(DateTime.parse("2020-11-01T00:00:00Z"));
fakeClock.setTo(Instant.parse("2020-11-01T00:00:00Z"));
Registrar registrar = loadRegistrar("NewRegistrar");
assertThat(registrar.getFailoverClientCertificate()).isEmpty();
InsecureCertificateException thrown =
@@ -378,7 +377,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
@Test
void testFail_failoverCertFileWithMultipleViolations() throws Exception {
fakeClock.setTo(DateTime.parse("2055-10-01T00:00:00Z"));
fakeClock.setTo(Instant.parse("2055-10-01T00:00:00Z"));
Registrar registrar = loadRegistrar("NewRegistrar");
assertThat(registrar.getFailoverClientCertificate()).isEmpty();
InsecureCertificateException thrown =
@@ -395,7 +394,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarCommand>
@Test
void testSuccess_failoverCertFile() throws Exception {
fakeClock.setTo(DateTime.parse("2020-11-01T00:00:00Z"));
fakeClock.setTo(Instant.parse("2020-11-01T00:00:00Z"));
Registrar registrar = loadRegistrar("NewRegistrar");
assertThat(registrar.getFailoverClientCertificate()).isEmpty();
runCommand("--failover_cert_file=" + getCertFilename(SAMPLE_CERT3), "--force", "NewRegistrar");
@@ -37,7 +37,6 @@ import google.registry.util.CidrAddressBlock;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -61,7 +60,7 @@ class ValidateLoginCredentialsCommandTest extends CommandTestCase<ValidateLoginC
.setState(ACTIVE)
.setAllowedTlds(ImmutableSet.of("tld"))
.build());
fakeClock.setTo(DateTime.parse("2020-11-01T00:00:00Z"));
fakeClock.setTo(Instant.parse("2020-11-01T00:00:00Z"));
command.certificateChecker =
new CertificateChecker(
ImmutableSortedMap.of(START_INSTANT, 825, Instant.parse("2020-09-01T00:00:00Z"), 398),
@@ -108,7 +108,6 @@ public class RecreateBillingRecurrencesCommandTest
otherNewRecurrence);
}
@Test
void testFailure_badDomain() {
assertThat(assertThrows(IllegalArgumentException.class, () -> runCommandForced("foo.tld")))
@@ -17,7 +17,8 @@ package google.registry.tools.params;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.joda.time.DateTime;
import java.time.Instant;
import java.time.format.DateTimeParseException;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link DateParameter}. */
@@ -28,23 +29,22 @@ class DateParameterTest {
@Test
void testConvert_onlyDate() {
String exampleDate = "2014-01-01";
assertThat(instance.convert(exampleDate)).isEqualTo(DateTime.parse("2014-01-01T00:00:00Z"));
assertThat(instance.convert(exampleDate)).isEqualTo(Instant.parse("2014-01-01T00:00:00Z"));
}
@Test
void testConvert_numeric_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("1234"));
assertThrows(DateTimeParseException.class, () -> instance.convert("1234"));
}
@Test
void testConvert_validDateAndTime_throwsException() {
assertThrows(
IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02:03.004Z"));
assertThrows(DateTimeParseException.class, () -> instance.convert("2014-01-01T01:02:03.004Z"));
}
@Test
void testConvert_invalidDate_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-13-33"));
assertThrows(DateTimeParseException.class, () -> instance.convert("2014-13-33"));
}
@Test
@@ -54,31 +54,31 @@ class DateParameterTest {
@Test
void testConvert_empty_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
assertThrows(DateTimeParseException.class, () -> instance.convert(""));
}
@Test
void testConvert_sillyString_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
assertThrows(DateTimeParseException.class, () -> instance.convert("foo"));
}
@Test
void testConvert_partialDate_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01"));
assertThrows(DateTimeParseException.class, () -> instance.convert("2014-01"));
}
@Test
void testConvert_onlyTime_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("T01:02:03"));
assertThrows(DateTimeParseException.class, () -> instance.convert("T01:02:03"));
}
@Test
void testConvert_partialDateAndPartialTime_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("9T9"));
assertThrows(DateTimeParseException.class, () -> instance.convert("9T9"));
}
@Test
void testConvert_dateAndPartialTime_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02"));
assertThrows(DateTimeParseException.class, () -> instance.convert("2014-01-01T01:02"));
}
}
@@ -18,8 +18,8 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.beust.jcommander.ParameterException;
import org.joda.time.Duration;
import org.joda.time.Period;
import java.time.Duration;
import java.time.format.DateTimeParseException;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link DurationParameter}. */
@@ -29,32 +29,32 @@ class DurationParameterTest {
@Test
void testConvert_isoHours() {
assertThat(instance.convert("PT36H")).isEqualTo(Duration.standardHours(36));
assertThat(instance.convert("PT36H")).isEqualTo(Duration.ofHours(36));
}
@Test
void testConvert_isoDaysAndHours() {
assertThat(instance.convert("P1DT12H")).isEqualTo(Duration.standardHours(36));
assertThat(instance.convert("P1DT12H")).isEqualTo(Duration.ofHours(36));
}
@Test
void testConvert_isoLowercase_isAllowed() {
assertThat(instance.convert("pt36h")).isEqualTo(Duration.standardHours(36));
assertThat(instance.convert("pt36h")).isEqualTo(Duration.ofHours(36));
}
@Test
void testIsoMissingP_notAllowed() {
assertThrows(IllegalArgumentException.class, () -> Period.parse("T36H"));
assertThrows(DateTimeParseException.class, () -> instance.convert("T36H"));
}
@Test
void testIsoMissingPT_notAllowed() {
assertThrows(IllegalArgumentException.class, () -> Period.parse("36H"));
assertThrows(DateTimeParseException.class, () -> instance.convert("36H"));
}
@Test
void testConvert_isoMissingP_notAllowed() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("T36H"));
assertThrows(DateTimeParseException.class, () -> instance.convert("T36H"));
}
@Test
@@ -64,17 +64,17 @@ class DurationParameterTest {
@Test
void testConvert_empty_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
assertThrows(DateTimeParseException.class, () -> instance.convert(""));
}
@Test
void testConvert_numeric_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("1234"));
assertThrows(DateTimeParseException.class, () -> instance.convert("1234"));
}
@Test
void testConvert_sillyString_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
assertThrows(DateTimeParseException.class, () -> instance.convert("foo"));
}
@Test
@@ -15,40 +15,39 @@
package google.registry.tools.params;
import static com.google.common.truth.Truth.assertThat;
import static org.joda.time.DateTimeZone.UTC;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.beust.jcommander.ParameterException;
import org.joda.time.DateTime;
import java.time.Instant;
import java.time.format.DateTimeParseException;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link DateTimeParameter}. */
class DateTimeParameterTest {
/** Unit tests for {@link InstantParameter}. */
class InstantParameterTest {
private final DateTimeParameter instance = new DateTimeParameter();
private final InstantParameter instance = new InstantParameter();
@Test
void testConvert_numeric_returnsMillisFromEpochUtc() {
assertThat(instance.convert("1234")).isEqualTo(new DateTime(1234L, UTC));
assertThat(instance.convert("1234")).isEqualTo(Instant.ofEpochMilli(1234L));
}
@Test
void testConvert_iso8601_returnsSameAsDateTimeParse() {
String exampleDate = "2014-01-01T01:02:03.004Z";
assertThat(instance.convert(exampleDate))
.isEqualTo(DateTime.parse(exampleDate));
assertThat(instance.convert(exampleDate)).isEqualTo(Instant.parse(exampleDate));
}
@Test
void testConvert_isoDateTimeWithMillis_returnsSameAsDateTimeParse() {
String exampleDate = "2014-01-01T01:02:03.004Z";
assertThat(instance.convert(exampleDate)).isEqualTo(DateTime.parse(exampleDate));
assertThat(instance.convert(exampleDate)).isEqualTo(Instant.parse(exampleDate));
}
@Test
void testConvert_weirdTimezone_convertsToUtc() {
assertThat(instance.convert("1984-12-18T00:00:00-0520"))
.isEqualTo(DateTime.parse("1984-12-18T05:20:00Z"));
assertThat(instance.convert("1984-12-18T00:00:00-05:20"))
.isEqualTo(Instant.parse("1984-12-18T05:20:00Z"));
}
@Test
@@ -58,47 +57,47 @@ class DateTimeParameterTest {
@Test
void testConvert_empty_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
assertThrows(DateTimeParseException.class, () -> instance.convert(""));
}
@Test
void testConvert_sillyString_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
assertThrows(DateTimeParseException.class, () -> instance.convert("foo"));
}
@Test
void testConvert_partialDate_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01"));
assertThrows(DateTimeParseException.class, () -> instance.convert("2014-01"));
}
@Test
void testConvert_onlyDate_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01"));
assertThrows(DateTimeParseException.class, () -> instance.convert("2014-01-01"));
}
@Test
void testConvert_partialTime_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("T01:02"));
assertThrows(DateTimeParseException.class, () -> instance.convert("T01:02"));
}
@Test
void testConvert_onlyTime_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("T01:02:03"));
assertThrows(DateTimeParseException.class, () -> instance.convert("T01:02:03"));
}
@Test
void testConvert_partialDateAndPartialTime_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("9T9"));
assertThrows(DateTimeParseException.class, () -> instance.convert("9T9"));
}
@Test
void testConvert_dateAndPartialTime_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02"));
assertThrows(DateTimeParseException.class, () -> instance.convert("2014-01-01T01:02"));
}
@Test
void testConvert_noTimeZone_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2014-01-01T01:02:03"));
assertThrows(DateTimeParseException.class, () -> instance.convert("2014-01-01T01:02:03"));
}
@Test
@@ -1,71 +0,0 @@
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.tools.params;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.beust.jcommander.ParameterException;
import org.joda.time.DateTime;
import org.joda.time.Interval;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link IntervalParameter}. */
class IntervalParameterTest {
private final IntervalParameter instance = new IntervalParameter();
@Test
void testConvert() {
assertThat(instance.convert("2004-06-09T12:30:00Z/2004-07-10T13:30:00Z"))
.isEqualTo(new Interval(
DateTime.parse("2004-06-09T12:30:00Z"),
DateTime.parse("2004-07-10T13:30:00Z")));
}
@Test
void testConvert_singleDate() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("2004-06-09T12:30:00Z"));
}
@Test
void testConvert_backwardsInterval() {
assertThrows(
IllegalArgumentException.class,
() -> instance.convert("2004-07-10T13:30:00Z/2004-06-09T12:30:00Z"));
}
@Test
void testConvert_empty_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
}
@Test
void testConvert_null_throws() {
assertThrows(NullPointerException.class, () -> instance.convert(null));
}
@Test
void testConvert_sillyString_throws() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
}
@Test
void testValidate_sillyString_throws() {
ParameterException thrown =
assertThrows(ParameterException.class, () -> instance.validate("--time", "foo"));
assertThat(thrown).hasMessageThat().contains("--time=foo not an");
}
}
@@ -132,4 +132,3 @@ class KeyValueMapParameterTest {
assertThrows(IllegalArgumentException.class, () -> currencyUnitToStringMap.convert("foo"));
}
}
@@ -18,7 +18,8 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.beust.jcommander.ParameterException;
import org.joda.time.YearMonth;
import java.time.YearMonth;
import java.time.format.DateTimeParseException;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link YearMonthParameter}. */
@@ -28,7 +29,7 @@ class YearMonthParameterTest {
@Test
void testConvert_awfulMonth() {
assertThat(instance.convert("1984-12")).isEqualTo(new YearMonth(1984, 12));
assertThat(instance.convert("1984-12")).isEqualTo(YearMonth.of(1984, 12));
}
@Test
@@ -38,22 +39,22 @@ class YearMonthParameterTest {
@Test
void testConvert_empty_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert(""));
assertThrows(DateTimeParseException.class, () -> instance.convert(""));
}
@Test
void testConvert_sillyString_throwsException() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("foo"));
assertThrows(DateTimeParseException.class, () -> instance.convert("foo"));
}
@Test
void testConvert_wrongOrder() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("12-1984"));
assertThrows(DateTimeParseException.class, () -> instance.convert("12-1984"));
}
@Test
void testConvert_noHyphen() {
assertThrows(IllegalArgumentException.class, () -> instance.convert("198412"));
assertThrows(DateTimeParseException.class, () -> instance.convert("198412"));
}
@Test
@@ -18,8 +18,8 @@ import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.persistActiveHost;
import google.registry.testing.FakeClock;
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;
@@ -32,7 +32,7 @@ class ListHostsActionTest extends ListActionTestCase {
void beforeEach() {
createTld("foo");
action = new ListHostsAction();
action.clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
action.clock = new FakeClock(Instant.parse("2000-01-01T00:00:00Z"));
}
@Test
@@ -17,8 +17,8 @@ package google.registry.tools.server;
import static google.registry.testing.DatabaseHelper.createTld;
import google.registry.testing.FakeClock;
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;
@@ -31,7 +31,7 @@ class ListTldsActionTest extends ListActionTestCase {
void beforeEach() {
createTld("xn--q9jyb4c");
action = new ListTldsAction();
action.clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
action.clock = new FakeClock(Instant.parse("2000-01-01T00:00:00Z"));
}
@Test
@@ -25,7 +25,7 @@ import google.registry.testing.ConsoleApiParamsUtils;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeResponse;
import google.registry.tools.GsonUtils;
import org.joda.time.DateTime;
import java.time.Instant;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -33,7 +33,7 @@ public abstract class ConsoleActionBaseTestCase {
protected static final Gson GSON = GsonUtils.provideGson();
protected final FakeClock clock = new FakeClock(DateTime.parse("2024-04-15T00:00:00.000Z"));
protected final FakeClock clock = new FakeClock(Instant.parse("2024-04-15T00:00:00.000Z"));
@RegisterExtension
final JpaTestExtensions.JpaIntegrationTestExtension jpa =
@@ -14,7 +14,6 @@
package google.registry.ui.server.console;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.truth.Truth.assertThat;
import static jakarta.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
@@ -38,7 +38,7 @@ import google.registry.testing.FakeResponse;
import google.registry.tools.DomainLockUtils;
import google.registry.util.StringGenerator;
import jakarta.servlet.http.HttpServletResponse;
import org.joda.time.Duration;
import java.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -150,7 +150,7 @@ public class ConsoleRegistryLockVerifyActionTest extends ConsoleActionBaseTestCa
@Test
void testFailure_expiredLock() {
saveRegistryLock(createDefaultLockBuilder().build());
clock.advanceBy(Duration.standardDays(1));
clock.advanceBy(Duration.ofDays(1));
action.run();
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_BAD_REQUEST);
assertThat(response.getPayload()).isEqualTo("The pending lock has expired; please try again");
@@ -29,10 +29,10 @@ import google.registry.request.auth.AuthResult;
import google.registry.testing.ConsoleApiParamsUtils;
import google.registry.testing.FakeResponse;
import jakarta.servlet.http.HttpServletResponse;
import java.time.Duration;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Nullable;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -135,14 +135,14 @@ public class PasswordResetVerifyActionTest extends ConsoleActionBaseTestCase {
@Test
void testFailure_get_expired() throws Exception {
clock.advanceBy(Duration.standardDays(1));
clock.advanceBy(Duration.ofDays(1));
createAction("GET", verificationCode, null).run();
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_BAD_REQUEST);
}
@Test
void testFailure_post_expired() throws Exception {
clock.advanceBy(Duration.standardDays(1));
clock.advanceBy(Duration.ofDays(1));
createAction("POST", verificationCode, "newPassword").run();
assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_BAD_REQUEST);
}
@@ -84,7 +84,6 @@ class SecurityActionTest extends ConsoleActionBaseTestCase {
AuthenticatedRegistrarAccessor.createForTesting(
ImmutableSetMultimap.of("registrarId", AuthenticatedRegistrarAccessor.Role.ADMIN));
@BeforeEach
void beforeEach() {
testRegistrar = saveRegistrar("registrarId");
@@ -97,7 +97,6 @@ public class ConsoleScreenshotTest {
assertThat(driver.getCurrentUrl()).endsWith("?registrarId=TheRegistrar");
}
@RetryingTest(3)
void dums_mainPage() throws Exception {
server.setGlobalRole(GlobalRole.FTE);
@@ -15,56 +15,54 @@
package google.registry.xml;
import static com.google.common.truth.Truth.assertThat;
import static org.joda.time.DateTimeZone.UTC;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.time.Instant;
import java.time.format.DateTimeParseException;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link UtcDateTimeAdapter}. */
class UtcDateTimeAdapterTest {
/** Unit tests for {@link UtcInstantAdapter}. */
class UtcInstantAdapterTest {
@Test
void testMarshal() {
assertThat(new UtcDateTimeAdapter().marshal(new DateTime(2010, 10, 17, 4, 20, 0, UTC)))
.isEqualTo("2010-10-17T04:20:00Z");
assertThat(new UtcInstantAdapter().marshal(Instant.parse("2010-10-17T04:20:00Z")))
.isEqualTo("2010-10-17T04:20:00.000Z");
}
@Test
void testMarshalConvertsToZuluTime() {
assertThat(new UtcDateTimeAdapter().marshal(
new DateTime(2010, 10, 17, 0, 20, 0, DateTimeZone.forOffsetHours(-4))))
.isEqualTo("2010-10-17T04:20:00Z");
assertThat(new UtcInstantAdapter().marshal(Instant.parse("2010-10-17T00:20:00-04:00")))
.isEqualTo("2010-10-17T04:20:00.000Z");
}
@Test
void testMarshalEmpty() {
assertThat(new UtcDateTimeAdapter().marshal(null)).isEmpty();
assertThat(new UtcInstantAdapter().marshal(null)).isEmpty();
}
@Test
void testUnmarshal() {
assertThat(new UtcDateTimeAdapter().unmarshal("2010-10-17T04:20:00Z"))
.isEqualTo(new DateTime(2010, 10, 17, 4, 20, 0, UTC));
assertThat(new UtcInstantAdapter().unmarshal("2010-10-17T04:20:00Z"))
.isEqualTo(Instant.parse("2010-10-17T04:20:00Z"));
}
@Test
void testUnmarshalConvertsToZuluTime() {
assertThat(new UtcDateTimeAdapter().unmarshal("2010-10-17T00:20:00-04:00"))
.isEqualTo(new DateTime(2010, 10, 17, 4, 20, 0, UTC));
assertThat(new UtcInstantAdapter().unmarshal("2010-10-17T00:20:00-04:00"))
.isEqualTo(Instant.parse("2010-10-17T04:20:00Z"));
}
@Test
void testUnmarshalEmpty() {
assertThat(new UtcDateTimeAdapter().unmarshal(null)).isNull();
assertThat(new UtcDateTimeAdapter().unmarshal("")).isNull();
assertThat(new UtcInstantAdapter().unmarshal(null)).isNull();
assertThat(new UtcInstantAdapter().unmarshal("")).isNull();
}
@Test
void testUnmarshalInvalid() {
assertThrows(
IllegalArgumentException.class,
() -> assertThat(new UtcDateTimeAdapter().unmarshal("oh my goth")).isNull());
DateTimeParseException.class,
() -> assertThat(new UtcInstantAdapter().unmarshal("oh my goth")).isNull());
}
}
@@ -17,7 +17,6 @@ package google.registry.xml;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.util.DiffUtils.prettyPrintXmlDeepDiff;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
@@ -26,6 +25,9 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.net.InetAddresses;
import com.google.common.net.InternetDomainName;
import java.time.Instant;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.HashSet;
@@ -33,7 +35,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
import org.joda.time.format.ISODateTimeFormat;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.XML;
@@ -247,18 +248,12 @@ public class XmlTestUtils {
}
String string = obj.toString();
// We use a slightly different datetime format (both legal) than the samples, so normalize
// both into Datetime objects.
// both into Instant objects.
try {
return new AbstractMap.SimpleEntry<>(
null, ISODateTimeFormat.dateTime().parseDateTime(string).toDateTime(UTC));
} catch (IllegalArgumentException e) {
// It wasn't a DateTime.
}
try {
return new AbstractMap.SimpleEntry<>(
null, ISODateTimeFormat.dateTimeNoMillis().parseDateTime(string).toDateTime(UTC));
} catch (IllegalArgumentException e) {
// It wasn't a DateTime.
null, Instant.parse(string).truncatedTo(ChronoUnit.SECONDS));
} catch (DateTimeParseException e) {
// It wasn't an Instant.
}
try {
if (!InternetDomainName.isValid(string)) {
@@ -284,4 +279,3 @@ public class XmlTestUtils {
ImmutableMap.of()).getValue();
}
}
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rde:deposit xmlns:contact="urn:ietf:params:xml:ns:contact-1.0" xmlns:rdeContact="urn:ietf:params:xml:ns:rdeContact-1.0" xmlns:launch="urn:ietf:params:xml:ns:launch-1.0" xmlns:rdeEppParams="urn:ietf:params:xml:ns:rdeEppParams-1.0" xmlns:rdeNotification="urn:ietf:params:xml:ns:rdeNotification-1.0" xmlns:host="urn:ietf:params:xml:ns:host-1.0" xmlns:rdeIDN="urn:ietf:params:xml:ns:rdeIDN-1.0" xmlns:eppcom="urn:ietf:params:xml:ns:eppcom-1.0" xmlns:smd="urn:ietf:params:xml:ns:signedMark-1.0" xmlns:rdeHost="urn:ietf:params:xml:ns:rdeHost-1.0" xmlns:rdeReport="urn:ietf:params:xml:ns:rdeReport-1.0" xmlns:fee11="urn:ietf:params:xml:ns:fee-0.11" xmlns:fee12="urn:ietf:params:xml:ns:fee-0.12" xmlns:iirdea="urn:ietf:params:xml:ns:iirdea-1.0" xmlns:rdeHeader="urn:ietf:params:xml:ns:rdeHeader-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xmlns:rdeDomain="urn:ietf:params:xml:ns:rdeDomain-1.0" xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" xmlns:rdeNNDN="urn:ietf:params:xml:ns:rdeNNDN-1.0" xmlns:rdeRegistrar="urn:ietf:params:xml:ns:rdeRegistrar-1.0" xmlns:rgp="urn:ietf:params:xml:ns:rgp-1.0" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:rde="urn:ietf:params:xml:ns:rde-1.0" xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1" xmlns:mark="urn:ietf:params:xml:ns:mark-1.0" xmlns:rdePolicy="urn:ietf:params:xml:ns:rdePolicy-1.0" xmlns:fee_1_00="urn:ietf:params:xml:ns:epp:fee-1.0" xmlns:fee06="urn:ietf:params:xml:ns:fee-0.6" type="FULL" id="AAAABXDKZ6WAA"%RESEND%>
<rde:watermark>2000-01-01T00:00:00Z</rde:watermark>
<rde:watermark>2000-01-01T00:00:00.000Z</rde:watermark>
<rde:rdeMenu>
<rde:version>1.0</rde:version>
<rde:objURI>urn:ietf:params:xml:ns:rdeDomain-1.0</rde:objURI>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rde:deposit xmlns:contact="urn:ietf:params:xml:ns:contact-1.0" xmlns:rdeContact="urn:ietf:params:xml:ns:rdeContact-1.0" xmlns:launch="urn:ietf:params:xml:ns:launch-1.0" xmlns:rdeEppParams="urn:ietf:params:xml:ns:rdeEppParams-1.0" xmlns:rdeNotification="urn:ietf:params:xml:ns:rdeNotification-1.0" xmlns:host="urn:ietf:params:xml:ns:host-1.0" xmlns:rdeIDN="urn:ietf:params:xml:ns:rdeIDN-1.0" xmlns:eppcom="urn:ietf:params:xml:ns:eppcom-1.0" xmlns:smd="urn:ietf:params:xml:ns:signedMark-1.0" xmlns:rdeHost="urn:ietf:params:xml:ns:rdeHost-1.0" xmlns:rdeReport="urn:ietf:params:xml:ns:rdeReport-1.0" xmlns:fee11="urn:ietf:params:xml:ns:fee-0.11" xmlns:fee12="urn:ietf:params:xml:ns:fee-0.12" xmlns:iirdea="urn:ietf:params:xml:ns:iirdea-1.0" xmlns:rdeHeader="urn:ietf:params:xml:ns:rdeHeader-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xmlns:rdeDomain="urn:ietf:params:xml:ns:rdeDomain-1.0" xmlns:epp="urn:ietf:params:xml:ns:epp-1.0" xmlns:rdeNNDN="urn:ietf:params:xml:ns:rdeNNDN-1.0" xmlns:rdeRegistrar="urn:ietf:params:xml:ns:rdeRegistrar-1.0" xmlns:rgp="urn:ietf:params:xml:ns:rgp-1.0" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:rde="urn:ietf:params:xml:ns:rde-1.0" xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1" xmlns:mark="urn:ietf:params:xml:ns:mark-1.0" xmlns:rdePolicy="urn:ietf:params:xml:ns:rdePolicy-1.0" xmlns:fee_1_00="urn:ietf:params:xml:ns:epp:fee-1.0" xmlns:fee06="urn:ietf:params:xml:ns:fee-0.6" type="FULL" id="AAAABXDKZ6WAA"%RESEND%>
<rde:watermark>2000-01-01T00:00:00Z</rde:watermark>
<rde:watermark>2000-01-01T00:00:00.000Z</rde:watermark>
<rde:rdeMenu>
<rde:version>1.0</rde:version>
<rde:objURI>urn:ietf:params:xml:ns:rdeDomain-1.0</rde:objURI>
@@ -5,9 +5,9 @@
<rdeReport:rydeSpecEscrow>draft-arias-noguchi-registry-data-escrow-06</rdeReport:rydeSpecEscrow>
<rdeReport:rydeSpecMapping>draft-arias-noguchi-dnrd-objects-mapping-05</rdeReport:rydeSpecMapping>
<rdeReport:resend>%RESEND%</rdeReport:resend>
<rdeReport:crDate>2000-01-01T00:00:00Z</rdeReport:crDate>
<rdeReport:crDate>2000-01-01T00:00:00.000Z</rdeReport:crDate>
<rdeReport:kind>FULL</rdeReport:kind>
<rdeReport:watermark>2000-01-01T00:00:00Z</rdeReport:watermark>
<rdeReport:watermark>2000-01-01T00:00:00.000Z</rdeReport:watermark>
<rdeHeader:header>
<rdeHeader:tld>soy</rdeHeader:tld>
<rdeHeader:count uri="urn:ietf:params:xml:ns:rdeDomain-1.0">1</rdeHeader:count>
@@ -23,4 +23,3 @@
</trID>
</response>
</epp>
@@ -77,8 +77,6 @@
<rdeDom:exDate>2015-04-03T22:00:00.0Z</rdeDom:exDate>
</rdeDom:domain>
<!-- Host: ns1.example.com -->
<rdeHost:host>
<rdeHost:name>ns1.example.com</rdeHost:name>