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