Enable Cloud SQL when Datastore is enabled for unit test (#502)

* Enable Cloud SQL when Datastore is enabled for unit test

* Add explanation for why add a ETA field in GenerateEscrowDepositCommand

* Fix line length

* Ignore membershipt test but bring back test suite

* Fix tiny issue
This commit is contained in:
Shicong Huang 2020-03-10 12:26:25 -04:00 committed by GitHub
parent c8387a5669
commit bd0c9e7f51
181 changed files with 874 additions and 992 deletions

Binary file not shown.

View file

@ -870,7 +870,8 @@ test {
// Don't run any tests from this task, all testing gets done in the
// FilteringTest tasks.
exclude "**"
}.dependsOn(fragileTest, outcastTest, standardTest, registryToolIntegrationTest)
// TODO(weiminyu): Remove dependency on sqlIntegrationTest
}.dependsOn(fragileTest, outcastTest, standardTest, registryToolIntegrationTest, sqlIntegrationTest)
createUberJar('nomulus', 'nomulus', 'google.registry.tools.RegistryTool')

View file

@ -28,11 +28,13 @@ import com.beust.jcommander.ParameterException;
import com.beust.jcommander.Parameters;
import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.common.annotations.VisibleForTesting;
import google.registry.model.rde.RdeMode;
import google.registry.rde.RdeStagingAction;
import google.registry.tools.params.DateTimeParameter;
import google.registry.util.AppEngineServiceUtils;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Named;
@ -75,7 +77,16 @@ final class GenerateEscrowDepositCommand implements CommandWithRemoteApi {
private String outdir;
@Inject AppEngineServiceUtils appEngineServiceUtils;
@Inject @Named("rde-report") Queue queue;
@Inject
@Named("rde-report")
Queue queue;
// ETA is a required property for TaskOptions but we let the service to set it when submitting the
// task to the task queue. However, the local test service doesn't do that for us during the unit
// test, so we add this field here to let the unit test be able to inject the ETA to pass the
// test.
@VisibleForTesting Optional<Long> maybeEtaMillis = Optional.empty();
@Override
public void run() {
@ -115,6 +126,9 @@ final class GenerateEscrowDepositCommand implements CommandWithRemoteApi {
if (revision != null) {
opts = opts.param(PARAM_REVISION, String.valueOf(revision));
}
if (maybeEtaMillis.isPresent()) {
opts = opts.etaMillis(maybeEtaMillis.get());
}
queue.add(opts);
}
}

View file

@ -46,10 +46,8 @@ public class CommitLogCheckpointActionTest {
private static final String QUEUE_NAME = "export-commits";
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue()
.build();
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
CommitLogCheckpointStrategy strategy = mock(CommitLogCheckpointStrategy.class);

View file

@ -47,9 +47,7 @@ import org.junit.runners.JUnit4;
public class CommitLogCheckpointStrategyTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Rule
public final InjectRule inject = new InjectRule();

View file

@ -50,9 +50,7 @@ import org.junit.runners.JUnit4;
public class ExportCommitLogDiffActionTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
/** Local GCS service available for testing. */
private final GcsService gcsService = GcsServiceFactory.createGcsService();

View file

@ -62,9 +62,7 @@ public class GcsDiffFileListerTest {
private final TestLogHandler logHandler = new TestLogHandler();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Before
public void before() throws Exception {

View file

@ -71,9 +71,7 @@ public class RestoreCommitLogsActionTest {
final GcsService gcsService = createGcsService();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Before
public void init() {

View file

@ -61,7 +61,7 @@ public class AsyncTaskEnqueuerTest extends ShardableTestCase {
@Rule
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastore().withTaskQueue().build();
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
@Rule public final InjectRule inject = new InjectRule();

View file

@ -70,7 +70,7 @@ public class ResaveEntityActionTest extends ShardableTestCase {
@Rule
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastore().withTaskQueue().build();
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
@Rule public final InjectRule inject = new InjectRule();
@Rule public final MockitoRule mocks = MockitoJUnit.rule();

View file

@ -39,9 +39,12 @@ public class CommitLogFanoutActionTest {
private static final String QUEUE = "the-queue";
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue(Joiner.on('\n').join(
public final AppEngineRule appEngine =
AppEngineRule.builder()
.withDatastoreAndCloudSql()
.withTaskQueue(
Joiner.on('\n')
.join(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
"<queue-entries>",
" <queue>",

View file

@ -54,9 +54,12 @@ public class TldFanoutActionTest {
private final FakeResponse response = new FakeResponse();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue(Joiner.on('\n').join(
public final AppEngineRule appEngine =
AppEngineRule.builder()
.withDatastoreAndCloudSql()
.withTaskQueue(
Joiner.on('\n')
.join(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
"<queue-entries>",
" <queue>",

View file

@ -46,10 +46,8 @@ import org.junit.runners.JUnit4;
public final class DnsInjectionTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue()
.build();
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
@Rule
public final InjectRule inject = new InjectRule();

View file

@ -35,10 +35,9 @@ import org.junit.runners.JUnit4;
public class DnsQueueTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue()
.build();
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
private DnsQueue dnsQueue;
private final FakeClock clock = new FakeClock(DateTime.parse("2010-01-01T10:00:00Z"));

View file

@ -55,10 +55,8 @@ import org.junit.runners.JUnit4;
public class PublishDnsUpdatesActionTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue()
.build();
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
@Rule
public final InjectRule inject = new InjectRule();

View file

@ -73,9 +73,12 @@ public class ReadDnsQueueActionTest {
private FakeClock clock = new FakeClock(DateTime.parse("3000-01-01TZ"));
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue(Joiner.on('\n').join(
public final AppEngineRule appEngine =
AppEngineRule.builder()
.withDatastoreAndCloudSql()
.withTaskQueue(
Joiner.on('\n')
.join(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
"<queue-entries>",
" <queue>",

View file

@ -42,7 +42,7 @@ public class RefreshDnsActionTest {
@Rule
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastore().withTaskQueue().build();
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
private final DnsQueue dnsQueue = mock(DnsQueue.class);
private final FakeClock clock = new FakeClock();

View file

@ -69,7 +69,9 @@ import org.mockito.junit.MockitoRule;
@RunWith(JUnit4.class)
public class CloudDnsWriterTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
private static final Inet4Address IPv4 = (Inet4Address) InetAddresses.forString("127.0.0.1");

View file

@ -76,7 +76,7 @@ public class DnsUpdateWriterTest {
@Rule
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastore().withTaskQueue().build();
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
@Rule public final InjectRule inject = new InjectRule();

View file

@ -62,10 +62,9 @@ import org.junit.runners.JUnit4;
public class BigqueryPollJobActionTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue()
.build();
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
private static final String PROJECT_ID = "project_id";
private static final String JOB_ID = "job_id";
private static final String CHAINED_QUEUE_NAME = UpdateSnapshotViewAction.QUEUE;

View file

@ -59,7 +59,8 @@ public class ExportPremiumTermsActionTest {
private static final String EXPECTED_FILE_CONTENT =
DISCLAIMER_WITH_NEWLINE + "0,USD 549.00\n" + "2048,USD 549.00\n";
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private final DriveConnection driveConnection = mock(DriveConnection.class);
private final Response response = mock(Response.class);

View file

@ -48,7 +48,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class ExportReservedTermsActionTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private final DriveConnection driveConnection = mock(DriveConnection.class);
private final Response response = mock(Response.class);

View file

@ -32,9 +32,7 @@ import org.junit.runners.JUnit4;
public class ExportUtilsTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void test_exportReservedTerms() {

View file

@ -60,9 +60,7 @@ import org.junit.runners.JUnit4;
public class SyncGroupMembersActionTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Rule
public final InjectRule inject = new InjectRule();

View file

@ -40,10 +40,8 @@ import org.junit.runners.JUnit4;
public class SyncRegistrarsSheetActionTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue()
.build();
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
private final FakeResponse response = new FakeResponse();
private final SyncRegistrarsSheet syncRegistrarsSheet = mock(SyncRegistrarsSheet.class);

View file

@ -58,7 +58,9 @@ import org.mockito.junit.MockitoRule;
@RunWith(JUnit4.class)
public class SyncRegistrarsSheetTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
@Rule public final InjectRule inject = new InjectRule();

View file

@ -56,7 +56,9 @@ public class CheckApiActionTest {
private static final DateTime START_TIME = DateTime.parse("2000-01-01T00:00:00.0Z");
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
@Mock private CheckApiMetrics checkApiMetrics;

View file

@ -48,10 +48,8 @@ import org.junit.runners.JUnit4;
public class EppCommitLogsTest extends ShardableTestCase {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue()
.build();
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
@Rule
public final InjectRule inject = new InjectRule();

View file

@ -66,7 +66,10 @@ import org.mockito.junit.MockitoRule;
@RunWith(JUnit4.class)
public class EppControllerTest extends ShardableTestCase {
@Rule public AppEngineRule appEngineRule = new AppEngineRule.Builder().withDatastore().build();
@Rule
public AppEngineRule appEngineRule =
new AppEngineRule.Builder().withDatastoreAndCloudSql().build();
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
@Mock SessionMetadata sessionMetadata;

View file

@ -32,10 +32,8 @@ import org.junit.runners.JUnit4;
public class EppLifecycleContactTest extends EppTestCase {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue()
.build();
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
@Test
public void testContactLifecycle() throws Exception {

View file

@ -64,7 +64,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
@Rule
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastore().withTaskQueue().build();
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
@Before
public void initTld() {

View file

@ -39,10 +39,8 @@ import org.junit.runners.JUnit4;
public class EppLifecycleHostTest extends EppTestCase {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue()
.build();
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
@Test
public void testLifecycle() throws Exception {

View file

@ -30,7 +30,7 @@ public class EppLifecycleLoginTest extends EppTestCase {
@Rule
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastore().withTaskQueue().build();
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
@Test
public void testLoginAndLogout_recordsEppMetric() throws Exception {

View file

@ -30,9 +30,7 @@ import org.junit.runners.JUnit4;
public class EppLoggedOutTest extends EppTestCase {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testHello() throws Exception {

View file

@ -33,7 +33,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class EppLoginTlsTest extends EppTestCase {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
void setClientCertificateHash(String clientCertificateHash) {
setTransportCredentials(

View file

@ -26,9 +26,7 @@ import org.junit.runners.JUnit4;
public class EppXxeAttackTest extends EppTestCase {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testRemoteXmlExternalEntity() throws Exception {

View file

@ -48,9 +48,7 @@ import org.junit.runners.JUnit4;
public class ExtensionManagerTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testDuplicateExtensionsForbidden() {

View file

@ -83,10 +83,8 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
public enum UserPrivileges { NORMAL, SUPERUSER }
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue()
.build();
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
@Rule
public final InjectRule inject = new InjectRule();

View file

@ -38,7 +38,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public final class TlsCredentialsTest extends ShardableTestCase {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testProvideClientCertificateHash() {

View file

@ -63,7 +63,8 @@ public class AllocationTokenFlowUtilsTest extends ShardableTestCase {
private final AllocationTokenFlowUtils flowUtils =
new AllocationTokenFlowUtils(new AllocationTokenCustomLogic());
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Before
public void initTest() {

View file

@ -35,7 +35,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class HostFlowUtilsTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void test_validExternalHostName_validates() throws Exception {

View file

@ -37,7 +37,8 @@ public class KmsKeyringTest {
@Rule public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private KmsKeyring keyring;

View file

@ -36,7 +36,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class KmsUpdaterTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Rule public final BouncyCastleProviderRule bouncy = new BouncyCastleProviderRule();

View file

@ -62,7 +62,8 @@ public class ChildEntityInputTest {
private static final DateTime now = DateTime.now(DateTimeZone.UTC);
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
DomainBase domainA;
DomainBase domainB;
HistoryEntry domainHistoryEntryA;

View file

@ -48,7 +48,7 @@ public final class CommitLogManifestInputTest {
private static final DateTime DATE_TIME_NEW2 = DateTime.parse("2017-12-19T12:00Z");
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testInputOlderThan_allFound() throws Exception {

View file

@ -56,7 +56,8 @@ public class EppResourceInputsTest {
private static final double EPSILON = 0.0001;
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@SuppressWarnings("unchecked")
private <T> T serializeAndDeserialize(T obj) throws Exception {
try (ByteArrayOutputStream byteOut = new ByteArrayOutputStream();

View file

@ -35,9 +35,7 @@ import org.junit.runners.JUnit4;
public class CreateAutoTimestampTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
/** Timestamped class. */
@Entity

View file

@ -49,19 +49,17 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public abstract class EntityTestCase {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
protected FakeClock fakeClock = new FakeClock(DateTime.now(UTC));
@Rule
public InjectRule inject = new InjectRule();
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastoreAndCloudSql().withClock(fakeClock).build();
protected FakeClock clock = new FakeClock(DateTime.now(UTC));
@Rule public InjectRule inject = new InjectRule();
@Before
public void injectClock() {
inject.setStaticField(Ofy.class, "clock", clock);
inject.setStaticField(Ofy.class, "clock", fakeClock);
}
// Helper method to find private fields including inherited ones.
@ -77,17 +75,17 @@ public abstract class EntityTestCase {
}
/** Verify that fields are either indexed or not, depending on the parameter. */
private void verifyIndexingHelper(
Object obj,
boolean indexed,
Collection<String> fieldPaths) throws Exception {
outer: for (String fieldPath : fieldPaths) {
private void verifyIndexingHelper(Object obj, boolean indexed, Collection<String> fieldPaths)
throws Exception {
outer:
for (String fieldPath : fieldPaths) {
// Walk the field path and grab the value referred to on the object using reflection.
Object fieldValue = obj;
for (String fieldName : Splitter.on('.').split(fieldPath)) {
if (fieldValue == null) {
throw new RuntimeException(String.format("field '%s' not found on %s",
fieldPath, obj.getClass().getSimpleName()));
throw new RuntimeException(
String.format(
"field '%s' not found on %s", fieldPath, obj.getClass().getSimpleName()));
}
Field field = getField(fieldValue.getClass(), fieldName);
field.setAccessible(true);
@ -149,14 +147,14 @@ public abstract class EntityTestCase {
// because verifyIndexingHelper knows how to descend into collections.
if (Collection.class.isAssignableFrom(fieldClass)) {
Type inner = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
fieldClass = inner instanceof ParameterizedType
fieldClass =
inner instanceof ParameterizedType
? (Class<?>) ((ParameterizedType) inner).getRawType()
: (Class<?>) inner;
}
// Descend into persisted ImmutableObject classes, but not anything else.
if (ImmutableObject.class.isAssignableFrom(fieldClass)) {
getAllPotentiallyIndexedFieldPaths(fieldClass)
.stream()
getAllPotentiallyIndexedFieldPaths(fieldClass).stream()
.map(subfield -> field.getName() + "." + subfield)
.distinct()
.forEachOrdered(fields::add);

View file

@ -46,7 +46,7 @@ public class EppResourceTest extends EntityTestCase {
persistResource(originalContact.asBuilder().setEmailAddress("different@fake.lol").build());
assertThat(EppResource.loadCached(ImmutableList.of(Key.create(originalContact))))
.containsExactly(Key.create(originalContact), originalContact);
assertThat(loadByForeignKey(ContactResource.class, "contact123", clock.nowUtc()))
assertThat(loadByForeignKey(ContactResource.class, "contact123", fakeClock.nowUtc()))
.hasValue(modifiedContact);
}
@ -57,10 +57,10 @@ public class EppResourceTest extends EntityTestCase {
.containsExactly(Key.create(originalHost), originalHost);
HostResource modifiedHost =
persistResource(
originalHost.asBuilder().setLastTransferTime(clock.nowUtc().minusDays(60)).build());
originalHost.asBuilder().setLastTransferTime(fakeClock.nowUtc().minusDays(60)).build());
assertThat(EppResource.loadCached(ImmutableList.of(Key.create(originalHost))))
.containsExactly(Key.create(originalHost), originalHost);
assertThat(loadByForeignKey(HostResource.class, "ns1.example.com", clock.nowUtc()))
assertThat(loadByForeignKey(HostResource.class, "ns1.example.com", fakeClock.nowUtc()))
.hasValue(modifiedHost);
}
}

View file

@ -41,10 +41,8 @@ import org.junit.runners.JUnit4;
public class EppResourceUtilsTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.withTaskQueue()
.build();
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
@Rule
public final InjectRule inject = new InjectRule();

View file

@ -50,9 +50,7 @@ import org.junit.runners.JUnit4;
public class ImmutableObjectTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Before
public void register() {

View file

@ -49,7 +49,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public final class OteAccountBuilderTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testGetRegistrarToTldMap() {

View file

@ -26,7 +26,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public final class OteStatsTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testSuccess_allPass() throws Exception {

View file

@ -30,7 +30,7 @@ import org.junit.runners.JUnit4;
public class SchemaVersionTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testGoldenSchemaFile() {

View file

@ -35,9 +35,7 @@ import org.junit.runners.JUnit4;
public class UpdateAutoTimestampTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
/** Timestamped class. */
@Entity

View file

@ -29,27 +29,23 @@ import static org.junit.Assert.assertThrows;
import google.registry.model.EntityTestCase;
import google.registry.model.domain.DomainBase;
import google.registry.model.registry.Registry;
import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageRule;
import google.registry.schema.cursor.CursorDao;
import google.registry.testing.FakeClock;
import org.joda.time.DateTime;
import org.junit.Rule;
import org.junit.Before;
import org.junit.Test;
/** Unit tests for {@link Cursor}. */
public class CursorTest extends EntityTestCase {
private final FakeClock fakeClock = new FakeClock(DateTime.parse("2010-10-17TZ"));
@Rule
public final JpaIntegrationWithCoverageRule jpaRule =
new JpaTestRules.Builder().withClock(fakeClock).buildIntegrationWithCoverageRule();
@Before
public void setUp() {
fakeClock.setTo(DateTime.parse("2010-10-17TZ"));
}
@Test
public void testSuccess_persistScopedCursor() {
createTld("tld");
clock.advanceOneMilli();
this.fakeClock.advanceOneMilli();
final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z");
Cursor cursor = Cursor.create(RDE_UPLOAD, time, Registry.get("tld"));
CursorDao.saveCursor(cursor, "tld");
@ -85,7 +81,7 @@ public class CursorTest extends EntityTestCase {
@Test
public void testFailure_invalidScopeOnCreate() {
createTld("tld");
clock.advanceOneMilli();
this.fakeClock.advanceOneMilli();
final DateTime time = DateTime.parse("2012-07-12T03:30:00.000Z");
final DomainBase domain = persistActiveDomain("notaregistry.tld");
IllegalArgumentException thrown =

View file

@ -30,9 +30,7 @@ import org.junit.runners.JUnit4;
public class GaeUserIdConverterTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@After
public void verifyNoLingeringEntities() {

View file

@ -32,9 +32,7 @@ import org.junit.runners.JUnit4;
public class ContactCommandTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private void doXmlRoundtripTest(String inputFilename) throws Exception {
EppLoader eppLoader = new EppLoader(this, inputFilename);

View file

@ -48,18 +48,22 @@ public class ContactResourceTest extends EntityTestCase {
public void setUp() {
createTld("foobar");
// Set up a new persisted ContactResource entity.
contactResource = persistResource(cloneAndSetAutoTimestamps(
contactResource =
persistResource(
cloneAndSetAutoTimestamps(
new ContactResource.Builder()
.setContactId("contact_id")
.setRepoId("1-FOOBAR")
.setCreationClientId("a registrar")
.setLastEppUpdateTime(clock.nowUtc())
.setLastEppUpdateTime(fakeClock.nowUtc())
.setLastEppUpdateClientId("another registrar")
.setLastTransferTime(clock.nowUtc())
.setLastTransferTime(fakeClock.nowUtc())
.setPersistedCurrentSponsorClientId("a third registrar")
.setLocalizedPostalInfo(new PostalInfo.Builder()
.setLocalizedPostalInfo(
new PostalInfo.Builder()
.setType(Type.LOCALIZED)
.setAddress(new ContactAddress.Builder()
.setAddress(
new ContactAddress.Builder()
.setStreet(ImmutableList.of("111 8th Ave", "4th Floor"))
.setCity("New York")
.setState("NY")
@ -67,9 +71,11 @@ public class ContactResourceTest extends EntityTestCase {
.setCountryCode("US")
.build())
.build())
.setInternationalizedPostalInfo(new PostalInfo.Builder()
.setInternationalizedPostalInfo(
new PostalInfo.Builder()
.setType(Type.INTERNATIONALIZED)
.setAddress(new ContactAddress.Builder()
.setAddress(
new ContactAddress.Builder()
.setStreet(ImmutableList.of("111 8th Ave", "4th Floor"))
.setCity("New York")
.setState("NY")
@ -77,32 +83,37 @@ public class ContactResourceTest extends EntityTestCase {
.setCountryCode("US")
.build())
.build())
.setVoiceNumber(new ContactPhoneNumber.Builder()
.setPhoneNumber("867-5309")
.build())
.setFaxNumber(new ContactPhoneNumber.Builder()
.setVoiceNumber(
new ContactPhoneNumber.Builder().setPhoneNumber("867-5309").build())
.setFaxNumber(
new ContactPhoneNumber.Builder()
.setPhoneNumber("867-5309")
.setExtension("1000")
.build())
.setEmailAddress("jenny@example.com")
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("passw0rd")))
.setDisclose(new Disclose.Builder()
.setDisclose(
new Disclose.Builder()
.setVoice(new PresenceMarker())
.setEmail(new PresenceMarker())
.setFax(new PresenceMarker())
.setFlag(true)
.setAddrs(ImmutableList.of(PostalInfoChoice.create(Type.INTERNATIONALIZED)))
.setNames(ImmutableList.of(PostalInfoChoice.create(Type.INTERNATIONALIZED)))
.setOrgs(ImmutableList.of(PostalInfoChoice.create(Type.INTERNATIONALIZED)))
.setAddrs(
ImmutableList.of(PostalInfoChoice.create(Type.INTERNATIONALIZED)))
.setNames(
ImmutableList.of(PostalInfoChoice.create(Type.INTERNATIONALIZED)))
.setOrgs(
ImmutableList.of(PostalInfoChoice.create(Type.INTERNATIONALIZED)))
.build())
.setStatusValues(ImmutableSet.of(StatusValue.OK))
.setTransferData(new TransferData.Builder()
.setTransferData(
new TransferData.Builder()
.setGainingClientId("gaining")
.setLosingClientId("losing")
.setPendingTransferExpirationTime(clock.nowUtc())
.setPendingTransferExpirationTime(fakeClock.nowUtc())
.setServerApproveEntities(
ImmutableSet.of(Key.create(BillingEvent.OneTime.class, 1)))
.setTransferRequestTime(clock.nowUtc())
.setTransferRequestTime(fakeClock.nowUtc())
.setTransferStatus(TransferStatus.SERVER_APPROVED)
.setTransferRequestTrid(Trid.create("client-trid", "server-trid"))
.build())
@ -112,17 +123,14 @@ public class ContactResourceTest extends EntityTestCase {
@Test
public void testPersistence() {
assertThat(
loadByForeignKey(ContactResource.class, contactResource.getForeignKey(), clock.nowUtc()))
loadByForeignKey(
ContactResource.class, contactResource.getForeignKey(), fakeClock.nowUtc()))
.hasValue(contactResource);
}
@Test
public void testIndexing() throws Exception {
verifyIndexing(
contactResource,
"deletionTime",
"currentSponsorClientId",
"searchName");
verifyIndexing(contactResource, "deletionTime", "currentSponsorClientId", "searchName");
}
@Test
@ -131,27 +139,30 @@ public class ContactResourceTest extends EntityTestCase {
assertThat(new ContactResource.Builder().setContactId("").build().getContactId()).isNull();
assertThat(new ContactResource.Builder().setContactId(" ").build().getContactId()).isNotNull();
// Nested ImmutableObjects should also be fixed
assertThat(new ContactResource.Builder()
.setInternationalizedPostalInfo(new PostalInfo.Builder()
.setType(Type.INTERNATIONALIZED)
.setName(null)
.build())
assertThat(
new ContactResource.Builder()
.setInternationalizedPostalInfo(
new PostalInfo.Builder().setType(Type.INTERNATIONALIZED).setName(null).build())
.build()
.getInternationalizedPostalInfo().getName()).isNull();
assertThat(new ContactResource.Builder()
.setInternationalizedPostalInfo(new PostalInfo.Builder()
.setType(Type.INTERNATIONALIZED)
.setName("")
.build())
.getInternationalizedPostalInfo()
.getName())
.isNull();
assertThat(
new ContactResource.Builder()
.setInternationalizedPostalInfo(
new PostalInfo.Builder().setType(Type.INTERNATIONALIZED).setName("").build())
.build()
.getInternationalizedPostalInfo().getName()).isNull();
assertThat(new ContactResource.Builder()
.setInternationalizedPostalInfo(new PostalInfo.Builder()
.setType(Type.INTERNATIONALIZED)
.setName(" ")
.build())
.getInternationalizedPostalInfo()
.getName())
.isNull();
assertThat(
new ContactResource.Builder()
.setInternationalizedPostalInfo(
new PostalInfo.Builder().setType(Type.INTERNATIONALIZED).setName(" ").build())
.build()
.getInternationalizedPostalInfo().getName()).isNotNull();
.getInternationalizedPostalInfo()
.getName())
.isNotNull();
}
@Test
@ -170,13 +181,15 @@ public class ContactResourceTest extends EntityTestCase {
.hasExactlyStatusValues(StatusValue.OK);
// If there are other status values, OK should be suppressed.
assertAboutContacts()
.that(new ContactResource.Builder()
.that(
new ContactResource.Builder()
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_HOLD))
.build())
.hasExactlyStatusValues(StatusValue.CLIENT_HOLD);
// When OK is suppressed, it should be removed even if it was originally there.
assertAboutContacts()
.that(new ContactResource.Builder()
.that(
new ContactResource.Builder()
.setStatusValues(ImmutableSet.of(StatusValue.OK, StatusValue.CLIENT_HOLD))
.build())
.hasExactlyStatusValues(StatusValue.CLIENT_HOLD);
@ -184,18 +197,23 @@ public class ContactResourceTest extends EntityTestCase {
@Test
public void testExpiredTransfer() {
ContactResource afterTransfer = contactResource.asBuilder()
.setTransferData(contactResource.getTransferData().asBuilder()
ContactResource afterTransfer =
contactResource
.asBuilder()
.setTransferData(
contactResource
.getTransferData()
.asBuilder()
.setTransferStatus(TransferStatus.PENDING)
.setPendingTransferExpirationTime(clock.nowUtc().plusDays(1))
.setPendingTransferExpirationTime(fakeClock.nowUtc().plusDays(1))
.setGainingClientId("winner")
.build())
.build()
.cloneProjectedAtTime(clock.nowUtc().plusDays(1));
assertThat(afterTransfer.getTransferData().getTransferStatus()).isEqualTo(
TransferStatus.SERVER_APPROVED);
.cloneProjectedAtTime(fakeClock.nowUtc().plusDays(1));
assertThat(afterTransfer.getTransferData().getTransferStatus())
.isEqualTo(TransferStatus.SERVER_APPROVED);
assertThat(afterTransfer.getCurrentSponsorClientId()).isEqualTo("winner");
assertThat(afterTransfer.getLastTransferTime()).isEqualTo(clock.nowUtc().plusDays(1));
assertThat(afterTransfer.getLastTransferTime()).isEqualTo(fakeClock.nowUtc().plusDays(1));
}
@Test

View file

@ -27,11 +27,8 @@ import google.registry.model.domain.launch.LaunchNotice;
import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
import google.registry.model.eppcommon.StatusValue;
import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageRule;
import javax.persistence.EntityManager;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -40,10 +37,6 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class DomainBaseSqlTest extends EntityTestCase {
@Rule
public final JpaIntegrationWithCoverageRule jpaRule =
new JpaTestRules.Builder().buildIntegrationWithCoverageRule();
DomainBase domain;
Key<ContactResource> contactKey;
Key<ContactResource> contact2Key;
@ -58,9 +51,9 @@ public class DomainBaseSqlTest extends EntityTestCase {
.setFullyQualifiedDomainName("example.com")
.setRepoId("4-COM")
.setCreationClientId("a registrar")
.setLastEppUpdateTime(clock.nowUtc())
.setLastEppUpdateTime(fakeClock.nowUtc())
.setLastEppUpdateClientId("AnotherRegistrar")
.setLastTransferTime(clock.nowUtc())
.setLastTransferTime(fakeClock.nowUtc())
.setStatusValues(
ImmutableSet.of(
StatusValue.CLIENT_DELETE_PROHIBITED,
@ -73,7 +66,7 @@ public class DomainBaseSqlTest extends EntityTestCase {
.setContacts(ImmutableSet.of(DesignatedContact.create(Type.ADMIN, contact2Key)))
.setSubordinateHosts(ImmutableSet.of("ns1.example.com"))
.setPersistedCurrentSponsorClientId("losing")
.setRegistrationExpirationTime(clock.nowUtc().plusYears(1))
.setRegistrationExpirationTime(fakeClock.nowUtc().plusYears(1))
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("password")))
.setDsData(ImmutableSet.of(DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2})))
.setLaunchNotice(

View file

@ -108,9 +108,9 @@ public class DomainBaseTest extends EntityTestCase {
.setFullyQualifiedDomainName("example.com")
.setRepoId("4-COM")
.setCreationClientId("a registrar")
.setLastEppUpdateTime(clock.nowUtc())
.setLastEppUpdateTime(fakeClock.nowUtc())
.setLastEppUpdateClientId("AnotherRegistrar")
.setLastTransferTime(clock.nowUtc())
.setLastTransferTime(fakeClock.nowUtc())
.setStatusValues(
ImmutableSet.of(
StatusValue.CLIENT_DELETE_PROHIBITED,
@ -124,7 +124,7 @@ public class DomainBaseTest extends EntityTestCase {
.setNameservers(ImmutableSet.of(hostKey))
.setSubordinateHosts(ImmutableSet.of("ns1.example.com"))
.setPersistedCurrentSponsorClientId("losing")
.setRegistrationExpirationTime(clock.nowUtc().plusYears(1))
.setRegistrationExpirationTime(fakeClock.nowUtc().plusYears(1))
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("password")))
.setDsData(
ImmutableSet.of(DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2})))
@ -134,13 +134,13 @@ public class DomainBaseTest extends EntityTestCase {
new TransferData.Builder()
.setGainingClientId("gaining")
.setLosingClientId("losing")
.setPendingTransferExpirationTime(clock.nowUtc())
.setPendingTransferExpirationTime(fakeClock.nowUtc())
.setServerApproveEntities(
ImmutableSet.of(oneTimeBillKey, recurringBillKey, autorenewPollKey))
.setServerApproveBillingEvent(oneTimeBillKey)
.setServerApproveAutorenewEvent(recurringBillKey)
.setServerApproveAutorenewPollMessage(autorenewPollKey)
.setTransferRequestTime(clock.nowUtc().plusDays(1))
.setTransferRequestTime(fakeClock.nowUtc().plusDays(1))
.setTransferStatus(TransferStatus.SERVER_APPROVED)
.setTransferRequestTrid(Trid.create("client-trid", "server-trid"))
.build())
@ -150,13 +150,16 @@ public class DomainBaseTest extends EntityTestCase {
.setSmdId("smdid")
.addGracePeriod(
GracePeriod.create(
GracePeriodStatus.ADD, clock.nowUtc().plusDays(1), "registrar", null))
GracePeriodStatus.ADD,
fakeClock.nowUtc().plusDays(1),
"registrar",
null))
.build()));
}
@Test
public void testPersistence() {
assertThat(loadByForeignKey(DomainBase.class, domain.getForeignKey(), clock.nowUtc()))
assertThat(loadByForeignKey(DomainBase.class, domain.getForeignKey(), fakeClock.nowUtc()))
.hasValue(domain);
}
@ -323,7 +326,7 @@ public class DomainBaseTest extends EntityTestCase {
assertThat(domain.getTransferData().getTransferStatus())
.isEqualTo(TransferStatus.SERVER_APPROVED);
assertThat(domain.getCurrentSponsorClientId()).isEqualTo("winner");
assertThat(domain.getLastTransferTime()).isEqualTo(clock.nowUtc().plusDays(1));
assertThat(domain.getLastTransferTime()).isEqualTo(fakeClock.nowUtc().plusDays(1));
assertThat(domain.getRegistrationExpirationTime()).isEqualTo(newExpirationTime);
assertThat(domain.getAutorenewBillingEvent()).isEqualTo(newAutorenewEvent);
}
@ -336,9 +339,9 @@ public class DomainBaseTest extends EntityTestCase {
.setReason(Reason.TRANSFER)
.setClientId("winner")
.setTargetId("example.com")
.setEventTime(clock.nowUtc())
.setEventTime(fakeClock.nowUtc())
.setBillingTime(
clock
fakeClock
.nowUtc()
.plusDays(1)
.plus(Registry.get("com").getTransferGracePeriodLength()))
@ -355,8 +358,8 @@ public class DomainBaseTest extends EntityTestCase {
.getTransferData()
.asBuilder()
.setTransferStatus(TransferStatus.PENDING)
.setTransferRequestTime(clock.nowUtc().minusDays(4))
.setPendingTransferExpirationTime(clock.nowUtc().plusDays(1))
.setTransferRequestTime(fakeClock.nowUtc().minusDays(4))
.setPendingTransferExpirationTime(fakeClock.nowUtc().plusDays(1))
.setGainingClientId("winner")
.setServerApproveBillingEvent(Key.create(transferBillingEvent))
.setServerApproveEntities(ImmutableSet.of(Key.create(transferBillingEvent)))
@ -365,9 +368,9 @@ public class DomainBaseTest extends EntityTestCase {
// Okay for billing event to be null since the point of this grace period is just
// to check that the transfer will clear all existing grace periods.
GracePeriod.create(
GracePeriodStatus.ADD, clock.nowUtc().plusDays(100), "foo", null))
GracePeriodStatus.ADD, fakeClock.nowUtc().plusDays(100), "foo", null))
.build();
DomainBase afterTransfer = domain.cloneProjectedAtTime(clock.nowUtc().plusDays(1));
DomainBase afterTransfer = domain.cloneProjectedAtTime(fakeClock.nowUtc().plusDays(1));
DateTime newExpirationTime = oldExpirationTime.plusYears(1);
Key<BillingEvent.Recurring> serverApproveAutorenewEvent =
domain.getTransferData().getServerApproveAutorenewEvent();
@ -376,20 +379,26 @@ public class DomainBaseTest extends EntityTestCase {
.containsExactly(
GracePeriod.create(
GracePeriodStatus.TRANSFER,
clock.nowUtc().plusDays(1).plus(Registry.get("com").getTransferGracePeriodLength()),
fakeClock
.nowUtc()
.plusDays(1)
.plus(Registry.get("com").getTransferGracePeriodLength()),
"winner",
Key.create(transferBillingEvent)));
// If we project after the grace period expires all should be the same except the grace period.
DomainBase afterGracePeriod =
domain.cloneProjectedAtTime(
clock.nowUtc().plusDays(2).plus(Registry.get("com").getTransferGracePeriodLength()));
fakeClock
.nowUtc()
.plusDays(2)
.plus(Registry.get("com").getTransferGracePeriodLength()));
assertTransferred(afterGracePeriod, newExpirationTime, serverApproveAutorenewEvent);
assertThat(afterGracePeriod.getGracePeriods()).isEmpty();
}
@Test
public void testExpiredTransfer() {
doExpiredTransferTest(clock.nowUtc().plusMonths(1));
doExpiredTransferTest(fakeClock.nowUtc().plusMonths(1));
}
@Test
@ -397,7 +406,7 @@ public class DomainBaseTest extends EntityTestCase {
// Since transfer swallows a preceding autorenew, this should be identical to the regular
// transfer case (and specifically, the new expiration and grace periods will be the same as if
// there was no autorenew).
doExpiredTransferTest(clock.nowUtc().minusDays(1));
doExpiredTransferTest(fakeClock.nowUtc().minusDays(1));
}
private void setupPendingTransferDomain(
@ -421,7 +430,7 @@ public class DomainBaseTest extends EntityTestCase {
@Test
public void testEppLastUpdateTimeAndClientId_autoRenewBeforeTransferSuccess() {
DateTime now = clock.nowUtc();
DateTime now = fakeClock.nowUtc();
DateTime transferRequestDateTime = now.plusDays(1);
DateTime autorenewDateTime = now.plusDays(3);
DateTime transferSuccessDateTime = now.plusDays(5);
@ -440,7 +449,7 @@ public class DomainBaseTest extends EntityTestCase {
@Test
public void testEppLastUpdateTimeAndClientId_autoRenewAfterTransferSuccess() {
DateTime now = clock.nowUtc();
DateTime now = fakeClock.nowUtc();
DateTime transferRequestDateTime = now.plusDays(1);
DateTime autorenewDateTime = now.plusDays(3);
DateTime transferSuccessDateTime = now.plusDays(5);
@ -470,7 +479,7 @@ public class DomainBaseTest extends EntityTestCase {
@Test
public void testEppLastUpdateTimeAndClientId_isSetCorrectlyWithNullPreviousValue() {
DateTime now = clock.nowUtc();
DateTime now = fakeClock.nowUtc();
DateTime autorenewDateTime = now.plusDays(3);
setupUnmodifiedDomain(autorenewDateTime);
@ -487,12 +496,12 @@ public class DomainBaseTest extends EntityTestCase {
public void testStackedGracePeriods() {
ImmutableList<GracePeriod> gracePeriods =
ImmutableList.of(
GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(3), "foo", null),
GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(2), "bar", null),
GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(1), "baz", null));
GracePeriod.create(GracePeriodStatus.ADD, fakeClock.nowUtc().plusDays(3), "foo", null),
GracePeriod.create(GracePeriodStatus.ADD, fakeClock.nowUtc().plusDays(2), "bar", null),
GracePeriod.create(GracePeriodStatus.ADD, fakeClock.nowUtc().plusDays(1), "baz", null));
domain = domain.asBuilder().setGracePeriods(ImmutableSet.copyOf(gracePeriods)).build();
for (int i = 1; i < 3; ++i) {
assertThat(domain.cloneProjectedAtTime(clock.nowUtc().plusDays(i)).getGracePeriods())
assertThat(domain.cloneProjectedAtTime(fakeClock.nowUtc().plusDays(i)).getGracePeriods())
.containsExactlyElementsIn(Iterables.limit(gracePeriods, 3 - i));
}
}
@ -501,12 +510,14 @@ public class DomainBaseTest extends EntityTestCase {
public void testGracePeriodsByType() {
ImmutableSet<GracePeriod> addGracePeriods =
ImmutableSet.of(
GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(3), "foo", null),
GracePeriod.create(GracePeriodStatus.ADD, clock.nowUtc().plusDays(1), "baz", null));
GracePeriod.create(GracePeriodStatus.ADD, fakeClock.nowUtc().plusDays(3), "foo", null),
GracePeriod.create(GracePeriodStatus.ADD, fakeClock.nowUtc().plusDays(1), "baz", null));
ImmutableSet<GracePeriod> renewGracePeriods =
ImmutableSet.of(
GracePeriod.create(GracePeriodStatus.RENEW, clock.nowUtc().plusDays(3), "foo", null),
GracePeriod.create(GracePeriodStatus.RENEW, clock.nowUtc().plusDays(1), "baz", null));
GracePeriod.create(
GracePeriodStatus.RENEW, fakeClock.nowUtc().plusDays(3), "foo", null),
GracePeriod.create(
GracePeriodStatus.RENEW, fakeClock.nowUtc().plusDays(1), "baz", null));
domain =
domain
.asBuilder()

View file

@ -82,7 +82,7 @@ public class DomainCommandTest extends ResourceCommandTestCase {
persistActiveContact("jd1234");
DomainCommand.Create create =
(DomainCommand.Create) loadEppResourceCommand("domain_create.xml");
create.cloneAndLinkReferences(clock.nowUtc());
create.cloneAndLinkReferences(fakeClock.nowUtc());
}
@Test
@ -90,7 +90,7 @@ public class DomainCommandTest extends ResourceCommandTestCase {
// This EPP command wouldn't be allowed for policy reasons, but should clone-and-link fine.
DomainCommand.Create create =
(DomainCommand.Create) loadEppResourceCommand("domain_create_empty.xml");
create.cloneAndLinkReferences(clock.nowUtc());
create.cloneAndLinkReferences(fakeClock.nowUtc());
}
@Test
@ -100,7 +100,7 @@ public class DomainCommandTest extends ResourceCommandTestCase {
DomainCommand.Create create =
(DomainCommand.Create)
loadEppResourceCommand("domain_create_missing_non_registrant_contacts.xml");
create.cloneAndLinkReferences(clock.nowUtc());
create.cloneAndLinkReferences(fakeClock.nowUtc());
}
@Test
@ -132,7 +132,7 @@ public class DomainCommandTest extends ResourceCommandTestCase {
persistActiveContact("sh8013");
DomainCommand.Update update =
(DomainCommand.Update) loadEppResourceCommand("domain_update.xml");
update.cloneAndLinkReferences(clock.nowUtc());
update.cloneAndLinkReferences(fakeClock.nowUtc());
}
@Test
@ -140,7 +140,7 @@ public class DomainCommandTest extends ResourceCommandTestCase {
// This EPP command wouldn't be allowed for policy reasons, but should clone-and-link fine.
DomainCommand.Update update =
(DomainCommand.Update) loadEppResourceCommand("domain_update_empty.xml");
update.cloneAndLinkReferences(clock.nowUtc());
update.cloneAndLinkReferences(fakeClock.nowUtc());
}
@Test

View file

@ -39,9 +39,11 @@ import org.junit.runners.JUnit4;
public class GracePeriodTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore() // Needed to be able to construct Keys.
public final AppEngineRule appEngine =
AppEngineRule.builder()
.withDatastoreAndCloudSql() // Needed to be able to construct Keys.
.build();
private final DateTime now = DateTime.now(UTC);
private BillingEvent.OneTime onetime;

View file

@ -102,7 +102,7 @@ public class AllocationTokenTest extends EntityTestCase {
new AllocationToken.Builder().setToken("abc123").setTokenType(SINGLE_USE).build();
assertThat(tokenBeforePersisting.getCreationTime()).isEmpty();
AllocationToken tokenAfterPersisting = persistResource(tokenBeforePersisting);
assertThat(tokenAfterPersisting.getCreationTime()).hasValue(clock.nowUtc());
assertThat(tokenAfterPersisting.getCreationTime()).hasValue(fakeClock.nowUtc());
}
@Test

View file

@ -41,7 +41,7 @@ import org.junit.Test;
/** Unit tests for {@link HostResource}. */
public class HostResourceTest extends EntityTestCase {
final DateTime day3 = clock.nowUtc();
final DateTime day3 = fakeClock.nowUtc();
final DateTime day2 = day3.minusDays(1);
final DateTime day1 = day2.minusDays(1);
@ -61,10 +61,10 @@ public class HostResourceTest extends EntityTestCase {
new TransferData.Builder()
.setGainingClientId("gaining")
.setLosingClientId("losing")
.setPendingTransferExpirationTime(clock.nowUtc())
.setPendingTransferExpirationTime(fakeClock.nowUtc())
.setServerApproveEntities(
ImmutableSet.of(Key.create(BillingEvent.OneTime.class, 1)))
.setTransferRequestTime(clock.nowUtc())
.setTransferRequestTime(fakeClock.nowUtc())
.setTransferStatus(TransferStatus.SERVER_APPROVED)
.setTransferRequestTrid(Trid.create("client-trid", "server-trid"))
.build())
@ -76,9 +76,9 @@ public class HostResourceTest extends EntityTestCase {
.setRepoId("DEADBEEF-COM")
.setFullyQualifiedHostName("ns1.example.com")
.setCreationClientId("a registrar")
.setLastEppUpdateTime(clock.nowUtc())
.setLastEppUpdateTime(fakeClock.nowUtc())
.setLastEppUpdateClientId("another registrar")
.setLastTransferTime(clock.nowUtc())
.setLastTransferTime(fakeClock.nowUtc())
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.setStatusValues(ImmutableSet.of(StatusValue.OK))
.setSuperordinateDomain(Key.create(domain))
@ -87,7 +87,7 @@ public class HostResourceTest extends EntityTestCase {
@Test
public void testPersistence() {
assertThat(loadByForeignKey(HostResource.class, host.getForeignKey(), clock.nowUtc()))
assertThat(loadByForeignKey(HostResource.class, host.getForeignKey(), fakeClock.nowUtc()))
.hasValue(host);
}
@ -106,13 +106,22 @@ public class HostResourceTest extends EntityTestCase {
@Test
public void testEmptyStringsBecomeNull() {
assertThat(new HostResource.Builder().setPersistedCurrentSponsorClientId(null).build()
assertThat(
new HostResource.Builder()
.setPersistedCurrentSponsorClientId(null)
.build()
.getPersistedCurrentSponsorClientId())
.isNull();
assertThat(new HostResource.Builder().setPersistedCurrentSponsorClientId("").build()
assertThat(
new HostResource.Builder()
.setPersistedCurrentSponsorClientId("")
.build()
.getPersistedCurrentSponsorClientId())
.isNull();
assertThat(new HostResource.Builder().setPersistedCurrentSponsorClientId(" ").build()
assertThat(
new HostResource.Builder()
.setPersistedCurrentSponsorClientId(" ")
.build()
.getPersistedCurrentSponsorClientId())
.isNotNull();
}
@ -138,13 +147,15 @@ public class HostResourceTest extends EntityTestCase {
.hasExactlyStatusValues(StatusValue.OK);
// If there are other status values, OK should be suppressed.
assertAboutHosts()
.that(new HostResource.Builder()
.that(
new HostResource.Builder()
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_HOLD))
.build())
.hasExactlyStatusValues(StatusValue.CLIENT_HOLD);
// When OK is suppressed, it should be removed even if it was originally there.
assertAboutHosts()
.that(new HostResource.Builder()
.that(
new HostResource.Builder()
.setStatusValues(ImmutableSet.of(StatusValue.OK, StatusValue.CLIENT_HOLD))
.build())
.hasExactlyStatusValues(StatusValue.CLIENT_HOLD);
@ -181,10 +192,7 @@ public class HostResourceTest extends EntityTestCase {
@Test
public void testComputeLastTransferTime_hostNeverSwitchedDomains_domainWasNeverTransferred() {
domain = domain.asBuilder().setLastTransferTime(null).build();
host = host.asBuilder()
.setLastTransferTime(null)
.setLastSuperordinateChange(null)
.build();
host = host.asBuilder().setLastTransferTime(null).setLastSuperordinateChange(null).build();
assertThat(host.computeLastTransferTime(domain)).isNull();
}
@ -194,7 +202,8 @@ public class HostResourceTest extends EntityTestCase {
// Domain was transferred on Day 2.
// Host was always subordinate to domain (and was created before the transfer).
domain = domain.asBuilder().setLastTransferTime(day2).build();
host = host.asBuilder()
host =
host.asBuilder()
.setCreationTimeForTest(day1)
.setLastTransferTime(null)
.setLastSuperordinateChange(null)
@ -215,7 +224,7 @@ public class HostResourceTest extends EntityTestCase {
.setRepoId("DEADBEEF-COM")
.setFullyQualifiedHostName("ns1.example.com")
.setCreationClientId("a registrar")
.setLastEppUpdateTime(clock.nowUtc())
.setLastEppUpdateTime(fakeClock.nowUtc())
.setLastEppUpdateClientId("another registrar")
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.setStatusValues(ImmutableSet.of(StatusValue.OK))
@ -230,10 +239,7 @@ public class HostResourceTest extends EntityTestCase {
// Host was made subordinate to domain on Day 2.
// Domain was never transferred.
domain = domain.asBuilder().setLastTransferTime(null).build();
host = host.asBuilder()
.setLastTransferTime(day1)
.setLastSuperordinateChange(day2)
.build();
host = host.asBuilder().setLastTransferTime(day1).setLastSuperordinateChange(day2).build();
assertThat(host.computeLastTransferTime(domain)).isEqualTo(day1);
}
@ -243,10 +249,7 @@ public class HostResourceTest extends EntityTestCase {
// Domain was transferred on Day 2.
// Host was made subordinate to domain on Day 3.
domain = domain.asBuilder().setLastTransferTime(day2).build();
host = host.asBuilder()
.setLastTransferTime(day1)
.setLastSuperordinateChange(day3)
.build();
host = host.asBuilder().setLastTransferTime(day1).setLastSuperordinateChange(day3).build();
assertThat(host.computeLastTransferTime(domain)).isEqualTo(day1);
}
@ -256,10 +259,7 @@ public class HostResourceTest extends EntityTestCase {
// Host was made subordinate to domain on Day 2.
// Domain was transferred on Day 3.
domain = domain.asBuilder().setLastTransferTime(day3).build();
host = host.asBuilder()
.setLastTransferTime(day1)
.setLastSuperordinateChange(day2)
.build();
host = host.asBuilder().setLastTransferTime(day1).setLastSuperordinateChange(day2).build();
assertThat(host.computeLastTransferTime(domain)).isEqualTo(day3);
}
}

View file

@ -55,7 +55,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
// Persist a host and implicitly persist a ForeignKeyIndex for it.
HostResource host = persistActiveHost("ns1.example.com");
ForeignKeyIndex<HostResource> fki =
ForeignKeyIndex.load(HostResource.class, "ns1.example.com", clock.nowUtc());
ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc());
assertThat(ofy().load().key(fki.getResourceKey()).now()).isEqualTo(host);
assertThat(fki.getDeletionTime()).isEqualTo(END_OF_TIME);
}
@ -65,62 +65,64 @@ public class ForeignKeyIndexTest extends EntityTestCase {
// Persist a host and implicitly persist a ForeignKeyIndex for it.
persistActiveHost("ns1.example.com");
verifyIndexing(
ForeignKeyIndex.load(HostResource.class, "ns1.example.com", clock.nowUtc()),
ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc()),
"deletionTime");
}
@Test
public void testLoadForNonexistentForeignKey_returnsNull() {
assertThat(ForeignKeyIndex.load(HostResource.class, "ns1.example.com", clock.nowUtc()))
assertThat(ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc()))
.isNull();
}
@Test
public void testLoadForDeletedForeignKey_returnsNull() {
HostResource host = persistActiveHost("ns1.example.com");
persistResource(ForeignKeyIndex.create(host, clock.nowUtc().minusDays(1)));
assertThat(ForeignKeyIndex.load(HostResource.class, "ns1.example.com", clock.nowUtc()))
persistResource(ForeignKeyIndex.create(host, fakeClock.nowUtc().minusDays(1)));
assertThat(ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc()))
.isNull();
}
@Test
public void testLoad_newerKeyHasBeenSoftDeleted() {
HostResource host1 = persistActiveHost("ns1.example.com");
clock.advanceOneMilli();
fakeClock.advanceOneMilli();
ForeignKeyHostIndex fki = new ForeignKeyHostIndex();
fki.foreignKey = "ns1.example.com";
fki.topReference = Key.create(host1);
fki.deletionTime = clock.nowUtc();
fki.deletionTime = fakeClock.nowUtc();
persistResource(fki);
assertThat(ForeignKeyIndex.load(
HostResource.class, "ns1.example.com", clock.nowUtc())).isNull();
assertThat(ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc()))
.isNull();
}
@Test
public void testBatchLoad_skipsDeletedAndNonexistent() {
persistActiveHost("ns1.example.com");
HostResource host = persistActiveHost("ns2.example.com");
persistResource(ForeignKeyIndex.create(host, clock.nowUtc().minusDays(1)));
assertThat(ForeignKeyIndex.load(
persistResource(ForeignKeyIndex.create(host, fakeClock.nowUtc().minusDays(1)));
assertThat(
ForeignKeyIndex.load(
HostResource.class,
ImmutableList.of("ns1.example.com", "ns2.example.com", "ns3.example.com"),
clock.nowUtc()).keySet())
fakeClock.nowUtc())
.keySet())
.containsExactly("ns1.example.com");
}
@Test
public void testDeadCodeThatDeletedScrapCommandsReference() {
persistActiveHost("omg");
assertThat(ForeignKeyIndex.load(HostResource.class, "omg", clock.nowUtc()).getForeignKey())
assertThat(ForeignKeyIndex.load(HostResource.class, "omg", fakeClock.nowUtc()).getForeignKey())
.isEqualTo("omg");
}
private ForeignKeyIndex<HostResource> loadHostFki(String hostname) {
return ForeignKeyIndex.load(HostResource.class, hostname, clock.nowUtc());
return ForeignKeyIndex.load(HostResource.class, hostname, fakeClock.nowUtc());
}
private ForeignKeyIndex<ContactResource> loadContactFki(String contactId) {
return ForeignKeyIndex.load(ContactResource.class, contactId, clock.nowUtc());
return ForeignKeyIndex.load(ContactResource.class, contactId, fakeClock.nowUtc());
}
@Test
@ -129,17 +131,17 @@ public class ForeignKeyIndexTest extends EntityTestCase {
ForeignKeyIndex.loadCached(
HostResource.class,
ImmutableList.of("ns5.example.com", "ns6.example.com"),
clock.nowUtc()))
fakeClock.nowUtc()))
.isEmpty();
persistActiveHost("ns4.example.com");
persistActiveHost("ns5.example.com");
persistActiveHost("ns6.example.com");
clock.advanceOneMilli();
fakeClock.advanceOneMilli();
assertThat(
ForeignKeyIndex.loadCached(
HostResource.class,
ImmutableList.of("ns6.example.com", "ns5.example.com", "ns4.example.com"),
clock.nowUtc()))
fakeClock.nowUtc()))
.containsExactly("ns4.example.com", loadHostFki("ns4.example.com"));
}
@ -151,7 +153,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
ForeignKeyIndex.loadCached(
HostResource.class,
ImmutableList.of("ns1.example.com", "ns2.example.com"),
clock.nowUtc()))
fakeClock.nowUtc()))
.containsExactly(
"ns1.example.com",
loadHostFki("ns1.example.com"),
@ -164,7 +166,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
ForeignKeyIndex.loadCached(
HostResource.class,
ImmutableList.of("ns3.example.com", "ns2.example.com", "ns1.example.com"),
clock.nowUtc()))
fakeClock.nowUtc()))
.containsExactly(
"ns1.example.com", loadHostFki("ns1.example.com"),
"ns2.example.com", loadHostFki("ns2.example.com"),
@ -175,34 +177,34 @@ public class ForeignKeyIndexTest extends EntityTestCase {
public void test_loadCached_doesntSeeHostChangesWhileCacheIsValid() {
HostResource originalHost = persistActiveHost("ns1.example.com");
ForeignKeyIndex<HostResource> originalFki = loadHostFki("ns1.example.com");
clock.advanceOneMilli();
fakeClock.advanceOneMilli();
assertThat(
ForeignKeyIndex.loadCached(
HostResource.class, ImmutableList.of("ns1.example.com"), clock.nowUtc()))
HostResource.class, ImmutableList.of("ns1.example.com"), fakeClock.nowUtc()))
.containsExactly("ns1.example.com", originalFki);
HostResource modifiedHost =
persistResource(
originalHost.asBuilder().setPersistedCurrentSponsorClientId("OtherRegistrar").build());
clock.advanceOneMilli();
fakeClock.advanceOneMilli();
ForeignKeyIndex<HostResource> newFki = loadHostFki("ns1.example.com");
assertThat(newFki).isNotEqualTo(originalFki);
assertThat(loadByForeignKey(HostResource.class, "ns1.example.com", clock.nowUtc()))
assertThat(loadByForeignKey(HostResource.class, "ns1.example.com", fakeClock.nowUtc()))
.hasValue(modifiedHost);
assertThat(
ForeignKeyIndex.loadCached(
HostResource.class, ImmutableList.of("ns1.example.com"), clock.nowUtc()))
HostResource.class, ImmutableList.of("ns1.example.com"), fakeClock.nowUtc()))
.containsExactly("ns1.example.com", originalFki);
}
@Test
public void test_loadCached_filtersOutSoftDeletedHosts() {
persistActiveHost("ns1.example.com");
persistDeletedHost("ns2.example.com", clock.nowUtc().minusDays(1));
persistDeletedHost("ns2.example.com", fakeClock.nowUtc().minusDays(1));
assertThat(
ForeignKeyIndex.loadCached(
HostResource.class,
ImmutableList.of("ns1.example.com", "ns2.example.com"),
clock.nowUtc()))
fakeClock.nowUtc()))
.containsExactly("ns1.example.com", loadHostFki("ns1.example.com"));
}
@ -214,7 +216,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
ForeignKeyIndex.loadCached(
ContactResource.class,
ImmutableList.of("contactid1", "contactid2"),
clock.nowUtc()))
fakeClock.nowUtc()))
.containsExactly("contactid1", fki1);
persistActiveContact("contactid2");
deleteResource(fki1);
@ -222,13 +224,13 @@ public class ForeignKeyIndexTest extends EntityTestCase {
ForeignKeyIndex.loadCached(
ContactResource.class,
ImmutableList.of("contactid1", "contactid2"),
clock.nowUtc()))
fakeClock.nowUtc()))
.containsExactly("contactid1", fki1);
assertThat(
ForeignKeyIndex.load(
ContactResource.class,
ImmutableList.of("contactid1", "contactid2"),
clock.nowUtc()))
fakeClock.nowUtc()))
.containsExactly("contactid2", loadContactFki("contactid2"));
}
}

View file

@ -38,9 +38,7 @@ import org.junit.runners.JUnit4;
public class CommitLogBucketTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Rule
public final InjectRule inject = new InjectRule();

View file

@ -32,9 +32,7 @@ import org.junit.runners.JUnit4;
public class CommitLogCheckpointTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private static final DateTime T1 = START_OF_TIME;
private static final DateTime T2 = START_OF_TIME.plusMillis(1);

View file

@ -39,9 +39,7 @@ import org.junit.runners.JUnit4;
public class CommitLogMutationTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private static final DateTime NOW = DateTime.now(DateTimeZone.UTC);

View file

@ -25,9 +25,7 @@ import org.junit.runners.JUnit4;
public class ObjectifyServiceTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void test_initOfy_canBeCalledTwice() {

View file

@ -47,9 +47,7 @@ import org.junit.runners.JUnit4;
public class OfyCommitLogTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Rule
public final InjectRule inject = new InjectRule();

View file

@ -63,9 +63,7 @@ import org.junit.runners.JUnit4;
public class OfyTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
/** An entity to use in save and delete tests. */
private HistoryEntry someObject;

View file

@ -46,9 +46,7 @@ import org.junit.runners.JUnit4;
public class PollMessageExternalKeyConverterTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Rule
public InjectRule inject = new InjectRule();

View file

@ -36,12 +36,14 @@ public class PollMessageTest extends EntityTestCase {
@Before
public void setUp() {
createTld("foobar");
historyEntry = persistResource(new HistoryEntry.Builder()
historyEntry =
persistResource(
new HistoryEntry.Builder()
.setParent(persistActiveDomain("foo.foobar"))
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setPeriod(Period.create(1, Period.Unit.YEARS))
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
.setModificationTime(clock.nowUtc())
.setModificationTime(fakeClock.nowUtc())
.setClientId("foo")
.setTrid(Trid.create("ABC-123", "server-trid"))
.setBySuperuser(false)
@ -52,10 +54,11 @@ public class PollMessageTest extends EntityTestCase {
@Test
public void testPersistenceOneTime() {
PollMessage.OneTime pollMessage = persistResource(
PollMessage.OneTime pollMessage =
persistResource(
new PollMessage.OneTime.Builder()
.setClientId("TheRegistrar")
.setEventTime(clock.nowUtc())
.setEventTime(fakeClock.nowUtc())
.setMsg("Test poll message")
.setParent(historyEntry)
.build());
@ -64,13 +67,14 @@ public class PollMessageTest extends EntityTestCase {
@Test
public void testPersistenceAutorenew() {
PollMessage.Autorenew pollMessage = persistResource(
PollMessage.Autorenew pollMessage =
persistResource(
new PollMessage.Autorenew.Builder()
.setClientId("TheRegistrar")
.setEventTime(clock.nowUtc())
.setEventTime(fakeClock.nowUtc())
.setMsg("Test poll message")
.setParent(historyEntry)
.setAutorenewEndTime(clock.nowUtc().plusDays(365))
.setAutorenewEndTime(fakeClock.nowUtc().plusDays(365))
.setTargetId("foobar.foo")
.build());
assertThat(ofy().load().entity(pollMessage).now()).isEqualTo(pollMessage);
@ -78,13 +82,14 @@ public class PollMessageTest extends EntityTestCase {
@Test
public void testIndexingAutorenew() throws Exception {
PollMessage.Autorenew pollMessage = persistResource(
PollMessage.Autorenew pollMessage =
persistResource(
new PollMessage.Autorenew.Builder()
.setClientId("TheRegistrar")
.setEventTime(clock.nowUtc())
.setEventTime(fakeClock.nowUtc())
.setMsg("Test poll message")
.setParent(historyEntry)
.setAutorenewEndTime(clock.nowUtc().plusDays(365))
.setAutorenewEndTime(fakeClock.nowUtc().plusDays(365))
.setTargetId("foobar.foo")
.build());
verifyIndexing(pollMessage);

View file

@ -35,7 +35,8 @@ import org.junit.runners.JUnit4;
public class RdeRevisionTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testGetNextRevision_objectDoesntExist_returnsZero() {
assertThat(getNextRevision("torment", DateTime.parse("1984-12-18TZ"), FULL))

View file

@ -66,7 +66,7 @@ public class RegistrarTest extends EntityTestCase {
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
.setWhoisServer("whois.example.com")
.setBlockPremiumNames(true)
.setClientCertificate(SAMPLE_CERT, clock.nowUtc())
.setClientCertificate(SAMPLE_CERT, fakeClock.nowUtc())
.setIpAddressWhitelist(
ImmutableList.of(
CidrAddressBlock.create("192.168.1.1/31"),
@ -128,7 +128,11 @@ public class RegistrarTest extends EntityTestCase {
@Test
public void testPersistence() {
assertThat(registrar).isEqualTo(ofy().load().type(Registrar.class)
assertThat(registrar)
.isEqualTo(
ofy()
.load()
.type(Registrar.class)
.parent(EntityGroupRoot.getCrossTldKey())
.id(registrar.getClientId())
.now());
@ -186,12 +190,10 @@ public class RegistrarTest extends EntityTestCase {
@Test
public void testSetCertificateHash_alsoSetsHash() {
registrar = registrar.asBuilder().setClientCertificate(null, clock.nowUtc()).build();
clock.advanceOneMilli();
registrar = registrar.asBuilder()
.setClientCertificate(SAMPLE_CERT, clock.nowUtc())
.build();
assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(clock.nowUtc());
registrar = registrar.asBuilder().setClientCertificate(null, fakeClock.nowUtc()).build();
fakeClock.advanceOneMilli();
registrar = registrar.asBuilder().setClientCertificate(SAMPLE_CERT, fakeClock.nowUtc()).build();
assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(fakeClock.nowUtc());
assertThat(registrar.getClientCertificate()).isEqualTo(SAMPLE_CERT);
assertThat(registrar.getClientCertificateHash()).isEqualTo(SAMPLE_CERT_HASH);
}
@ -199,44 +201,43 @@ public class RegistrarTest extends EntityTestCase {
@Test
public void testDeleteCertificateHash_alsoDeletesHash() {
assertThat(registrar.getClientCertificateHash()).isNotNull();
clock.advanceOneMilli();
registrar = registrar.asBuilder()
.setClientCertificate(null, clock.nowUtc())
.build();
assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(clock.nowUtc());
fakeClock.advanceOneMilli();
registrar = registrar.asBuilder().setClientCertificate(null, fakeClock.nowUtc()).build();
assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(fakeClock.nowUtc());
assertThat(registrar.getClientCertificate()).isNull();
assertThat(registrar.getClientCertificateHash()).isNull();
}
@Test
public void testSetFailoverCertificateHash_alsoSetsHash() {
clock.advanceOneMilli();
registrar = registrar.asBuilder()
.setFailoverClientCertificate(SAMPLE_CERT2, clock.nowUtc())
fakeClock.advanceOneMilli();
registrar =
registrar
.asBuilder()
.setFailoverClientCertificate(SAMPLE_CERT2, fakeClock.nowUtc())
.build();
assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(clock.nowUtc());
assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(fakeClock.nowUtc());
assertThat(registrar.getFailoverClientCertificate()).isEqualTo(SAMPLE_CERT2);
assertThat(registrar.getFailoverClientCertificateHash()).isEqualTo(SAMPLE_CERT2_HASH);
}
@Test
public void testDeleteFailoverCertificateHash_alsoDeletesHash() {
registrar = registrar.asBuilder()
.setFailoverClientCertificate(SAMPLE_CERT, clock.nowUtc())
.build();
registrar =
registrar.asBuilder().setFailoverClientCertificate(SAMPLE_CERT, fakeClock.nowUtc()).build();
assertThat(registrar.getFailoverClientCertificateHash()).isNotNull();
clock.advanceOneMilli();
registrar = registrar.asBuilder()
.setFailoverClientCertificate(null, clock.nowUtc())
.build();
assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(clock.nowUtc());
fakeClock.advanceOneMilli();
registrar =
registrar.asBuilder().setFailoverClientCertificate(null, fakeClock.nowUtc()).build();
assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(fakeClock.nowUtc());
assertThat(registrar.getFailoverClientCertificate()).isNull();
assertThat(registrar.getFailoverClientCertificateHash()).isNull();
}
@Test
public void testSuccess_clearingIanaAndBillingIds() {
registrar.asBuilder()
registrar
.asBuilder()
.setType(Type.TEST)
.setIanaIdentifier(null)
.setBillingIdentifier(null)
@ -245,9 +246,7 @@ public class RegistrarTest extends EntityTestCase {
@Test
public void testSuccess_clearingBillingAccountMap() {
registrar = registrar.asBuilder()
.setBillingAccountMap(null)
.build();
registrar = registrar.asBuilder().setBillingAccountMap(null).build();
assertThat(registrar.getBillingAccountMap()).isEmpty();
}
@ -422,7 +421,8 @@ public class RegistrarTest extends EntityTestCase {
@Test
public void testSuccess_setAllowedTlds() {
assertThat(
registrar.asBuilder()
registrar
.asBuilder()
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
.build()
.getAllowedTlds())
@ -432,7 +432,8 @@ public class RegistrarTest extends EntityTestCase {
@Test
public void testSuccess_setAllowedTldsUncached() {
assertThat(
registrar.asBuilder()
registrar
.asBuilder()
.setAllowedTldsUncached(ImmutableSet.of("xn--q9jyb4c"))
.build()
.getAllowedTlds())
@ -455,9 +456,12 @@ public class RegistrarTest extends EntityTestCase {
@Test
public void testFailure_driveFolderId_asFullUrl() {
String driveFolderId =
"https://drive.google.com/drive/folders/1j3v7RZkU25DjbTx2-Q93H04zKOBau89M";
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> registrar.asBuilder().setDriveFolderId(
"https://drive.google.com/drive/folders/1j3v7RZkU25DjbTx2-Q93H04zKOBau89M"));
assertThrows(
IllegalArgumentException.class,
() -> registrar.asBuilder().setDriveFolderId(driveFolderId));
assertThat(thrown).hasMessageThat().isEqualTo("Drive folder ID must not be a full URL");
}
@ -483,9 +487,7 @@ public class RegistrarTest extends EntityTestCase {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress(""));
assertThat(thrown)
.hasMessageThat()
.isEqualTo("Provided email is not a valid email address");
assertThat(thrown).hasMessageThat().isEqualTo("Provided email is not a valid email address");
}
@Test
@ -512,9 +514,7 @@ public class RegistrarTest extends EntityTestCase {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress(""));
assertThat(thrown)
.hasMessageThat()
.isEqualTo("Provided email is not a valid email address");
assertThat(thrown).hasMessageThat().isEqualTo("Provided email is not a valid email address");
}
@Test
@ -568,8 +568,7 @@ public class RegistrarTest extends EntityTestCase {
@Test
public void testLoadByClientIdCached_isTransactionless() {
tm()
.transact(
tm().transact(
() -> {
assertThat(Registrar.loadByClientIdCached("registrar")).isPresent();
// Load something as a control to make sure we are seeing loaded keys in the session

View file

@ -34,7 +34,7 @@ import org.junit.runners.JUnit4;
public class RegistriesTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private void initTestTlds() {
createTlds("foo", "a.b.c"); // Test a multipart tld.

View file

@ -24,8 +24,6 @@ import static google.registry.testing.SqlHelper.getRegistryLocksByRegistrarId;
import static google.registry.testing.SqlHelper.saveRegistryLock;
import static org.junit.Assert.assertThrows;
import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageRule;
import google.registry.schema.domain.RegistryLock;
import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock;
@ -41,11 +39,9 @@ public final class RegistryLockDaoTest {
private final FakeClock fakeClock = new FakeClock();
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final JpaIntegrationWithCoverageRule jpaRule =
new JpaTestRules.Builder().withClock(fakeClock).buildIntegrationWithCoverageRule();
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastoreAndCloudSql().withClock(fakeClock).build();
@Test
public void testSaveAndLoad_success() {

View file

@ -112,30 +112,24 @@ public class RegistryTest extends EntityTestCase {
@Test
public void testSettingNumDnsPublishShards() {
Registry registry =
Registry.get("tld").asBuilder().setNumDnsPublishLocks(2).build();
Registry registry = Registry.get("tld").asBuilder().setNumDnsPublishLocks(2).build();
assertThat(registry.getNumDnsPublishLocks()).isEqualTo(2);
}
@Test
public void testSetReservedList_doesntMutateExistingRegistry() {
ReservedList rl15 = persistReservedList(
"tld-reserved15",
"potato,FULLY_BLOCKED",
"phone,FULLY_BLOCKED");
ReservedList rl16 = persistReservedList(
"tld-reserved16",
"port,FULLY_BLOCKED",
"manteau,FULLY_BLOCKED");
ReservedList rl15 =
persistReservedList("tld-reserved15", "potato,FULLY_BLOCKED", "phone,FULLY_BLOCKED");
ReservedList rl16 =
persistReservedList("tld-reserved16", "port,FULLY_BLOCKED", "manteau,FULLY_BLOCKED");
Registry registry1 =
newRegistry("propter", "PROPTER")
.asBuilder()
.setReservedLists(ImmutableSet.of(rl15))
.build();
assertThat(registry1.getReservedLists()).hasSize(1);
Registry registry2 = registry1.asBuilder()
.setReservedLists(ImmutableSet.of(rl15, rl16))
.build();
Registry registry2 =
registry1.asBuilder().setReservedLists(ImmutableSet.of(rl15, rl16)).build();
assertThat(registry1.getReservedLists()).hasSize(1);
assertThat(registry2.getReservedLists()).hasSize(2);
}
@ -162,16 +156,12 @@ public class RegistryTest extends EntityTestCase {
@Test
public void testSetReservedLists() {
ReservedList rl5 = persistReservedList(
"tld-reserved5",
"lol,FULLY_BLOCKED",
"cat,FULLY_BLOCKED");
ReservedList rl6 = persistReservedList(
"tld-reserved6",
"hammock,FULLY_BLOCKED",
"mouse,FULLY_BLOCKED");
Registry r = Registry.get("tld")
.asBuilder().setReservedLists(ImmutableSet.of(rl5, rl6)).build();
ReservedList rl5 =
persistReservedList("tld-reserved5", "lol,FULLY_BLOCKED", "cat,FULLY_BLOCKED");
ReservedList rl6 =
persistReservedList("tld-reserved6", "hammock,FULLY_BLOCKED", "mouse,FULLY_BLOCKED");
Registry r =
Registry.get("tld").asBuilder().setReservedLists(ImmutableSet.of(rl5, rl6)).build();
assertThat(r.getReservedLists().stream().map(Key::getName))
.containsExactly("tld-reserved5", "tld-reserved6");
r = Registry.get("tld").asBuilder().setReservedLists(ImmutableSet.of()).build();
@ -180,16 +170,10 @@ public class RegistryTest extends EntityTestCase {
@Test
public void testSetReservedListsByName() {
persistReservedList(
"tld-reserved24",
"lol,FULLY_BLOCKED",
"cat,FULLY_BLOCKED");
persistReservedList(
"tld-reserved25",
"mit,FULLY_BLOCKED",
"tim,FULLY_BLOCKED");
Registry r = Registry
.get("tld")
persistReservedList("tld-reserved24", "lol,FULLY_BLOCKED", "cat,FULLY_BLOCKED");
persistReservedList("tld-reserved25", "mit,FULLY_BLOCKED", "tim,FULLY_BLOCKED");
Registry r =
Registry.get("tld")
.asBuilder()
.setReservedListsByName(ImmutableSet.of("tld-reserved24", "tld-reserved25"))
.build();
@ -232,7 +216,9 @@ public class RegistryTest extends EntityTestCase {
@Test
public void testPdtLooksLikeGa() {
Registry registry = Registry.get("tld").asBuilder()
Registry registry =
Registry.get("tld")
.asBuilder()
.setTldStateTransitions(ImmutableSortedMap.of(START_OF_TIME, TldState.PDT))
.build();
assertThat(registry.getTldState(START_OF_TIME)).isEqualTo(GENERAL_AVAILABILITY);
@ -246,71 +232,83 @@ public class RegistryTest extends EntityTestCase {
.setTldStateTransitions(
ImmutableSortedMap.<DateTime, TldState>naturalOrder()
.put(START_OF_TIME, PREDELEGATION)
.put(clock.nowUtc().plusMonths(1), START_DATE_SUNRISE)
.put(clock.nowUtc().plusMonths(2), QUIET_PERIOD)
.put(clock.nowUtc().plusMonths(3), GENERAL_AVAILABILITY)
.put(fakeClock.nowUtc().plusMonths(1), START_DATE_SUNRISE)
.put(fakeClock.nowUtc().plusMonths(2), QUIET_PERIOD)
.put(fakeClock.nowUtc().plusMonths(3), GENERAL_AVAILABILITY)
.build())
.build();
assertThat(registry.getTldState(clock.nowUtc())).isEqualTo(PREDELEGATION);
assertThat(registry.getTldState(clock.nowUtc().plusMillis(1))).isEqualTo(PREDELEGATION);
assertThat(registry.getTldState(clock.nowUtc().plusMonths(1).minusMillis(1)))
assertThat(registry.getTldState(fakeClock.nowUtc())).isEqualTo(PREDELEGATION);
assertThat(registry.getTldState(fakeClock.nowUtc().plusMillis(1))).isEqualTo(PREDELEGATION);
assertThat(registry.getTldState(fakeClock.nowUtc().plusMonths(1).minusMillis(1)))
.isEqualTo(PREDELEGATION);
assertThat(registry.getTldState(clock.nowUtc().plusMonths(1))).isEqualTo(START_DATE_SUNRISE);
assertThat(registry.getTldState(clock.nowUtc().plusMonths(1).plusMillis(1)))
assertThat(registry.getTldState(fakeClock.nowUtc().plusMonths(1)))
.isEqualTo(START_DATE_SUNRISE);
assertThat(registry.getTldState(clock.nowUtc().plusMonths(2).minusMillis(1)))
assertThat(registry.getTldState(fakeClock.nowUtc().plusMonths(1).plusMillis(1)))
.isEqualTo(START_DATE_SUNRISE);
assertThat(registry.getTldState(clock.nowUtc().plusMonths(2))).isEqualTo(QUIET_PERIOD);
assertThat(registry.getTldState(clock.nowUtc().plusMonths(2).plusMillis(1)))
assertThat(registry.getTldState(fakeClock.nowUtc().plusMonths(2).minusMillis(1)))
.isEqualTo(START_DATE_SUNRISE);
assertThat(registry.getTldState(fakeClock.nowUtc().plusMonths(2))).isEqualTo(QUIET_PERIOD);
assertThat(registry.getTldState(fakeClock.nowUtc().plusMonths(2).plusMillis(1)))
.isEqualTo(QUIET_PERIOD);
assertThat(registry.getTldState(clock.nowUtc().plusMonths(3).minusMillis(1)))
assertThat(registry.getTldState(fakeClock.nowUtc().plusMonths(3).minusMillis(1)))
.isEqualTo(QUIET_PERIOD);
assertThat(registry.getTldState(clock.nowUtc().plusMonths(3))).isEqualTo(GENERAL_AVAILABILITY);
assertThat(registry.getTldState(clock.nowUtc().plusMonths(3).plusMillis(1)))
assertThat(registry.getTldState(fakeClock.nowUtc().plusMonths(3)))
.isEqualTo(GENERAL_AVAILABILITY);
assertThat(registry.getTldState(fakeClock.nowUtc().plusMonths(3).plusMillis(1)))
.isEqualTo(GENERAL_AVAILABILITY);
assertThat(registry.getTldState(END_OF_TIME)).isEqualTo(GENERAL_AVAILABILITY);
}
@Test
public void testQuietPeriodCanAppearMultipleTimesAnywhere() {
Registry.get("tld").asBuilder()
.setTldStateTransitions(ImmutableSortedMap.<DateTime, TldState>naturalOrder()
Registry.get("tld")
.asBuilder()
.setTldStateTransitions(
ImmutableSortedMap.<DateTime, TldState>naturalOrder()
.put(START_OF_TIME, PREDELEGATION)
.put(clock.nowUtc().plusMonths(1), QUIET_PERIOD)
.put(clock.nowUtc().plusMonths(2), START_DATE_SUNRISE)
.put(clock.nowUtc().plusMonths(3), QUIET_PERIOD)
.put(clock.nowUtc().plusMonths(6), GENERAL_AVAILABILITY)
.put(fakeClock.nowUtc().plusMonths(1), QUIET_PERIOD)
.put(fakeClock.nowUtc().plusMonths(2), START_DATE_SUNRISE)
.put(fakeClock.nowUtc().plusMonths(3), QUIET_PERIOD)
.put(fakeClock.nowUtc().plusMonths(6), GENERAL_AVAILABILITY)
.build())
.build();
}
@Test
public void testRenewBillingCostTransitionTimes() {
Registry registry = Registry.get("tld").asBuilder()
.setRenewBillingCostTransitions(ImmutableSortedMap.of(
START_OF_TIME, Money.of(USD, 8),
clock.nowUtc(), Money.of(USD, 1),
clock.nowUtc().plusMonths(1), Money.of(USD, 2),
clock.nowUtc().plusMonths(2), Money.of(USD, 3))).build();
Registry registry =
Registry.get("tld")
.asBuilder()
.setRenewBillingCostTransitions(
ImmutableSortedMap.of(
START_OF_TIME,
Money.of(USD, 8),
fakeClock.nowUtc(),
Money.of(USD, 1),
fakeClock.nowUtc().plusMonths(1),
Money.of(USD, 2),
fakeClock.nowUtc().plusMonths(2),
Money.of(USD, 3)))
.build();
assertThat(registry.getStandardRenewCost(START_OF_TIME)).isEqualTo(Money.of(USD, 8));
assertThat(registry.getStandardRenewCost(clock.nowUtc().minusMillis(1)))
assertThat(registry.getStandardRenewCost(fakeClock.nowUtc().minusMillis(1)))
.isEqualTo(Money.of(USD, 8));
assertThat(registry.getStandardRenewCost(clock.nowUtc())).isEqualTo(Money.of(USD, 1));
assertThat(registry.getStandardRenewCost(clock.nowUtc().plusMillis(1)))
assertThat(registry.getStandardRenewCost(fakeClock.nowUtc())).isEqualTo(Money.of(USD, 1));
assertThat(registry.getStandardRenewCost(fakeClock.nowUtc().plusMillis(1)))
.isEqualTo(Money.of(USD, 1));
assertThat(registry.getStandardRenewCost(clock.nowUtc().plusMonths(1).minusMillis(1)))
assertThat(registry.getStandardRenewCost(fakeClock.nowUtc().plusMonths(1).minusMillis(1)))
.isEqualTo(Money.of(USD, 1));
assertThat(registry.getStandardRenewCost(clock.nowUtc().plusMonths(1)))
assertThat(registry.getStandardRenewCost(fakeClock.nowUtc().plusMonths(1)))
.isEqualTo(Money.of(USD, 2));
assertThat(registry.getStandardRenewCost(clock.nowUtc().plusMonths(1).plusMillis(1)))
assertThat(registry.getStandardRenewCost(fakeClock.nowUtc().plusMonths(1).plusMillis(1)))
.isEqualTo(Money.of(USD, 2));
assertThat(registry.getStandardRenewCost(clock.nowUtc().plusMonths(2).minusMillis(1)))
assertThat(registry.getStandardRenewCost(fakeClock.nowUtc().plusMonths(2).minusMillis(1)))
.isEqualTo(Money.of(USD, 2));
assertThat(registry.getStandardRenewCost(clock.nowUtc().plusMonths(2)))
assertThat(registry.getStandardRenewCost(fakeClock.nowUtc().plusMonths(2)))
.isEqualTo(Money.of(USD, 3));
assertThat(registry.getStandardRenewCost(clock.nowUtc().plusMonths(2).plusMillis(1)))
assertThat(registry.getStandardRenewCost(fakeClock.nowUtc().plusMonths(2).plusMillis(1)))
.isEqualTo(Money.of(USD, 3));
assertThat(registry.getStandardRenewCost(clock.nowUtc().plusMonths(3).minusMillis(1)))
assertThat(registry.getStandardRenewCost(fakeClock.nowUtc().plusMonths(3).minusMillis(1)))
.isEqualTo(Money.of(USD, 3));
assertThat(registry.getStandardRenewCost(END_OF_TIME)).isEqualTo(Money.of(USD, 3));
}
@ -320,10 +318,10 @@ public class RegistryTest extends EntityTestCase {
Registry registry = Registry.get("tld");
// The default value of 11 is set in createTld().
assertThat(registry.getStandardRenewCost(START_OF_TIME)).isEqualTo(Money.of(USD, 11));
assertThat(registry.getStandardRenewCost(clock.nowUtc().minusMillis(1)))
assertThat(registry.getStandardRenewCost(fakeClock.nowUtc().minusMillis(1)))
.isEqualTo(Money.of(USD, 11));
assertThat(registry.getStandardRenewCost(clock.nowUtc())).isEqualTo(Money.of(USD, 11));
assertThat(registry.getStandardRenewCost(clock.nowUtc().plusMillis(1)))
assertThat(registry.getStandardRenewCost(fakeClock.nowUtc())).isEqualTo(Money.of(USD, 11));
assertThat(registry.getStandardRenewCost(fakeClock.nowUtc().plusMillis(1)))
.isEqualTo(Money.of(USD, 11));
assertThat(registry.getStandardRenewCost(END_OF_TIME)).isEqualTo(Money.of(USD, 11));
}
@ -371,8 +369,8 @@ public class RegistryTest extends EntityTestCase {
.asBuilder()
.setTldStateTransitions(
ImmutableSortedMap.of(
clock.nowUtc(), GENERAL_AVAILABILITY,
clock.nowUtc().plusMonths(1), START_DATE_SUNRISE))
fakeClock.nowUtc(), GENERAL_AVAILABILITY,
fakeClock.nowUtc().plusMonths(1), START_DATE_SUNRISE))
.build());
}
@ -385,8 +383,8 @@ public class RegistryTest extends EntityTestCase {
.asBuilder()
.setTldStateTransitions(
ImmutableSortedMap.of(
clock.nowUtc(), START_DATE_SUNRISE,
clock.nowUtc().plusMonths(1), START_DATE_SUNRISE))
fakeClock.nowUtc(), START_DATE_SUNRISE,
fakeClock.nowUtc().plusMonths(1), START_DATE_SUNRISE))
.build());
}
@ -511,26 +509,29 @@ public class RegistryTest extends EntityTestCase {
@Test
public void testEapFee_undefined() {
assertThat(Registry.get("tld").getEapFeeFor(clock.nowUtc()).getCost())
assertThat(Registry.get("tld").getEapFeeFor(fakeClock.nowUtc()).getCost())
.isEqualTo(BigDecimal.ZERO.setScale(2, ROUND_UNNECESSARY));
}
@Test
public void testEapFee_specified() {
DateTime a = clock.nowUtc().minusDays(1);
DateTime b = clock.nowUtc().plusDays(1);
DateTime a = fakeClock.nowUtc().minusDays(1);
DateTime b = fakeClock.nowUtc().plusDays(1);
Registry registry =
Registry.get("tld").asBuilder().setEapFeeSchedule(
Registry.get("tld")
.asBuilder()
.setEapFeeSchedule(
ImmutableSortedMap.of(
START_OF_TIME, Money.of(USD, 0),
a, Money.of(USD, 100),
b, Money.of(USD, 50))).build();
b, Money.of(USD, 50)))
.build();
assertThat(registry.getEapFeeFor(clock.nowUtc()).getCost())
assertThat(registry.getEapFeeFor(fakeClock.nowUtc()).getCost())
.isEqualTo(new BigDecimal("100.00"));
assertThat(registry.getEapFeeFor(clock.nowUtc().minusDays(2)).getCost())
assertThat(registry.getEapFeeFor(fakeClock.nowUtc().minusDays(2)).getCost())
.isEqualTo(BigDecimal.ZERO.setScale(2, ROUND_UNNECESSARY));
assertThat(registry.getEapFeeFor(clock.nowUtc().plusDays(2)).getCost())
assertThat(registry.getEapFeeFor(fakeClock.nowUtc().plusDays(2)).getCost())
.isEqualTo(new BigDecimal("50.00"));
}

View file

@ -36,7 +36,8 @@ public class GenrulePremiumListTest {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String LISTS_DIRECTORY = "google/registry/config/files/premium/";
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testParse_allPremiumLists() throws Exception {

View file

@ -36,7 +36,8 @@ public class GenruleReservedListTest {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String LISTS_DIRECTORY = "google/registry/config/files/reserved/";
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testParse_allReservedLists() throws Exception {

View file

@ -39,7 +39,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class PremiumListTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Before
public void before() {

View file

@ -61,7 +61,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class PremiumListUtilsTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
// Set long persist times on caches so they can be tested (cache times default to 0 in tests).
@Rule

View file

@ -53,9 +53,7 @@ public class ReservedListTest {
public final InjectRule inject = new InjectRule();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
FakeClock clock = new FakeClock(DateTime.parse("2010-01-01T10:00:00Z"));

View file

@ -40,7 +40,7 @@ public class HistoryEntryTest extends EntityTestCase {
DomainTransactionRecord transactionRecord =
new DomainTransactionRecord.Builder()
.setTld("foobar")
.setReportingTime(clock.nowUtc())
.setReportingTime(fakeClock.nowUtc())
.setReportField(TransactionReportField.NET_ADDS_1_YR)
.setReportAmount(1)
.build();
@ -51,7 +51,7 @@ public class HistoryEntryTest extends EntityTestCase {
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setPeriod(Period.create(1, Period.Unit.YEARS))
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
.setModificationTime(clock.nowUtc())
.setModificationTime(fakeClock.nowUtc())
.setClientId("foo")
.setOtherClientId("otherClient")
.setTrid(Trid.create("ABC-123", "server-trid"))

View file

@ -30,7 +30,9 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class KmsSecretRevisionTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private KmsSecretRevision secretRevision;
@Before

View file

@ -28,7 +28,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class KmsSecretTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private KmsSecret secret;
private KmsSecretRevision secretRevision;

View file

@ -28,8 +28,6 @@ import static org.mockito.Mockito.when;
import google.registry.model.ofy.Ofy;
import google.registry.model.server.Lock.LockState;
import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageRule;
import google.registry.schema.server.LockDao;
import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock;
@ -56,12 +54,11 @@ public class LockTest {
private LockMetrics origLockMetrics;
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule public final InjectRule inject = new InjectRule();
@Rule
public final JpaIntegrationWithCoverageRule jpaRule =
new JpaTestRules.Builder().withClock(clock).buildIntegrationWithCoverageRule();
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastoreAndCloudSql().withClock(clock).build();
@Rule public final InjectRule inject = new InjectRule();
private Optional<Lock> acquire(String tld, Duration leaseLength, LockState expectedLockState) {
Lock.lockMetrics = mock(LockMetrics.class);

View file

@ -30,9 +30,7 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class ServerSecretTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Before
public void before() {

View file

@ -36,9 +36,8 @@ import org.junit.runners.JUnit4;
public class SignedMarkRevocationListTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private final FakeClock clock = new FakeClock(DateTime.parse("2013-01-01T00:00:00Z"));
@Test

View file

@ -41,9 +41,7 @@ import org.junit.runners.JUnit4;
public class ClaimsListShardTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private final int shardSize = 10;

View file

@ -26,7 +26,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class TmchCrlTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void testSuccess() {

View file

@ -36,9 +36,7 @@ import org.junit.runners.JUnit4;
public class TransferDataTest {
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private final DateTime now = DateTime.now(UTC);

View file

@ -51,9 +51,7 @@ public class CommitLogRevisionsTranslatorFactoryTest {
}
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Rule
public final InjectRule inject = new InjectRule();

View file

@ -41,9 +41,7 @@ public class StatusValueAdapterTest {
// Needed to create HostResources.
@Rule
public AppEngineRule appEngine = new AppEngineRule.Builder()
.withDatastore()
.build();
public AppEngineRule appEngine = new AppEngineRule.Builder().withDatastoreAndCloudSql().build();
@Test
public void testMarshalling() throws Exception {

View file

@ -32,7 +32,7 @@ public class BackendServletTest {
@Rule
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastore().withLocalModules().build();
AppEngineRule.builder().withDatastoreAndCloudSql().withLocalModules().build();
private final HttpServletRequest req = mock(HttpServletRequest.class);
private final HttpServletResponse rsp = mock(HttpServletResponse.class);

View file

@ -32,7 +32,7 @@ public class FrontendServletTest {
@Rule
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastore().withLocalModules().build();
AppEngineRule.builder().withDatastoreAndCloudSql().withLocalModules().build();
private final HttpServletRequest req = mock(HttpServletRequest.class);
private final HttpServletResponse rsp = mock(HttpServletResponse.class);

View file

@ -32,7 +32,7 @@ public class PubApiServletTest {
@Rule
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastore().withLocalModules().build();
AppEngineRule.builder().withDatastoreAndCloudSql().withLocalModules().build();
private final HttpServletRequest req = mock(HttpServletRequest.class);
private final HttpServletResponse rsp = mock(HttpServletResponse.class);

View file

@ -30,7 +30,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class EppMetricTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test
public void test_invalidTld_isRecordedAsInvalid() {

View file

@ -41,7 +41,8 @@ public class JpaEntityCoverage extends ExternalResource {
"BaseTransferObject",
"DelegationSignerData",
"DesignatedContact",
"GracePeriod");
"GracePeriod",
"RegistrarContact");
private static final ImmutableSet<Class> ALL_JPA_ENTITIES =
PersistenceXmlUtility.getManagedClasses().stream()

Some files were not shown because too many files have changed in this diff Show more