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 // Don't run any tests from this task, all testing gets done in the
// FilteringTest tasks. // FilteringTest tasks.
exclude "**" 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') 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.beust.jcommander.Parameters;
import com.google.appengine.api.taskqueue.Queue; import com.google.appengine.api.taskqueue.Queue;
import com.google.appengine.api.taskqueue.TaskOptions; import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.common.annotations.VisibleForTesting;
import google.registry.model.rde.RdeMode; import google.registry.model.rde.RdeMode;
import google.registry.rde.RdeStagingAction; import google.registry.rde.RdeStagingAction;
import google.registry.tools.params.DateTimeParameter; import google.registry.tools.params.DateTimeParameter;
import google.registry.util.AppEngineServiceUtils; import google.registry.util.AppEngineServiceUtils;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -75,7 +77,16 @@ final class GenerateEscrowDepositCommand implements CommandWithRemoteApi {
private String outdir; private String outdir;
@Inject AppEngineServiceUtils appEngineServiceUtils; @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 @Override
public void run() { public void run() {
@ -115,6 +126,9 @@ final class GenerateEscrowDepositCommand implements CommandWithRemoteApi {
if (revision != null) { if (revision != null) {
opts = opts.param(PARAM_REVISION, String.valueOf(revision)); opts = opts.param(PARAM_REVISION, String.valueOf(revision));
} }
if (maybeEtaMillis.isPresent()) {
opts = opts.etaMillis(maybeEtaMillis.get());
}
queue.add(opts); queue.add(opts);
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -39,17 +39,20 @@ public class CommitLogFanoutActionTest {
private static final String QUEUE = "the-queue"; private static final String QUEUE = "the-queue";
@Rule @Rule
public final AppEngineRule appEngine = AppEngineRule.builder() public final AppEngineRule appEngine =
.withDatastore() AppEngineRule.builder()
.withTaskQueue(Joiner.on('\n').join( .withDatastoreAndCloudSql()
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>", .withTaskQueue(
"<queue-entries>", Joiner.on('\n')
" <queue>", .join(
" <name>the-queue</name>", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
" <rate>1/s</rate>", "<queue-entries>",
" </queue>", " <queue>",
"</queue-entries>")) " <name>the-queue</name>",
.build(); " <rate>1/s</rate>",
" </queue>",
"</queue-entries>"))
.build();
@Test @Test
public void testSuccess() { public void testSuccess() {

View file

@ -54,17 +54,20 @@ public class TldFanoutActionTest {
private final FakeResponse response = new FakeResponse(); private final FakeResponse response = new FakeResponse();
@Rule @Rule
public final AppEngineRule appEngine = AppEngineRule.builder() public final AppEngineRule appEngine =
.withDatastore() AppEngineRule.builder()
.withTaskQueue(Joiner.on('\n').join( .withDatastoreAndCloudSql()
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>", .withTaskQueue(
"<queue-entries>", Joiner.on('\n')
" <queue>", .join(
" <name>the-queue</name>", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
" <rate>1/s</rate>", "<queue-entries>",
" </queue>", " <queue>",
"</queue-entries>")) " <name>the-queue</name>",
.build(); " <rate>1/s</rate>",
" </queue>",
"</queue-entries>"))
.build();
private static ImmutableListMultimap<String, String> getParamsMap(String... keysAndValues) { private static ImmutableListMultimap<String, String> getParamsMap(String... keysAndValues) {
ImmutableListMultimap.Builder<String, String> params = new ImmutableListMultimap.Builder<>(); ImmutableListMultimap.Builder<String, String> params = new ImmutableListMultimap.Builder<>();

View file

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

View file

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

View file

@ -73,22 +73,25 @@ public class ReadDnsQueueActionTest {
private FakeClock clock = new FakeClock(DateTime.parse("3000-01-01TZ")); private FakeClock clock = new FakeClock(DateTime.parse("3000-01-01TZ"));
@Rule @Rule
public final AppEngineRule appEngine = AppEngineRule.builder() public final AppEngineRule appEngine =
.withDatastore() AppEngineRule.builder()
.withTaskQueue(Joiner.on('\n').join( .withDatastoreAndCloudSql()
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>", .withTaskQueue(
"<queue-entries>", Joiner.on('\n')
" <queue>", .join(
" <name>dns-publish</name>", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
" <rate>1/s</rate>", "<queue-entries>",
" </queue>", " <queue>",
" <queue>", " <name>dns-publish</name>",
" <name>dns-pull</name>", " <rate>1/s</rate>",
" <mode>pull</mode>", " </queue>",
" </queue>", " <queue>",
"</queue-entries>")) " <name>dns-pull</name>",
.withClock(clock) " <mode>pull</mode>",
.build(); " </queue>",
"</queue-entries>"))
.withClock(clock)
.build();
@Before @Before
public void before() { public void before() {

View file

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

View file

@ -69,7 +69,9 @@ import org.mockito.junit.MockitoRule;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class CloudDnsWriterTest { 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(); @Rule public final MockitoRule mocks = MockitoJUnit.rule();
private static final Inet4Address IPv4 = (Inet4Address) InetAddresses.forString("127.0.0.1"); private static final Inet4Address IPv4 = (Inet4Address) InetAddresses.forString("127.0.0.1");

View file

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

View file

@ -62,10 +62,9 @@ import org.junit.runners.JUnit4;
public class BigqueryPollJobActionTest { public class BigqueryPollJobActionTest {
@Rule @Rule
public final AppEngineRule appEngine = AppEngineRule.builder() public final AppEngineRule appEngine =
.withDatastore() AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
.withTaskQueue()
.build();
private static final String PROJECT_ID = "project_id"; private static final String PROJECT_ID = "project_id";
private static final String JOB_ID = "job_id"; private static final String JOB_ID = "job_id";
private static final String CHAINED_QUEUE_NAME = UpdateSnapshotViewAction.QUEUE; 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 = private static final String EXPECTED_FILE_CONTENT =
DISCLAIMER_WITH_NEWLINE + "0,USD 549.00\n" + "2048,USD 549.00\n"; 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 DriveConnection driveConnection = mock(DriveConnection.class);
private final Response response = mock(Response.class); private final Response response = mock(Response.class);

View file

@ -48,7 +48,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class ExportReservedTermsActionTest { 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 DriveConnection driveConnection = mock(DriveConnection.class);
private final Response response = mock(Response.class); private final Response response = mock(Response.class);

View file

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

View file

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

View file

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

View file

@ -58,7 +58,9 @@ import org.mockito.junit.MockitoRule;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class SyncRegistrarsSheetTest { 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 MockitoRule mocks = MockitoJUnit.rule();
@Rule public final InjectRule inject = new InjectRule(); @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"); 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(); @Rule public final MockitoRule mocks = MockitoJUnit.rule();
@Mock private CheckApiMetrics checkApiMetrics; @Mock private CheckApiMetrics checkApiMetrics;

View file

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

View file

@ -66,7 +66,10 @@ import org.mockito.junit.MockitoRule;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class EppControllerTest extends ShardableTestCase { 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(); @Rule public final MockitoRule mocks = MockitoJUnit.rule();
@Mock SessionMetadata sessionMetadata; @Mock SessionMetadata sessionMetadata;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -33,7 +33,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class EppLoginTlsTest extends EppTestCase { 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) { void setClientCertificateHash(String clientCertificateHash) {
setTransportCredentials( setTransportCredentials(

View file

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

View file

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

View file

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

View file

@ -38,7 +38,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public final class TlsCredentialsTest extends ShardableTestCase { 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 @Test
public void testProvideClientCertificateHash() { public void testProvideClientCertificateHash() {

View file

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

View file

@ -35,7 +35,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class HostFlowUtilsTest { public class HostFlowUtilsTest {
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build(); @Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test @Test
public void test_validExternalHostName_validates() throws Exception { 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 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; private KmsKeyring keyring;

View file

@ -36,7 +36,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class KmsUpdaterTest { 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(); @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); private static final DateTime now = DateTime.now(DateTimeZone.UTC);
@Rule @Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build(); public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
DomainBase domainA; DomainBase domainA;
DomainBase domainB; DomainBase domainB;
HistoryEntry domainHistoryEntryA; 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"); private static final DateTime DATE_TIME_NEW2 = DateTime.parse("2017-12-19T12:00Z");
@Rule @Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build(); public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test @Test
public void testInputOlderThan_allFound() throws Exception { public void testInputOlderThan_allFound() throws Exception {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -48,81 +48,89 @@ public class ContactResourceTest extends EntityTestCase {
public void setUp() { public void setUp() {
createTld("foobar"); createTld("foobar");
// Set up a new persisted ContactResource entity. // Set up a new persisted ContactResource entity.
contactResource = persistResource(cloneAndSetAutoTimestamps( contactResource =
new ContactResource.Builder() persistResource(
.setContactId("contact_id") cloneAndSetAutoTimestamps(
.setRepoId("1-FOOBAR") new ContactResource.Builder()
.setCreationClientId("a registrar") .setContactId("contact_id")
.setLastEppUpdateTime(clock.nowUtc()) .setRepoId("1-FOOBAR")
.setLastEppUpdateClientId("another registrar") .setCreationClientId("a registrar")
.setLastTransferTime(clock.nowUtc()) .setLastEppUpdateTime(fakeClock.nowUtc())
.setPersistedCurrentSponsorClientId("a third registrar") .setLastEppUpdateClientId("another registrar")
.setLocalizedPostalInfo(new PostalInfo.Builder() .setLastTransferTime(fakeClock.nowUtc())
.setType(Type.LOCALIZED) .setPersistedCurrentSponsorClientId("a third registrar")
.setAddress(new ContactAddress.Builder() .setLocalizedPostalInfo(
.setStreet(ImmutableList.of("111 8th Ave", "4th Floor")) new PostalInfo.Builder()
.setCity("New York") .setType(Type.LOCALIZED)
.setState("NY") .setAddress(
.setZip("10011") new ContactAddress.Builder()
.setCountryCode("US") .setStreet(ImmutableList.of("111 8th Ave", "4th Floor"))
.build()) .setCity("New York")
.build()) .setState("NY")
.setInternationalizedPostalInfo(new PostalInfo.Builder() .setZip("10011")
.setType(Type.INTERNATIONALIZED) .setCountryCode("US")
.setAddress(new ContactAddress.Builder() .build())
.setStreet(ImmutableList.of("111 8th Ave", "4th Floor")) .build())
.setCity("New York") .setInternationalizedPostalInfo(
.setState("NY") new PostalInfo.Builder()
.setZip("10011") .setType(Type.INTERNATIONALIZED)
.setCountryCode("US") .setAddress(
.build()) new ContactAddress.Builder()
.build()) .setStreet(ImmutableList.of("111 8th Ave", "4th Floor"))
.setVoiceNumber(new ContactPhoneNumber.Builder() .setCity("New York")
.setPhoneNumber("867-5309") .setState("NY")
.build()) .setZip("10011")
.setFaxNumber(new ContactPhoneNumber.Builder() .setCountryCode("US")
.setPhoneNumber("867-5309") .build())
.setExtension("1000") .build())
.build()) .setVoiceNumber(
.setEmailAddress("jenny@example.com") new ContactPhoneNumber.Builder().setPhoneNumber("867-5309").build())
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("passw0rd"))) .setFaxNumber(
.setDisclose(new Disclose.Builder() new ContactPhoneNumber.Builder()
.setVoice(new PresenceMarker()) .setPhoneNumber("867-5309")
.setEmail(new PresenceMarker()) .setExtension("1000")
.setFax(new PresenceMarker()) .build())
.setFlag(true) .setEmailAddress("jenny@example.com")
.setAddrs(ImmutableList.of(PostalInfoChoice.create(Type.INTERNATIONALIZED))) .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("passw0rd")))
.setNames(ImmutableList.of(PostalInfoChoice.create(Type.INTERNATIONALIZED))) .setDisclose(
.setOrgs(ImmutableList.of(PostalInfoChoice.create(Type.INTERNATIONALIZED))) new Disclose.Builder()
.build()) .setVoice(new PresenceMarker())
.setStatusValues(ImmutableSet.of(StatusValue.OK)) .setEmail(new PresenceMarker())
.setTransferData(new TransferData.Builder() .setFax(new PresenceMarker())
.setGainingClientId("gaining") .setFlag(true)
.setLosingClientId("losing") .setAddrs(
.setPendingTransferExpirationTime(clock.nowUtc()) ImmutableList.of(PostalInfoChoice.create(Type.INTERNATIONALIZED)))
.setServerApproveEntities( .setNames(
ImmutableSet.of(Key.create(BillingEvent.OneTime.class, 1))) ImmutableList.of(PostalInfoChoice.create(Type.INTERNATIONALIZED)))
.setTransferRequestTime(clock.nowUtc()) .setOrgs(
.setTransferStatus(TransferStatus.SERVER_APPROVED) ImmutableList.of(PostalInfoChoice.create(Type.INTERNATIONALIZED)))
.setTransferRequestTrid(Trid.create("client-trid", "server-trid")) .build())
.build()) .setStatusValues(ImmutableSet.of(StatusValue.OK))
.build())); .setTransferData(
new TransferData.Builder()
.setGainingClientId("gaining")
.setLosingClientId("losing")
.setPendingTransferExpirationTime(fakeClock.nowUtc())
.setServerApproveEntities(
ImmutableSet.of(Key.create(BillingEvent.OneTime.class, 1)))
.setTransferRequestTime(fakeClock.nowUtc())
.setTransferStatus(TransferStatus.SERVER_APPROVED)
.setTransferRequestTrid(Trid.create("client-trid", "server-trid"))
.build())
.build()));
} }
@Test @Test
public void testPersistence() { public void testPersistence() {
assertThat( assertThat(
loadByForeignKey(ContactResource.class, contactResource.getForeignKey(), clock.nowUtc())) loadByForeignKey(
ContactResource.class, contactResource.getForeignKey(), fakeClock.nowUtc()))
.hasValue(contactResource); .hasValue(contactResource);
} }
@Test @Test
public void testIndexing() throws Exception { public void testIndexing() throws Exception {
verifyIndexing( verifyIndexing(contactResource, "deletionTime", "currentSponsorClientId", "searchName");
contactResource,
"deletionTime",
"currentSponsorClientId",
"searchName");
} }
@Test @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()).isNull();
assertThat(new ContactResource.Builder().setContactId(" ").build().getContactId()).isNotNull(); assertThat(new ContactResource.Builder().setContactId(" ").build().getContactId()).isNotNull();
// Nested ImmutableObjects should also be fixed // Nested ImmutableObjects should also be fixed
assertThat(new ContactResource.Builder() assertThat(
.setInternationalizedPostalInfo(new PostalInfo.Builder() new ContactResource.Builder()
.setType(Type.INTERNATIONALIZED) .setInternationalizedPostalInfo(
.setName(null) new PostalInfo.Builder().setType(Type.INTERNATIONALIZED).setName(null).build())
.build()) .build()
.build() .getInternationalizedPostalInfo()
.getInternationalizedPostalInfo().getName()).isNull(); .getName())
assertThat(new ContactResource.Builder() .isNull();
.setInternationalizedPostalInfo(new PostalInfo.Builder() assertThat(
.setType(Type.INTERNATIONALIZED) new ContactResource.Builder()
.setName("") .setInternationalizedPostalInfo(
.build()) new PostalInfo.Builder().setType(Type.INTERNATIONALIZED).setName("").build())
.build() .build()
.getInternationalizedPostalInfo().getName()).isNull(); .getInternationalizedPostalInfo()
assertThat(new ContactResource.Builder() .getName())
.setInternationalizedPostalInfo(new PostalInfo.Builder() .isNull();
.setType(Type.INTERNATIONALIZED) assertThat(
.setName(" ") new ContactResource.Builder()
.build()) .setInternationalizedPostalInfo(
.build() new PostalInfo.Builder().setType(Type.INTERNATIONALIZED).setName(" ").build())
.getInternationalizedPostalInfo().getName()).isNotNull(); .build()
.getInternationalizedPostalInfo()
.getName())
.isNotNull();
} }
@Test @Test
@ -170,32 +181,39 @@ public class ContactResourceTest extends EntityTestCase {
.hasExactlyStatusValues(StatusValue.OK); .hasExactlyStatusValues(StatusValue.OK);
// If there are other status values, OK should be suppressed. // If there are other status values, OK should be suppressed.
assertAboutContacts() assertAboutContacts()
.that(new ContactResource.Builder() .that(
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_HOLD)) new ContactResource.Builder()
.build()) .setStatusValues(ImmutableSet.of(StatusValue.CLIENT_HOLD))
.build())
.hasExactlyStatusValues(StatusValue.CLIENT_HOLD); .hasExactlyStatusValues(StatusValue.CLIENT_HOLD);
// When OK is suppressed, it should be removed even if it was originally there. // When OK is suppressed, it should be removed even if it was originally there.
assertAboutContacts() assertAboutContacts()
.that(new ContactResource.Builder() .that(
.setStatusValues(ImmutableSet.of(StatusValue.OK, StatusValue.CLIENT_HOLD)) new ContactResource.Builder()
.build()) .setStatusValues(ImmutableSet.of(StatusValue.OK, StatusValue.CLIENT_HOLD))
.build())
.hasExactlyStatusValues(StatusValue.CLIENT_HOLD); .hasExactlyStatusValues(StatusValue.CLIENT_HOLD);
} }
@Test @Test
public void testExpiredTransfer() { public void testExpiredTransfer() {
ContactResource afterTransfer = contactResource.asBuilder() ContactResource afterTransfer =
.setTransferData(contactResource.getTransferData().asBuilder() contactResource
.setTransferStatus(TransferStatus.PENDING) .asBuilder()
.setPendingTransferExpirationTime(clock.nowUtc().plusDays(1)) .setTransferData(
.setGainingClientId("winner") contactResource
.build()) .getTransferData()
.build() .asBuilder()
.cloneProjectedAtTime(clock.nowUtc().plusDays(1)); .setTransferStatus(TransferStatus.PENDING)
assertThat(afterTransfer.getTransferData().getTransferStatus()).isEqualTo( .setPendingTransferExpirationTime(fakeClock.nowUtc().plusDays(1))
TransferStatus.SERVER_APPROVED); .setGainingClientId("winner")
.build())
.build()
.cloneProjectedAtTime(fakeClock.nowUtc().plusDays(1));
assertThat(afterTransfer.getTransferData().getTransferStatus())
.isEqualTo(TransferStatus.SERVER_APPROVED);
assertThat(afterTransfer.getCurrentSponsorClientId()).isEqualTo("winner"); assertThat(afterTransfer.getCurrentSponsorClientId()).isEqualTo("winner");
assertThat(afterTransfer.getLastTransferTime()).isEqualTo(clock.nowUtc().plusDays(1)); assertThat(afterTransfer.getLastTransferTime()).isEqualTo(fakeClock.nowUtc().plusDays(1));
} }
@Test @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.domain.secdns.DelegationSignerData;
import google.registry.model.eppcommon.AuthInfo.PasswordAuth; import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.StatusValue;
import google.registry.persistence.transaction.JpaTestRules;
import google.registry.persistence.transaction.JpaTestRules.JpaIntegrationWithCoverageRule;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -40,10 +37,6 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class DomainBaseSqlTest extends EntityTestCase { public class DomainBaseSqlTest extends EntityTestCase {
@Rule
public final JpaIntegrationWithCoverageRule jpaRule =
new JpaTestRules.Builder().buildIntegrationWithCoverageRule();
DomainBase domain; DomainBase domain;
Key<ContactResource> contactKey; Key<ContactResource> contactKey;
Key<ContactResource> contact2Key; Key<ContactResource> contact2Key;
@ -58,9 +51,9 @@ public class DomainBaseSqlTest extends EntityTestCase {
.setFullyQualifiedDomainName("example.com") .setFullyQualifiedDomainName("example.com")
.setRepoId("4-COM") .setRepoId("4-COM")
.setCreationClientId("a registrar") .setCreationClientId("a registrar")
.setLastEppUpdateTime(clock.nowUtc()) .setLastEppUpdateTime(fakeClock.nowUtc())
.setLastEppUpdateClientId("AnotherRegistrar") .setLastEppUpdateClientId("AnotherRegistrar")
.setLastTransferTime(clock.nowUtc()) .setLastTransferTime(fakeClock.nowUtc())
.setStatusValues( .setStatusValues(
ImmutableSet.of( ImmutableSet.of(
StatusValue.CLIENT_DELETE_PROHIBITED, StatusValue.CLIENT_DELETE_PROHIBITED,
@ -73,7 +66,7 @@ public class DomainBaseSqlTest extends EntityTestCase {
.setContacts(ImmutableSet.of(DesignatedContact.create(Type.ADMIN, contact2Key))) .setContacts(ImmutableSet.of(DesignatedContact.create(Type.ADMIN, contact2Key)))
.setSubordinateHosts(ImmutableSet.of("ns1.example.com")) .setSubordinateHosts(ImmutableSet.of("ns1.example.com"))
.setPersistedCurrentSponsorClientId("losing") .setPersistedCurrentSponsorClientId("losing")
.setRegistrationExpirationTime(clock.nowUtc().plusYears(1)) .setRegistrationExpirationTime(fakeClock.nowUtc().plusYears(1))
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("password"))) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("password")))
.setDsData(ImmutableSet.of(DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2}))) .setDsData(ImmutableSet.of(DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2})))
.setLaunchNotice( .setLaunchNotice(

View file

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

View file

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

View file

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

View file

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

View file

@ -41,7 +41,7 @@ import org.junit.Test;
/** Unit tests for {@link HostResource}. */ /** Unit tests for {@link HostResource}. */
public class HostResourceTest extends EntityTestCase { public class HostResourceTest extends EntityTestCase {
final DateTime day3 = clock.nowUtc(); final DateTime day3 = fakeClock.nowUtc();
final DateTime day2 = day3.minusDays(1); final DateTime day2 = day3.minusDays(1);
final DateTime day1 = day2.minusDays(1); final DateTime day1 = day2.minusDays(1);
@ -61,10 +61,10 @@ public class HostResourceTest extends EntityTestCase {
new TransferData.Builder() new TransferData.Builder()
.setGainingClientId("gaining") .setGainingClientId("gaining")
.setLosingClientId("losing") .setLosingClientId("losing")
.setPendingTransferExpirationTime(clock.nowUtc()) .setPendingTransferExpirationTime(fakeClock.nowUtc())
.setServerApproveEntities( .setServerApproveEntities(
ImmutableSet.of(Key.create(BillingEvent.OneTime.class, 1))) ImmutableSet.of(Key.create(BillingEvent.OneTime.class, 1)))
.setTransferRequestTime(clock.nowUtc()) .setTransferRequestTime(fakeClock.nowUtc())
.setTransferStatus(TransferStatus.SERVER_APPROVED) .setTransferStatus(TransferStatus.SERVER_APPROVED)
.setTransferRequestTrid(Trid.create("client-trid", "server-trid")) .setTransferRequestTrid(Trid.create("client-trid", "server-trid"))
.build()) .build())
@ -76,9 +76,9 @@ public class HostResourceTest extends EntityTestCase {
.setRepoId("DEADBEEF-COM") .setRepoId("DEADBEEF-COM")
.setFullyQualifiedHostName("ns1.example.com") .setFullyQualifiedHostName("ns1.example.com")
.setCreationClientId("a registrar") .setCreationClientId("a registrar")
.setLastEppUpdateTime(clock.nowUtc()) .setLastEppUpdateTime(fakeClock.nowUtc())
.setLastEppUpdateClientId("another registrar") .setLastEppUpdateClientId("another registrar")
.setLastTransferTime(clock.nowUtc()) .setLastTransferTime(fakeClock.nowUtc())
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1"))) .setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.setStatusValues(ImmutableSet.of(StatusValue.OK)) .setStatusValues(ImmutableSet.of(StatusValue.OK))
.setSuperordinateDomain(Key.create(domain)) .setSuperordinateDomain(Key.create(domain))
@ -87,7 +87,7 @@ public class HostResourceTest extends EntityTestCase {
@Test @Test
public void testPersistence() { public void testPersistence() {
assertThat(loadByForeignKey(HostResource.class, host.getForeignKey(), clock.nowUtc())) assertThat(loadByForeignKey(HostResource.class, host.getForeignKey(), fakeClock.nowUtc()))
.hasValue(host); .hasValue(host);
} }
@ -106,15 +106,24 @@ public class HostResourceTest extends EntityTestCase {
@Test @Test
public void testEmptyStringsBecomeNull() { public void testEmptyStringsBecomeNull() {
assertThat(new HostResource.Builder().setPersistedCurrentSponsorClientId(null).build() assertThat(
.getPersistedCurrentSponsorClientId()) new HostResource.Builder()
.isNull(); .setPersistedCurrentSponsorClientId(null)
assertThat(new HostResource.Builder().setPersistedCurrentSponsorClientId("").build() .build()
.getPersistedCurrentSponsorClientId()) .getPersistedCurrentSponsorClientId())
.isNull(); .isNull();
assertThat(new HostResource.Builder().setPersistedCurrentSponsorClientId(" ").build() assertThat(
.getPersistedCurrentSponsorClientId()) new HostResource.Builder()
.isNotNull(); .setPersistedCurrentSponsorClientId("")
.build()
.getPersistedCurrentSponsorClientId())
.isNull();
assertThat(
new HostResource.Builder()
.setPersistedCurrentSponsorClientId(" ")
.build()
.getPersistedCurrentSponsorClientId())
.isNotNull();
} }
@Test @Test
@ -138,15 +147,17 @@ public class HostResourceTest extends EntityTestCase {
.hasExactlyStatusValues(StatusValue.OK); .hasExactlyStatusValues(StatusValue.OK);
// If there are other status values, OK should be suppressed. // If there are other status values, OK should be suppressed.
assertAboutHosts() assertAboutHosts()
.that(new HostResource.Builder() .that(
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_HOLD)) new HostResource.Builder()
.build()) .setStatusValues(ImmutableSet.of(StatusValue.CLIENT_HOLD))
.build())
.hasExactlyStatusValues(StatusValue.CLIENT_HOLD); .hasExactlyStatusValues(StatusValue.CLIENT_HOLD);
// When OK is suppressed, it should be removed even if it was originally there. // When OK is suppressed, it should be removed even if it was originally there.
assertAboutHosts() assertAboutHosts()
.that(new HostResource.Builder() .that(
.setStatusValues(ImmutableSet.of(StatusValue.OK, StatusValue.CLIENT_HOLD)) new HostResource.Builder()
.build()) .setStatusValues(ImmutableSet.of(StatusValue.OK, StatusValue.CLIENT_HOLD))
.build())
.hasExactlyStatusValues(StatusValue.CLIENT_HOLD); .hasExactlyStatusValues(StatusValue.CLIENT_HOLD);
} }
@ -181,10 +192,7 @@ public class HostResourceTest extends EntityTestCase {
@Test @Test
public void testComputeLastTransferTime_hostNeverSwitchedDomains_domainWasNeverTransferred() { public void testComputeLastTransferTime_hostNeverSwitchedDomains_domainWasNeverTransferred() {
domain = domain.asBuilder().setLastTransferTime(null).build(); domain = domain.asBuilder().setLastTransferTime(null).build();
host = host.asBuilder() host = host.asBuilder().setLastTransferTime(null).setLastSuperordinateChange(null).build();
.setLastTransferTime(null)
.setLastSuperordinateChange(null)
.build();
assertThat(host.computeLastTransferTime(domain)).isNull(); assertThat(host.computeLastTransferTime(domain)).isNull();
} }
@ -194,11 +202,12 @@ public class HostResourceTest extends EntityTestCase {
// Domain was transferred on Day 2. // Domain was transferred on Day 2.
// Host was always subordinate to domain (and was created before the transfer). // Host was always subordinate to domain (and was created before the transfer).
domain = domain.asBuilder().setLastTransferTime(day2).build(); domain = domain.asBuilder().setLastTransferTime(day2).build();
host = host.asBuilder() host =
.setCreationTimeForTest(day1) host.asBuilder()
.setLastTransferTime(null) .setCreationTimeForTest(day1)
.setLastSuperordinateChange(null) .setLastTransferTime(null)
.build(); .setLastSuperordinateChange(null)
.build();
assertThat(host.computeLastTransferTime(domain)).isEqualTo(day2); assertThat(host.computeLastTransferTime(domain)).isEqualTo(day2);
} }
@ -215,7 +224,7 @@ public class HostResourceTest extends EntityTestCase {
.setRepoId("DEADBEEF-COM") .setRepoId("DEADBEEF-COM")
.setFullyQualifiedHostName("ns1.example.com") .setFullyQualifiedHostName("ns1.example.com")
.setCreationClientId("a registrar") .setCreationClientId("a registrar")
.setLastEppUpdateTime(clock.nowUtc()) .setLastEppUpdateTime(fakeClock.nowUtc())
.setLastEppUpdateClientId("another registrar") .setLastEppUpdateClientId("another registrar")
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1"))) .setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.setStatusValues(ImmutableSet.of(StatusValue.OK)) .setStatusValues(ImmutableSet.of(StatusValue.OK))
@ -230,10 +239,7 @@ public class HostResourceTest extends EntityTestCase {
// Host was made subordinate to domain on Day 2. // Host was made subordinate to domain on Day 2.
// Domain was never transferred. // Domain was never transferred.
domain = domain.asBuilder().setLastTransferTime(null).build(); domain = domain.asBuilder().setLastTransferTime(null).build();
host = host.asBuilder() host = host.asBuilder().setLastTransferTime(day1).setLastSuperordinateChange(day2).build();
.setLastTransferTime(day1)
.setLastSuperordinateChange(day2)
.build();
assertThat(host.computeLastTransferTime(domain)).isEqualTo(day1); assertThat(host.computeLastTransferTime(domain)).isEqualTo(day1);
} }
@ -243,10 +249,7 @@ public class HostResourceTest extends EntityTestCase {
// Domain was transferred on Day 2. // Domain was transferred on Day 2.
// Host was made subordinate to domain on Day 3. // Host was made subordinate to domain on Day 3.
domain = domain.asBuilder().setLastTransferTime(day2).build(); domain = domain.asBuilder().setLastTransferTime(day2).build();
host = host.asBuilder() host = host.asBuilder().setLastTransferTime(day1).setLastSuperordinateChange(day3).build();
.setLastTransferTime(day1)
.setLastSuperordinateChange(day3)
.build();
assertThat(host.computeLastTransferTime(domain)).isEqualTo(day1); assertThat(host.computeLastTransferTime(domain)).isEqualTo(day1);
} }
@ -256,10 +259,7 @@ public class HostResourceTest extends EntityTestCase {
// Host was made subordinate to domain on Day 2. // Host was made subordinate to domain on Day 2.
// Domain was transferred on Day 3. // Domain was transferred on Day 3.
domain = domain.asBuilder().setLastTransferTime(day3).build(); domain = domain.asBuilder().setLastTransferTime(day3).build();
host = host.asBuilder() host = host.asBuilder().setLastTransferTime(day1).setLastSuperordinateChange(day2).build();
.setLastTransferTime(day1)
.setLastSuperordinateChange(day2)
.build();
assertThat(host.computeLastTransferTime(domain)).isEqualTo(day3); 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. // Persist a host and implicitly persist a ForeignKeyIndex for it.
HostResource host = persistActiveHost("ns1.example.com"); HostResource host = persistActiveHost("ns1.example.com");
ForeignKeyIndex<HostResource> fki = 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(ofy().load().key(fki.getResourceKey()).now()).isEqualTo(host);
assertThat(fki.getDeletionTime()).isEqualTo(END_OF_TIME); 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. // Persist a host and implicitly persist a ForeignKeyIndex for it.
persistActiveHost("ns1.example.com"); persistActiveHost("ns1.example.com");
verifyIndexing( verifyIndexing(
ForeignKeyIndex.load(HostResource.class, "ns1.example.com", clock.nowUtc()), ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc()),
"deletionTime"); "deletionTime");
} }
@Test @Test
public void testLoadForNonexistentForeignKey_returnsNull() { 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(); .isNull();
} }
@Test @Test
public void testLoadForDeletedForeignKey_returnsNull() { public void testLoadForDeletedForeignKey_returnsNull() {
HostResource host = persistActiveHost("ns1.example.com"); HostResource host = persistActiveHost("ns1.example.com");
persistResource(ForeignKeyIndex.create(host, clock.nowUtc().minusDays(1))); persistResource(ForeignKeyIndex.create(host, fakeClock.nowUtc().minusDays(1)));
assertThat(ForeignKeyIndex.load(HostResource.class, "ns1.example.com", clock.nowUtc())) assertThat(ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc()))
.isNull(); .isNull();
} }
@Test @Test
public void testLoad_newerKeyHasBeenSoftDeleted() { public void testLoad_newerKeyHasBeenSoftDeleted() {
HostResource host1 = persistActiveHost("ns1.example.com"); HostResource host1 = persistActiveHost("ns1.example.com");
clock.advanceOneMilli(); fakeClock.advanceOneMilli();
ForeignKeyHostIndex fki = new ForeignKeyHostIndex(); ForeignKeyHostIndex fki = new ForeignKeyHostIndex();
fki.foreignKey = "ns1.example.com"; fki.foreignKey = "ns1.example.com";
fki.topReference = Key.create(host1); fki.topReference = Key.create(host1);
fki.deletionTime = clock.nowUtc(); fki.deletionTime = fakeClock.nowUtc();
persistResource(fki); persistResource(fki);
assertThat(ForeignKeyIndex.load( assertThat(ForeignKeyIndex.load(HostResource.class, "ns1.example.com", fakeClock.nowUtc()))
HostResource.class, "ns1.example.com", clock.nowUtc())).isNull(); .isNull();
} }
@Test @Test
public void testBatchLoad_skipsDeletedAndNonexistent() { public void testBatchLoad_skipsDeletedAndNonexistent() {
persistActiveHost("ns1.example.com"); persistActiveHost("ns1.example.com");
HostResource host = persistActiveHost("ns2.example.com"); HostResource host = persistActiveHost("ns2.example.com");
persistResource(ForeignKeyIndex.create(host, clock.nowUtc().minusDays(1))); persistResource(ForeignKeyIndex.create(host, fakeClock.nowUtc().minusDays(1)));
assertThat(ForeignKeyIndex.load( assertThat(
HostResource.class, ForeignKeyIndex.load(
ImmutableList.of("ns1.example.com", "ns2.example.com", "ns3.example.com"), HostResource.class,
clock.nowUtc()).keySet()) ImmutableList.of("ns1.example.com", "ns2.example.com", "ns3.example.com"),
.containsExactly("ns1.example.com"); fakeClock.nowUtc())
.keySet())
.containsExactly("ns1.example.com");
} }
@Test @Test
public void testDeadCodeThatDeletedScrapCommandsReference() { public void testDeadCodeThatDeletedScrapCommandsReference() {
persistActiveHost("omg"); persistActiveHost("omg");
assertThat(ForeignKeyIndex.load(HostResource.class, "omg", clock.nowUtc()).getForeignKey()) assertThat(ForeignKeyIndex.load(HostResource.class, "omg", fakeClock.nowUtc()).getForeignKey())
.isEqualTo("omg"); .isEqualTo("omg");
} }
private ForeignKeyIndex<HostResource> loadHostFki(String hostname) { 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) { private ForeignKeyIndex<ContactResource> loadContactFki(String contactId) {
return ForeignKeyIndex.load(ContactResource.class, contactId, clock.nowUtc()); return ForeignKeyIndex.load(ContactResource.class, contactId, fakeClock.nowUtc());
} }
@Test @Test
@ -129,17 +131,17 @@ public class ForeignKeyIndexTest extends EntityTestCase {
ForeignKeyIndex.loadCached( ForeignKeyIndex.loadCached(
HostResource.class, HostResource.class,
ImmutableList.of("ns5.example.com", "ns6.example.com"), ImmutableList.of("ns5.example.com", "ns6.example.com"),
clock.nowUtc())) fakeClock.nowUtc()))
.isEmpty(); .isEmpty();
persistActiveHost("ns4.example.com"); persistActiveHost("ns4.example.com");
persistActiveHost("ns5.example.com"); persistActiveHost("ns5.example.com");
persistActiveHost("ns6.example.com"); persistActiveHost("ns6.example.com");
clock.advanceOneMilli(); fakeClock.advanceOneMilli();
assertThat( assertThat(
ForeignKeyIndex.loadCached( ForeignKeyIndex.loadCached(
HostResource.class, HostResource.class,
ImmutableList.of("ns6.example.com", "ns5.example.com", "ns4.example.com"), ImmutableList.of("ns6.example.com", "ns5.example.com", "ns4.example.com"),
clock.nowUtc())) fakeClock.nowUtc()))
.containsExactly("ns4.example.com", loadHostFki("ns4.example.com")); .containsExactly("ns4.example.com", loadHostFki("ns4.example.com"));
} }
@ -151,7 +153,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
ForeignKeyIndex.loadCached( ForeignKeyIndex.loadCached(
HostResource.class, HostResource.class,
ImmutableList.of("ns1.example.com", "ns2.example.com"), ImmutableList.of("ns1.example.com", "ns2.example.com"),
clock.nowUtc())) fakeClock.nowUtc()))
.containsExactly( .containsExactly(
"ns1.example.com", "ns1.example.com",
loadHostFki("ns1.example.com"), loadHostFki("ns1.example.com"),
@ -164,7 +166,7 @@ public class ForeignKeyIndexTest extends EntityTestCase {
ForeignKeyIndex.loadCached( ForeignKeyIndex.loadCached(
HostResource.class, HostResource.class,
ImmutableList.of("ns3.example.com", "ns2.example.com", "ns1.example.com"), ImmutableList.of("ns3.example.com", "ns2.example.com", "ns1.example.com"),
clock.nowUtc())) fakeClock.nowUtc()))
.containsExactly( .containsExactly(
"ns1.example.com", loadHostFki("ns1.example.com"), "ns1.example.com", loadHostFki("ns1.example.com"),
"ns2.example.com", loadHostFki("ns2.example.com"), "ns2.example.com", loadHostFki("ns2.example.com"),
@ -175,34 +177,34 @@ public class ForeignKeyIndexTest extends EntityTestCase {
public void test_loadCached_doesntSeeHostChangesWhileCacheIsValid() { public void test_loadCached_doesntSeeHostChangesWhileCacheIsValid() {
HostResource originalHost = persistActiveHost("ns1.example.com"); HostResource originalHost = persistActiveHost("ns1.example.com");
ForeignKeyIndex<HostResource> originalFki = loadHostFki("ns1.example.com"); ForeignKeyIndex<HostResource> originalFki = loadHostFki("ns1.example.com");
clock.advanceOneMilli(); fakeClock.advanceOneMilli();
assertThat( assertThat(
ForeignKeyIndex.loadCached( 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); .containsExactly("ns1.example.com", originalFki);
HostResource modifiedHost = HostResource modifiedHost =
persistResource( persistResource(
originalHost.asBuilder().setPersistedCurrentSponsorClientId("OtherRegistrar").build()); originalHost.asBuilder().setPersistedCurrentSponsorClientId("OtherRegistrar").build());
clock.advanceOneMilli(); fakeClock.advanceOneMilli();
ForeignKeyIndex<HostResource> newFki = loadHostFki("ns1.example.com"); ForeignKeyIndex<HostResource> newFki = loadHostFki("ns1.example.com");
assertThat(newFki).isNotEqualTo(originalFki); assertThat(newFki).isNotEqualTo(originalFki);
assertThat(loadByForeignKey(HostResource.class, "ns1.example.com", clock.nowUtc())) assertThat(loadByForeignKey(HostResource.class, "ns1.example.com", fakeClock.nowUtc()))
.hasValue(modifiedHost); .hasValue(modifiedHost);
assertThat( assertThat(
ForeignKeyIndex.loadCached( 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); .containsExactly("ns1.example.com", originalFki);
} }
@Test @Test
public void test_loadCached_filtersOutSoftDeletedHosts() { public void test_loadCached_filtersOutSoftDeletedHosts() {
persistActiveHost("ns1.example.com"); persistActiveHost("ns1.example.com");
persistDeletedHost("ns2.example.com", clock.nowUtc().minusDays(1)); persistDeletedHost("ns2.example.com", fakeClock.nowUtc().minusDays(1));
assertThat( assertThat(
ForeignKeyIndex.loadCached( ForeignKeyIndex.loadCached(
HostResource.class, HostResource.class,
ImmutableList.of("ns1.example.com", "ns2.example.com"), ImmutableList.of("ns1.example.com", "ns2.example.com"),
clock.nowUtc())) fakeClock.nowUtc()))
.containsExactly("ns1.example.com", loadHostFki("ns1.example.com")); .containsExactly("ns1.example.com", loadHostFki("ns1.example.com"));
} }
@ -211,24 +213,24 @@ public class ForeignKeyIndexTest extends EntityTestCase {
persistActiveContact("contactid1"); persistActiveContact("contactid1");
ForeignKeyIndex<ContactResource> fki1 = loadContactFki("contactid1"); ForeignKeyIndex<ContactResource> fki1 = loadContactFki("contactid1");
assertThat( assertThat(
ForeignKeyIndex.loadCached( ForeignKeyIndex.loadCached(
ContactResource.class, ContactResource.class,
ImmutableList.of("contactid1", "contactid2"), ImmutableList.of("contactid1", "contactid2"),
clock.nowUtc())) fakeClock.nowUtc()))
.containsExactly("contactid1", fki1); .containsExactly("contactid1", fki1);
persistActiveContact("contactid2"); persistActiveContact("contactid2");
deleteResource(fki1); deleteResource(fki1);
assertThat( assertThat(
ForeignKeyIndex.loadCached( ForeignKeyIndex.loadCached(
ContactResource.class, ContactResource.class,
ImmutableList.of("contactid1", "contactid2"), ImmutableList.of("contactid1", "contactid2"),
clock.nowUtc())) fakeClock.nowUtc()))
.containsExactly("contactid1", fki1); .containsExactly("contactid1", fki1);
assertThat( assertThat(
ForeignKeyIndex.load( ForeignKeyIndex.load(
ContactResource.class, ContactResource.class,
ImmutableList.of("contactid1", "contactid2"), ImmutableList.of("contactid1", "contactid2"),
clock.nowUtc())) fakeClock.nowUtc()))
.containsExactly("contactid2", loadContactFki("contactid2")); .containsExactly("contactid2", loadContactFki("contactid2"));
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -35,7 +35,8 @@ import org.junit.runners.JUnit4;
public class RdeRevisionTest { public class RdeRevisionTest {
@Rule @Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build(); public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
@Test @Test
public void testGetNextRevision_objectDoesntExist_returnsZero() { public void testGetNextRevision_objectDoesntExist_returnsZero() {
assertThat(getNextRevision("torment", DateTime.parse("1984-12-18TZ"), FULL)) 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")) .setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
.setWhoisServer("whois.example.com") .setWhoisServer("whois.example.com")
.setBlockPremiumNames(true) .setBlockPremiumNames(true)
.setClientCertificate(SAMPLE_CERT, clock.nowUtc()) .setClientCertificate(SAMPLE_CERT, fakeClock.nowUtc())
.setIpAddressWhitelist( .setIpAddressWhitelist(
ImmutableList.of( ImmutableList.of(
CidrAddressBlock.create("192.168.1.1/31"), CidrAddressBlock.create("192.168.1.1/31"),
@ -128,10 +128,14 @@ public class RegistrarTest extends EntityTestCase {
@Test @Test
public void testPersistence() { public void testPersistence() {
assertThat(registrar).isEqualTo(ofy().load().type(Registrar.class) assertThat(registrar)
.parent(EntityGroupRoot.getCrossTldKey()) .isEqualTo(
.id(registrar.getClientId()) ofy()
.now()); .load()
.type(Registrar.class)
.parent(EntityGroupRoot.getCrossTldKey())
.id(registrar.getClientId())
.now());
} }
@Test @Test
@ -186,12 +190,10 @@ public class RegistrarTest extends EntityTestCase {
@Test @Test
public void testSetCertificateHash_alsoSetsHash() { public void testSetCertificateHash_alsoSetsHash() {
registrar = registrar.asBuilder().setClientCertificate(null, clock.nowUtc()).build(); registrar = registrar.asBuilder().setClientCertificate(null, fakeClock.nowUtc()).build();
clock.advanceOneMilli(); fakeClock.advanceOneMilli();
registrar = registrar.asBuilder() registrar = registrar.asBuilder().setClientCertificate(SAMPLE_CERT, fakeClock.nowUtc()).build();
.setClientCertificate(SAMPLE_CERT, clock.nowUtc()) assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(fakeClock.nowUtc());
.build();
assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(clock.nowUtc());
assertThat(registrar.getClientCertificate()).isEqualTo(SAMPLE_CERT); assertThat(registrar.getClientCertificate()).isEqualTo(SAMPLE_CERT);
assertThat(registrar.getClientCertificateHash()).isEqualTo(SAMPLE_CERT_HASH); assertThat(registrar.getClientCertificateHash()).isEqualTo(SAMPLE_CERT_HASH);
} }
@ -199,44 +201,43 @@ public class RegistrarTest extends EntityTestCase {
@Test @Test
public void testDeleteCertificateHash_alsoDeletesHash() { public void testDeleteCertificateHash_alsoDeletesHash() {
assertThat(registrar.getClientCertificateHash()).isNotNull(); assertThat(registrar.getClientCertificateHash()).isNotNull();
clock.advanceOneMilli(); fakeClock.advanceOneMilli();
registrar = registrar.asBuilder() registrar = registrar.asBuilder().setClientCertificate(null, fakeClock.nowUtc()).build();
.setClientCertificate(null, clock.nowUtc()) assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(fakeClock.nowUtc());
.build();
assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(clock.nowUtc());
assertThat(registrar.getClientCertificate()).isNull(); assertThat(registrar.getClientCertificate()).isNull();
assertThat(registrar.getClientCertificateHash()).isNull(); assertThat(registrar.getClientCertificateHash()).isNull();
} }
@Test @Test
public void testSetFailoverCertificateHash_alsoSetsHash() { public void testSetFailoverCertificateHash_alsoSetsHash() {
clock.advanceOneMilli(); fakeClock.advanceOneMilli();
registrar = registrar.asBuilder() registrar =
.setFailoverClientCertificate(SAMPLE_CERT2, clock.nowUtc()) registrar
.build(); .asBuilder()
assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(clock.nowUtc()); .setFailoverClientCertificate(SAMPLE_CERT2, fakeClock.nowUtc())
.build();
assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(fakeClock.nowUtc());
assertThat(registrar.getFailoverClientCertificate()).isEqualTo(SAMPLE_CERT2); assertThat(registrar.getFailoverClientCertificate()).isEqualTo(SAMPLE_CERT2);
assertThat(registrar.getFailoverClientCertificateHash()).isEqualTo(SAMPLE_CERT2_HASH); assertThat(registrar.getFailoverClientCertificateHash()).isEqualTo(SAMPLE_CERT2_HASH);
} }
@Test @Test
public void testDeleteFailoverCertificateHash_alsoDeletesHash() { public void testDeleteFailoverCertificateHash_alsoDeletesHash() {
registrar = registrar.asBuilder() registrar =
.setFailoverClientCertificate(SAMPLE_CERT, clock.nowUtc()) registrar.asBuilder().setFailoverClientCertificate(SAMPLE_CERT, fakeClock.nowUtc()).build();
.build();
assertThat(registrar.getFailoverClientCertificateHash()).isNotNull(); assertThat(registrar.getFailoverClientCertificateHash()).isNotNull();
clock.advanceOneMilli(); fakeClock.advanceOneMilli();
registrar = registrar.asBuilder() registrar =
.setFailoverClientCertificate(null, clock.nowUtc()) registrar.asBuilder().setFailoverClientCertificate(null, fakeClock.nowUtc()).build();
.build(); assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(fakeClock.nowUtc());
assertThat(registrar.getLastCertificateUpdateTime()).isEqualTo(clock.nowUtc());
assertThat(registrar.getFailoverClientCertificate()).isNull(); assertThat(registrar.getFailoverClientCertificate()).isNull();
assertThat(registrar.getFailoverClientCertificateHash()).isNull(); assertThat(registrar.getFailoverClientCertificateHash()).isNull();
} }
@Test @Test
public void testSuccess_clearingIanaAndBillingIds() { public void testSuccess_clearingIanaAndBillingIds() {
registrar.asBuilder() registrar
.asBuilder()
.setType(Type.TEST) .setType(Type.TEST)
.setIanaIdentifier(null) .setIanaIdentifier(null)
.setBillingIdentifier(null) .setBillingIdentifier(null)
@ -244,10 +245,8 @@ public class RegistrarTest extends EntityTestCase {
} }
@Test @Test
public void testSuccess_clearingBillingAccountMap() { public void testSuccess_clearingBillingAccountMap() {
registrar = registrar.asBuilder() registrar = registrar.asBuilder().setBillingAccountMap(null).build();
.setBillingAccountMap(null)
.build();
assertThat(registrar.getBillingAccountMap()).isEmpty(); assertThat(registrar.getBillingAccountMap()).isEmpty();
} }
@ -422,7 +421,8 @@ public class RegistrarTest extends EntityTestCase {
@Test @Test
public void testSuccess_setAllowedTlds() { public void testSuccess_setAllowedTlds() {
assertThat( assertThat(
registrar.asBuilder() registrar
.asBuilder()
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c")) .setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
.build() .build()
.getAllowedTlds()) .getAllowedTlds())
@ -432,7 +432,8 @@ public class RegistrarTest extends EntityTestCase {
@Test @Test
public void testSuccess_setAllowedTldsUncached() { public void testSuccess_setAllowedTldsUncached() {
assertThat( assertThat(
registrar.asBuilder() registrar
.asBuilder()
.setAllowedTldsUncached(ImmutableSet.of("xn--q9jyb4c")) .setAllowedTldsUncached(ImmutableSet.of("xn--q9jyb4c"))
.build() .build()
.getAllowedTlds()) .getAllowedTlds())
@ -455,9 +456,12 @@ public class RegistrarTest extends EntityTestCase {
@Test @Test
public void testFailure_driveFolderId_asFullUrl() { public void testFailure_driveFolderId_asFullUrl() {
String driveFolderId =
"https://drive.google.com/drive/folders/1j3v7RZkU25DjbTx2-Q93H04zKOBau89M";
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> registrar.asBuilder().setDriveFolderId( assertThrows(
"https://drive.google.com/drive/folders/1j3v7RZkU25DjbTx2-Q93H04zKOBau89M")); IllegalArgumentException.class,
() -> registrar.asBuilder().setDriveFolderId(driveFolderId));
assertThat(thrown).hasMessageThat().isEqualTo("Drive folder ID must not be a full URL"); assertThat(thrown).hasMessageThat().isEqualTo("Drive folder ID must not be a full URL");
} }
@ -483,9 +487,7 @@ public class RegistrarTest extends EntityTestCase {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress("")); IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress(""));
assertThat(thrown) assertThat(thrown).hasMessageThat().isEqualTo("Provided email is not a valid email address");
.hasMessageThat()
.isEqualTo("Provided email is not a valid email address");
} }
@Test @Test
@ -512,9 +514,7 @@ public class RegistrarTest extends EntityTestCase {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( assertThrows(
IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress("")); IllegalArgumentException.class, () -> registrar.asBuilder().setEmailAddress(""));
assertThat(thrown) assertThat(thrown).hasMessageThat().isEqualTo("Provided email is not a valid email address");
.hasMessageThat()
.isEqualTo("Provided email is not a valid email address");
} }
@Test @Test
@ -568,8 +568,7 @@ public class RegistrarTest extends EntityTestCase {
@Test @Test
public void testLoadByClientIdCached_isTransactionless() { public void testLoadByClientIdCached_isTransactionless() {
tm() tm().transact(
.transact(
() -> { () -> {
assertThat(Registrar.loadByClientIdCached("registrar")).isPresent(); assertThat(Registrar.loadByClientIdCached("registrar")).isPresent();
// Load something as a control to make sure we are seeing loaded keys in the session // 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 { public class RegistriesTest {
@Rule @Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build(); public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
private void initTestTlds() { private void initTestTlds() {
createTlds("foo", "a.b.c"); // Test a multipart tld. 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 google.registry.testing.SqlHelper.saveRegistryLock;
import static org.junit.Assert.assertThrows; 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.schema.domain.RegistryLock;
import google.registry.testing.AppEngineRule; import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock; import google.registry.testing.FakeClock;
@ -41,11 +39,9 @@ public final class RegistryLockDaoTest {
private final FakeClock fakeClock = new FakeClock(); private final FakeClock fakeClock = new FakeClock();
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule @Rule
public final JpaIntegrationWithCoverageRule jpaRule = public final AppEngineRule appEngine =
new JpaTestRules.Builder().withClock(fakeClock).buildIntegrationWithCoverageRule(); AppEngineRule.builder().withDatastoreAndCloudSql().withClock(fakeClock).build();
@Test @Test
public void testSaveAndLoad_success() { public void testSaveAndLoad_success() {

View file

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

View file

@ -36,7 +36,8 @@ public class GenrulePremiumListTest {
private static final FluentLogger logger = FluentLogger.forEnclosingClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String LISTS_DIRECTORY = "google/registry/config/files/premium/"; 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 @Test
public void testParse_allPremiumLists() throws Exception { 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 FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String LISTS_DIRECTORY = "google/registry/config/files/reserved/"; 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 @Test
public void testParse_allReservedLists() throws Exception { public void testParse_allReservedLists() throws Exception {

View file

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

View file

@ -61,7 +61,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class PremiumListUtilsTest { 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). // Set long persist times on caches so they can be tested (cache times default to 0 in tests).
@Rule @Rule

View file

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

View file

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

View file

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

View file

@ -28,7 +28,8 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class KmsSecretTest { 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 KmsSecret secret;
private KmsSecretRevision secretRevision; 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.ofy.Ofy;
import google.registry.model.server.Lock.LockState; 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.schema.server.LockDao;
import google.registry.testing.AppEngineRule; import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock; import google.registry.testing.FakeClock;
@ -56,12 +54,11 @@ public class LockTest {
private LockMetrics origLockMetrics; private LockMetrics origLockMetrics;
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule public final InjectRule inject = new InjectRule();
@Rule @Rule
public final JpaIntegrationWithCoverageRule jpaRule = public final AppEngineRule appEngine =
new JpaTestRules.Builder().withClock(clock).buildIntegrationWithCoverageRule(); AppEngineRule.builder().withDatastoreAndCloudSql().withClock(clock).build();
@Rule public final InjectRule inject = new InjectRule();
private Optional<Lock> acquire(String tld, Duration leaseLength, LockState expectedLockState) { private Optional<Lock> acquire(String tld, Duration leaseLength, LockState expectedLockState) {
Lock.lockMetrics = mock(LockMetrics.class); Lock.lockMetrics = mock(LockMetrics.class);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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