mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Fix all uses of DateTime.now() to use DateTimeZone.UTC
Almost all uses were in test classes, which I replaced with clock.nowUTC(). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=134993149
This commit is contained in:
parent
d853e59c7f
commit
b7a2c36be8
10 changed files with 26 additions and 24 deletions
|
@ -81,7 +81,7 @@ import org.joda.time.DateTime;
|
|||
* try (OutputStream output = new FileOutputStream(out);
|
||||
* Ghostryde.Encryptor encryptor = ghost.openEncryptor(output, publicKey);
|
||||
* Ghostryde.Compressor kompressor = ghost.openCompressor(encryptor);
|
||||
* OutputStream go = ghost.openOutput(kompressor, in.getName(), DateTime.now());
|
||||
* OutputStream go = ghost.openOutput(kompressor, in.getName(), DateTime.now(UTC));
|
||||
* InputStream input = new FileInputStream(in)) {
|
||||
* ByteStreams.copy(input, go);
|
||||
* }}</pre>
|
||||
|
@ -109,7 +109,7 @@ import org.joda.time.DateTime;
|
|||
*
|
||||
* <pre> {@code
|
||||
* byte[] data = "hello kitty".getBytes(UTF_8);
|
||||
* byte[] blob = Ghostryde.encode(data, publicKey, "lol.txt", DateTime.now());
|
||||
* byte[] blob = Ghostryde.encode(data, publicKey, "lol.txt", DateTime.now(UTC));
|
||||
* Ghostryde.Result result = Ghostryde.decode(blob, privateKey);
|
||||
* }</pre>
|
||||
*
|
||||
|
|
|
@ -38,7 +38,6 @@ import java.io.InputStream;
|
|||
import javax.inject.Inject;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
* Utility functions for escrow file import.
|
||||
|
@ -134,7 +133,7 @@ public class RdeImportUtils {
|
|||
String tld = parser.getHeader().getTld();
|
||||
try {
|
||||
Registry registry = Registry.get(tld);
|
||||
TldState currentState = registry.getTldState(DateTime.now());
|
||||
TldState currentState = registry.getTldState(clock.nowUtc());
|
||||
checkArgument(
|
||||
currentState == TldState.PREDELEGATION,
|
||||
String.format("Tld '%s' is in state %s and cannot be imported", tld, currentState));
|
||||
|
|
|
@ -50,7 +50,7 @@ public class ContactInfoFlowTest extends ResourceFlowTestCase<ContactInfoFlow, C
|
|||
new ContactResource.Builder()
|
||||
.setContactId("sh8013")
|
||||
.setRepoId("2FF-ROID")
|
||||
.setDeletionTime(active ? null : DateTime.now().minusDays(1))
|
||||
.setDeletionTime(active ? null : clock.nowUtc().minusDays(1))
|
||||
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_DELETE_PROHIBITED))
|
||||
.setInternationalizedPostalInfo(new PostalInfo.Builder()
|
||||
.setType(Type.INTERNATIONALIZED)
|
||||
|
@ -87,7 +87,7 @@ public class ContactInfoFlowTest extends ResourceFlowTestCase<ContactInfoFlow, C
|
|||
.setEmail(new PresenceMarker())
|
||||
.build())
|
||||
.build());
|
||||
assertThat(isDeleted(contact, DateTime.now())).isNotEqualTo(active);
|
||||
assertThat(isDeleted(contact, clock.nowUtc())).isNotEqualTo(active);
|
||||
return contact;
|
||||
}
|
||||
|
||||
|
|
|
@ -274,7 +274,7 @@ public class DomainApplicationInfoFlowTest
|
|||
persistResource(new DomainApplication.Builder()
|
||||
.setRepoId("123-COM")
|
||||
.setFullyQualifiedDomainName("timber.com")
|
||||
.setDeletionTime(DateTime.now().minusDays(1))
|
||||
.setDeletionTime(clock.nowUtc().minusDays(1))
|
||||
.setRegistrant(Key.create(persistActiveContact("jd1234")))
|
||||
.build());
|
||||
runFlow();
|
||||
|
|
|
@ -51,7 +51,7 @@ public class HostInfoFlowTest extends ResourceFlowTestCase<HostInfoFlow, HostRes
|
|||
new HostResource.Builder()
|
||||
.setFullyQualifiedHostName(getUniqueIdFromCommand())
|
||||
.setRepoId("1FF-FOOBAR")
|
||||
.setDeletionTime(active ? null : DateTime.now().minusDays(1))
|
||||
.setDeletionTime(active ? null : clock.nowUtc().minusDays(1))
|
||||
.setCurrentSponsorClientId("my sponsor")
|
||||
.setStatusValues(
|
||||
ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
|
||||
|
@ -66,7 +66,7 @@ public class HostInfoFlowTest extends ResourceFlowTestCase<HostInfoFlow, HostRes
|
|||
.setLastEppUpdateTime(DateTime.parse("1999-12-03T09:00:00.0Z"))
|
||||
.setLastTransferTime(DateTime.parse("2000-04-08T09:00:00.0Z"))
|
||||
.build());
|
||||
assertThat(isDeleted(host, DateTime.now())).isNotEqualTo(active);
|
||||
assertThat(isDeleted(host, clock.nowUtc())).isNotEqualTo(active);
|
||||
return host;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import static google.registry.testing.DatastoreHelper.createTld;
|
|||
import static google.registry.testing.DatastoreHelper.newDomainApplication;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistSimpleResource;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.googlecode.objectify.Key;
|
||||
|
@ -63,14 +64,14 @@ public class DomainApplicationIndexTest extends EntityTestCase {
|
|||
DomainApplicationIndex savedIndex = DomainApplicationIndex.load("example.com");
|
||||
assertThat(savedIndex).isNotNull();
|
||||
assertThat(savedIndex.getKeys()).containsExactly(Key.create(application));
|
||||
assertThat(loadActiveApplicationsByDomainName("example.com", DateTime.now()))
|
||||
assertThat(loadActiveApplicationsByDomainName("example.com", clock.nowUtc()))
|
||||
.containsExactly(application);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_noApplications() {
|
||||
assertThat(DomainApplicationIndex.load("example.com")).isNull();
|
||||
assertThat(loadActiveApplicationsByDomainName("example.com", DateTime.now())).isEmpty();
|
||||
assertThat(loadActiveApplicationsByDomainName("example.com", clock.nowUtc())).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -85,7 +86,7 @@ public class DomainApplicationIndexTest extends EntityTestCase {
|
|||
assertThat(savedIndex).isNotNull();
|
||||
assertThat(savedIndex.getKeys()).containsExactly(
|
||||
Key.create(application1), Key.create(application2), Key.create(application3));
|
||||
assertThat(loadActiveApplicationsByDomainName("example.com", DateTime.now()))
|
||||
assertThat(loadActiveApplicationsByDomainName("example.com", clock.nowUtc()))
|
||||
.containsExactly(application1, application2, application3);
|
||||
}
|
||||
|
||||
|
@ -96,7 +97,7 @@ public class DomainApplicationIndexTest extends EntityTestCase {
|
|||
persistResource(createUpdatedInstance(application1));
|
||||
persistResource(createUpdatedInstance(application2));
|
||||
persistResource(createUpdatedInstance(application1));
|
||||
assertThat(loadActiveApplicationsByDomainName("example.com", DateTime.now()))
|
||||
assertThat(loadActiveApplicationsByDomainName("example.com", clock.nowUtc()))
|
||||
.containsExactly(application1, application2);
|
||||
}
|
||||
|
||||
|
@ -107,14 +108,14 @@ public class DomainApplicationIndexTest extends EntityTestCase {
|
|||
persistSimpleResource(
|
||||
newDomainApplication("example.com")
|
||||
.asBuilder()
|
||||
.setDeletionTime(DateTime.now().minusDays(30))
|
||||
.setDeletionTime(DateTime.now(UTC).minusDays(30))
|
||||
.build());
|
||||
persistResource(createUpdatedInstance(application1));
|
||||
persistResource(createUpdatedInstance(application2));
|
||||
DomainApplicationIndex savedIndex =
|
||||
DomainApplicationIndex.load(application1.getFullyQualifiedDomainName());
|
||||
assertThat(savedIndex.getKeys()).hasSize(2);
|
||||
assertThat(loadActiveApplicationsByDomainName("example.com", DateTime.now()))
|
||||
assertThat(loadActiveApplicationsByDomainName("example.com", DateTime.now(UTC)))
|
||||
.containsExactly(application1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ public class OfyCommitLogTest {
|
|||
@Test
|
||||
public void testTransactNew_deleteNotBackedUpKind_throws() throws Exception {
|
||||
final CommitLogManifest backupsArentAllowedOnMe =
|
||||
CommitLogManifest.create(getBucketKey(1), DateTime.now(), ImmutableSet.<Key<?>>of());
|
||||
CommitLogManifest.create(getBucketKey(1), clock.nowUtc(), ImmutableSet.<Key<?>>of());
|
||||
thrown.expect(IllegalArgumentException.class, "Can't save/delete a @NotBackedUp");
|
||||
ofy().transactNew(new VoidWork() {
|
||||
@Override
|
||||
|
@ -211,7 +211,7 @@ public class OfyCommitLogTest {
|
|||
@Test
|
||||
public void testTransactNew_saveNotBackedUpKind_throws() throws Exception {
|
||||
final CommitLogManifest backupsArentAllowedOnMe =
|
||||
CommitLogManifest.create(getBucketKey(1), DateTime.now(), ImmutableSet.<Key<?>>of());
|
||||
CommitLogManifest.create(getBucketKey(1), clock.nowUtc(), ImmutableSet.<Key<?>>of());
|
||||
ofy().saveWithoutBackup().entity(backupsArentAllowedOnMe).now();
|
||||
thrown.expect(IllegalArgumentException.class, "Can't save/delete a @NotBackedUp");
|
||||
ofy().transactNew(new VoidWork() {
|
||||
|
|
|
@ -19,6 +19,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
|
|||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.persistNewRegistrar;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
@ -79,7 +80,7 @@ public class RdeImportUtilsTest extends ShardableTestCase {
|
|||
@Before
|
||||
public void before() {
|
||||
clock = new FakeClock();
|
||||
clock.setTo(DateTime.now());
|
||||
clock.setTo(DateTime.now(UTC));
|
||||
rdeImportUtils = new RdeImportUtils(ofy(), clock, "import-bucket", gcsUtils);
|
||||
createTld("test", TldState.PREDELEGATION);
|
||||
createTld("getld", TldState.GENERAL_AVAILABILITY);
|
||||
|
@ -188,8 +189,8 @@ public class RdeImportUtilsTest extends ShardableTestCase {
|
|||
}
|
||||
|
||||
/** Confirms that a ForeignKeyIndex exists in the datastore for a given resource. */
|
||||
private static <T extends EppResource> void assertForeignKeyIndexFor(final T resource) {
|
||||
assertThat(ForeignKeyIndex.load(resource.getClass(), resource.getForeignKey(), DateTime.now()))
|
||||
private <T extends EppResource> void assertForeignKeyIndexFor(final T resource) {
|
||||
assertThat(ForeignKeyIndex.load(resource.getClass(), resource.getForeignKey(), clock.nowUtc()))
|
||||
.isNotNull();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import static google.registry.testing.DatastoreHelper.persistResource;
|
|||
import static google.registry.testing.GcsTestingUtils.writeGcsFile;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
import static org.joda.time.Duration.standardDays;
|
||||
import static org.joda.time.Duration.standardSeconds;
|
||||
import static org.mockito.Matchers.any;
|
||||
|
@ -127,7 +128,7 @@ public class RdeReportActionTest {
|
|||
writeGcsFile(
|
||||
gcsService,
|
||||
reportFile,
|
||||
Ghostryde.encode(REPORT_XML.read(), encryptKey, "darkside.xml", DateTime.now()));
|
||||
Ghostryde.encode(REPORT_XML.read(), encryptKey, "darkside.xml", DateTime.now(UTC)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -207,8 +207,8 @@ public class WhoisServerTest {
|
|||
persistResource(makeHostResource("ns2.cat.lol", "bad:f00d:cafe::15:beef")),
|
||||
persistResource(
|
||||
makeRegistrar("example", "Example Registrar", ACTIVE))).asBuilder()
|
||||
.setCreationTimeForTest(DateTime.now().minusDays(2))
|
||||
.setDeletionTime(DateTime.now().minusDays(1)).build());
|
||||
.setCreationTimeForTest(clock.nowUtc().minusDays(2))
|
||||
.setDeletionTime(clock.nowUtc().minusDays(1)).build());
|
||||
DomainResource domain2 = persistResource(makeDomainResource("cat.lol",
|
||||
persistResource(
|
||||
makeContactResource(
|
||||
|
@ -221,7 +221,7 @@ public class WhoisServerTest {
|
|||
persistResource(makeHostResource("ns2.google.lol", "4311::f143")),
|
||||
persistResource((registrar = makeRegistrar(
|
||||
"example", "Example Registrar", ACTIVE)))).asBuilder()
|
||||
.setCreationTimeForTest(DateTime.now()).build());
|
||||
.setCreationTimeForTest(clock.nowUtc()).build());
|
||||
persistSimpleResources(makeRegistrarContacts(registrar));
|
||||
assertThat(domain1.getRepoId()).isNotEqualTo(domain2.getRepoId());
|
||||
newWhoisServer("domain cat.lol\r\n").run();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue