mirror of
https://github.com/google/nomulus.git
synced 2025-06-12 23:44:46 +02:00
Upgrade mapreduce and DNS tests from JUnit 4 to JUnit 5 (#701)
* Upgrade mapreduce and DNS tests from JUnit 4 to JUnit 5 * Merge branch 'master' into junit5-batch-and-dns
This commit is contained in:
parent
56be3f37ef
commit
bdc269baf7
47 changed files with 659 additions and 800 deletions
|
@ -33,29 +33,26 @@ import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import google.registry.util.TaskQueueUtils;
|
import google.registry.util.TaskQueueUtils;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link CommitLogCheckpointAction}. */
|
/** Unit tests for {@link CommitLogCheckpointAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class CommitLogCheckpointActionTest {
|
public class CommitLogCheckpointActionTest {
|
||||||
|
|
||||||
private static final String QUEUE_NAME = "export-commits";
|
private static final String QUEUE_NAME = "export-commits";
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
||||||
|
|
||||||
CommitLogCheckpointStrategy strategy = mock(CommitLogCheckpointStrategy.class);
|
private CommitLogCheckpointStrategy strategy = mock(CommitLogCheckpointStrategy.class);
|
||||||
|
|
||||||
DateTime now = DateTime.now(UTC);
|
private DateTime now = DateTime.now(UTC);
|
||||||
CommitLogCheckpointAction task = new CommitLogCheckpointAction();
|
private CommitLogCheckpointAction task = new CommitLogCheckpointAction();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void beforeEach() {
|
||||||
task.clock = new FakeClock(now);
|
task.clock = new FakeClock(now);
|
||||||
task.strategy = strategy;
|
task.strategy = strategy;
|
||||||
task.taskQueueUtils = new TaskQueueUtils(new Retrier(null, 1));
|
task.taskQueueUtils = new TaskQueueUtils(new Retrier(null, 1));
|
||||||
|
@ -66,7 +63,7 @@ public class CommitLogCheckpointActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_noCheckpointEverWritten_writesCheckpointAndEnqueuesTask() {
|
void testRun_noCheckpointEverWritten_writesCheckpointAndEnqueuesTask() {
|
||||||
task.run();
|
task.run();
|
||||||
assertTasksEnqueued(
|
assertTasksEnqueued(
|
||||||
QUEUE_NAME,
|
QUEUE_NAME,
|
||||||
|
@ -78,7 +75,7 @@ public class CommitLogCheckpointActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_checkpointWrittenBeforeNow_writesCheckpointAndEnqueuesTask() {
|
void testRun_checkpointWrittenBeforeNow_writesCheckpointAndEnqueuesTask() {
|
||||||
DateTime oneMinuteAgo = now.minusMinutes(1);
|
DateTime oneMinuteAgo = now.minusMinutes(1);
|
||||||
persistResource(CommitLogCheckpointRoot.create(oneMinuteAgo));
|
persistResource(CommitLogCheckpointRoot.create(oneMinuteAgo));
|
||||||
task.run();
|
task.run();
|
||||||
|
@ -92,7 +89,7 @@ public class CommitLogCheckpointActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_checkpointWrittenAfterNow_doesntOverwrite_orEnqueueTask() {
|
void testRun_checkpointWrittenAfterNow_doesntOverwrite_orEnqueueTask() {
|
||||||
DateTime oneMinuteFromNow = now.plusMinutes(1);
|
DateTime oneMinuteFromNow = now.plusMinutes(1);
|
||||||
persistResource(CommitLogCheckpointRoot.create(oneMinuteFromNow));
|
persistResource(CommitLogCheckpointRoot.create(oneMinuteFromNow));
|
||||||
task.run();
|
task.run();
|
||||||
|
|
|
@ -36,27 +36,22 @@ import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link CommitLogCheckpointStrategy}. */
|
/** Unit tests for {@link CommitLogCheckpointStrategy}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class CommitLogCheckpointStrategyTest {
|
public class CommitLogCheckpointStrategyTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
public final InjectRule inject = new InjectRule();
|
|
||||||
|
|
||||||
|
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
|
||||||
final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
|
private final Ofy ofy = new Ofy(clock);
|
||||||
final Ofy ofy = new Ofy(clock);
|
private final TransactionManager tm = new DatastoreTransactionManager(ofy);
|
||||||
final TransactionManager tm = new DatastoreTransactionManager(ofy);
|
private final CommitLogCheckpointStrategy strategy = new CommitLogCheckpointStrategy();
|
||||||
final CommitLogCheckpointStrategy strategy = new CommitLogCheckpointStrategy();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supplier to inject into CommitLogBucket for doling out predictable bucket IDs.
|
* Supplier to inject into CommitLogBucket for doling out predictable bucket IDs.
|
||||||
|
@ -64,7 +59,7 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
* <p>If not overridden, the supplier returns 1 so that other saves won't hit an NPE (since even
|
* <p>If not overridden, the supplier returns 1 so that other saves won't hit an NPE (since even
|
||||||
* if they use saveWithoutBackup() the transaction still selects a bucket key early).
|
* if they use saveWithoutBackup() the transaction still selects a bucket key early).
|
||||||
*/
|
*/
|
||||||
final FakeSupplier<Integer> fakeBucketIdSupplier = new FakeSupplier<>(1);
|
private final FakeSupplier<Integer> fakeBucketIdSupplier = new FakeSupplier<>(1);
|
||||||
|
|
||||||
/** Gross but necessary supplier that can be modified to return the desired value. */
|
/** Gross but necessary supplier that can be modified to return the desired value. */
|
||||||
private static class FakeSupplier<T> implements Supplier<T> {
|
private static class FakeSupplier<T> implements Supplier<T> {
|
||||||
|
@ -74,7 +69,7 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
/** Set this value field to make the supplier return this value. */
|
/** Set this value field to make the supplier return this value. */
|
||||||
T value = null;
|
T value = null;
|
||||||
|
|
||||||
public FakeSupplier(T defaultValue) {
|
FakeSupplier(T defaultValue) {
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,8 +79,8 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void beforeEach() {
|
||||||
strategy.clock = clock;
|
strategy.clock = clock;
|
||||||
strategy.ofy = ofy;
|
strategy.ofy = ofy;
|
||||||
|
|
||||||
|
@ -102,13 +97,13 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_readBucketTimestamps_noCommitLogs() {
|
void test_readBucketTimestamps_noCommitLogs() {
|
||||||
assertThat(strategy.readBucketTimestamps())
|
assertThat(strategy.readBucketTimestamps())
|
||||||
.containsExactly(1, START_OF_TIME, 2, START_OF_TIME, 3, START_OF_TIME);
|
.containsExactly(1, START_OF_TIME, 2, START_OF_TIME, 3, START_OF_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_readBucketTimestamps_withSomeCommitLogs() {
|
void test_readBucketTimestamps_withSomeCommitLogs() {
|
||||||
DateTime startTime = clock.nowUtc();
|
DateTime startTime = clock.nowUtc();
|
||||||
writeCommitLogToBucket(1);
|
writeCommitLogToBucket(1);
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
|
@ -118,7 +113,7 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_readBucketTimestamps_againAfterUpdate_reflectsUpdate() {
|
void test_readBucketTimestamps_againAfterUpdate_reflectsUpdate() {
|
||||||
DateTime firstTime = clock.nowUtc();
|
DateTime firstTime = clock.nowUtc();
|
||||||
writeCommitLogToBucket(1);
|
writeCommitLogToBucket(1);
|
||||||
writeCommitLogToBucket(2);
|
writeCommitLogToBucket(2);
|
||||||
|
@ -133,14 +128,14 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_readNewCommitLogsAndFindThreshold_noCommitsAtAll_returnsEndOfTime() {
|
void test_readNewCommitLogsAndFindThreshold_noCommitsAtAll_returnsEndOfTime() {
|
||||||
ImmutableMap<Integer, DateTime> bucketTimes =
|
ImmutableMap<Integer, DateTime> bucketTimes =
|
||||||
ImmutableMap.of(1, START_OF_TIME, 2, START_OF_TIME, 3, START_OF_TIME);
|
ImmutableMap.of(1, START_OF_TIME, 2, START_OF_TIME, 3, START_OF_TIME);
|
||||||
assertThat(strategy.readNewCommitLogsAndFindThreshold(bucketTimes)).isEqualTo(END_OF_TIME);
|
assertThat(strategy.readNewCommitLogsAndFindThreshold(bucketTimes)).isEqualTo(END_OF_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_readNewCommitLogsAndFindThreshold_noNewCommits_returnsEndOfTime() {
|
void test_readNewCommitLogsAndFindThreshold_noNewCommits_returnsEndOfTime() {
|
||||||
DateTime now = clock.nowUtc();
|
DateTime now = clock.nowUtc();
|
||||||
writeCommitLogToBucket(1);
|
writeCommitLogToBucket(1);
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
|
@ -153,7 +148,7 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_readNewCommitLogsAndFindThreshold_tiedNewCommits_returnsCommitTimeMinusOne() {
|
void test_readNewCommitLogsAndFindThreshold_tiedNewCommits_returnsCommitTimeMinusOne() {
|
||||||
DateTime now = clock.nowUtc();
|
DateTime now = clock.nowUtc();
|
||||||
writeCommitLogToBucket(1);
|
writeCommitLogToBucket(1);
|
||||||
writeCommitLogToBucket(2);
|
writeCommitLogToBucket(2);
|
||||||
|
@ -164,7 +159,7 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_readNewCommitLogsAndFindThreshold_someNewCommits_returnsEarliestTimeMinusOne() {
|
void test_readNewCommitLogsAndFindThreshold_someNewCommits_returnsEarliestTimeMinusOne() {
|
||||||
DateTime now = clock.nowUtc();
|
DateTime now = clock.nowUtc();
|
||||||
writeCommitLogToBucket(1); // 1A
|
writeCommitLogToBucket(1); // 1A
|
||||||
writeCommitLogToBucket(2); // 2A
|
writeCommitLogToBucket(2); // 2A
|
||||||
|
@ -191,7 +186,7 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_readNewCommitLogsAndFindThreshold_commitsAtBucketTimes() {
|
void test_readNewCommitLogsAndFindThreshold_commitsAtBucketTimes() {
|
||||||
DateTime now = clock.nowUtc();
|
DateTime now = clock.nowUtc();
|
||||||
ImmutableMap<Integer, DateTime> bucketTimes =
|
ImmutableMap<Integer, DateTime> bucketTimes =
|
||||||
ImmutableMap.of(1, now.minusMillis(1), 2, now, 3, now.plusMillis(1));
|
ImmutableMap.of(1, now.minusMillis(1), 2, now, 3, now.plusMillis(1));
|
||||||
|
@ -199,7 +194,7 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_computeBucketCheckpointTimes_earlyThreshold_setsEverythingToThreshold() {
|
void test_computeBucketCheckpointTimes_earlyThreshold_setsEverythingToThreshold() {
|
||||||
DateTime now = clock.nowUtc();
|
DateTime now = clock.nowUtc();
|
||||||
ImmutableMap<Integer, DateTime> bucketTimes =
|
ImmutableMap<Integer, DateTime> bucketTimes =
|
||||||
ImmutableMap.of(1, now.minusMillis(1), 2, now, 3, now.plusMillis(1));
|
ImmutableMap.of(1, now.minusMillis(1), 2, now, 3, now.plusMillis(1));
|
||||||
|
@ -208,7 +203,7 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_computeBucketCheckpointTimes_middleThreshold_clampsToThreshold() {
|
void test_computeBucketCheckpointTimes_middleThreshold_clampsToThreshold() {
|
||||||
DateTime now = clock.nowUtc();
|
DateTime now = clock.nowUtc();
|
||||||
ImmutableMap<Integer, DateTime> bucketTimes =
|
ImmutableMap<Integer, DateTime> bucketTimes =
|
||||||
ImmutableMap.of(1, now.minusMillis(1), 2, now, 3, now.plusMillis(1));
|
ImmutableMap.of(1, now.minusMillis(1), 2, now, 3, now.plusMillis(1));
|
||||||
|
@ -217,7 +212,7 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_computeBucketCheckpointTimes_lateThreshold_leavesBucketTimesAsIs() {
|
void test_computeBucketCheckpointTimes_lateThreshold_leavesBucketTimesAsIs() {
|
||||||
DateTime now = clock.nowUtc();
|
DateTime now = clock.nowUtc();
|
||||||
ImmutableMap<Integer, DateTime> bucketTimes =
|
ImmutableMap<Integer, DateTime> bucketTimes =
|
||||||
ImmutableMap.of(1, now.minusMillis(1), 2, now, 3, now.plusMillis(1));
|
ImmutableMap.of(1, now.minusMillis(1), 2, now, 3, now.plusMillis(1));
|
||||||
|
@ -226,7 +221,7 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_computeCheckpoint_noCommitsAtAll_bucketCheckpointTimesAreStartOfTime() {
|
void test_computeCheckpoint_noCommitsAtAll_bucketCheckpointTimesAreStartOfTime() {
|
||||||
assertThat(strategy.computeCheckpoint())
|
assertThat(strategy.computeCheckpoint())
|
||||||
.isEqualTo(CommitLogCheckpoint.create(
|
.isEqualTo(CommitLogCheckpoint.create(
|
||||||
clock.nowUtc(),
|
clock.nowUtc(),
|
||||||
|
@ -234,7 +229,7 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_computeCheckpoint_noNewCommitLogs_bucketCheckpointTimesAreBucketTimes() {
|
void test_computeCheckpoint_noNewCommitLogs_bucketCheckpointTimesAreBucketTimes() {
|
||||||
DateTime now = clock.nowUtc();
|
DateTime now = clock.nowUtc();
|
||||||
writeCommitLogToBucket(1);
|
writeCommitLogToBucket(1);
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
|
@ -250,7 +245,7 @@ public class CommitLogCheckpointStrategyTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_computeCheckpoint_someNewCommits_bucketCheckpointTimesAreClampedToThreshold() {
|
void test_computeCheckpoint_someNewCommits_bucketCheckpointTimesAreClampedToThreshold() {
|
||||||
DateTime now = clock.nowUtc();
|
DateTime now = clock.nowUtc();
|
||||||
writeCommitLogToBucket(1); // 1A
|
writeCommitLogToBucket(1); // 1A
|
||||||
writeCommitLogToBucket(2); // 2A
|
writeCommitLogToBucket(2); // 2A
|
||||||
|
|
|
@ -29,14 +29,11 @@ import google.registry.testing.InjectRule;
|
||||||
import google.registry.testing.mapreduce.MapreduceTestCase;
|
import google.registry.testing.mapreduce.MapreduceTestCase;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link DeleteOldCommitLogsAction}. */
|
/** Unit tests for {@link DeleteOldCommitLogsAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class DeleteOldCommitLogsActionTest
|
public class DeleteOldCommitLogsActionTest
|
||||||
extends MapreduceTestCase<DeleteOldCommitLogsAction> {
|
extends MapreduceTestCase<DeleteOldCommitLogsAction> {
|
||||||
|
|
||||||
|
@ -44,11 +41,10 @@ public class DeleteOldCommitLogsActionTest
|
||||||
private final FakeResponse response = new FakeResponse();
|
private final FakeResponse response = new FakeResponse();
|
||||||
private ContactResource contact;
|
private ContactResource contact;
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
public final InjectRule inject = new InjectRule();
|
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
void beforeEach() {
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
action = new DeleteOldCommitLogsAction();
|
action = new DeleteOldCommitLogsAction();
|
||||||
action.mrRunner = makeDefaultRunner();
|
action.mrRunner = makeDefaultRunner();
|
||||||
|
@ -107,11 +103,9 @@ public class DeleteOldCommitLogsActionTest
|
||||||
return ImmutableList.copyOf(ofy().load().type(clazz).iterable());
|
return ImmutableList.copyOf(ofy().load().type(clazz).iterable());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Check that with very short maxAge, only the referenced elements remain. */
|
||||||
* Check that with very short maxAge, only the referenced elements remain.
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void test_shortMaxAge() throws Exception {
|
void test_shortMaxAge() throws Exception {
|
||||||
runMapreduce(Duration.millis(1));
|
runMapreduce(Duration.millis(1));
|
||||||
|
|
||||||
assertThat(ImmutableList.copyOf(ofy().load().type(CommitLogManifest.class).keys().iterable()))
|
assertThat(ImmutableList.copyOf(ofy().load().type(CommitLogManifest.class).keys().iterable()))
|
||||||
|
@ -121,11 +115,9 @@ public class DeleteOldCommitLogsActionTest
|
||||||
assertThat(ofyLoadType(CommitLogMutation.class)).hasSize(contact.getRevisions().size() * 3);
|
assertThat(ofyLoadType(CommitLogMutation.class)).hasSize(contact.getRevisions().size() * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Check that with very long maxAge, all the elements remain. */
|
||||||
* Check that with very long maxAge, all the elements remain.
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void test_longMaxAge() throws Exception {
|
void test_longMaxAge() throws Exception {
|
||||||
|
|
||||||
ImmutableList<CommitLogManifest> initialManifests = ofyLoadType(CommitLogManifest.class);
|
ImmutableList<CommitLogManifest> initialManifests = ofyLoadType(CommitLogManifest.class);
|
||||||
ImmutableList<CommitLogMutation> initialMutations = ofyLoadType(CommitLogMutation.class);
|
ImmutableList<CommitLogMutation> initialMutations = ofyLoadType(CommitLogMutation.class);
|
||||||
|
|
|
@ -39,17 +39,14 @@ import google.registry.testing.GcsTestingUtils;
|
||||||
import google.registry.testing.TestObject;
|
import google.registry.testing.TestObject;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link ExportCommitLogDiffAction}. */
|
/** Unit tests for {@link ExportCommitLogDiffAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class ExportCommitLogDiffActionTest {
|
public class ExportCommitLogDiffActionTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder()
|
AppEngineRule.builder()
|
||||||
.withDatastoreAndCloudSql()
|
.withDatastoreAndCloudSql()
|
||||||
|
@ -64,15 +61,15 @@ public class ExportCommitLogDiffActionTest {
|
||||||
|
|
||||||
private final ExportCommitLogDiffAction task = new ExportCommitLogDiffAction();
|
private final ExportCommitLogDiffAction task = new ExportCommitLogDiffAction();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void beforeEach() {
|
||||||
task.gcsService = gcsService;
|
task.gcsService = gcsService;
|
||||||
task.gcsBucket = "gcs bucket";
|
task.gcsBucket = "gcs bucket";
|
||||||
task.batchSize = 5;
|
task.batchSize = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_noCommitHistory_onlyUpperCheckpointExported() throws Exception {
|
void testRun_noCommitHistory_onlyUpperCheckpointExported() throws Exception {
|
||||||
task.lowerCheckpointTime = oneMinuteAgo;
|
task.lowerCheckpointTime = oneMinuteAgo;
|
||||||
task.upperCheckpointTime = now;
|
task.upperCheckpointTime = now;
|
||||||
|
|
||||||
|
@ -104,7 +101,7 @@ public class ExportCommitLogDiffActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_regularCommitHistory_exportsCorrectCheckpointDiff() throws Exception {
|
void testRun_regularCommitHistory_exportsCorrectCheckpointDiff() throws Exception {
|
||||||
task.lowerCheckpointTime = oneMinuteAgo;
|
task.lowerCheckpointTime = oneMinuteAgo;
|
||||||
task.upperCheckpointTime = now;
|
task.upperCheckpointTime = now;
|
||||||
|
|
||||||
|
@ -175,7 +172,7 @@ public class ExportCommitLogDiffActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_simultaneousTransactions_bothExported() throws Exception {
|
void testRun_simultaneousTransactions_bothExported() throws Exception {
|
||||||
task.lowerCheckpointTime = oneMinuteAgo;
|
task.lowerCheckpointTime = oneMinuteAgo;
|
||||||
task.upperCheckpointTime = now;
|
task.upperCheckpointTime = now;
|
||||||
|
|
||||||
|
@ -227,7 +224,7 @@ public class ExportCommitLogDiffActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_exportsAcrossMultipleBatches() throws Exception {
|
void testRun_exportsAcrossMultipleBatches() throws Exception {
|
||||||
task.batchSize = 2;
|
task.batchSize = 2;
|
||||||
task.lowerCheckpointTime = oneMinuteAgo;
|
task.lowerCheckpointTime = oneMinuteAgo;
|
||||||
task.upperCheckpointTime = now;
|
task.upperCheckpointTime = now;
|
||||||
|
@ -288,7 +285,7 @@ public class ExportCommitLogDiffActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_checkpointDiffWithNeverTouchedBuckets_exportsCorrectly() throws Exception {
|
void testRun_checkpointDiffWithNeverTouchedBuckets_exportsCorrectly() throws Exception {
|
||||||
task.lowerCheckpointTime = oneMinuteAgo;
|
task.lowerCheckpointTime = oneMinuteAgo;
|
||||||
task.upperCheckpointTime = now;
|
task.upperCheckpointTime = now;
|
||||||
|
|
||||||
|
@ -322,8 +319,7 @@ public class ExportCommitLogDiffActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_checkpointDiffWithNonExistentBucketTimestamps_exportsCorrectly()
|
void testRun_checkpointDiffWithNonExistentBucketTimestamps_exportsCorrectly() throws Exception {
|
||||||
throws Exception {
|
|
||||||
// Non-existent bucket timestamps can exist when the commit log bucket count was increased
|
// Non-existent bucket timestamps can exist when the commit log bucket count was increased
|
||||||
// recently.
|
// recently.
|
||||||
|
|
||||||
|
@ -404,7 +400,7 @@ public class ExportCommitLogDiffActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_exportingFromStartOfTime_exportsAllCommits() throws Exception {
|
void testRun_exportingFromStartOfTime_exportsAllCommits() throws Exception {
|
||||||
task.lowerCheckpointTime = START_OF_TIME;
|
task.lowerCheckpointTime = START_OF_TIME;
|
||||||
task.upperCheckpointTime = now;
|
task.upperCheckpointTime = now;
|
||||||
|
|
||||||
|
|
|
@ -44,28 +44,25 @@ import java.util.List;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link GcsDiffFileLister}. */
|
/** Unit tests for {@link GcsDiffFileLister}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class GcsDiffFileListerTest {
|
public class GcsDiffFileListerTest {
|
||||||
|
|
||||||
static final String GCS_BUCKET = "gcs bucket";
|
private static final String GCS_BUCKET = "gcs bucket";
|
||||||
|
|
||||||
final DateTime now = DateTime.now(UTC);
|
private final DateTime now = DateTime.now(UTC);
|
||||||
final GcsDiffFileLister diffLister = new GcsDiffFileLister();
|
private final GcsDiffFileLister diffLister = new GcsDiffFileLister();
|
||||||
final GcsService gcsService = GcsServiceFactory.createGcsService();
|
private final GcsService gcsService = GcsServiceFactory.createGcsService();
|
||||||
private final TestLogHandler logHandler = new TestLogHandler();
|
private final TestLogHandler logHandler = new TestLogHandler();
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() throws Exception {
|
void beforeEach() throws Exception {
|
||||||
diffLister.gcsService = gcsService;
|
diffLister.gcsService = gcsService;
|
||||||
diffLister.gcsBucket = GCS_BUCKET;
|
diffLister.gcsBucket = GCS_BUCKET;
|
||||||
diffLister.executor = newDirectExecutorService();
|
diffLister.executor = newDirectExecutorService();
|
||||||
|
@ -111,13 +108,13 @@ public class GcsDiffFileListerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testList_noFilesFound() {
|
void testList_noFilesFound() {
|
||||||
DateTime fromTime = now.plusMillis(1);
|
DateTime fromTime = now.plusMillis(1);
|
||||||
assertThat(listDiffFiles(fromTime, null)).isEmpty();
|
assertThat(listDiffFiles(fromTime, null)).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testList_patchesHoles() {
|
void testList_patchesHoles() {
|
||||||
// Fake out the GCS list() method to return only the first and last file.
|
// Fake out the GCS list() method to return only the first and last file.
|
||||||
// We can't use Mockito.spy() because GcsService's impl is final.
|
// We can't use Mockito.spy() because GcsService's impl is final.
|
||||||
diffLister.gcsService = (GcsService) newProxyInstance(
|
diffLister.gcsService = (GcsService) newProxyInstance(
|
||||||
|
@ -162,7 +159,7 @@ public class GcsDiffFileListerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testList_failsOnFork() throws Exception {
|
void testList_failsOnFork() throws Exception {
|
||||||
// We currently have files for now-4m ... now, construct the following sequence:
|
// We currently have files for now-4m ... now, construct the following sequence:
|
||||||
// now-8m <- now-7m <- now-6m now-5m <- now-4m ... now
|
// now-8m <- now-7m <- now-6m now-5m <- now-4m ... now
|
||||||
// ^___________________________|
|
// ^___________________________|
|
||||||
|
@ -179,7 +176,7 @@ public class GcsDiffFileListerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testList_boundaries() {
|
void testList_boundaries() {
|
||||||
assertThat(listDiffFiles(now.minusMinutes(4), now))
|
assertThat(listDiffFiles(now.minusMinutes(4), now))
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
now.minusMinutes(4),
|
now.minusMinutes(4),
|
||||||
|
@ -192,7 +189,7 @@ public class GcsDiffFileListerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testList_failsOnGaps() throws Exception {
|
void testList_failsOnGaps() throws Exception {
|
||||||
// We currently have files for now-4m ... now, construct the following sequence:
|
// We currently have files for now-4m ... now, construct the following sequence:
|
||||||
// now-8m <- now-7m <- now-6m {missing} <- now-4m ... now
|
// now-8m <- now-7m <- now-6m {missing} <- now-4m ... now
|
||||||
for (int i = 6; i < 9; ++i) {
|
for (int i = 6; i < 9; ++i) {
|
||||||
|
@ -228,7 +225,7 @@ public class GcsDiffFileListerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testList_toTimeSpecified() {
|
void testList_toTimeSpecified() {
|
||||||
assertThat(listDiffFiles(
|
assertThat(listDiffFiles(
|
||||||
now.minusMinutes(4).minusSeconds(1), now.minusMinutes(2).plusSeconds(1)))
|
now.minusMinutes(4).minusSeconds(1), now.minusMinutes(2).plusSeconds(1)))
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
|
|
|
@ -54,31 +54,28 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link RestoreCommitLogsAction}. */
|
/** Unit tests for {@link RestoreCommitLogsAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class RestoreCommitLogsActionTest {
|
public class RestoreCommitLogsActionTest {
|
||||||
|
|
||||||
static final String GCS_BUCKET = "gcs bucket";
|
private static final String GCS_BUCKET = "gcs bucket";
|
||||||
|
|
||||||
final DateTime now = DateTime.now(UTC);
|
private final DateTime now = DateTime.now(UTC);
|
||||||
final RestoreCommitLogsAction action = new RestoreCommitLogsAction();
|
private final RestoreCommitLogsAction action = new RestoreCommitLogsAction();
|
||||||
final GcsService gcsService = createGcsService();
|
private final GcsService gcsService = createGcsService();
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder()
|
AppEngineRule.builder()
|
||||||
.withDatastoreAndCloudSql()
|
.withDatastoreAndCloudSql()
|
||||||
.withOfyTestEntities(TestObject.class)
|
.withOfyTestEntities(TestObject.class)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() {
|
void beforeEach() {
|
||||||
action.gcsService = gcsService;
|
action.gcsService = gcsService;
|
||||||
action.dryRun = false;
|
action.dryRun = false;
|
||||||
action.datastoreService = DatastoreServiceFactory.getDatastoreService();
|
action.datastoreService = DatastoreServiceFactory.getDatastoreService();
|
||||||
|
@ -91,7 +88,7 @@ public class RestoreCommitLogsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestore_multipleDiffFiles() throws Exception {
|
void testRestore_multipleDiffFiles() throws Exception {
|
||||||
ofy().saveWithoutBackup().entities(
|
ofy().saveWithoutBackup().entities(
|
||||||
TestObject.create("previous to keep"),
|
TestObject.create("previous to keep"),
|
||||||
TestObject.create("previous to delete")).now();
|
TestObject.create("previous to delete")).now();
|
||||||
|
@ -141,7 +138,7 @@ public class RestoreCommitLogsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestore_noManifests() throws Exception {
|
void testRestore_noManifests() throws Exception {
|
||||||
ofy().saveWithoutBackup().entity(
|
ofy().saveWithoutBackup().entity(
|
||||||
TestObject.create("previous to keep")).now();
|
TestObject.create("previous to keep")).now();
|
||||||
saveDiffFileNotToRestore(now.minusMinutes(1));
|
saveDiffFileNotToRestore(now.minusMinutes(1));
|
||||||
|
@ -155,7 +152,7 @@ public class RestoreCommitLogsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestore_manifestWithNoDeletions() throws Exception {
|
void testRestore_manifestWithNoDeletions() throws Exception {
|
||||||
ofy().saveWithoutBackup().entity(TestObject.create("previous to keep")).now();
|
ofy().saveWithoutBackup().entity(TestObject.create("previous to keep")).now();
|
||||||
Key<CommitLogBucket> bucketKey = getBucketKey(1);
|
Key<CommitLogBucket> bucketKey = getBucketKey(1);
|
||||||
Key<CommitLogManifest> manifestKey = CommitLogManifest.createKey(bucketKey, now);
|
Key<CommitLogManifest> manifestKey = CommitLogManifest.createKey(bucketKey, now);
|
||||||
|
@ -174,7 +171,7 @@ public class RestoreCommitLogsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestore_manifestWithNoMutations() throws Exception {
|
void testRestore_manifestWithNoMutations() throws Exception {
|
||||||
ofy().saveWithoutBackup().entities(
|
ofy().saveWithoutBackup().entities(
|
||||||
TestObject.create("previous to keep"),
|
TestObject.create("previous to keep"),
|
||||||
TestObject.create("previous to delete")).now();
|
TestObject.create("previous to delete")).now();
|
||||||
|
@ -195,7 +192,7 @@ public class RestoreCommitLogsActionTest {
|
||||||
|
|
||||||
// This is a pathological case that shouldn't be possible, but we should be robust to it.
|
// This is a pathological case that shouldn't be possible, but we should be robust to it.
|
||||||
@Test
|
@Test
|
||||||
public void testRestore_manifestWithNoMutationsOrDeletions() throws Exception {
|
void testRestore_manifestWithNoMutationsOrDeletions() throws Exception {
|
||||||
ofy().saveWithoutBackup().entities(
|
ofy().saveWithoutBackup().entities(
|
||||||
TestObject.create("previous to keep")).now();
|
TestObject.create("previous to keep")).now();
|
||||||
saveDiffFileNotToRestore(now.minusMinutes(1));
|
saveDiffFileNotToRestore(now.minusMinutes(1));
|
||||||
|
@ -211,7 +208,7 @@ public class RestoreCommitLogsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestore_mutateExistingEntity() throws Exception {
|
void testRestore_mutateExistingEntity() throws Exception {
|
||||||
ofy().saveWithoutBackup().entity(TestObject.create("existing", "a")).now();
|
ofy().saveWithoutBackup().entity(TestObject.create("existing", "a")).now();
|
||||||
Key<CommitLogManifest> manifestKey = CommitLogManifest.createKey(getBucketKey(1), now);
|
Key<CommitLogManifest> manifestKey = CommitLogManifest.createKey(getBucketKey(1), now);
|
||||||
saveDiffFileNotToRestore(now.minusMinutes(1));
|
saveDiffFileNotToRestore(now.minusMinutes(1));
|
||||||
|
@ -229,7 +226,7 @@ public class RestoreCommitLogsActionTest {
|
||||||
|
|
||||||
// This should be harmless; deletes are idempotent.
|
// This should be harmless; deletes are idempotent.
|
||||||
@Test
|
@Test
|
||||||
public void testRestore_deleteMissingEntity() throws Exception {
|
void testRestore_deleteMissingEntity() throws Exception {
|
||||||
ofy().saveWithoutBackup().entity(TestObject.create("previous to keep", "a")).now();
|
ofy().saveWithoutBackup().entity(TestObject.create("previous to keep", "a")).now();
|
||||||
saveDiffFileNotToRestore(now.minusMinutes(1));
|
saveDiffFileNotToRestore(now.minusMinutes(1));
|
||||||
Iterable<ImmutableObject> commitLogs = saveDiffFile(
|
Iterable<ImmutableObject> commitLogs = saveDiffFile(
|
||||||
|
|
|
@ -50,26 +50,24 @@ import google.registry.util.Retrier;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.mockito.junit.MockitoRule;
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
|
|
||||||
/** Unit tests for {@link AsyncTaskEnqueuer}. */
|
/** Unit tests for {@link AsyncTaskEnqueuer}. */
|
||||||
@RunWith(JUnit4.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class AsyncTaskEnqueuerTest {
|
public class AsyncTaskEnqueuerTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
||||||
|
|
||||||
@Rule public final InjectRule inject = new InjectRule();
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
|
|
||||||
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
|
|
||||||
|
|
||||||
@Mock private AppEngineServiceUtils appEngineServiceUtils;
|
@Mock private AppEngineServiceUtils appEngineServiceUtils;
|
||||||
|
|
||||||
|
@ -77,8 +75,8 @@ public class AsyncTaskEnqueuerTest {
|
||||||
private final CapturingLogHandler logHandler = new CapturingLogHandler();
|
private final CapturingLogHandler logHandler = new CapturingLogHandler();
|
||||||
private final FakeClock clock = new FakeClock(DateTime.parse("2015-05-18T12:34:56Z"));
|
private final FakeClock clock = new FakeClock(DateTime.parse("2015-05-18T12:34:56Z"));
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void beforeEach() {
|
||||||
LoggerConfig.getConfig(AsyncTaskEnqueuer.class).addHandler(logHandler);
|
LoggerConfig.getConfig(AsyncTaskEnqueuer.class).addHandler(logHandler);
|
||||||
when(appEngineServiceUtils.getServiceHostname("backend")).thenReturn("backend.hostname.fake");
|
when(appEngineServiceUtils.getServiceHostname("backend")).thenReturn("backend.hostname.fake");
|
||||||
asyncTaskEnqueuer = createForTesting(appEngineServiceUtils, clock, standardSeconds(90));
|
asyncTaskEnqueuer = createForTesting(appEngineServiceUtils, clock, standardSeconds(90));
|
||||||
|
@ -96,7 +94,7 @@ public class AsyncTaskEnqueuerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_enqueueAsyncResave_success() {
|
void test_enqueueAsyncResave_success() {
|
||||||
ContactResource contact = persistActiveContact("jd23456");
|
ContactResource contact = persistActiveContact("jd23456");
|
||||||
asyncTaskEnqueuer.enqueueAsyncResave(contact, clock.nowUtc(), clock.nowUtc().plusDays(5));
|
asyncTaskEnqueuer.enqueueAsyncResave(contact, clock.nowUtc(), clock.nowUtc().plusDays(5));
|
||||||
assertTasksEnqueued(
|
assertTasksEnqueued(
|
||||||
|
@ -114,7 +112,7 @@ public class AsyncTaskEnqueuerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_enqueueAsyncResave_multipleResaves() {
|
void test_enqueueAsyncResave_multipleResaves() {
|
||||||
ContactResource contact = persistActiveContact("jd23456");
|
ContactResource contact = persistActiveContact("jd23456");
|
||||||
DateTime now = clock.nowUtc();
|
DateTime now = clock.nowUtc();
|
||||||
asyncTaskEnqueuer.enqueueAsyncResave(
|
asyncTaskEnqueuer.enqueueAsyncResave(
|
||||||
|
@ -130,16 +128,15 @@ public class AsyncTaskEnqueuerTest {
|
||||||
.header("content-type", "application/x-www-form-urlencoded")
|
.header("content-type", "application/x-www-form-urlencoded")
|
||||||
.param(PARAM_RESOURCE_KEY, Key.create(contact).getString())
|
.param(PARAM_RESOURCE_KEY, Key.create(contact).getString())
|
||||||
.param(PARAM_REQUESTED_TIME, now.toString())
|
.param(PARAM_REQUESTED_TIME, now.toString())
|
||||||
.param(
|
.param(PARAM_RESAVE_TIMES, "2015-05-20T14:34:56.000Z,2015-05-21T15:34:56.000Z")
|
||||||
PARAM_RESAVE_TIMES,
|
|
||||||
"2015-05-20T14:34:56.000Z,2015-05-21T15:34:56.000Z")
|
|
||||||
.etaDelta(
|
.etaDelta(
|
||||||
standardHours(24).minus(standardSeconds(30)),
|
standardHours(24).minus(standardSeconds(30)),
|
||||||
standardHours(24).plus(standardSeconds(30))));
|
standardHours(24).plus(standardSeconds(30))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void test_enqueueAsyncResave_ignoresTasksTooFarIntoFuture() throws Exception {
|
void test_enqueueAsyncResave_ignoresTasksTooFarIntoFuture() throws Exception {
|
||||||
ContactResource contact = persistActiveContact("jd23456");
|
ContactResource contact = persistActiveContact("jd23456");
|
||||||
asyncTaskEnqueuer.enqueueAsyncResave(contact, clock.nowUtc(), clock.nowUtc().plusDays(31));
|
asyncTaskEnqueuer.enqueueAsyncResave(contact, clock.nowUtc(), clock.nowUtc().plusDays(31));
|
||||||
assertNoTasksEnqueued(QUEUE_ASYNC_ACTIONS);
|
assertNoTasksEnqueued(QUEUE_ASYNC_ACTIONS);
|
||||||
|
@ -147,7 +144,7 @@ public class AsyncTaskEnqueuerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEnqueueRelock() {
|
void testEnqueueRelock() {
|
||||||
RegistryLock lock =
|
RegistryLock lock =
|
||||||
saveRegistryLock(
|
saveRegistryLock(
|
||||||
new RegistryLock.Builder()
|
new RegistryLock.Builder()
|
||||||
|
@ -177,8 +174,9 @@ public class AsyncTaskEnqueuerTest {
|
||||||
standardHours(6).plus(standardSeconds(30))));
|
standardHours(6).plus(standardSeconds(30))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_enqueueRelock_noDuration() {
|
void testFailure_enqueueRelock_noDuration() {
|
||||||
RegistryLock lockWithoutDuration =
|
RegistryLock lockWithoutDuration =
|
||||||
saveRegistryLock(
|
saveRegistryLock(
|
||||||
new RegistryLock.Builder()
|
new RegistryLock.Builder()
|
||||||
|
|
|
@ -21,19 +21,16 @@ import static google.registry.batch.AsyncTaskMetrics.OperationType.CONTACT_AND_H
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link AsyncTaskMetrics}. */
|
/** Unit tests for {@link AsyncTaskMetrics}. */
|
||||||
@RunWith(JUnit4.class)
|
class AsyncTaskMetricsTest {
|
||||||
public class AsyncTaskMetricsTest {
|
|
||||||
|
|
||||||
private final FakeClock clock = new FakeClock();
|
private final FakeClock clock = new FakeClock();
|
||||||
private final AsyncTaskMetrics asyncTaskMetrics = new AsyncTaskMetrics(clock);
|
private final AsyncTaskMetrics asyncTaskMetrics = new AsyncTaskMetrics(clock);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRecordAsyncFlowResult_calculatesDurationMillisCorrectly() {
|
void testRecordAsyncFlowResult_calculatesDurationMillisCorrectly() {
|
||||||
asyncTaskMetrics.recordAsyncFlowResult(
|
asyncTaskMetrics.recordAsyncFlowResult(
|
||||||
CONTACT_AND_HOST_DELETE,
|
CONTACT_AND_HOST_DELETE,
|
||||||
SUCCESS,
|
SUCCESS,
|
||||||
|
|
|
@ -105,19 +105,16 @@ import google.registry.util.SystemSleeper;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
|
||||||
/** Unit tests for {@link DeleteContactsAndHostsAction}. */
|
/** Unit tests for {@link DeleteContactsAndHostsAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class DeleteContactsAndHostsActionTest
|
public class DeleteContactsAndHostsActionTest
|
||||||
extends MapreduceTestCase<DeleteContactsAndHostsAction> {
|
extends MapreduceTestCase<DeleteContactsAndHostsAction> {
|
||||||
|
|
||||||
@Rule public final InjectRule inject = new InjectRule();
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
|
|
||||||
private AsyncTaskEnqueuer enqueuer;
|
private AsyncTaskEnqueuer enqueuer;
|
||||||
private final FakeClock clock = new FakeClock(DateTime.parse("2015-01-15T11:22:33Z"));
|
private final FakeClock clock = new FakeClock(DateTime.parse("2015-01-15T11:22:33Z"));
|
||||||
|
@ -146,8 +143,8 @@ public class DeleteContactsAndHostsActionTest
|
||||||
ofy().clearSessionCache();
|
ofy().clearSessionCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
void beforeEach() {
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
enqueuer =
|
enqueuer =
|
||||||
AsyncTaskEnqueuerTest.createForTesting(
|
AsyncTaskEnqueuerTest.createForTesting(
|
||||||
|
@ -171,7 +168,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_contact_referencedByActiveDomain_doesNotGetDeleted() throws Exception {
|
void testSuccess_contact_referencedByActiveDomain_doesNotGetDeleted() throws Exception {
|
||||||
ContactResource contact = persistContactPendingDelete("blah8221");
|
ContactResource contact = persistContactPendingDelete("blah8221");
|
||||||
persistResource(newDomainBase("example.tld", contact));
|
persistResource(newDomainBase("example.tld", contact));
|
||||||
DateTime timeEnqueued = clock.nowUtc();
|
DateTime timeEnqueued = clock.nowUtc();
|
||||||
|
@ -211,17 +208,17 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_contact_notReferenced_getsDeleted_andPiiWipedOut() throws Exception {
|
void testSuccess_contact_notReferenced_getsDeleted_andPiiWipedOut() throws Exception {
|
||||||
runSuccessfulContactDeletionTest(Optional.of("fakeClientTrid"));
|
runSuccessfulContactDeletionTest(Optional.of("fakeClientTrid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_contact_andNoClientTrid_deletesSuccessfully() throws Exception {
|
void testSuccess_contact_andNoClientTrid_deletesSuccessfully() throws Exception {
|
||||||
runSuccessfulContactDeletionTest(Optional.empty());
|
runSuccessfulContactDeletionTest(Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_cannotAcquireLock() {
|
void test_cannotAcquireLock() {
|
||||||
// Make lock acquisition fail.
|
// Make lock acquisition fail.
|
||||||
acquireLock();
|
acquireLock();
|
||||||
enqueueMapreduceOnly();
|
enqueueMapreduceOnly();
|
||||||
|
@ -229,7 +226,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_mapreduceHasWorkToDo_lockIsAcquired() {
|
void test_mapreduceHasWorkToDo_lockIsAcquired() {
|
||||||
ContactResource contact = persistContactPendingDelete("blah8221");
|
ContactResource contact = persistContactPendingDelete("blah8221");
|
||||||
persistResource(newDomainBase("example.tld", contact));
|
persistResource(newDomainBase("example.tld", contact));
|
||||||
DateTime timeEnqueued = clock.nowUtc();
|
DateTime timeEnqueued = clock.nowUtc();
|
||||||
|
@ -244,7 +241,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_noTasksToLease_releasesLockImmediately() {
|
void test_noTasksToLease_releasesLockImmediately() {
|
||||||
enqueueMapreduceOnly();
|
enqueueMapreduceOnly();
|
||||||
// If the Lock was correctly released, then we can acquire it now.
|
// If the Lock was correctly released, then we can acquire it now.
|
||||||
assertThat(acquireLock()).isPresent();
|
assertThat(acquireLock()).isPresent();
|
||||||
|
@ -293,8 +290,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_contactWithoutPendingTransfer_isDeletedAndHasNoTransferData()
|
void testSuccess_contactWithoutPendingTransfer_isDeletedAndHasNoTransferData() throws Exception {
|
||||||
throws Exception {
|
|
||||||
ContactResource contact = persistContactPendingDelete("blah8221");
|
ContactResource contact = persistContactPendingDelete("blah8221");
|
||||||
enqueuer.enqueueAsyncDelete(
|
enqueuer.enqueueAsyncDelete(
|
||||||
contact,
|
contact,
|
||||||
|
@ -308,7 +304,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_contactWithPendingTransfer_getsDeleted() throws Exception {
|
void testSuccess_contactWithPendingTransfer_getsDeleted() throws Exception {
|
||||||
DateTime transferRequestTime = clock.nowUtc().minusDays(3);
|
DateTime transferRequestTime = clock.nowUtc().minusDays(3);
|
||||||
ContactResource contact =
|
ContactResource contact =
|
||||||
persistContactWithPendingTransfer(
|
persistContactWithPendingTransfer(
|
||||||
|
@ -371,7 +367,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_contact_referencedByDeletedDomain_getsDeleted() throws Exception {
|
void testSuccess_contact_referencedByDeletedDomain_getsDeleted() throws Exception {
|
||||||
ContactResource contactUsed = persistContactPendingDelete("blah1234");
|
ContactResource contactUsed = persistContactPendingDelete("blah1234");
|
||||||
persistResource(
|
persistResource(
|
||||||
newDomainBase("example.tld", contactUsed)
|
newDomainBase("example.tld", contactUsed)
|
||||||
|
@ -410,7 +406,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_contact_notRequestedByOwner_doesNotGetDeleted() throws Exception {
|
void testSuccess_contact_notRequestedByOwner_doesNotGetDeleted() throws Exception {
|
||||||
ContactResource contact = persistContactPendingDelete("jane0991");
|
ContactResource contact = persistContactPendingDelete("jane0991");
|
||||||
enqueuer.enqueueAsyncDelete(
|
enqueuer.enqueueAsyncDelete(
|
||||||
contact,
|
contact,
|
||||||
|
@ -438,7 +434,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_contact_notRequestedByOwner_isSuperuser_getsDeleted() throws Exception {
|
void testSuccess_contact_notRequestedByOwner_isSuperuser_getsDeleted() throws Exception {
|
||||||
ContactResource contact = persistContactWithPii("nate007");
|
ContactResource contact = persistContactWithPii("nate007");
|
||||||
enqueuer.enqueueAsyncDelete(
|
enqueuer.enqueueAsyncDelete(
|
||||||
contact,
|
contact,
|
||||||
|
@ -480,7 +476,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_targetResourcesDontExist_areDelayedForADay() throws Exception {
|
void testSuccess_targetResourcesDontExist_areDelayedForADay() throws Exception {
|
||||||
ContactResource contactNotSaved = newContactResource("somecontact");
|
ContactResource contactNotSaved = newContactResource("somecontact");
|
||||||
HostResource hostNotSaved = newHostResource("a11.blah.foo");
|
HostResource hostNotSaved = newHostResource("a11.blah.foo");
|
||||||
DateTime timeBeforeRun = clock.nowUtc();
|
DateTime timeBeforeRun = clock.nowUtc();
|
||||||
|
@ -519,7 +515,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_unparseableTasks_areDelayedForADay() throws Exception {
|
void testSuccess_unparseableTasks_areDelayedForADay() throws Exception {
|
||||||
TaskOptions task =
|
TaskOptions task =
|
||||||
TaskOptions.Builder.withMethod(Method.PULL).param("gobbledygook", "kljhadfgsd9f7gsdfh");
|
TaskOptions.Builder.withMethod(Method.PULL).param("gobbledygook", "kljhadfgsd9f7gsdfh");
|
||||||
getQueue(QUEUE_ASYNC_DELETE).add(task);
|
getQueue(QUEUE_ASYNC_DELETE).add(task);
|
||||||
|
@ -535,7 +531,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_resourcesNotInPendingDelete_areSkipped() throws Exception {
|
void testSuccess_resourcesNotInPendingDelete_areSkipped() throws Exception {
|
||||||
ContactResource contact = persistActiveContact("blah2222");
|
ContactResource contact = persistActiveContact("blah2222");
|
||||||
HostResource host = persistActiveHost("rustles.your.jimmies");
|
HostResource host = persistActiveHost("rustles.your.jimmies");
|
||||||
DateTime timeEnqueued = clock.nowUtc();
|
DateTime timeEnqueued = clock.nowUtc();
|
||||||
|
@ -567,7 +563,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_alreadyDeletedResources_areSkipped() throws Exception {
|
void testSuccess_alreadyDeletedResources_areSkipped() throws Exception {
|
||||||
ContactResource contactDeleted = persistDeletedContact("blah1236", clock.nowUtc().minusDays(2));
|
ContactResource contactDeleted = persistDeletedContact("blah1236", clock.nowUtc().minusDays(2));
|
||||||
HostResource hostDeleted = persistDeletedHost("a.lim.lop", clock.nowUtc().minusDays(3));
|
HostResource hostDeleted = persistDeletedHost("a.lim.lop", clock.nowUtc().minusDays(3));
|
||||||
enqueuer.enqueueAsyncDelete(
|
enqueuer.enqueueAsyncDelete(
|
||||||
|
@ -590,7 +586,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_host_referencedByActiveDomain_doesNotGetDeleted() throws Exception {
|
void testSuccess_host_referencedByActiveDomain_doesNotGetDeleted() throws Exception {
|
||||||
HostResource host = persistHostPendingDelete("ns1.example.tld");
|
HostResource host = persistHostPendingDelete("ns1.example.tld");
|
||||||
persistUsedDomain("example.tld", persistActiveContact("abc456"), host);
|
persistUsedDomain("example.tld", persistActiveContact("abc456"), host);
|
||||||
DateTime timeEnqueued = clock.nowUtc();
|
DateTime timeEnqueued = clock.nowUtc();
|
||||||
|
@ -627,12 +623,12 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_host_notReferenced_getsDeleted() throws Exception {
|
void testSuccess_host_notReferenced_getsDeleted() throws Exception {
|
||||||
runSuccessfulHostDeletionTest(Optional.of("fakeClientTrid"));
|
runSuccessfulHostDeletionTest(Optional.of("fakeClientTrid"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_host_andNoClientTrid_deletesSuccessfully() throws Exception {
|
void testSuccess_host_andNoClientTrid_deletesSuccessfully() throws Exception {
|
||||||
runSuccessfulHostDeletionTest(Optional.empty());
|
runSuccessfulHostDeletionTest(Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -675,7 +671,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_host_referencedByDeletedDomain_getsDeleted() throws Exception {
|
void testSuccess_host_referencedByDeletedDomain_getsDeleted() throws Exception {
|
||||||
HostResource host = persistHostPendingDelete("ns1.example.tld");
|
HostResource host = persistHostPendingDelete("ns1.example.tld");
|
||||||
persistResource(
|
persistResource(
|
||||||
newDomainBase("example.tld")
|
newDomainBase("example.tld")
|
||||||
|
@ -715,7 +711,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_subordinateHost_getsDeleted() throws Exception {
|
void testSuccess_subordinateHost_getsDeleted() throws Exception {
|
||||||
DomainBase domain =
|
DomainBase domain =
|
||||||
persistResource(
|
persistResource(
|
||||||
newDomainBase("example.tld")
|
newDomainBase("example.tld")
|
||||||
|
@ -766,7 +762,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_host_notRequestedByOwner_doesNotGetDeleted() throws Exception {
|
void testSuccess_host_notRequestedByOwner_doesNotGetDeleted() throws Exception {
|
||||||
HostResource host = persistHostPendingDelete("ns2.example.tld");
|
HostResource host = persistHostPendingDelete("ns2.example.tld");
|
||||||
enqueuer.enqueueAsyncDelete(
|
enqueuer.enqueueAsyncDelete(
|
||||||
host,
|
host,
|
||||||
|
@ -794,7 +790,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_host_notRequestedByOwner_isSuperuser_getsDeleted() throws Exception {
|
void testSuccess_host_notRequestedByOwner_isSuperuser_getsDeleted() throws Exception {
|
||||||
HostResource host = persistHostPendingDelete("ns66.example.tld");
|
HostResource host = persistHostPendingDelete("ns66.example.tld");
|
||||||
enqueuer.enqueueAsyncDelete(
|
enqueuer.enqueueAsyncDelete(
|
||||||
host,
|
host,
|
||||||
|
@ -828,7 +824,7 @@ public class DeleteContactsAndHostsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_deleteABunchOfContactsAndHosts_butNotSome() throws Exception {
|
void testSuccess_deleteABunchOfContactsAndHosts_butNotSome() throws Exception {
|
||||||
ContactResource c1 = persistContactPendingDelete("nsaid54");
|
ContactResource c1 = persistContactPendingDelete("nsaid54");
|
||||||
ContactResource c2 = persistContactPendingDelete("nsaid55");
|
ContactResource c2 = persistContactPendingDelete("nsaid55");
|
||||||
ContactResource c3 = persistContactPendingDelete("nsaid57");
|
ContactResource c3 = persistContactPendingDelete("nsaid57");
|
||||||
|
|
|
@ -52,23 +52,19 @@ import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link DeleteProberDataAction}. */
|
/** Unit tests for {@link DeleteProberDataAction}. */
|
||||||
@RunWith(JUnit4.class)
|
class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDataAction> {
|
||||||
public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDataAction> {
|
|
||||||
|
|
||||||
private static final DateTime DELETION_TIME = DateTime.parse("2010-01-01T00:00:00.000Z");
|
private static final DateTime DELETION_TIME = DateTime.parse("2010-01-01T00:00:00.000Z");
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension final SystemPropertyRule systemPropertyRule = new SystemPropertyRule();
|
||||||
public final SystemPropertyRule systemPropertyRule = new SystemPropertyRule();
|
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() {
|
void beforeEach() {
|
||||||
// Entities in these two should not be touched.
|
// Entities in these two should not be touched.
|
||||||
createTld("tld", "TLD");
|
createTld("tld", "TLD");
|
||||||
// Since "example" doesn't end with .test, its entities won't be deleted even though it is of
|
// Since "example" doesn't end with .test, its entities won't be deleted even though it is of
|
||||||
|
@ -105,7 +101,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_deletesAllAndOnlyProberData() throws Exception {
|
void test_deletesAllAndOnlyProberData() throws Exception {
|
||||||
Set<ImmutableObject> tldEntities = persistLotsOfDomains("tld");
|
Set<ImmutableObject> tldEntities = persistLotsOfDomains("tld");
|
||||||
Set<ImmutableObject> exampleEntities = persistLotsOfDomains("example");
|
Set<ImmutableObject> exampleEntities = persistLotsOfDomains("example");
|
||||||
Set<ImmutableObject> notTestEntities = persistLotsOfDomains("not-test.test");
|
Set<ImmutableObject> notTestEntities = persistLotsOfDomains("not-test.test");
|
||||||
|
@ -120,7 +116,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_deletesAllAndOnlyGivenTlds() throws Exception {
|
void testSuccess_deletesAllAndOnlyGivenTlds() throws Exception {
|
||||||
Set<ImmutableObject> tldEntities = persistLotsOfDomains("tld");
|
Set<ImmutableObject> tldEntities = persistLotsOfDomains("tld");
|
||||||
Set<ImmutableObject> exampleEntities = persistLotsOfDomains("example");
|
Set<ImmutableObject> exampleEntities = persistLotsOfDomains("example");
|
||||||
Set<ImmutableObject> notTestEntities = persistLotsOfDomains("not-test.test");
|
Set<ImmutableObject> notTestEntities = persistLotsOfDomains("not-test.test");
|
||||||
|
@ -136,7 +132,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFail_givenNonTestTld() {
|
void testFail_givenNonTestTld() {
|
||||||
action.tlds = ImmutableSet.of("not-test.test");
|
action.tlds = ImmutableSet.of("not-test.test");
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(IllegalArgumentException.class, this::runMapreduce);
|
assertThrows(IllegalArgumentException.class, this::runMapreduce);
|
||||||
|
@ -146,7 +142,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFail_givenNonExistentTld() {
|
void testFail_givenNonExistentTld() {
|
||||||
action.tlds = ImmutableSet.of("non-existent.test");
|
action.tlds = ImmutableSet.of("non-existent.test");
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(IllegalArgumentException.class, this::runMapreduce);
|
assertThrows(IllegalArgumentException.class, this::runMapreduce);
|
||||||
|
@ -156,7 +152,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFail_givenNonDotTestTldOnProd() {
|
void testFail_givenNonDotTestTldOnProd() {
|
||||||
action.tlds = ImmutableSet.of("example");
|
action.tlds = ImmutableSet.of("example");
|
||||||
RegistryEnvironment.PRODUCTION.setup(systemPropertyRule);
|
RegistryEnvironment.PRODUCTION.setup(systemPropertyRule);
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
|
@ -167,7 +163,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_doesntDeleteNicDomainForProbers() throws Exception {
|
void testSuccess_doesntDeleteNicDomainForProbers() throws Exception {
|
||||||
DomainBase nic = persistActiveDomain("nic.ib-any.test");
|
DomainBase nic = persistActiveDomain("nic.ib-any.test");
|
||||||
ForeignKeyIndex<DomainBase> fkiNic =
|
ForeignKeyIndex<DomainBase> fkiNic =
|
||||||
ForeignKeyIndex.load(DomainBase.class, "nic.ib-any.test", START_OF_TIME);
|
ForeignKeyIndex.load(DomainBase.class, "nic.ib-any.test", START_OF_TIME);
|
||||||
|
@ -178,7 +174,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDryRun_doesntDeleteData() throws Exception {
|
void testDryRun_doesntDeleteData() throws Exception {
|
||||||
Set<ImmutableObject> tldEntities = persistLotsOfDomains("tld");
|
Set<ImmutableObject> tldEntities = persistLotsOfDomains("tld");
|
||||||
Set<ImmutableObject> oaEntities = persistLotsOfDomains("oa-canary.test");
|
Set<ImmutableObject> oaEntities = persistLotsOfDomains("oa-canary.test");
|
||||||
action.isDryRun = true;
|
action.isDryRun = true;
|
||||||
|
@ -188,7 +184,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_activeDomain_isSoftDeleted() throws Exception {
|
void testSuccess_activeDomain_isSoftDeleted() throws Exception {
|
||||||
DomainBase domain = persistResource(
|
DomainBase domain = persistResource(
|
||||||
newDomainBase("blah.ib-any.test")
|
newDomainBase("blah.ib-any.test")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -203,7 +199,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_activeDomain_doubleMapSoftDeletes() throws Exception {
|
void testSuccess_activeDomain_doubleMapSoftDeletes() throws Exception {
|
||||||
DomainBase domain = persistResource(
|
DomainBase domain = persistResource(
|
||||||
newDomainBase("blah.ib-any.test")
|
newDomainBase("blah.ib-any.test")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -220,7 +216,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_recentlyCreatedDomain_isntDeletedYet() throws Exception {
|
void test_recentlyCreatedDomain_isntDeletedYet() throws Exception {
|
||||||
persistResource(
|
persistResource(
|
||||||
newDomainBase("blah.ib-any.test")
|
newDomainBase("blah.ib-any.test")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -234,7 +230,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDryRun_doesntSoftDeleteData() throws Exception {
|
void testDryRun_doesntSoftDeleteData() throws Exception {
|
||||||
DomainBase domain = persistResource(
|
DomainBase domain = persistResource(
|
||||||
newDomainBase("blah.ib-any.test")
|
newDomainBase("blah.ib-any.test")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -246,7 +242,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_domainWithSubordinateHosts_isSkipped() throws Exception {
|
void test_domainWithSubordinateHosts_isSkipped() throws Exception {
|
||||||
persistActiveHost("ns1.blah.ib-any.test");
|
persistActiveHost("ns1.blah.ib-any.test");
|
||||||
DomainBase nakedDomain =
|
DomainBase nakedDomain =
|
||||||
persistDeletedDomain("todelete.ib-any.test", DateTime.now(UTC).minusYears(1));
|
persistDeletedDomain("todelete.ib-any.test", DateTime.now(UTC).minusYears(1));
|
||||||
|
@ -263,7 +259,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_registryAdminClientId_isRequiredForSoftDeletion() {
|
void testFailure_registryAdminClientId_isRequiredForSoftDeletion() {
|
||||||
persistResource(
|
persistResource(
|
||||||
newDomainBase("blah.ib-any.test")
|
newDomainBase("blah.ib-any.test")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
|
|
@ -59,28 +59,25 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link ExpandRecurringBillingEventsAction}. */
|
/** Unit tests for {@link ExpandRecurringBillingEventsAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class ExpandRecurringBillingEventsActionTest
|
public class ExpandRecurringBillingEventsActionTest
|
||||||
extends MapreduceTestCase<ExpandRecurringBillingEventsAction> {
|
extends MapreduceTestCase<ExpandRecurringBillingEventsAction> {
|
||||||
@Rule
|
|
||||||
public final InjectRule inject = new InjectRule();
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
|
|
||||||
private final DateTime beginningOfTest = DateTime.parse("2000-10-02T00:00:00Z");
|
private final DateTime beginningOfTest = DateTime.parse("2000-10-02T00:00:00Z");
|
||||||
private final FakeClock clock = new FakeClock(beginningOfTest);
|
private final FakeClock clock = new FakeClock(beginningOfTest);
|
||||||
|
|
||||||
DomainBase domain;
|
private DomainBase domain;
|
||||||
HistoryEntry historyEntry;
|
private HistoryEntry historyEntry;
|
||||||
BillingEvent.Recurring recurring;
|
private BillingEvent.Recurring recurring;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() {
|
void beforeEach() {
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
action = new ExpandRecurringBillingEventsAction();
|
action = new ExpandRecurringBillingEventsAction();
|
||||||
action.mrRunner = makeDefaultRunner();
|
action.mrRunner = makeDefaultRunner();
|
||||||
|
@ -161,7 +158,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent() throws Exception {
|
void testSuccess_expandSingleEvent() throws Exception {
|
||||||
persistResource(recurring);
|
persistResource(recurring);
|
||||||
action.cursorTimeParam = Optional.of(START_OF_TIME);
|
action.cursorTimeParam = Optional.of(START_OF_TIME);
|
||||||
runMapreduce();
|
runMapreduce();
|
||||||
|
@ -176,7 +173,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_deletedDomain() throws Exception {
|
void testSuccess_expandSingleEvent_deletedDomain() throws Exception {
|
||||||
DateTime deletionTime = DateTime.parse("2000-08-01T00:00:00Z");
|
DateTime deletionTime = DateTime.parse("2000-08-01T00:00:00Z");
|
||||||
DomainBase deletedDomain = persistDeletedDomain("deleted.tld", deletionTime);
|
DomainBase deletedDomain = persistDeletedDomain("deleted.tld", deletionTime);
|
||||||
historyEntry = persistResource(new HistoryEntry.Builder().setParent(deletedDomain).build());
|
historyEntry = persistResource(new HistoryEntry.Builder().setParent(deletedDomain).build());
|
||||||
|
@ -208,7 +205,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_idempotentForDuplicateRuns() throws Exception {
|
void testSuccess_expandSingleEvent_idempotentForDuplicateRuns() throws Exception {
|
||||||
persistResource(recurring);
|
persistResource(recurring);
|
||||||
action.cursorTimeParam = Optional.of(START_OF_TIME);
|
action.cursorTimeParam = Optional.of(START_OF_TIME);
|
||||||
runMapreduce();
|
runMapreduce();
|
||||||
|
@ -225,7 +222,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_idempotentForExistingOneTime() throws Exception {
|
void testSuccess_expandSingleEvent_idempotentForExistingOneTime() throws Exception {
|
||||||
persistResource(recurring);
|
persistResource(recurring);
|
||||||
BillingEvent.OneTime persisted = persistResource(defaultOneTimeBuilder()
|
BillingEvent.OneTime persisted = persistResource(defaultOneTimeBuilder()
|
||||||
.setParent(historyEntry)
|
.setParent(historyEntry)
|
||||||
|
@ -240,8 +237,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_notIdempotentForDifferentBillingTime()
|
void testSuccess_expandSingleEvent_notIdempotentForDifferentBillingTime() throws Exception {
|
||||||
throws Exception {
|
|
||||||
persistResource(recurring);
|
persistResource(recurring);
|
||||||
action.cursorTimeParam = Optional.of(START_OF_TIME);
|
action.cursorTimeParam = Optional.of(START_OF_TIME);
|
||||||
runMapreduce();
|
runMapreduce();
|
||||||
|
@ -259,8 +255,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_notIdempotentForDifferentRecurring()
|
void testSuccess_expandSingleEvent_notIdempotentForDifferentRecurring() throws Exception {
|
||||||
throws Exception {
|
|
||||||
persistResource(recurring);
|
persistResource(recurring);
|
||||||
BillingEvent.Recurring recurring2 = persistResource(recurring.asBuilder()
|
BillingEvent.Recurring recurring2 = persistResource(recurring.asBuilder()
|
||||||
.setId(3L)
|
.setId(3L)
|
||||||
|
@ -289,7 +284,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_ignoreRecurringBeforeWindow() throws Exception {
|
void testSuccess_ignoreRecurringBeforeWindow() throws Exception {
|
||||||
recurring = persistResource(recurring.asBuilder()
|
recurring = persistResource(recurring.asBuilder()
|
||||||
.setEventTime(DateTime.parse("1997-01-05T00:00:00Z"))
|
.setEventTime(DateTime.parse("1997-01-05T00:00:00Z"))
|
||||||
.setRecurrenceEndTime(DateTime.parse("1999-10-05T00:00:00Z"))
|
.setRecurrenceEndTime(DateTime.parse("1999-10-05T00:00:00Z"))
|
||||||
|
@ -303,7 +298,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_ignoreRecurringAfterWindow() throws Exception {
|
void testSuccess_ignoreRecurringAfterWindow() throws Exception {
|
||||||
recurring = persistResource(recurring.asBuilder()
|
recurring = persistResource(recurring.asBuilder()
|
||||||
.setEventTime(clock.nowUtc().plusYears(2))
|
.setEventTime(clock.nowUtc().plusYears(2))
|
||||||
.build());
|
.build());
|
||||||
|
@ -315,7 +310,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_billingTimeAtCursorTime() throws Exception {
|
void testSuccess_expandSingleEvent_billingTimeAtCursorTime() throws Exception {
|
||||||
persistResource(recurring);
|
persistResource(recurring);
|
||||||
action.cursorTimeParam = Optional.of(DateTime.parse("2000-02-19T00:00:00Z"));
|
action.cursorTimeParam = Optional.of(DateTime.parse("2000-02-19T00:00:00Z"));
|
||||||
runMapreduce();
|
runMapreduce();
|
||||||
|
@ -328,8 +323,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_cursorTimeBetweenEventAndBillingTime()
|
void testSuccess_expandSingleEvent_cursorTimeBetweenEventAndBillingTime() throws Exception {
|
||||||
throws Exception {
|
|
||||||
persistResource(recurring);
|
persistResource(recurring);
|
||||||
action.cursorTimeParam = Optional.of(DateTime.parse("2000-01-12T00:00:00Z"));
|
action.cursorTimeParam = Optional.of(DateTime.parse("2000-01-12T00:00:00Z"));
|
||||||
runMapreduce();
|
runMapreduce();
|
||||||
|
@ -342,7 +336,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_billingTimeAtExecutionTime() throws Exception {
|
void testSuccess_expandSingleEvent_billingTimeAtExecutionTime() throws Exception {
|
||||||
DateTime testTime = DateTime.parse("2000-02-19T00:00:00Z").minusMillis(1);
|
DateTime testTime = DateTime.parse("2000-02-19T00:00:00Z").minusMillis(1);
|
||||||
persistResource(recurring);
|
persistResource(recurring);
|
||||||
action.cursorTimeParam = Optional.of(START_OF_TIME);
|
action.cursorTimeParam = Optional.of(START_OF_TIME);
|
||||||
|
@ -359,7 +353,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_multipleYearCreate() throws Exception {
|
void testSuccess_expandSingleEvent_multipleYearCreate() throws Exception {
|
||||||
DateTime testTime = beginningOfTest.plusYears(2);
|
DateTime testTime = beginningOfTest.plusYears(2);
|
||||||
action.cursorTimeParam = Optional.of(recurring.getEventTime());
|
action.cursorTimeParam = Optional.of(recurring.getEventTime());
|
||||||
recurring =
|
recurring =
|
||||||
|
@ -381,7 +375,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_withCursor() throws Exception {
|
void testSuccess_expandSingleEvent_withCursor() throws Exception {
|
||||||
persistResource(recurring);
|
persistResource(recurring);
|
||||||
saveCursor(START_OF_TIME);
|
saveCursor(START_OF_TIME);
|
||||||
runMapreduce();
|
runMapreduce();
|
||||||
|
@ -394,7 +388,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_withCursorPastExpected() throws Exception {
|
void testSuccess_expandSingleEvent_withCursorPastExpected() throws Exception {
|
||||||
persistResource(recurring);
|
persistResource(recurring);
|
||||||
// Simulate a quick second run of the mapreduce (this should be a no-op).
|
// Simulate a quick second run of the mapreduce (this should be a no-op).
|
||||||
saveCursor(clock.nowUtc().minusSeconds(1));
|
saveCursor(clock.nowUtc().minusSeconds(1));
|
||||||
|
@ -406,7 +400,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_recurrenceEndBeforeEvent() throws Exception {
|
void testSuccess_expandSingleEvent_recurrenceEndBeforeEvent() throws Exception {
|
||||||
// This can occur when a domain is transferred or deleted before a domain comes up for renewal.
|
// This can occur when a domain is transferred or deleted before a domain comes up for renewal.
|
||||||
recurring = persistResource(recurring.asBuilder()
|
recurring = persistResource(recurring.asBuilder()
|
||||||
.setRecurrenceEndTime(recurring.getEventTime().minusDays(5))
|
.setRecurrenceEndTime(recurring.getEventTime().minusDays(5))
|
||||||
|
@ -420,7 +414,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_dryRun() throws Exception {
|
void testSuccess_expandSingleEvent_dryRun() throws Exception {
|
||||||
persistResource(recurring);
|
persistResource(recurring);
|
||||||
action.isDryRun = true;
|
action.isDryRun = true;
|
||||||
saveCursor(START_OF_TIME); // Need a saved cursor to verify that it didn't move.
|
saveCursor(START_OF_TIME); // Need a saved cursor to verify that it didn't move.
|
||||||
|
@ -432,7 +426,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_multipleYears() throws Exception {
|
void testSuccess_expandSingleEvent_multipleYears() throws Exception {
|
||||||
DateTime testTime = clock.nowUtc().plusYears(5);
|
DateTime testTime = clock.nowUtc().plusYears(5);
|
||||||
clock.setTo(testTime);
|
clock.setTo(testTime);
|
||||||
List<BillingEvent> expectedEvents = new ArrayList<>();
|
List<BillingEvent> expectedEvents = new ArrayList<>();
|
||||||
|
@ -463,7 +457,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_multipleYears_cursorInBetweenYears() throws Exception {
|
void testSuccess_expandSingleEvent_multipleYears_cursorInBetweenYears() throws Exception {
|
||||||
DateTime testTime = clock.nowUtc().plusYears(5);
|
DateTime testTime = clock.nowUtc().plusYears(5);
|
||||||
clock.setTo(testTime);
|
clock.setTo(testTime);
|
||||||
List<BillingEvent> expectedEvents = new ArrayList<>();
|
List<BillingEvent> expectedEvents = new ArrayList<>();
|
||||||
|
@ -492,7 +486,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_singleEvent_beforeRenewal() throws Exception {
|
void testSuccess_singleEvent_beforeRenewal() throws Exception {
|
||||||
DateTime testTime = DateTime.parse("2000-01-04T00:00:00Z");
|
DateTime testTime = DateTime.parse("2000-01-04T00:00:00Z");
|
||||||
clock.setTo(testTime);
|
clock.setTo(testTime);
|
||||||
persistResource(recurring);
|
persistResource(recurring);
|
||||||
|
@ -505,7 +499,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_singleEvent_afterRecurrenceEnd_inAutorenewGracePeriod() throws Exception {
|
void testSuccess_singleEvent_afterRecurrenceEnd_inAutorenewGracePeriod() throws Exception {
|
||||||
// The domain creation date is 1999-01-05, and the first renewal date is thus 2000-01-05.
|
// The domain creation date is 1999-01-05, and the first renewal date is thus 2000-01-05.
|
||||||
DateTime testTime = DateTime.parse("2001-02-06T00:00:00Z");
|
DateTime testTime = DateTime.parse("2001-02-06T00:00:00Z");
|
||||||
clock.setTo(testTime);
|
clock.setTo(testTime);
|
||||||
|
@ -530,8 +524,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_singleEvent_afterRecurrenceEnd_outsideAutorenewGracePeriod()
|
void testSuccess_singleEvent_afterRecurrenceEnd_outsideAutorenewGracePeriod() throws Exception {
|
||||||
throws Exception {
|
|
||||||
// The domain creation date is 1999-01-05, and the first renewal date is thus 2000-01-05.
|
// The domain creation date is 1999-01-05, and the first renewal date is thus 2000-01-05.
|
||||||
DateTime testTime = DateTime.parse("2001-02-06T00:00:00Z");
|
DateTime testTime = DateTime.parse("2001-02-06T00:00:00Z");
|
||||||
clock.setTo(testTime);
|
clock.setTo(testTime);
|
||||||
|
@ -556,7 +549,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_billingTimeOnLeapYear() throws Exception {
|
void testSuccess_expandSingleEvent_billingTimeOnLeapYear() throws Exception {
|
||||||
recurring =
|
recurring =
|
||||||
persistResource(
|
persistResource(
|
||||||
recurring.asBuilder().setEventTime(DateTime.parse("2000-01-15T00:00:00Z")).build());
|
recurring.asBuilder().setEventTime(DateTime.parse("2000-01-15T00:00:00Z")).build());
|
||||||
|
@ -575,7 +568,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandSingleEvent_billingTimeNotOnLeapYear() throws Exception {
|
void testSuccess_expandSingleEvent_billingTimeNotOnLeapYear() throws Exception {
|
||||||
DateTime testTime = DateTime.parse("2001-12-01T00:00:00Z");
|
DateTime testTime = DateTime.parse("2001-12-01T00:00:00Z");
|
||||||
recurring =
|
recurring =
|
||||||
persistResource(
|
persistResource(
|
||||||
|
@ -597,7 +590,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_expandMultipleEvents() throws Exception {
|
void testSuccess_expandMultipleEvents() throws Exception {
|
||||||
persistResource(recurring);
|
persistResource(recurring);
|
||||||
BillingEvent.Recurring recurring2 = persistResource(recurring.asBuilder()
|
BillingEvent.Recurring recurring2 = persistResource(recurring.asBuilder()
|
||||||
.setEventTime(recurring.getEventTime().plusMonths(3))
|
.setEventTime(recurring.getEventTime().plusMonths(3))
|
||||||
|
@ -630,7 +623,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_premiumDomain() throws Exception {
|
void testSuccess_premiumDomain() throws Exception {
|
||||||
persistResource(
|
persistResource(
|
||||||
Registry.get("tld")
|
Registry.get("tld")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -651,7 +644,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_varyingRenewPrices() throws Exception {
|
void testSuccess_varyingRenewPrices() throws Exception {
|
||||||
DateTime testTime = beginningOfTest.plusYears(1);
|
DateTime testTime = beginningOfTest.plusYears(1);
|
||||||
persistResource(
|
persistResource(
|
||||||
Registry.get("tld")
|
Registry.get("tld")
|
||||||
|
@ -691,7 +684,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_cursorAfterExecutionTime() {
|
void testFailure_cursorAfterExecutionTime() {
|
||||||
action.cursorTimeParam = Optional.of(clock.nowUtc().plusYears(1));
|
action.cursorTimeParam = Optional.of(clock.nowUtc().plusYears(1));
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(IllegalArgumentException.class, this::runMapreduce);
|
assertThrows(IllegalArgumentException.class, this::runMapreduce);
|
||||||
|
@ -701,7 +694,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_cursorAtExecutionTime() {
|
void testFailure_cursorAtExecutionTime() {
|
||||||
// The clock advances one milli on runMapreduce.
|
// The clock advances one milli on runMapreduce.
|
||||||
action.cursorTimeParam = Optional.of(clock.nowUtc().plusMillis(1));
|
action.cursorTimeParam = Optional.of(clock.nowUtc().plusMillis(1));
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
|
@ -712,7 +705,7 @@ public class ExpandRecurringBillingEventsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_mapperException_doesNotMoveCursor() throws Exception {
|
void testFailure_mapperException_doesNotMoveCursor() throws Exception {
|
||||||
saveCursor(START_OF_TIME); // Need a saved cursor to verify that it didn't move.
|
saveCursor(START_OF_TIME); // Need a saved cursor to verify that it didn't move.
|
||||||
// Set target to a TLD that doesn't exist.
|
// Set target to a TLD that doesn't exist.
|
||||||
recurring = persistResource(recurring.asBuilder().setTargetId("domain.junk").build());
|
recurring = persistResource(recurring.asBuilder().setTargetId("domain.junk").build());
|
||||||
|
|
|
@ -61,27 +61,24 @@ import google.registry.util.SystemSleeper;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
|
||||||
/** Unit tests for {@link RefreshDnsOnHostRenameAction}. */
|
/** Unit tests for {@link RefreshDnsOnHostRenameAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class RefreshDnsOnHostRenameActionTest
|
public class RefreshDnsOnHostRenameActionTest
|
||||||
extends MapreduceTestCase<RefreshDnsOnHostRenameAction> {
|
extends MapreduceTestCase<RefreshDnsOnHostRenameAction> {
|
||||||
|
|
||||||
@Rule public final InjectRule inject = new InjectRule();
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
|
|
||||||
private AsyncTaskEnqueuer enqueuer;
|
private AsyncTaskEnqueuer enqueuer;
|
||||||
private final FakeClock clock = new FakeClock(DateTime.parse("2015-01-15T11:22:33Z"));
|
private final FakeClock clock = new FakeClock(DateTime.parse("2015-01-15T11:22:33Z"));
|
||||||
private final FakeResponse fakeResponse = new FakeResponse();
|
private final FakeResponse fakeResponse = new FakeResponse();
|
||||||
@Mock private RequestStatusChecker requestStatusChecker;
|
@Mock private RequestStatusChecker requestStatusChecker;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
void beforeEach() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
enqueuer =
|
enqueuer =
|
||||||
AsyncTaskEnqueuerTest.createForTesting(
|
AsyncTaskEnqueuerTest.createForTesting(
|
||||||
|
@ -124,7 +121,7 @@ public class RefreshDnsOnHostRenameActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_dnsUpdateEnqueued() throws Exception {
|
void testSuccess_dnsUpdateEnqueued() throws Exception {
|
||||||
HostResource host = persistActiveHost("ns1.example.tld");
|
HostResource host = persistActiveHost("ns1.example.tld");
|
||||||
persistResource(newDomainBase("example.tld", host));
|
persistResource(newDomainBase("example.tld", host));
|
||||||
persistResource(newDomainBase("otherexample.tld", host));
|
persistResource(newDomainBase("otherexample.tld", host));
|
||||||
|
@ -141,7 +138,7 @@ public class RefreshDnsOnHostRenameActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_multipleHostsProcessedInBatch() throws Exception {
|
void testSuccess_multipleHostsProcessedInBatch() throws Exception {
|
||||||
HostResource host1 = persistActiveHost("ns1.example.tld");
|
HostResource host1 = persistActiveHost("ns1.example.tld");
|
||||||
HostResource host2 = persistActiveHost("ns2.example.tld");
|
HostResource host2 = persistActiveHost("ns2.example.tld");
|
||||||
HostResource host3 = persistActiveHost("ns3.example.tld");
|
HostResource host3 = persistActiveHost("ns3.example.tld");
|
||||||
|
@ -165,7 +162,7 @@ public class RefreshDnsOnHostRenameActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_deletedHost_doesntTriggerDnsRefresh() throws Exception {
|
void testSuccess_deletedHost_doesntTriggerDnsRefresh() throws Exception {
|
||||||
HostResource host = persistDeletedHost("ns11.fakesss.tld", clock.nowUtc().minusDays(4));
|
HostResource host = persistDeletedHost("ns11.fakesss.tld", clock.nowUtc().minusDays(4));
|
||||||
persistResource(newDomainBase("example1.tld", host));
|
persistResource(newDomainBase("example1.tld", host));
|
||||||
DateTime timeEnqueued = clock.nowUtc();
|
DateTime timeEnqueued = clock.nowUtc();
|
||||||
|
@ -180,7 +177,7 @@ public class RefreshDnsOnHostRenameActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_noDnsTasksForDeletedDomain() throws Exception {
|
void testSuccess_noDnsTasksForDeletedDomain() throws Exception {
|
||||||
HostResource renamedHost = persistActiveHost("ns1.example.tld");
|
HostResource renamedHost = persistActiveHost("ns1.example.tld");
|
||||||
persistResource(
|
persistResource(
|
||||||
newDomainBase("example.tld", renamedHost)
|
newDomainBase("example.tld", renamedHost)
|
||||||
|
@ -194,7 +191,7 @@ public class RefreshDnsOnHostRenameActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_hostDoesntExist_delaysTask() throws Exception {
|
void testRun_hostDoesntExist_delaysTask() throws Exception {
|
||||||
HostResource host = newHostResource("ns1.example.tld");
|
HostResource host = newHostResource("ns1.example.tld");
|
||||||
enqueuer.enqueueAsyncDnsRefresh(host, clock.nowUtc());
|
enqueuer.enqueueAsyncDnsRefresh(host, clock.nowUtc());
|
||||||
enqueueMapreduceOnly();
|
enqueueMapreduceOnly();
|
||||||
|
@ -208,7 +205,7 @@ public class RefreshDnsOnHostRenameActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_cannotAcquireLock() {
|
void test_cannotAcquireLock() {
|
||||||
// Make lock acquisition fail.
|
// Make lock acquisition fail.
|
||||||
acquireLock();
|
acquireLock();
|
||||||
enqueueMapreduceOnly();
|
enqueueMapreduceOnly();
|
||||||
|
@ -217,7 +214,7 @@ public class RefreshDnsOnHostRenameActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_mapreduceHasWorkToDo_lockIsAcquired() {
|
void test_mapreduceHasWorkToDo_lockIsAcquired() {
|
||||||
HostResource host = persistActiveHost("ns1.example.tld");
|
HostResource host = persistActiveHost("ns1.example.tld");
|
||||||
enqueuer.enqueueAsyncDnsRefresh(host, clock.nowUtc());
|
enqueuer.enqueueAsyncDnsRefresh(host, clock.nowUtc());
|
||||||
enqueueMapreduceOnly();
|
enqueueMapreduceOnly();
|
||||||
|
@ -225,7 +222,7 @@ public class RefreshDnsOnHostRenameActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_noTasksToLease_releasesLockImmediately() throws Exception {
|
void test_noTasksToLease_releasesLockImmediately() throws Exception {
|
||||||
enqueueMapreduceOnly();
|
enqueueMapreduceOnly();
|
||||||
assertNoDnsTasksEnqueued();
|
assertNoDnsTasksEnqueued();
|
||||||
assertNoTasksEnqueued(QUEUE_ASYNC_HOST_RENAME);
|
assertNoTasksEnqueued(QUEUE_ASYNC_HOST_RENAME);
|
||||||
|
|
|
@ -44,14 +44,11 @@ import google.registry.util.AppEngineServiceUtils;
|
||||||
import google.registry.util.StringGenerator.Alphabets;
|
import google.registry.util.StringGenerator.Alphabets;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link RelockDomainAction}. */
|
/** Unit tests for {@link RelockDomainAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class RelockDomainActionTest {
|
public class RelockDomainActionTest {
|
||||||
|
|
||||||
private static final String DOMAIN_NAME = "example.tld";
|
private static final String DOMAIN_NAME = "example.tld";
|
||||||
|
@ -67,7 +64,7 @@ public class RelockDomainActionTest {
|
||||||
AsyncTaskEnqueuerTest.createForTesting(
|
AsyncTaskEnqueuerTest.createForTesting(
|
||||||
mock(AppEngineServiceUtils.class), clock, Duration.ZERO));
|
mock(AppEngineServiceUtils.class), clock, Duration.ZERO));
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngineRule =
|
public final AppEngineRule appEngineRule =
|
||||||
AppEngineRule.builder()
|
AppEngineRule.builder()
|
||||||
.withDatastoreAndCloudSql()
|
.withDatastoreAndCloudSql()
|
||||||
|
@ -78,8 +75,8 @@ public class RelockDomainActionTest {
|
||||||
private RegistryLock oldLock;
|
private RegistryLock oldLock;
|
||||||
private RelockDomainAction action;
|
private RelockDomainAction action;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
void beforeEach() {
|
||||||
createTlds("tld", "net");
|
createTlds("tld", "net");
|
||||||
HostResource host = persistActiveHost("ns1.example.net");
|
HostResource host = persistActiveHost("ns1.example.net");
|
||||||
domain = persistResource(newDomainBase(DOMAIN_NAME, host));
|
domain = persistResource(newDomainBase(DOMAIN_NAME, host));
|
||||||
|
@ -95,7 +92,7 @@ public class RelockDomainActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLock() {
|
void testLock() {
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(reloadDomain(domain).getStatusValues())
|
assertThat(reloadDomain(domain).getStatusValues())
|
||||||
.containsAtLeastElementsIn(REGISTRY_LOCK_STATUSES);
|
.containsAtLeastElementsIn(REGISTRY_LOCK_STATUSES);
|
||||||
|
@ -107,7 +104,7 @@ public class RelockDomainActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_unknownCode() {
|
void testFailure_unknownCode() {
|
||||||
action = createAction(12128675309L);
|
action = createAction(12128675309L);
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
|
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
|
||||||
|
@ -115,7 +112,7 @@ public class RelockDomainActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_pendingDelete() {
|
void testFailure_pendingDelete() {
|
||||||
persistResource(domain.asBuilder().setStatusValues(ImmutableSet.of(PENDING_DELETE)).build());
|
persistResource(domain.asBuilder().setStatusValues(ImmutableSet.of(PENDING_DELETE)).build());
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
|
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
|
||||||
|
@ -124,7 +121,7 @@ public class RelockDomainActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_pendingTransfer() {
|
void testFailure_pendingTransfer() {
|
||||||
persistResource(domain.asBuilder().setStatusValues(ImmutableSet.of(PENDING_TRANSFER)).build());
|
persistResource(domain.asBuilder().setStatusValues(ImmutableSet.of(PENDING_TRANSFER)).build());
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
|
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
|
||||||
|
@ -133,7 +130,7 @@ public class RelockDomainActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_domainAlreadyLocked() {
|
void testFailure_domainAlreadyLocked() {
|
||||||
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, CLIENT_ID, null, true);
|
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, CLIENT_ID, null, true);
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
|
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
|
||||||
|
@ -142,7 +139,7 @@ public class RelockDomainActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_domainDeleted() {
|
void testFailure_domainDeleted() {
|
||||||
persistDomainAsDeleted(domain, clock.nowUtc());
|
persistDomainAsDeleted(domain, clock.nowUtc());
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
|
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
|
||||||
|
@ -151,7 +148,7 @@ public class RelockDomainActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_domainTransferred() {
|
void testFailure_domainTransferred() {
|
||||||
persistResource(domain.asBuilder().setPersistedCurrentSponsorClientId("NewRegistrar").build());
|
persistResource(domain.asBuilder().setPersistedCurrentSponsorClientId("NewRegistrar").build());
|
||||||
action.run();
|
action.run();
|
||||||
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
|
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
|
||||||
|
@ -164,7 +161,7 @@ public class RelockDomainActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_relockAlreadySet() {
|
void testFailure_relockAlreadySet() {
|
||||||
RegistryLock newLock =
|
RegistryLock newLock =
|
||||||
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, CLIENT_ID, null, true);
|
domainLockUtils.administrativelyApplyLock(DOMAIN_NAME, CLIENT_ID, null, true);
|
||||||
saveRegistryLock(oldLock.asBuilder().setRelock(newLock).build());
|
saveRegistryLock(oldLock.asBuilder().setRelock(newLock).build());
|
||||||
|
|
|
@ -25,18 +25,14 @@ import google.registry.model.transfer.TransferStatus;
|
||||||
import google.registry.testing.FakeResponse;
|
import google.registry.testing.FakeResponse;
|
||||||
import google.registry.testing.mapreduce.MapreduceTestCase;
|
import google.registry.testing.mapreduce.MapreduceTestCase;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link ResaveAllEppResourcesAction}. */
|
/** Unit tests for {@link ResaveAllEppResourcesAction}. */
|
||||||
@RunWith(JUnit4.class)
|
class ResaveAllEppResourcesActionTest extends MapreduceTestCase<ResaveAllEppResourcesAction> {
|
||||||
public class ResaveAllEppResourcesActionTest
|
|
||||||
extends MapreduceTestCase<ResaveAllEppResourcesAction> {
|
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() {
|
void beforeEach() {
|
||||||
action = new ResaveAllEppResourcesAction();
|
action = new ResaveAllEppResourcesAction();
|
||||||
action.mrRunner = makeDefaultRunner();
|
action.mrRunner = makeDefaultRunner();
|
||||||
action.response = new FakeResponse();
|
action.response = new FakeResponse();
|
||||||
|
@ -48,7 +44,7 @@ public class ResaveAllEppResourcesActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_mapreduceSuccessfullyResavesEntity() throws Exception {
|
void test_mapreduceSuccessfullyResavesEntity() throws Exception {
|
||||||
ContactResource contact = persistActiveContact("test123");
|
ContactResource contact = persistActiveContact("test123");
|
||||||
DateTime creationTime = contact.getUpdateTimestamp().getTimestamp();
|
DateTime creationTime = contact.getUpdateTimestamp().getTimestamp();
|
||||||
assertThat(ofy().load().entity(contact).now().getUpdateTimestamp().getTimestamp())
|
assertThat(ofy().load().entity(contact).now().getUpdateTimestamp().getTimestamp())
|
||||||
|
@ -60,7 +56,7 @@ public class ResaveAllEppResourcesActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_mapreduceResolvesPendingTransfer() throws Exception {
|
void test_mapreduceResolvesPendingTransfer() throws Exception {
|
||||||
DateTime now = DateTime.now(UTC);
|
DateTime now = DateTime.now(UTC);
|
||||||
// Set up a contact with a transfer that implicitly completed five days ago.
|
// Set up a contact with a transfer that implicitly completed five days ago.
|
||||||
ContactResource contact =
|
ContactResource contact =
|
||||||
|
|
|
@ -49,33 +49,32 @@ import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import google.registry.util.AppEngineServiceUtils;
|
import google.registry.util.AppEngineServiceUtils;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.mockito.junit.MockitoRule;
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
|
|
||||||
/** Unit tests for {@link ResaveEntityAction}. */
|
/** Unit tests for {@link ResaveEntityAction}. */
|
||||||
@RunWith(JUnit4.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class ResaveEntityActionTest {
|
public class ResaveEntityActionTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
||||||
|
|
||||||
@Rule public final InjectRule inject = new InjectRule();
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
|
|
||||||
|
|
||||||
@Mock private AppEngineServiceUtils appEngineServiceUtils;
|
@Mock private AppEngineServiceUtils appEngineServiceUtils;
|
||||||
@Mock private Response response;
|
@Mock private Response response;
|
||||||
private final FakeClock clock = new FakeClock(DateTime.parse("2016-02-11T10:00:00Z"));
|
private final FakeClock clock = new FakeClock(DateTime.parse("2016-02-11T10:00:00Z"));
|
||||||
private AsyncTaskEnqueuer asyncTaskEnqueuer;
|
private AsyncTaskEnqueuer asyncTaskEnqueuer;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void beforeEach() {
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
when(appEngineServiceUtils.getServiceHostname("backend")).thenReturn("backend.hostname.fake");
|
when(appEngineServiceUtils.getServiceHostname("backend")).thenReturn("backend.hostname.fake");
|
||||||
asyncTaskEnqueuer =
|
asyncTaskEnqueuer =
|
||||||
|
@ -93,8 +92,9 @@ public class ResaveEntityActionTest {
|
||||||
action.run();
|
action.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void test_domainPendingTransfer_isResavedAndTransferCompleted() {
|
void test_domainPendingTransfer_isResavedAndTransferCompleted() {
|
||||||
DomainBase domain =
|
DomainBase domain =
|
||||||
persistDomainWithPendingTransfer(
|
persistDomainWithPendingTransfer(
|
||||||
persistDomainWithDependentResources(
|
persistDomainWithDependentResources(
|
||||||
|
@ -116,7 +116,7 @@ public class ResaveEntityActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_domainPendingDeletion_isResavedAndReenqueued() {
|
void test_domainPendingDeletion_isResavedAndReenqueued() {
|
||||||
DomainBase domain =
|
DomainBase domain =
|
||||||
persistResource(
|
persistResource(
|
||||||
newDomainBase("domain.tld")
|
newDomainBase("domain.tld")
|
||||||
|
|
|
@ -35,22 +35,18 @@ import java.io.StringWriter;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for Dagger injection of the DNS package. */
|
/** Unit tests for Dagger injection of the DNS package. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public final class DnsInjectionTest {
|
public final class DnsInjectionTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
public final InjectRule inject = new InjectRule();
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -59,8 +55,8 @@ public final class DnsInjectionTest {
|
||||||
private DnsTestComponent component;
|
private DnsTestComponent component;
|
||||||
private DnsQueue dnsQueue;
|
private DnsQueue dnsQueue;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void beforeEach() throws Exception {
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
when(rsp.getWriter()).thenReturn(new PrintWriter(httpOutput));
|
when(rsp.getWriter()).thenReturn(new PrintWriter(httpOutput));
|
||||||
component = DaggerDnsTestComponent.builder()
|
component = DaggerDnsTestComponent.builder()
|
||||||
|
@ -71,7 +67,7 @@ public final class DnsInjectionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadDnsQueueAction_injectsAndWorks() {
|
void testReadDnsQueueAction_injectsAndWorks() {
|
||||||
persistActiveSubordinateHost("ns1.example.lol", persistActiveDomain("example.lol"));
|
persistActiveSubordinateHost("ns1.example.lol", persistActiveDomain("example.lol"));
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
dnsQueue.addDomainRefreshTask("example.lol");
|
dnsQueue.addDomainRefreshTask("example.lol");
|
||||||
|
@ -81,7 +77,7 @@ public final class DnsInjectionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRefreshDns_domain_injectsAndWorks() {
|
void testRefreshDns_domain_injectsAndWorks() {
|
||||||
persistActiveDomain("example.lol");
|
persistActiveDomain("example.lol");
|
||||||
when(req.getParameter("type")).thenReturn("domain");
|
when(req.getParameter("type")).thenReturn("domain");
|
||||||
when(req.getParameter("name")).thenReturn("example.lol");
|
when(req.getParameter("name")).thenReturn("example.lol");
|
||||||
|
@ -90,7 +86,7 @@ public final class DnsInjectionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRefreshDns_missingDomain_throwsNotFound() {
|
void testRefreshDns_missingDomain_throwsNotFound() {
|
||||||
when(req.getParameter("type")).thenReturn("domain");
|
when(req.getParameter("type")).thenReturn("domain");
|
||||||
when(req.getParameter("name")).thenReturn("example.lol");
|
when(req.getParameter("name")).thenReturn("example.lol");
|
||||||
NotFoundException thrown =
|
NotFoundException thrown =
|
||||||
|
@ -99,7 +95,7 @@ public final class DnsInjectionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRefreshDns_host_injectsAndWorks() {
|
void testRefreshDns_host_injectsAndWorks() {
|
||||||
persistActiveSubordinateHost("ns1.example.lol", persistActiveDomain("example.lol"));
|
persistActiveSubordinateHost("ns1.example.lol", persistActiveDomain("example.lol"));
|
||||||
when(req.getParameter("type")).thenReturn("host");
|
when(req.getParameter("type")).thenReturn("host");
|
||||||
when(req.getParameter("name")).thenReturn("ns1.example.lol");
|
when(req.getParameter("name")).thenReturn("ns1.example.lol");
|
||||||
|
@ -108,7 +104,7 @@ public final class DnsInjectionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRefreshDns_missingHost_throwsNotFound() {
|
void testRefreshDns_missingHost_throwsNotFound() {
|
||||||
when(req.getParameter("type")).thenReturn("host");
|
when(req.getParameter("type")).thenReturn("host");
|
||||||
when(req.getParameter("name")).thenReturn("ns1.example.lol");
|
when(req.getParameter("name")).thenReturn("ns1.example.lol");
|
||||||
NotFoundException thrown =
|
NotFoundException thrown =
|
||||||
|
|
|
@ -24,31 +24,28 @@ import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link DnsQueue}. */
|
/** Unit tests for {@link DnsQueue}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class DnsQueueTest {
|
public class DnsQueueTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
AppEngineRule.builder().withDatastoreAndCloudSql().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"));
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() {
|
void beforeEach() {
|
||||||
dnsQueue = DnsQueue.createForTesting(clock);
|
dnsQueue = DnsQueue.createForTesting(clock);
|
||||||
dnsQueue.leaseTasksBatchSize = 10;
|
dnsQueue.leaseTasksBatchSize = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_addHostRefreshTask_success() {
|
void test_addHostRefreshTask_success() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
dnsQueue.addHostRefreshTask("octopus.tld");
|
dnsQueue.addHostRefreshTask("octopus.tld");
|
||||||
assertTasksEnqueued(
|
assertTasksEnqueued(
|
||||||
|
@ -61,7 +58,7 @@ public class DnsQueueTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_addHostRefreshTask_failsOnUnknownTld() {
|
void test_addHostRefreshTask_failsOnUnknownTld() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
@ -78,7 +75,7 @@ public class DnsQueueTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_addDomainRefreshTask_success() {
|
void test_addDomainRefreshTask_success() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
dnsQueue.addDomainRefreshTask("octopus.tld");
|
dnsQueue.addDomainRefreshTask("octopus.tld");
|
||||||
assertTasksEnqueued(
|
assertTasksEnqueued(
|
||||||
|
@ -91,7 +88,7 @@ public class DnsQueueTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_addDomainRefreshTask_failsOnUnknownTld() {
|
void test_addDomainRefreshTask_failsOnUnknownTld() {
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
assertThrows(
|
assertThrows(
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
|
|
|
@ -44,22 +44,18 @@ import google.registry.testing.FakeLockHandler;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link PublishDnsUpdatesAction}. */
|
/** Unit tests for {@link PublishDnsUpdatesAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class PublishDnsUpdatesActionTest {
|
public class PublishDnsUpdatesActionTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
public final InjectRule inject = new InjectRule();
|
|
||||||
private final FakeClock clock = new FakeClock(DateTime.parse("1971-01-01TZ"));
|
private final FakeClock clock = new FakeClock(DateTime.parse("1971-01-01TZ"));
|
||||||
private final FakeLockHandler lockHandler = new FakeLockHandler(true);
|
private final FakeLockHandler lockHandler = new FakeLockHandler(true);
|
||||||
private final DnsWriter dnsWriter = mock(DnsWriter.class);
|
private final DnsWriter dnsWriter = mock(DnsWriter.class);
|
||||||
|
@ -67,8 +63,8 @@ public class PublishDnsUpdatesActionTest {
|
||||||
private final DnsQueue dnsQueue = mock(DnsQueue.class);
|
private final DnsQueue dnsQueue = mock(DnsQueue.class);
|
||||||
private PublishDnsUpdatesAction action;
|
private PublishDnsUpdatesAction action;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void beforeEach() {
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
createTld("xn--q9jyb4c");
|
createTld("xn--q9jyb4c");
|
||||||
persistResource(
|
persistResource(
|
||||||
|
@ -104,7 +100,7 @@ public class PublishDnsUpdatesActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHost_published() {
|
void testHost_published() {
|
||||||
action = createAction("xn--q9jyb4c");
|
action = createAction("xn--q9jyb4c");
|
||||||
action.hosts = ImmutableSet.of("ns1.example.xn--q9jyb4c");
|
action.hosts = ImmutableSet.of("ns1.example.xn--q9jyb4c");
|
||||||
|
|
||||||
|
@ -132,7 +128,7 @@ public class PublishDnsUpdatesActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDomain_published() {
|
void testDomain_published() {
|
||||||
action = createAction("xn--q9jyb4c");
|
action = createAction("xn--q9jyb4c");
|
||||||
action.domains = ImmutableSet.of("example.xn--q9jyb4c");
|
action.domains = ImmutableSet.of("example.xn--q9jyb4c");
|
||||||
|
|
||||||
|
@ -160,7 +156,7 @@ public class PublishDnsUpdatesActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAction_acquiresCorrectLock() {
|
void testAction_acquiresCorrectLock() {
|
||||||
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setNumDnsPublishLocks(4).build());
|
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setNumDnsPublishLocks(4).build());
|
||||||
action = createAction("xn--q9jyb4c");
|
action = createAction("xn--q9jyb4c");
|
||||||
action.lockIndex = 2;
|
action.lockIndex = 2;
|
||||||
|
@ -178,7 +174,7 @@ public class PublishDnsUpdatesActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPublish_commitFails() {
|
void testPublish_commitFails() {
|
||||||
action = createAction("xn--q9jyb4c");
|
action = createAction("xn--q9jyb4c");
|
||||||
action.domains = ImmutableSet.of("example.xn--q9jyb4c", "example2.xn--q9jyb4c");
|
action.domains = ImmutableSet.of("example.xn--q9jyb4c", "example2.xn--q9jyb4c");
|
||||||
action.hosts =
|
action.hosts =
|
||||||
|
@ -207,11 +203,12 @@ public class PublishDnsUpdatesActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHostAndDomain_published() {
|
void testHostAndDomain_published() {
|
||||||
action = createAction("xn--q9jyb4c");
|
action = createAction("xn--q9jyb4c");
|
||||||
action.domains = ImmutableSet.of("example.xn--q9jyb4c", "example2.xn--q9jyb4c");
|
action.domains = ImmutableSet.of("example.xn--q9jyb4c", "example2.xn--q9jyb4c");
|
||||||
action.hosts = ImmutableSet.of(
|
action.hosts =
|
||||||
"ns1.example.xn--q9jyb4c", "ns2.example.xn--q9jyb4c", "ns1.example2.xn--q9jyb4c");
|
ImmutableSet.of(
|
||||||
|
"ns1.example.xn--q9jyb4c", "ns2.example.xn--q9jyb4c", "ns1.example2.xn--q9jyb4c");
|
||||||
|
|
||||||
action.run();
|
action.run();
|
||||||
|
|
||||||
|
@ -241,7 +238,7 @@ public class PublishDnsUpdatesActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrongTld_notPublished() {
|
void testWrongTld_notPublished() {
|
||||||
action = createAction("xn--q9jyb4c");
|
action = createAction("xn--q9jyb4c");
|
||||||
action.domains = ImmutableSet.of("example.com", "example2.com");
|
action.domains = ImmutableSet.of("example.com", "example2.com");
|
||||||
action.hosts = ImmutableSet.of("ns1.example.com", "ns2.example.com", "ns1.example2.com");
|
action.hosts = ImmutableSet.of("ns1.example.com", "ns2.example.com", "ns1.example2.com");
|
||||||
|
@ -269,7 +266,7 @@ public class PublishDnsUpdatesActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLockIsntAvailable() {
|
void testLockIsntAvailable() {
|
||||||
action = createAction("xn--q9jyb4c");
|
action = createAction("xn--q9jyb4c");
|
||||||
action.domains = ImmutableSet.of("example.com", "example2.com");
|
action.domains = ImmutableSet.of("example.com", "example2.com");
|
||||||
action.hosts = ImmutableSet.of("ns1.example.com", "ns2.example.com", "ns1.example2.com");
|
action.hosts = ImmutableSet.of("ns1.example.com", "ns2.example.com", "ns1.example2.com");
|
||||||
|
@ -293,7 +290,7 @@ public class PublishDnsUpdatesActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParam_invalidLockIndex() {
|
void testParam_invalidLockIndex() {
|
||||||
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setNumDnsPublishLocks(4).build());
|
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setNumDnsPublishLocks(4).build());
|
||||||
action = createAction("xn--q9jyb4c");
|
action = createAction("xn--q9jyb4c");
|
||||||
action.domains = ImmutableSet.of("example.com");
|
action.domains = ImmutableSet.of("example.com");
|
||||||
|
@ -319,7 +316,7 @@ public class PublishDnsUpdatesActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegistryParam_mismatchedMaxLocks() {
|
void testRegistryParam_mismatchedMaxLocks() {
|
||||||
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setNumDnsPublishLocks(4).build());
|
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setNumDnsPublishLocks(4).build());
|
||||||
action = createAction("xn--q9jyb4c");
|
action = createAction("xn--q9jyb4c");
|
||||||
action.domains = ImmutableSet.of("example.com");
|
action.domains = ImmutableSet.of("example.com");
|
||||||
|
@ -345,7 +342,7 @@ public class PublishDnsUpdatesActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrongDnsWriter() {
|
void testWrongDnsWriter() {
|
||||||
action = createAction("xn--q9jyb4c");
|
action = createAction("xn--q9jyb4c");
|
||||||
action.domains = ImmutableSet.of("example.com", "example2.com");
|
action.domains = ImmutableSet.of("example.com", "example2.com");
|
||||||
action.hosts = ImmutableSet.of("ns1.example.com", "ns2.example.com", "ns1.example2.com");
|
action.hosts = ImmutableSet.of("ns1.example.com", "ns2.example.com", "ns1.example2.com");
|
||||||
|
|
|
@ -56,14 +56,11 @@ import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link ReadDnsQueueAction}. */
|
/** Unit tests for {@link ReadDnsQueueAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class ReadDnsQueueActionTest {
|
public class ReadDnsQueueActionTest {
|
||||||
|
|
||||||
private static final int TEST_TLD_UPDATE_BATCH_SIZE = 100;
|
private static final int TEST_TLD_UPDATE_BATCH_SIZE = 100;
|
||||||
|
@ -72,7 +69,7 @@ public class ReadDnsQueueActionTest {
|
||||||
// test in the future. Set to year 3000 so it'll remain in the future for a very long time.
|
// test in the future. Set to year 3000 so it'll remain in the future for a very long time.
|
||||||
private FakeClock clock = new FakeClock(DateTime.parse("3000-01-01TZ"));
|
private FakeClock clock = new FakeClock(DateTime.parse("3000-01-01TZ"));
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder()
|
AppEngineRule.builder()
|
||||||
.withDatastoreAndCloudSql()
|
.withDatastoreAndCloudSql()
|
||||||
|
@ -93,8 +90,8 @@ public class ReadDnsQueueActionTest {
|
||||||
.withClock(clock)
|
.withClock(clock)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void beforeEach() {
|
||||||
// Because of b/73372999 - the FakeClock can't be in the past, or the TaskQueues stop working.
|
// Because of b/73372999 - the FakeClock can't be in the past, or the TaskQueues stop working.
|
||||||
// To make sure it's never in the past, we set the date far-far into the future
|
// To make sure it's never in the past, we set the date far-far into the future
|
||||||
clock.setTo(DateTime.parse("3000-01-01TZ"));
|
clock.setTo(DateTime.parse("3000-01-01TZ"));
|
||||||
|
@ -171,7 +168,7 @@ public class ReadDnsQueueActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_methodPostIsDefault() {
|
void testSuccess_methodPostIsDefault() {
|
||||||
dnsQueue.addDomainRefreshTask("domain.com");
|
dnsQueue.addDomainRefreshTask("domain.com");
|
||||||
dnsQueue.addDomainRefreshTask("domain.net");
|
dnsQueue.addDomainRefreshTask("domain.net");
|
||||||
dnsQueue.addDomainRefreshTask("domain.example");
|
dnsQueue.addDomainRefreshTask("domain.example");
|
||||||
|
@ -187,7 +184,7 @@ public class ReadDnsQueueActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_allSingleLockTlds() {
|
void testSuccess_allSingleLockTlds() {
|
||||||
dnsQueue.addDomainRefreshTask("domain.com");
|
dnsQueue.addDomainRefreshTask("domain.com");
|
||||||
dnsQueue.addDomainRefreshTask("domain.net");
|
dnsQueue.addDomainRefreshTask("domain.net");
|
||||||
dnsQueue.addDomainRefreshTask("domain.example");
|
dnsQueue.addDomainRefreshTask("domain.example");
|
||||||
|
@ -200,7 +197,7 @@ public class ReadDnsQueueActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_moreUpdatesThanQueueBatchSize() {
|
void testSuccess_moreUpdatesThanQueueBatchSize() {
|
||||||
// The task queue has a batch size of 1000 (that's the maximum number of items you can lease at
|
// The task queue has a batch size of 1000 (that's the maximum number of items you can lease at
|
||||||
// once).
|
// once).
|
||||||
ImmutableList<String> domains =
|
ImmutableList<String> domains =
|
||||||
|
@ -219,15 +216,14 @@ public class ReadDnsQueueActionTest {
|
||||||
assertThat(queuedParams).hasSize(15);
|
assertThat(queuedParams).hasSize(15);
|
||||||
// Check all the expected domains are indeed enqueued
|
// Check all the expected domains are indeed enqueued
|
||||||
assertThat(
|
assertThat(
|
||||||
queuedParams
|
queuedParams.stream()
|
||||||
.stream()
|
|
||||||
.map(params -> params.get("domains").stream().collect(onlyElement()))
|
.map(params -> params.get("domains").stream().collect(onlyElement()))
|
||||||
.flatMap(values -> Splitter.on(',').splitToList(values).stream()))
|
.flatMap(values -> Splitter.on(',').splitToList(values).stream()))
|
||||||
.containsExactlyElementsIn(domains);
|
.containsExactlyElementsIn(domains);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_twoDnsWriters() {
|
void testSuccess_twoDnsWriters() {
|
||||||
persistResource(
|
persistResource(
|
||||||
Registry.get("com")
|
Registry.get("com")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -242,7 +238,7 @@ public class ReadDnsQueueActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_differentUpdateTimes_usesMinimum() {
|
void testSuccess_differentUpdateTimes_usesMinimum() {
|
||||||
clock.setTo(DateTime.parse("3000-02-03TZ"));
|
clock.setTo(DateTime.parse("3000-02-03TZ"));
|
||||||
dnsQueue.addDomainRefreshTask("domain1.com");
|
dnsQueue.addDomainRefreshTask("domain1.com");
|
||||||
clock.setTo(DateTime.parse("3000-02-04TZ"));
|
clock.setTo(DateTime.parse("3000-02-04TZ"));
|
||||||
|
@ -256,18 +252,18 @@ public class ReadDnsQueueActionTest {
|
||||||
assertThat(getQueuedParams(DNS_PUBLISH_PUSH_QUEUE_NAME)).hasSize(1);
|
assertThat(getQueuedParams(DNS_PUBLISH_PUSH_QUEUE_NAME)).hasSize(1);
|
||||||
assertThat(getQueuedParams(DNS_PUBLISH_PUSH_QUEUE_NAME).get(0))
|
assertThat(getQueuedParams(DNS_PUBLISH_PUSH_QUEUE_NAME).get(0))
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
"enqueued", "3000-02-05T01:00:00.000Z",
|
"enqueued", "3000-02-05T01:00:00.000Z",
|
||||||
"itemsCreated", "3000-02-03T00:00:00.000Z",
|
"itemsCreated", "3000-02-03T00:00:00.000Z",
|
||||||
"tld", "com",
|
"tld", "com",
|
||||||
"dnsWriter", "comWriter",
|
"dnsWriter", "comWriter",
|
||||||
"domains", "domain1.com,domain2.com,domain3.com",
|
"domains", "domain1.com,domain2.com,domain3.com",
|
||||||
"hosts", "",
|
"hosts", "",
|
||||||
"lockIndex", "1",
|
"lockIndex", "1",
|
||||||
"numPublishLocks", "1");
|
"numPublishLocks", "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_oneTldPaused_returnedToQueue() {
|
void testSuccess_oneTldPaused_returnedToQueue() {
|
||||||
persistResource(Registry.get("net").asBuilder().setDnsPaused(true).build());
|
persistResource(Registry.get("net").asBuilder().setDnsPaused(true).build());
|
||||||
dnsQueue.addDomainRefreshTask("domain.com");
|
dnsQueue.addDomainRefreshTask("domain.com");
|
||||||
dnsQueue.addDomainRefreshTask("domain.net");
|
dnsQueue.addDomainRefreshTask("domain.net");
|
||||||
|
@ -281,7 +277,7 @@ public class ReadDnsQueueActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_oneTldUnknown_returnedToQueue() {
|
void testSuccess_oneTldUnknown_returnedToQueue() {
|
||||||
dnsQueue.addDomainRefreshTask("domain.com");
|
dnsQueue.addDomainRefreshTask("domain.com");
|
||||||
dnsQueue.addDomainRefreshTask("domain.example");
|
dnsQueue.addDomainRefreshTask("domain.example");
|
||||||
QueueFactory.getQueue(DNS_PULL_QUEUE_NAME)
|
QueueFactory.getQueue(DNS_PULL_QUEUE_NAME)
|
||||||
|
@ -301,7 +297,7 @@ public class ReadDnsQueueActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_corruptTaskTldMismatch_published() {
|
void testSuccess_corruptTaskTldMismatch_published() {
|
||||||
// TODO(mcilwain): what's the correct action to take in this case?
|
// TODO(mcilwain): what's the correct action to take in this case?
|
||||||
dnsQueue.addDomainRefreshTask("domain.com");
|
dnsQueue.addDomainRefreshTask("domain.com");
|
||||||
dnsQueue.addDomainRefreshTask("domain.example");
|
dnsQueue.addDomainRefreshTask("domain.example");
|
||||||
|
@ -322,7 +318,7 @@ public class ReadDnsQueueActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_corruptTaskNoTld_discarded() {
|
void testSuccess_corruptTaskNoTld_discarded() {
|
||||||
dnsQueue.addDomainRefreshTask("domain.com");
|
dnsQueue.addDomainRefreshTask("domain.com");
|
||||||
dnsQueue.addDomainRefreshTask("domain.example");
|
dnsQueue.addDomainRefreshTask("domain.example");
|
||||||
QueueFactory.getQueue(DNS_PULL_QUEUE_NAME)
|
QueueFactory.getQueue(DNS_PULL_QUEUE_NAME)
|
||||||
|
@ -341,7 +337,7 @@ public class ReadDnsQueueActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_corruptTaskNoName_discarded() {
|
void testSuccess_corruptTaskNoName_discarded() {
|
||||||
dnsQueue.addDomainRefreshTask("domain.com");
|
dnsQueue.addDomainRefreshTask("domain.com");
|
||||||
dnsQueue.addDomainRefreshTask("domain.example");
|
dnsQueue.addDomainRefreshTask("domain.example");
|
||||||
QueueFactory.getQueue(DNS_PULL_QUEUE_NAME)
|
QueueFactory.getQueue(DNS_PULL_QUEUE_NAME)
|
||||||
|
@ -360,7 +356,7 @@ public class ReadDnsQueueActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_corruptTaskNoType_discarded() {
|
void testSuccess_corruptTaskNoType_discarded() {
|
||||||
dnsQueue.addDomainRefreshTask("domain.com");
|
dnsQueue.addDomainRefreshTask("domain.com");
|
||||||
dnsQueue.addDomainRefreshTask("domain.example");
|
dnsQueue.addDomainRefreshTask("domain.example");
|
||||||
QueueFactory.getQueue(DNS_PULL_QUEUE_NAME)
|
QueueFactory.getQueue(DNS_PULL_QUEUE_NAME)
|
||||||
|
@ -379,7 +375,7 @@ public class ReadDnsQueueActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_corruptTaskWrongType_discarded() {
|
void testSuccess_corruptTaskWrongType_discarded() {
|
||||||
dnsQueue.addDomainRefreshTask("domain.com");
|
dnsQueue.addDomainRefreshTask("domain.com");
|
||||||
dnsQueue.addDomainRefreshTask("domain.example");
|
dnsQueue.addDomainRefreshTask("domain.example");
|
||||||
QueueFactory.getQueue(DNS_PULL_QUEUE_NAME)
|
QueueFactory.getQueue(DNS_PULL_QUEUE_NAME)
|
||||||
|
@ -399,7 +395,7 @@ public class ReadDnsQueueActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_zone_getsIgnored() {
|
void testSuccess_zone_getsIgnored() {
|
||||||
dnsQueue.addHostRefreshTask("ns1.domain.com");
|
dnsQueue.addHostRefreshTask("ns1.domain.com");
|
||||||
dnsQueue.addDomainRefreshTask("domain.net");
|
dnsQueue.addDomainRefreshTask("domain.net");
|
||||||
dnsQueue.addZoneRefreshTask("example");
|
dnsQueue.addZoneRefreshTask("example");
|
||||||
|
@ -420,7 +416,7 @@ public class ReadDnsQueueActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_manyDomainsAndHosts() {
|
void testSuccess_manyDomainsAndHosts() {
|
||||||
for (int i = 0; i < 150; i++) {
|
for (int i = 0; i < 150; i++) {
|
||||||
// 0: domain; 1: host 1; 2: host 2
|
// 0: domain; 1: host 1; 2: host 2
|
||||||
for (int thingType = 0; thingType < 3; thingType++) {
|
for (int thingType = 0; thingType < 3; thingType++) {
|
||||||
|
@ -491,7 +487,7 @@ public class ReadDnsQueueActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_lockGroupsHostBySuperordinateDomain() {
|
void testSuccess_lockGroupsHostBySuperordinateDomain() {
|
||||||
dnsQueue.addDomainRefreshTask("hello.multilock.uk");
|
dnsQueue.addDomainRefreshTask("hello.multilock.uk");
|
||||||
dnsQueue.addHostRefreshTask("ns1.abc.hello.multilock.uk");
|
dnsQueue.addHostRefreshTask("ns1.abc.hello.multilock.uk");
|
||||||
dnsQueue.addHostRefreshTask("ns2.hello.multilock.uk");
|
dnsQueue.addHostRefreshTask("ns2.hello.multilock.uk");
|
||||||
|
|
|
@ -30,17 +30,14 @@ import google.registry.request.HttpException.BadRequestException;
|
||||||
import google.registry.request.HttpException.NotFoundException;
|
import google.registry.request.HttpException.NotFoundException;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link RefreshDnsAction}. */
|
/** Unit tests for {@link RefreshDnsAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class RefreshDnsActionTest {
|
public class RefreshDnsActionTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
||||||
|
|
||||||
|
@ -51,13 +48,13 @@ public class RefreshDnsActionTest {
|
||||||
new RefreshDnsAction(name, type, clock, dnsQueue).run();
|
new RefreshDnsAction(name, type, clock, dnsQueue).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void beforeEach() {
|
||||||
createTld("xn--q9jyb4c");
|
createTld("xn--q9jyb4c");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_host() {
|
void testSuccess_host() {
|
||||||
DomainBase domain = persistActiveDomain("example.xn--q9jyb4c");
|
DomainBase domain = persistActiveDomain("example.xn--q9jyb4c");
|
||||||
persistActiveSubordinateHost("ns1.example.xn--q9jyb4c", domain);
|
persistActiveSubordinateHost("ns1.example.xn--q9jyb4c", domain);
|
||||||
run(TargetType.HOST, "ns1.example.xn--q9jyb4c");
|
run(TargetType.HOST, "ns1.example.xn--q9jyb4c");
|
||||||
|
@ -66,7 +63,7 @@ public class RefreshDnsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_externalHostNotEnqueued() {
|
void testSuccess_externalHostNotEnqueued() {
|
||||||
persistActiveDomain("example.xn--q9jyb4c");
|
persistActiveDomain("example.xn--q9jyb4c");
|
||||||
persistActiveHost("ns1.example.xn--q9jyb4c");
|
persistActiveHost("ns1.example.xn--q9jyb4c");
|
||||||
BadRequestException thrown =
|
BadRequestException thrown =
|
||||||
|
@ -85,7 +82,7 @@ public class RefreshDnsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_domain() {
|
void testSuccess_domain() {
|
||||||
persistActiveDomain("example.xn--q9jyb4c");
|
persistActiveDomain("example.xn--q9jyb4c");
|
||||||
run(TargetType.DOMAIN, "example.xn--q9jyb4c");
|
run(TargetType.DOMAIN, "example.xn--q9jyb4c");
|
||||||
verify(dnsQueue).addDomainRefreshTask("example.xn--q9jyb4c");
|
verify(dnsQueue).addDomainRefreshTask("example.xn--q9jyb4c");
|
||||||
|
@ -93,17 +90,17 @@ public class RefreshDnsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_unqualifiedName() {
|
void testFailure_unqualifiedName() {
|
||||||
assertThrows(BadRequestException.class, () -> run(TargetType.DOMAIN, "example"));
|
assertThrows(BadRequestException.class, () -> run(TargetType.DOMAIN, "example"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_hostDoesNotExist() {
|
void testFailure_hostDoesNotExist() {
|
||||||
assertThrows(NotFoundException.class, () -> run(TargetType.HOST, "ns1.example.xn--q9jyb4c"));
|
assertThrows(NotFoundException.class, () -> run(TargetType.HOST, "ns1.example.xn--q9jyb4c"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_domainDoesNotExist() {
|
void testFailure_domainDoesNotExist() {
|
||||||
assertThrows(NotFoundException.class, () -> run(TargetType.DOMAIN, "example.xn--q9jyb4c"));
|
assertThrows(NotFoundException.class, () -> run(TargetType.DOMAIN, "example.xn--q9jyb4c"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,13 +17,10 @@ package google.registry.dns.writer;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.junit.Assert.assertThrows;
|
import static org.junit.Assert.assertThrows;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link BaseDnsWriter}. */
|
/** Unit tests for {@link BaseDnsWriter}. */
|
||||||
@RunWith(JUnit4.class)
|
class BaseDnsWriterTest {
|
||||||
public class BaseDnsWriterTest {
|
|
||||||
|
|
||||||
static class StubDnsWriter extends BaseDnsWriter {
|
static class StubDnsWriter extends BaseDnsWriter {
|
||||||
|
|
||||||
|
@ -46,7 +43,7 @@ public class BaseDnsWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_cannotBeCalledTwice() {
|
void test_cannotBeCalledTwice() {
|
||||||
StubDnsWriter writer = new StubDnsWriter();
|
StubDnsWriter writer = new StubDnsWriter();
|
||||||
assertThat(writer.commitCallCount).isEqualTo(0);
|
assertThat(writer.commitCallCount).isEqualTo(0);
|
||||||
writer.commit();
|
writer.commit();
|
||||||
|
|
|
@ -53,27 +53,25 @@ import java.net.Inet4Address;
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.ArgumentMatchers;
|
import org.mockito.ArgumentMatchers;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.mockito.junit.MockitoRule;
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
|
|
||||||
/** Test case for {@link CloudDnsWriter}. */
|
/** Test case for {@link CloudDnsWriter}. */
|
||||||
@RunWith(JUnit4.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class CloudDnsWriterTest {
|
public class CloudDnsWriterTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
|
|
||||||
|
|
||||||
private static final Inet4Address IPv4 = (Inet4Address) InetAddresses.forString("127.0.0.1");
|
private static final Inet4Address IPv4 = (Inet4Address) InetAddresses.forString("127.0.0.1");
|
||||||
private static final Inet6Address IPv6 = (Inet6Address) InetAddresses.forString("::1");
|
private static final Inet6Address IPv6 = (Inet6Address) InetAddresses.forString("::1");
|
||||||
private static final Duration DEFAULT_A_TTL = Duration.standardSeconds(11);
|
private static final Duration DEFAULT_A_TTL = Duration.standardSeconds(11);
|
||||||
|
@ -116,8 +114,8 @@ public class CloudDnsWriterTest {
|
||||||
return listResourceRecordSetsRequest;
|
return listResourceRecordSetsRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void beforeEach() throws Exception {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
writer =
|
writer =
|
||||||
new CloudDnsWriter(
|
new CloudDnsWriter(
|
||||||
|
@ -312,15 +310,17 @@ public class CloudDnsWriterTest {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void testLoadDomain_nonExistentDomain() {
|
void testLoadDomain_nonExistentDomain() {
|
||||||
writer.publishDomain("example.tld");
|
writer.publishDomain("example.tld");
|
||||||
|
|
||||||
verifyZone(ImmutableSet.of());
|
verifyZone(ImmutableSet.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void testLoadDomain_noDsDataOrNameservers() {
|
void testLoadDomain_noDsDataOrNameservers() {
|
||||||
persistResource(fakeDomain("example.tld", ImmutableSet.of(), 0));
|
persistResource(fakeDomain("example.tld", ImmutableSet.of(), 0));
|
||||||
writer.publishDomain("example.tld");
|
writer.publishDomain("example.tld");
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ public class CloudDnsWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadDomain_deleteOldData() {
|
void testLoadDomain_deleteOldData() {
|
||||||
stubZone = fakeDomainRecords("example.tld", 2, 2, 2, 2);
|
stubZone = fakeDomainRecords("example.tld", 2, 2, 2, 2);
|
||||||
persistResource(fakeDomain("example.tld", ImmutableSet.of(), 0));
|
persistResource(fakeDomain("example.tld", ImmutableSet.of(), 0));
|
||||||
writer.publishDomain("example.tld");
|
writer.publishDomain("example.tld");
|
||||||
|
@ -337,7 +337,7 @@ public class CloudDnsWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadDomain_withExternalNs() {
|
void testLoadDomain_withExternalNs() {
|
||||||
persistResource(
|
persistResource(
|
||||||
fakeDomain("example.tld", ImmutableSet.of(persistResource(fakeHost("0.external"))), 0));
|
fakeDomain("example.tld", ImmutableSet.of(persistResource(fakeHost("0.external"))), 0));
|
||||||
writer.publishDomain("example.tld");
|
writer.publishDomain("example.tld");
|
||||||
|
@ -346,7 +346,7 @@ public class CloudDnsWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadDomain_withDsData() {
|
void testLoadDomain_withDsData() {
|
||||||
persistResource(
|
persistResource(
|
||||||
fakeDomain("example.tld", ImmutableSet.of(persistResource(fakeHost("0.external"))), 1));
|
fakeDomain("example.tld", ImmutableSet.of(persistResource(fakeHost("0.external"))), 1));
|
||||||
writer.publishDomain("example.tld");
|
writer.publishDomain("example.tld");
|
||||||
|
@ -355,7 +355,7 @@ public class CloudDnsWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadDomain_withInBailiwickNs_IPv4() {
|
void testLoadDomain_withInBailiwickNs_IPv4() {
|
||||||
persistResource(
|
persistResource(
|
||||||
fakeDomain(
|
fakeDomain(
|
||||||
"example.tld",
|
"example.tld",
|
||||||
|
@ -370,7 +370,7 @@ public class CloudDnsWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadDomain_withInBailiwickNs_IPv6() {
|
void testLoadDomain_withInBailiwickNs_IPv6() {
|
||||||
persistResource(
|
persistResource(
|
||||||
fakeDomain(
|
fakeDomain(
|
||||||
"example.tld",
|
"example.tld",
|
||||||
|
@ -385,7 +385,7 @@ public class CloudDnsWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadDomain_withNameserveThatEndsWithDomainName() {
|
void testLoadDomain_withNameserveThatEndsWithDomainName() {
|
||||||
persistResource(
|
persistResource(
|
||||||
fakeDomain(
|
fakeDomain(
|
||||||
"example.tld",
|
"example.tld",
|
||||||
|
@ -396,8 +396,9 @@ public class CloudDnsWriterTest {
|
||||||
verifyZone(fakeDomainRecords("example.tld", "ns.another-example.tld."));
|
verifyZone(fakeDomainRecords("example.tld", "ns.another-example.tld."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void testLoadHost_externalHost() {
|
void testLoadHost_externalHost() {
|
||||||
writer.publishHost("ns1.example.com");
|
writer.publishHost("ns1.example.com");
|
||||||
|
|
||||||
// external hosts should not be published in our zone
|
// external hosts should not be published in our zone
|
||||||
|
@ -405,7 +406,7 @@ public class CloudDnsWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLoadHost_removeStaleNsRecords() {
|
void testLoadHost_removeStaleNsRecords() {
|
||||||
// Initialize the zone with both NS records
|
// Initialize the zone with both NS records
|
||||||
stubZone = fakeDomainRecords("example.tld", 2, 0, 0, 0);
|
stubZone = fakeDomainRecords("example.tld", 2, 0, 0, 0);
|
||||||
|
|
||||||
|
@ -426,8 +427,9 @@ public class CloudDnsWriterTest {
|
||||||
verifyZone(fakeDomainRecords("example.tld", 1, 0, 0, 0));
|
verifyZone(fakeDomainRecords("example.tld", 1, 0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void retryMutateZoneOnError() {
|
void retryMutateZoneOnError() {
|
||||||
CloudDnsWriter spyWriter = spy(writer);
|
CloudDnsWriter spyWriter = spy(writer);
|
||||||
// First call - throw. Second call - do nothing.
|
// First call - throw. Second call - do nothing.
|
||||||
doThrow(ZoneStateException.class)
|
doThrow(ZoneStateException.class)
|
||||||
|
@ -439,8 +441,9 @@ public class CloudDnsWriterTest {
|
||||||
verify(spyWriter, times(2)).mutateZone(ArgumentMatchers.any());
|
verify(spyWriter, times(2)).mutateZone(ArgumentMatchers.any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void testLoadDomain_withClientHold() {
|
void testLoadDomain_withClientHold() {
|
||||||
persistResource(
|
persistResource(
|
||||||
fakeDomain(
|
fakeDomain(
|
||||||
"example.tld",
|
"example.tld",
|
||||||
|
@ -454,8 +457,9 @@ public class CloudDnsWriterTest {
|
||||||
verifyZone(ImmutableSet.of());
|
verifyZone(ImmutableSet.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void testLoadDomain_withServerHold() {
|
void testLoadDomain_withServerHold() {
|
||||||
persistResource(
|
persistResource(
|
||||||
fakeDomain(
|
fakeDomain(
|
||||||
"example.tld",
|
"example.tld",
|
||||||
|
@ -470,8 +474,9 @@ public class CloudDnsWriterTest {
|
||||||
verifyZone(ImmutableSet.of());
|
verifyZone(ImmutableSet.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void testLoadDomain_withPendingDelete() {
|
void testLoadDomain_withPendingDelete() {
|
||||||
persistResource(
|
persistResource(
|
||||||
fakeDomain(
|
fakeDomain(
|
||||||
"example.tld",
|
"example.tld",
|
||||||
|
@ -486,7 +491,7 @@ public class CloudDnsWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDuplicateRecords() {
|
void testDuplicateRecords() {
|
||||||
// In publishing DNS records, we can end up publishing information on the same host twice
|
// In publishing DNS records, we can end up publishing information on the same host twice
|
||||||
// (through a domain change and a host change), so this scenario needs to work.
|
// (through a domain change and a host change), so this scenario needs to work.
|
||||||
persistResource(
|
persistResource(
|
||||||
|
@ -504,7 +509,7 @@ public class CloudDnsWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidZoneNames() {
|
void testInvalidZoneNames() {
|
||||||
createTld("triple.secret.tld");
|
createTld("triple.secret.tld");
|
||||||
persistResource(
|
persistResource(
|
||||||
fakeDomain(
|
fakeDomain(
|
||||||
|
@ -518,8 +523,9 @@ public class CloudDnsWriterTest {
|
||||||
assertThat(zoneNameCaptor.getValue()).isEqualTo("triple-secret-tld");
|
assertThat(zoneNameCaptor.getValue()).isEqualTo("triple-secret-tld");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyCommit() {
|
void testEmptyCommit() {
|
||||||
writer.commit();
|
writer.commit();
|
||||||
verify(dnsConnection, times(0)).changes();
|
verify(dnsConnection, times(0)).changes();
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,10 +33,8 @@ import java.nio.ByteBuffer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.xbill.DNS.ARecord;
|
import org.xbill.DNS.ARecord;
|
||||||
import org.xbill.DNS.DClass;
|
import org.xbill.DNS.DClass;
|
||||||
import org.xbill.DNS.Flags;
|
import org.xbill.DNS.Flags;
|
||||||
|
@ -49,8 +47,7 @@ import org.xbill.DNS.Type;
|
||||||
import org.xbill.DNS.Update;
|
import org.xbill.DNS.Update;
|
||||||
|
|
||||||
/** Unit tests for {@link DnsMessageTransport}. */
|
/** Unit tests for {@link DnsMessageTransport}. */
|
||||||
@RunWith(JUnit4.class)
|
class DnsMessageTransportTest {
|
||||||
public class DnsMessageTransportTest {
|
|
||||||
|
|
||||||
private static final String UPDATE_HOST = "127.0.0.1";
|
private static final String UPDATE_HOST = "127.0.0.1";
|
||||||
|
|
||||||
|
@ -60,8 +57,9 @@ public class DnsMessageTransportTest {
|
||||||
private Message simpleQuery;
|
private Message simpleQuery;
|
||||||
private Message expectedResponse;
|
private Message expectedResponse;
|
||||||
private DnsMessageTransport resolver;
|
private DnsMessageTransport resolver;
|
||||||
@Before
|
|
||||||
public void before() throws Exception {
|
@BeforeEach
|
||||||
|
void beforeEach() throws Exception {
|
||||||
simpleQuery =
|
simpleQuery =
|
||||||
Message.newQuery(Record.newRecord(Name.fromString("example.com."), Type.A, DClass.IN));
|
Message.newQuery(Record.newRecord(Name.fromString("example.com."), Type.A, DClass.IN));
|
||||||
expectedResponse = responseMessageWithCode(simpleQuery, Rcode.NOERROR);
|
expectedResponse = responseMessageWithCode(simpleQuery, Rcode.NOERROR);
|
||||||
|
@ -71,7 +69,7 @@ public class DnsMessageTransportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSentMessageHasCorrectLengthAndContent() throws Exception {
|
void testSentMessageHasCorrectLengthAndContent() throws Exception {
|
||||||
ByteArrayInputStream inputStream =
|
ByteArrayInputStream inputStream =
|
||||||
new ByteArrayInputStream(messageToBytesWithLength(expectedResponse));
|
new ByteArrayInputStream(messageToBytesWithLength(expectedResponse));
|
||||||
when(mockSocket.getInputStream()).thenReturn(inputStream);
|
when(mockSocket.getInputStream()).thenReturn(inputStream);
|
||||||
|
@ -89,7 +87,7 @@ public class DnsMessageTransportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReceivedMessageWithLengthHasCorrectContent() throws Exception {
|
void testReceivedMessageWithLengthHasCorrectContent() throws Exception {
|
||||||
ByteArrayInputStream inputStream =
|
ByteArrayInputStream inputStream =
|
||||||
new ByteArrayInputStream(messageToBytesWithLength(expectedResponse));
|
new ByteArrayInputStream(messageToBytesWithLength(expectedResponse));
|
||||||
when(mockSocket.getInputStream()).thenReturn(inputStream);
|
when(mockSocket.getInputStream()).thenReturn(inputStream);
|
||||||
|
@ -102,7 +100,7 @@ public class DnsMessageTransportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEofReceivingResponse() throws Exception {
|
void testEofReceivingResponse() throws Exception {
|
||||||
byte[] messageBytes = messageToBytesWithLength(expectedResponse);
|
byte[] messageBytes = messageToBytesWithLength(expectedResponse);
|
||||||
ByteArrayInputStream inputStream =
|
ByteArrayInputStream inputStream =
|
||||||
new ByteArrayInputStream(Arrays.copyOf(messageBytes, messageBytes.length - 1));
|
new ByteArrayInputStream(Arrays.copyOf(messageBytes, messageBytes.length - 1));
|
||||||
|
@ -112,7 +110,7 @@ public class DnsMessageTransportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTimeoutReceivingResponse() throws Exception {
|
void testTimeoutReceivingResponse() throws Exception {
|
||||||
InputStream mockInputStream = mock(InputStream.class);
|
InputStream mockInputStream = mock(InputStream.class);
|
||||||
when(mockInputStream.read()).thenThrow(new SocketTimeoutException("testing"));
|
when(mockInputStream.read()).thenThrow(new SocketTimeoutException("testing"));
|
||||||
when(mockSocket.getInputStream()).thenReturn(mockInputStream);
|
when(mockSocket.getInputStream()).thenReturn(mockInputStream);
|
||||||
|
@ -126,7 +124,7 @@ public class DnsMessageTransportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSentMessageTooLongThrowsException() throws Exception {
|
void testSentMessageTooLongThrowsException() throws Exception {
|
||||||
Update oversize = new Update(Name.fromString("tld", Name.root));
|
Update oversize = new Update(Name.fromString("tld", Name.root));
|
||||||
for (int i = 0; i < 2000; i++) {
|
for (int i = 0; i < 2000; i++) {
|
||||||
oversize.add(
|
oversize.add(
|
||||||
|
@ -143,7 +141,7 @@ public class DnsMessageTransportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseIdMismatchThrowsExeption() throws Exception {
|
void testResponseIdMismatchThrowsExeption() throws Exception {
|
||||||
expectedResponse.getHeader().setID(1 + simpleQuery.getHeader().getID());
|
expectedResponse.getHeader().setID(1 + simpleQuery.getHeader().getID());
|
||||||
when(mockSocket.getInputStream())
|
when(mockSocket.getInputStream())
|
||||||
.thenReturn(new ByteArrayInputStream(messageToBytesWithLength(expectedResponse)));
|
.thenReturn(new ByteArrayInputStream(messageToBytesWithLength(expectedResponse)));
|
||||||
|
@ -159,7 +157,7 @@ public class DnsMessageTransportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResponseOpcodeMismatchThrowsException() throws Exception {
|
void testResponseOpcodeMismatchThrowsException() throws Exception {
|
||||||
simpleQuery.getHeader().setOpcode(Opcode.QUERY);
|
simpleQuery.getHeader().setOpcode(Opcode.QUERY);
|
||||||
expectedResponse.getHeader().setOpcode(Opcode.STATUS);
|
expectedResponse.getHeader().setOpcode(Opcode.STATUS);
|
||||||
when(mockSocket.getInputStream())
|
when(mockSocket.getInputStream())
|
||||||
|
|
|
@ -49,16 +49,16 @@ import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.mockito.junit.MockitoRule;
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
import org.xbill.DNS.Flags;
|
import org.xbill.DNS.Flags;
|
||||||
import org.xbill.DNS.Message;
|
import org.xbill.DNS.Message;
|
||||||
import org.xbill.DNS.Opcode;
|
import org.xbill.DNS.Opcode;
|
||||||
|
@ -70,15 +70,14 @@ import org.xbill.DNS.Type;
|
||||||
import org.xbill.DNS.Update;
|
import org.xbill.DNS.Update;
|
||||||
|
|
||||||
/** Unit tests for {@link DnsUpdateWriter}. */
|
/** Unit tests for {@link DnsUpdateWriter}. */
|
||||||
@RunWith(JUnit4.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class DnsUpdateWriterTest {
|
public class DnsUpdateWriterTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
||||||
|
|
||||||
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
@Rule public final InjectRule inject = new InjectRule();
|
|
||||||
|
|
||||||
@Mock private DnsMessageTransport mockResolver;
|
@Mock private DnsMessageTransport mockResolver;
|
||||||
@Captor private ArgumentCaptor<Update> updateCaptor;
|
@Captor private ArgumentCaptor<Update> updateCaptor;
|
||||||
|
@ -87,8 +86,8 @@ public class DnsUpdateWriterTest {
|
||||||
|
|
||||||
private DnsUpdateWriter writer;
|
private DnsUpdateWriter writer;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void beforeEach() throws Exception {
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
|
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
|
@ -99,7 +98,7 @@ public class DnsUpdateWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPublishDomainCreate_publishesNameServers() throws Exception {
|
void testPublishDomainCreate_publishesNameServers() throws Exception {
|
||||||
HostResource host1 = persistActiveHost("ns1.example.tld");
|
HostResource host1 = persistActiveHost("ns1.example.tld");
|
||||||
HostResource host2 = persistActiveHost("ns2.example.tld");
|
HostResource host2 = persistActiveHost("ns2.example.tld");
|
||||||
DomainBase domain =
|
DomainBase domain =
|
||||||
|
@ -120,8 +119,9 @@ public class DnsUpdateWriterTest {
|
||||||
assertThatTotalUpdateSetsIs(update, 2); // The delete and NS sets
|
assertThatTotalUpdateSetsIs(update, 2); // The delete and NS sets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void testPublishAtomic_noCommit() {
|
void testPublishAtomic_noCommit() {
|
||||||
HostResource host1 = persistActiveHost("ns.example1.tld");
|
HostResource host1 = persistActiveHost("ns.example1.tld");
|
||||||
DomainBase domain1 =
|
DomainBase domain1 =
|
||||||
persistActiveDomain("example1.tld")
|
persistActiveDomain("example1.tld")
|
||||||
|
@ -145,7 +145,7 @@ public class DnsUpdateWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPublishAtomic_oneUpdate() throws Exception {
|
void testPublishAtomic_oneUpdate() throws Exception {
|
||||||
HostResource host1 = persistActiveHost("ns.example1.tld");
|
HostResource host1 = persistActiveHost("ns.example1.tld");
|
||||||
DomainBase domain1 =
|
DomainBase domain1 =
|
||||||
persistActiveDomain("example1.tld")
|
persistActiveDomain("example1.tld")
|
||||||
|
@ -177,7 +177,7 @@ public class DnsUpdateWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPublishDomainCreate_publishesDelegationSigner() throws Exception {
|
void testPublishDomainCreate_publishesDelegationSigner() throws Exception {
|
||||||
DomainBase domain =
|
DomainBase domain =
|
||||||
persistActiveDomain("example.tld")
|
persistActiveDomain("example.tld")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -201,7 +201,7 @@ public class DnsUpdateWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPublishDomainWhenNotActive_removesDnsRecords() throws Exception {
|
void testPublishDomainWhenNotActive_removesDnsRecords() throws Exception {
|
||||||
DomainBase domain =
|
DomainBase domain =
|
||||||
persistActiveDomain("example.tld")
|
persistActiveDomain("example.tld")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -221,7 +221,7 @@ public class DnsUpdateWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPublishDomainDelete_removesDnsRecords() throws Exception {
|
void testPublishDomainDelete_removesDnsRecords() throws Exception {
|
||||||
persistDeletedDomain("example.tld", clock.nowUtc().minusDays(1));
|
persistDeletedDomain("example.tld", clock.nowUtc().minusDays(1));
|
||||||
|
|
||||||
writer.publishDomain("example.tld");
|
writer.publishDomain("example.tld");
|
||||||
|
@ -235,7 +235,7 @@ public class DnsUpdateWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPublishHostCreate_publishesAddressRecords() throws Exception {
|
void testPublishHostCreate_publishesAddressRecords() throws Exception {
|
||||||
HostResource host =
|
HostResource host =
|
||||||
persistResource(
|
persistResource(
|
||||||
newHostResource("ns1.example.tld")
|
newHostResource("ns1.example.tld")
|
||||||
|
@ -268,7 +268,7 @@ public class DnsUpdateWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPublishHostDelete_removesDnsRecords() throws Exception {
|
void testPublishHostDelete_removesDnsRecords() throws Exception {
|
||||||
persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
|
persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
|
||||||
persistActiveDomain("example.tld");
|
persistActiveDomain("example.tld");
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ public class DnsUpdateWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPublishHostDelete_removesGlueRecords() throws Exception {
|
void testPublishHostDelete_removesGlueRecords() throws Exception {
|
||||||
persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
|
persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
|
||||||
persistResource(
|
persistResource(
|
||||||
persistActiveDomain("example.tld")
|
persistActiveDomain("example.tld")
|
||||||
|
@ -305,7 +305,7 @@ public class DnsUpdateWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPublishDomainExternalAndInBailiwickNameServer() throws Exception {
|
void testPublishDomainExternalAndInBailiwickNameServer() throws Exception {
|
||||||
HostResource externalNameserver = persistResource(newHostResource("ns1.example.com"));
|
HostResource externalNameserver = persistResource(newHostResource("ns1.example.com"));
|
||||||
HostResource inBailiwickNameserver =
|
HostResource inBailiwickNameserver =
|
||||||
persistResource(
|
persistResource(
|
||||||
|
@ -342,7 +342,7 @@ public class DnsUpdateWriterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPublishDomainDeleteOrphanGlues() throws Exception {
|
void testPublishDomainDeleteOrphanGlues() throws Exception {
|
||||||
HostResource inBailiwickNameserver =
|
HostResource inBailiwickNameserver =
|
||||||
persistResource(
|
persistResource(
|
||||||
newHostResource("ns1.example.tld")
|
newHostResource("ns1.example.tld")
|
||||||
|
@ -377,9 +377,10 @@ public class DnsUpdateWriterTest {
|
||||||
assertThatTotalUpdateSetsIs(update, 6);
|
assertThatTotalUpdateSetsIs(update, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@SuppressWarnings("AssertThrowsMultipleStatements")
|
@SuppressWarnings("AssertThrowsMultipleStatements")
|
||||||
public void testPublishDomainFails_whenDnsUpdateReturnsError() throws Exception {
|
@Test
|
||||||
|
void testPublishDomainFails_whenDnsUpdateReturnsError() throws Exception {
|
||||||
DomainBase domain =
|
DomainBase domain =
|
||||||
persistActiveDomain("example.tld")
|
persistActiveDomain("example.tld")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -397,9 +398,10 @@ public class DnsUpdateWriterTest {
|
||||||
assertThat(thrown).hasMessageThat().contains("SERVFAIL");
|
assertThat(thrown).hasMessageThat().contains("SERVFAIL");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@SuppressWarnings("AssertThrowsMultipleStatements")
|
@SuppressWarnings("AssertThrowsMultipleStatements")
|
||||||
public void testPublishHostFails_whenDnsUpdateReturnsError() throws Exception {
|
@Test
|
||||||
|
void testPublishHostFails_whenDnsUpdateReturnsError() throws Exception {
|
||||||
HostResource host =
|
HostResource host =
|
||||||
persistActiveSubordinateHost("ns1.example.tld", persistActiveDomain("example.tld"))
|
persistActiveSubordinateHost("ns1.example.tld", persistActiveDomain("example.tld"))
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
|
|
@ -27,21 +27,19 @@ import google.registry.export.datastore.Operation;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.FakeResponse;
|
import google.registry.testing.FakeResponse;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.mockito.junit.MockitoRule;
|
|
||||||
|
|
||||||
/** Unit tests for {@link BackupDatastoreAction}. */
|
/** Unit tests for {@link BackupDatastoreAction}. */
|
||||||
@RunWith(JUnit4.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class BackupDatastoreActionTest {
|
public class BackupDatastoreActionTest {
|
||||||
|
|
||||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withTaskQueue().build();
|
@RegisterExtension
|
||||||
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withTaskQueue().build();
|
||||||
|
|
||||||
@Mock private DatastoreAdmin datastoreAdmin;
|
@Mock private DatastoreAdmin datastoreAdmin;
|
||||||
@Mock private Export exportRequest;
|
@Mock private Export exportRequest;
|
||||||
|
@ -50,8 +48,8 @@ public class BackupDatastoreActionTest {
|
||||||
private final FakeResponse response = new FakeResponse();
|
private final FakeResponse response = new FakeResponse();
|
||||||
private final BackupDatastoreAction action = new BackupDatastoreAction();
|
private final BackupDatastoreAction action = new BackupDatastoreAction();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() throws Exception {
|
void beforeEach() throws Exception {
|
||||||
action.datastoreAdmin = datastoreAdmin;
|
action.datastoreAdmin = datastoreAdmin;
|
||||||
action.response = response;
|
action.response = response;
|
||||||
|
|
||||||
|
@ -66,7 +64,7 @@ public class BackupDatastoreActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBackup_enqueuesPollTask() {
|
void testBackup_enqueuesPollTask() {
|
||||||
action.run();
|
action.run();
|
||||||
assertTasksEnqueued(
|
assertTasksEnqueued(
|
||||||
CheckBackupAction.QUEUE,
|
CheckBackupAction.QUEUE,
|
||||||
|
|
|
@ -52,17 +52,14 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link BigqueryPollJobAction}. */
|
/** Unit tests for {@link BigqueryPollJobAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class BigqueryPollJobActionTest {
|
public class BigqueryPollJobActionTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
||||||
|
|
||||||
|
@ -79,8 +76,8 @@ public class BigqueryPollJobActionTest {
|
||||||
private final CapturingLogHandler logHandler = new CapturingLogHandler();
|
private final CapturingLogHandler logHandler = new CapturingLogHandler();
|
||||||
private BigqueryPollJobAction action = new BigqueryPollJobAction();
|
private BigqueryPollJobAction action = new BigqueryPollJobAction();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() throws Exception {
|
void beforeEach() throws Exception {
|
||||||
action.bigquery = bigquery;
|
action.bigquery = bigquery;
|
||||||
when(bigquery.jobs()).thenReturn(bigqueryJobs);
|
when(bigquery.jobs()).thenReturn(bigqueryJobs);
|
||||||
when(bigqueryJobs.get(PROJECT_ID, JOB_ID)).thenReturn(bigqueryJobsGet);
|
when(bigqueryJobs.get(PROJECT_ID, JOB_ID)).thenReturn(bigqueryJobsGet);
|
||||||
|
@ -100,14 +97,14 @@ public class BigqueryPollJobActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_enqueuePollTask() {
|
void testSuccess_enqueuePollTask() {
|
||||||
new BigqueryPollJobEnqueuer(TASK_QUEUE_UTILS).enqueuePollTask(
|
new BigqueryPollJobEnqueuer(TASK_QUEUE_UTILS).enqueuePollTask(
|
||||||
new JobReference().setProjectId(PROJECT_ID).setJobId(JOB_ID));
|
new JobReference().setProjectId(PROJECT_ID).setJobId(JOB_ID));
|
||||||
assertTasksEnqueued(BigqueryPollJobAction.QUEUE, newPollJobTaskMatcher("GET"));
|
assertTasksEnqueued(BigqueryPollJobAction.QUEUE, newPollJobTaskMatcher("GET"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_enqueuePollTask_withChainedTask() throws Exception {
|
void testSuccess_enqueuePollTask_withChainedTask() throws Exception {
|
||||||
TaskOptions chainedTask = TaskOptions.Builder
|
TaskOptions chainedTask = TaskOptions.Builder
|
||||||
.withUrl("/_dr/something")
|
.withUrl("/_dr/something")
|
||||||
.method(Method.POST)
|
.method(Method.POST)
|
||||||
|
@ -126,7 +123,7 @@ public class BigqueryPollJobActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_jobCompletedSuccessfully() throws Exception {
|
void testSuccess_jobCompletedSuccessfully() throws Exception {
|
||||||
when(bigqueryJobsGet.execute()).thenReturn(
|
when(bigqueryJobsGet.execute()).thenReturn(
|
||||||
new Job().setStatus(new JobStatus().setState("DONE")));
|
new Job().setStatus(new JobStatus().setState("DONE")));
|
||||||
action.run();
|
action.run();
|
||||||
|
@ -135,7 +132,7 @@ public class BigqueryPollJobActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_chainedPayloadAndJobSucceeded_enqueuesChainedTask() throws Exception {
|
void testSuccess_chainedPayloadAndJobSucceeded_enqueuesChainedTask() throws Exception {
|
||||||
when(bigqueryJobsGet.execute()).thenReturn(
|
when(bigqueryJobsGet.execute()).thenReturn(
|
||||||
new Job().setStatus(new JobStatus().setState("DONE")));
|
new Job().setStatus(new JobStatus().setState("DONE")));
|
||||||
|
|
||||||
|
@ -167,7 +164,7 @@ public class BigqueryPollJobActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJobFailed() throws Exception {
|
void testJobFailed() throws Exception {
|
||||||
when(bigqueryJobsGet.execute()).thenReturn(new Job().setStatus(
|
when(bigqueryJobsGet.execute()).thenReturn(new Job().setStatus(
|
||||||
new JobStatus()
|
new JobStatus()
|
||||||
.setState("DONE")
|
.setState("DONE")
|
||||||
|
@ -179,20 +176,20 @@ public class BigqueryPollJobActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJobPending() throws Exception {
|
void testJobPending() throws Exception {
|
||||||
when(bigqueryJobsGet.execute()).thenReturn(
|
when(bigqueryJobsGet.execute()).thenReturn(
|
||||||
new Job().setStatus(new JobStatus().setState("PENDING")));
|
new Job().setStatus(new JobStatus().setState("PENDING")));
|
||||||
assertThrows(NotModifiedException.class, action::run);
|
assertThrows(NotModifiedException.class, action::run);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJobStatusUnreadable() throws Exception {
|
void testJobStatusUnreadable() throws Exception {
|
||||||
when(bigqueryJobsGet.execute()).thenThrow(IOException.class);
|
when(bigqueryJobsGet.execute()).thenThrow(IOException.class);
|
||||||
assertThrows(NotModifiedException.class, action::run);
|
assertThrows(NotModifiedException.class, action::run);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_badChainedTaskPayload() throws Exception {
|
void testFailure_badChainedTaskPayload() throws Exception {
|
||||||
when(bigqueryJobsGet.execute()).thenReturn(
|
when(bigqueryJobsGet.execute()).thenReturn(
|
||||||
new Job().setStatus(new JobStatus().setState("DONE")));
|
new Job().setStatus(new JobStatus().setState("DONE")));
|
||||||
action.payload = "payload".getBytes(UTF_8);
|
action.payload = "payload".getBytes(UTF_8);
|
||||||
|
|
|
@ -42,26 +42,26 @@ import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import google.registry.testing.TestDataHelper;
|
import google.registry.testing.TestDataHelper;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.mockito.junit.MockitoRule;
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
|
|
||||||
/** Unit tests for {@link CheckBackupAction}. */
|
/** Unit tests for {@link CheckBackupAction}. */
|
||||||
@RunWith(JUnit4.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class CheckBackupActionTest {
|
public class CheckBackupActionTest {
|
||||||
|
|
||||||
static final DateTime START_TIME = DateTime.parse("2014-08-01T01:02:03Z");
|
private static final DateTime START_TIME = DateTime.parse("2014-08-01T01:02:03Z");
|
||||||
static final DateTime COMPLETE_TIME = START_TIME.plus(Duration.standardMinutes(30));
|
private static final DateTime COMPLETE_TIME = START_TIME.plus(Duration.standardMinutes(30));
|
||||||
|
|
||||||
static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
|
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
|
||||||
|
|
||||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withTaskQueue().build();
|
@RegisterExtension
|
||||||
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withTaskQueue().build();
|
||||||
|
|
||||||
@Mock private DatastoreAdmin datastoreAdmin;
|
@Mock private DatastoreAdmin datastoreAdmin;
|
||||||
@Mock private Get getNotFoundBackupProgressRequest;
|
@Mock private Get getNotFoundBackupProgressRequest;
|
||||||
|
@ -72,8 +72,8 @@ public class CheckBackupActionTest {
|
||||||
private final FakeClock clock = new FakeClock(COMPLETE_TIME.plusMillis(1000));
|
private final FakeClock clock = new FakeClock(COMPLETE_TIME.plusMillis(1000));
|
||||||
private final CheckBackupAction action = new CheckBackupAction();
|
private final CheckBackupAction action = new CheckBackupAction();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() throws Exception {
|
void beforeEach() throws Exception {
|
||||||
action.requestMethod = Method.POST;
|
action.requestMethod = Method.POST;
|
||||||
action.datastoreAdmin = datastoreAdmin;
|
action.datastoreAdmin = datastoreAdmin;
|
||||||
action.clock = clock;
|
action.clock = clock;
|
||||||
|
@ -121,8 +121,9 @@ public class CheckBackupActionTest {
|
||||||
.param("kinds", kinds));
|
.param("kinds", kinds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_enqueuePollTask() {
|
void testSuccess_enqueuePollTask() {
|
||||||
CheckBackupAction.enqueuePollTask("some_backup_name", ImmutableSet.of("one", "two", "three"));
|
CheckBackupAction.enqueuePollTask("some_backup_name", ImmutableSet.of("one", "two", "three"));
|
||||||
assertTasksEnqueued(
|
assertTasksEnqueued(
|
||||||
CheckBackupAction.QUEUE,
|
CheckBackupAction.QUEUE,
|
||||||
|
@ -134,7 +135,7 @@ public class CheckBackupActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPost_forPendingBackup_returnsNotModified() throws Exception {
|
void testPost_forPendingBackup_returnsNotModified() throws Exception {
|
||||||
setPendingBackup();
|
setPendingBackup();
|
||||||
|
|
||||||
NotModifiedException thrown = assertThrows(NotModifiedException.class, action::run);
|
NotModifiedException thrown = assertThrows(NotModifiedException.class, action::run);
|
||||||
|
@ -144,7 +145,7 @@ public class CheckBackupActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPost_forStalePendingBackupBackup_returnsNoContent() throws Exception {
|
void testPost_forStalePendingBackupBackup_returnsNoContent() throws Exception {
|
||||||
setPendingBackup();
|
setPendingBackup();
|
||||||
clock.setTo(
|
clock.setTo(
|
||||||
START_TIME
|
START_TIME
|
||||||
|
@ -161,7 +162,7 @@ public class CheckBackupActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPost_forCompleteBackup_enqueuesLoadTask() throws Exception {
|
void testPost_forCompleteBackup_enqueuesLoadTask() throws Exception {
|
||||||
setCompleteBackup();
|
setCompleteBackup();
|
||||||
action.run();
|
action.run();
|
||||||
assertLoadTaskEnqueued(
|
assertLoadTaskEnqueued(
|
||||||
|
@ -171,7 +172,7 @@ public class CheckBackupActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPost_forCompleteBackup_withExtraKindsToLoad_enqueuesLoadTask() throws Exception {
|
void testPost_forCompleteBackup_withExtraKindsToLoad_enqueuesLoadTask() throws Exception {
|
||||||
setCompleteBackup();
|
setCompleteBackup();
|
||||||
action.kindsToLoadParam = "one,foo";
|
action.kindsToLoadParam = "one,foo";
|
||||||
|
|
||||||
|
@ -183,7 +184,7 @@ public class CheckBackupActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPost_forCompleteBackup_withEmptyKindsToLoad_skipsLoadTask() throws Exception {
|
void testPost_forCompleteBackup_withEmptyKindsToLoad_skipsLoadTask() throws Exception {
|
||||||
setCompleteBackup();
|
setCompleteBackup();
|
||||||
action.kindsToLoadParam = "";
|
action.kindsToLoadParam = "";
|
||||||
|
|
||||||
|
@ -191,8 +192,9 @@ public class CheckBackupActionTest {
|
||||||
assertNoTasksEnqueued("export-snapshot");
|
assertNoTasksEnqueued("export-snapshot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void testPost_forBadBackup_returnsBadRequest() throws Exception {
|
void testPost_forBadBackup_returnsBadRequest() throws Exception {
|
||||||
setBackupNotFound();
|
setBackupNotFound();
|
||||||
|
|
||||||
BadRequestException thrown = assertThrows(BadRequestException.class, action::run);
|
BadRequestException thrown = assertThrows(BadRequestException.class, action::run);
|
||||||
|
@ -200,7 +202,7 @@ public class CheckBackupActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGet_returnsInformation() throws Exception {
|
void testGet_returnsInformation() throws Exception {
|
||||||
setCompleteBackup();
|
setCompleteBackup();
|
||||||
action.requestMethod = Method.GET;
|
action.requestMethod = Method.GET;
|
||||||
|
|
||||||
|
@ -212,8 +214,9 @@ public class CheckBackupActionTest {
|
||||||
.trim());
|
.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
@Test
|
@Test
|
||||||
public void testGet_forBadBackup_returnsError() throws Exception {
|
void testGet_forBadBackup_returnsError() throws Exception {
|
||||||
setBackupNotFound();
|
setBackupNotFound();
|
||||||
action.requestMethod = Method.GET;
|
action.requestMethod = Method.GET;
|
||||||
|
|
||||||
|
|
|
@ -29,13 +29,10 @@ import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Streams;
|
import com.google.common.collect.Streams;
|
||||||
import com.google.re2j.Pattern;
|
import com.google.re2j.Pattern;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link ExportConstants}. */
|
/** Unit tests for {@link ExportConstants}. */
|
||||||
@RunWith(JUnit4.class)
|
class ExportConstantsTest {
|
||||||
public class ExportConstantsTest {
|
|
||||||
|
|
||||||
private static final String GOLDEN_BACKUP_KINDS_FILENAME = "backup_kinds.txt";
|
private static final String GOLDEN_BACKUP_KINDS_FILENAME = "backup_kinds.txt";
|
||||||
|
|
||||||
|
@ -53,17 +50,17 @@ public class ExportConstantsTest {
|
||||||
"");
|
"");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBackupKinds_matchGoldenBackupKindsFile() {
|
void testBackupKinds_matchGoldenBackupKindsFile() {
|
||||||
checkKindsMatchGoldenFile("backed-up", GOLDEN_BACKUP_KINDS_FILENAME, getBackupKinds());
|
checkKindsMatchGoldenFile("backed-up", GOLDEN_BACKUP_KINDS_FILENAME, getBackupKinds());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReportingKinds_matchGoldenReportingKindsFile() {
|
void testReportingKinds_matchGoldenReportingKindsFile() {
|
||||||
checkKindsMatchGoldenFile("reporting", GOLDEN_REPORTING_KINDS_FILENAME, getReportingKinds());
|
checkKindsMatchGoldenFile("reporting", GOLDEN_REPORTING_KINDS_FILENAME, getReportingKinds());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReportingKinds_areSubsetOfBackupKinds() {
|
void testReportingKinds_areSubsetOfBackupKinds() {
|
||||||
assertThat(getBackupKinds()).containsAtLeastElementsIn(getReportingKinds());
|
assertThat(getBackupKinds()).containsAtLeastElementsIn(getReportingKinds());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,23 +42,20 @@ import google.registry.testing.FakeResponse;
|
||||||
import google.registry.testing.mapreduce.MapreduceTestCase;
|
import google.registry.testing.mapreduce.MapreduceTestCase;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
|
||||||
/** Unit tests for {@link ExportDomainListsAction}. */
|
/** Unit tests for {@link ExportDomainListsAction}. */
|
||||||
@RunWith(JUnit4.class)
|
class ExportDomainListsActionTest extends MapreduceTestCase<ExportDomainListsAction> {
|
||||||
public class ExportDomainListsActionTest extends MapreduceTestCase<ExportDomainListsAction> {
|
|
||||||
|
|
||||||
private GcsService gcsService;
|
private GcsService gcsService;
|
||||||
private DriveConnection driveConnection = mock(DriveConnection.class);
|
private DriveConnection driveConnection = mock(DriveConnection.class);
|
||||||
private ArgumentCaptor<byte[]> bytesExportedToDrive = ArgumentCaptor.forClass(byte[].class);
|
private ArgumentCaptor<byte[]> bytesExportedToDrive = ArgumentCaptor.forClass(byte[].class);
|
||||||
private final FakeResponse response = new FakeResponse();
|
private final FakeResponse response = new FakeResponse();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() {
|
void beforeEach() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
createTld("testtld");
|
createTld("testtld");
|
||||||
persistResource(Registry.get("tld").asBuilder().setDriveFolderId("brouhaha").build());
|
persistResource(Registry.get("tld").asBuilder().setDriveFolderId("brouhaha").build());
|
||||||
|
@ -90,7 +87,7 @@ public class ExportDomainListsActionTest extends MapreduceTestCase<ExportDomainL
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_writesLinkToMapreduceConsoleToResponse() throws Exception {
|
void test_writesLinkToMapreduceConsoleToResponse() throws Exception {
|
||||||
runMapreduce();
|
runMapreduce();
|
||||||
assertThat(response.getPayload())
|
assertThat(response.getPayload())
|
||||||
.startsWith(
|
.startsWith(
|
||||||
|
@ -99,7 +96,7 @@ public class ExportDomainListsActionTest extends MapreduceTestCase<ExportDomainL
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_outputsOnlyActiveDomains() throws Exception {
|
void test_outputsOnlyActiveDomains() throws Exception {
|
||||||
persistActiveDomain("onetwo.tld");
|
persistActiveDomain("onetwo.tld");
|
||||||
persistActiveDomain("rudnitzky.tld");
|
persistActiveDomain("rudnitzky.tld");
|
||||||
persistDeletedDomain("mortuary.tld", DateTime.parse("2001-03-14T10:11:12Z"));
|
persistDeletedDomain("mortuary.tld", DateTime.parse("2001-03-14T10:11:12Z"));
|
||||||
|
@ -113,7 +110,7 @@ public class ExportDomainListsActionTest extends MapreduceTestCase<ExportDomainL
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_outputsOnlyDomainsOnRealTlds() throws Exception {
|
void test_outputsOnlyDomainsOnRealTlds() throws Exception {
|
||||||
persistActiveDomain("onetwo.tld");
|
persistActiveDomain("onetwo.tld");
|
||||||
persistActiveDomain("rudnitzky.tld");
|
persistActiveDomain("rudnitzky.tld");
|
||||||
persistActiveDomain("wontgo.testtld");
|
persistActiveDomain("wontgo.testtld");
|
||||||
|
@ -134,7 +131,7 @@ public class ExportDomainListsActionTest extends MapreduceTestCase<ExportDomainL
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_outputsDomainsFromDifferentTldsToMultipleFiles() throws Exception {
|
void test_outputsDomainsFromDifferentTldsToMultipleFiles() throws Exception {
|
||||||
createTld("tldtwo");
|
createTld("tldtwo");
|
||||||
persistResource(Registry.get("tldtwo").asBuilder().setDriveFolderId("hooray").build());
|
persistResource(Registry.get("tldtwo").asBuilder().setDriveFolderId("hooray").build());
|
||||||
|
|
||||||
|
|
|
@ -43,14 +43,12 @@ import google.registry.request.Response;
|
||||||
import google.registry.storage.drive.DriveConnection;
|
import google.registry.storage.drive.DriveConnection;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.ArgumentMatchers;
|
import org.mockito.ArgumentMatchers;
|
||||||
|
|
||||||
@RunWith(JUnit4.class)
|
/** Unit tests for {@link ExportPremiumTermsAction}. */
|
||||||
public class ExportPremiumTermsActionTest {
|
public class ExportPremiumTermsActionTest {
|
||||||
|
|
||||||
private static final String DISCLAIMER_WITH_NEWLINE = "# Premium Terms Export Disclaimer\n";
|
private static final String DISCLAIMER_WITH_NEWLINE = "# Premium Terms Export Disclaimer\n";
|
||||||
|
@ -59,7 +57,7 @@ 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
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
private final DriveConnection driveConnection = mock(DriveConnection.class);
|
private final DriveConnection driveConnection = mock(DriveConnection.class);
|
||||||
|
@ -74,8 +72,8 @@ public class ExportPremiumTermsActionTest {
|
||||||
action.run();
|
action.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() throws Exception {
|
void beforeEach() throws Exception {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
PremiumList pl = new PremiumList.Builder().setName("pl-name").build();
|
PremiumList pl = new PremiumList.Builder().setName("pl-name").build();
|
||||||
savePremiumListAndEntries(pl, PREMIUM_NAMES);
|
savePremiumListAndEntries(pl, PREMIUM_NAMES);
|
||||||
|
@ -90,7 +88,7 @@ public class ExportPremiumTermsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_exportPremiumTerms_success() throws IOException {
|
void test_exportPremiumTerms_success() throws IOException {
|
||||||
runAction("tld");
|
runAction("tld");
|
||||||
|
|
||||||
verify(driveConnection)
|
verify(driveConnection)
|
||||||
|
@ -108,7 +106,7 @@ public class ExportPremiumTermsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_exportPremiumTerms_success_emptyPremiumList() throws IOException {
|
void test_exportPremiumTerms_success_emptyPremiumList() throws IOException {
|
||||||
PremiumList pl = new PremiumList.Builder().setName("pl-name").build();
|
PremiumList pl = new PremiumList.Builder().setName("pl-name").build();
|
||||||
savePremiumListAndEntries(pl, ImmutableList.of());
|
savePremiumListAndEntries(pl, ImmutableList.of());
|
||||||
runAction("tld");
|
runAction("tld");
|
||||||
|
@ -128,7 +126,7 @@ public class ExportPremiumTermsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_exportPremiumTerms_doNothing_listNotConfigured() {
|
void test_exportPremiumTerms_doNothing_listNotConfigured() {
|
||||||
persistResource(Registry.get("tld").asBuilder().setPremiumList(null).build());
|
persistResource(Registry.get("tld").asBuilder().setPremiumList(null).build());
|
||||||
runAction("tld");
|
runAction("tld");
|
||||||
|
|
||||||
|
@ -140,7 +138,7 @@ public class ExportPremiumTermsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExportPremiumTerms_doNothing_driveIdNotConfiguredInTld() {
|
void testExportPremiumTerms_doNothing_driveIdNotConfiguredInTld() {
|
||||||
persistResource(Registry.get("tld").asBuilder().setDriveFolderId(null).build());
|
persistResource(Registry.get("tld").asBuilder().setDriveFolderId(null).build());
|
||||||
runAction("tld");
|
runAction("tld");
|
||||||
|
|
||||||
|
@ -153,7 +151,7 @@ public class ExportPremiumTermsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_exportPremiumTerms_failure_noSuchTld() {
|
void test_exportPremiumTerms_failure_noSuchTld() {
|
||||||
deleteTld("tld");
|
deleteTld("tld");
|
||||||
assertThrows(RuntimeException.class, () -> runAction("tld"));
|
assertThrows(RuntimeException.class, () -> runAction("tld"));
|
||||||
|
|
||||||
|
@ -165,7 +163,7 @@ public class ExportPremiumTermsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_exportPremiumTerms_failure_noPremiumList() {
|
void test_exportPremiumTerms_failure_noPremiumList() {
|
||||||
deletePremiumList(new PremiumList.Builder().setName("pl-name").build());
|
deletePremiumList(new PremiumList.Builder().setName("pl-name").build());
|
||||||
assertThrows(RuntimeException.class, () -> runAction("tld"));
|
assertThrows(RuntimeException.class, () -> runAction("tld"));
|
||||||
|
|
||||||
|
@ -177,7 +175,7 @@ public class ExportPremiumTermsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExportPremiumTerms_failure_driveIdThrowsException() throws IOException {
|
void testExportPremiumTerms_failure_driveIdThrowsException() throws IOException {
|
||||||
persistResource(Registry.get("tld").asBuilder().setDriveFolderId("bad_folder_id").build());
|
persistResource(Registry.get("tld").asBuilder().setDriveFolderId("bad_folder_id").build());
|
||||||
assertThrows(RuntimeException.class, () -> runAction("tld"));
|
assertThrows(RuntimeException.class, () -> runAction("tld"));
|
||||||
|
|
||||||
|
|
|
@ -38,17 +38,14 @@ import google.registry.request.Response;
|
||||||
import google.registry.storage.drive.DriveConnection;
|
import google.registry.storage.drive.DriveConnection;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link ExportReservedTermsAction}. */
|
/** Unit tests for {@link ExportReservedTermsAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class ExportReservedTermsActionTest {
|
public class ExportReservedTermsActionTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
private final DriveConnection driveConnection = mock(DriveConnection.class);
|
private final DriveConnection driveConnection = mock(DriveConnection.class);
|
||||||
|
@ -63,8 +60,8 @@ public class ExportReservedTermsActionTest {
|
||||||
action.run();
|
action.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() throws Exception {
|
void beforeEach() throws Exception {
|
||||||
ReservedList rl = persistReservedList(
|
ReservedList rl = persistReservedList(
|
||||||
"tld-reserved",
|
"tld-reserved",
|
||||||
"lol,FULLY_BLOCKED",
|
"lol,FULLY_BLOCKED",
|
||||||
|
@ -81,7 +78,7 @@ public class ExportReservedTermsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_uploadFileToDrive_succeeds() throws Exception {
|
void test_uploadFileToDrive_succeeds() throws Exception {
|
||||||
runAction("tld");
|
runAction("tld");
|
||||||
byte[] expected = "# This is a disclaimer.\ncat\nlol\n".getBytes(UTF_8);
|
byte[] expected = "# This is a disclaimer.\ncat\nlol\n".getBytes(UTF_8);
|
||||||
verify(driveConnection)
|
verify(driveConnection)
|
||||||
|
@ -91,7 +88,7 @@ public class ExportReservedTermsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_uploadFileToDrive_doesNothingIfReservedListsNotConfigured() {
|
void test_uploadFileToDrive_doesNothingIfReservedListsNotConfigured() {
|
||||||
persistResource(
|
persistResource(
|
||||||
Registry.get("tld")
|
Registry.get("tld")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -104,7 +101,7 @@ public class ExportReservedTermsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_uploadFileToDrive_doesNothingWhenDriveFolderIdIsNull() {
|
void test_uploadFileToDrive_doesNothingWhenDriveFolderIdIsNull() {
|
||||||
persistResource(Registry.get("tld").asBuilder().setDriveFolderId(null).build());
|
persistResource(Registry.get("tld").asBuilder().setDriveFolderId(null).build());
|
||||||
runAction("tld");
|
runAction("tld");
|
||||||
verify(response).setStatus(SC_OK);
|
verify(response).setStatus(SC_OK);
|
||||||
|
@ -113,7 +110,7 @@ public class ExportReservedTermsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_uploadFileToDrive_failsWhenDriveCannotBeReached() throws Exception {
|
void test_uploadFileToDrive_failsWhenDriveCannotBeReached() throws Exception {
|
||||||
when(driveConnection.createOrUpdateFile(
|
when(driveConnection.createOrUpdateFile(
|
||||||
anyString(),
|
anyString(),
|
||||||
any(MediaType.class),
|
any(MediaType.class),
|
||||||
|
@ -125,7 +122,7 @@ public class ExportReservedTermsActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_uploadFileToDrive_failsWhenTldDoesntExist() {
|
void test_uploadFileToDrive_failsWhenTldDoesntExist() {
|
||||||
RuntimeException thrown = assertThrows(RuntimeException.class, () -> runAction("fakeTld"));
|
RuntimeException thrown = assertThrows(RuntimeException.class, () -> runAction("fakeTld"));
|
||||||
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
|
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
|
||||||
assertThat(thrown)
|
assertThat(thrown)
|
||||||
|
|
|
@ -22,20 +22,17 @@ import static google.registry.testing.DatastoreHelper.persistResource;
|
||||||
import google.registry.model.registry.Registry;
|
import google.registry.model.registry.Registry;
|
||||||
import google.registry.model.registry.label.ReservedList;
|
import google.registry.model.registry.label.ReservedList;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link ExportUtils}. */
|
/** Unit tests for {@link ExportUtils}. */
|
||||||
@RunWith(JUnit4.class)
|
class ExportUtilsTest {
|
||||||
public class ExportUtilsTest {
|
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_exportReservedTerms() {
|
void test_exportReservedTerms() {
|
||||||
ReservedList rl1 = persistReservedList(
|
ReservedList rl1 = persistReservedList(
|
||||||
"tld-reserved1",
|
"tld-reserved1",
|
||||||
"lol,FULLY_BLOCKED",
|
"lol,FULLY_BLOCKED",
|
||||||
|
|
|
@ -45,10 +45,8 @@ import google.registry.testing.FakeSleeper;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
import google.registry.util.Retrier;
|
import google.registry.util.Retrier;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link SyncGroupMembersAction}.
|
* Unit tests for {@link SyncGroupMembersAction}.
|
||||||
|
@ -56,14 +54,12 @@ import org.junit.runners.JUnit4;
|
||||||
* <p>Note that this relies on the registrars NewRegistrar and TheRegistrar created by default in
|
* <p>Note that this relies on the registrars NewRegistrar and TheRegistrar created by default in
|
||||||
* {@link AppEngineRule}.
|
* {@link AppEngineRule}.
|
||||||
*/
|
*/
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class SyncGroupMembersActionTest {
|
public class SyncGroupMembersActionTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
public final InjectRule inject = new InjectRule();
|
|
||||||
|
|
||||||
private final DirectoryGroupsConnection connection = mock(DirectoryGroupsConnection.class);
|
private final DirectoryGroupsConnection connection = mock(DirectoryGroupsConnection.class);
|
||||||
private final Response response = mock(Response.class);
|
private final Response response = mock(Response.class);
|
||||||
|
@ -78,7 +74,7 @@ public class SyncGroupMembersActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getGroupEmailAddressForContactType_convertsToLowercase() {
|
void test_getGroupEmailAddressForContactType_convertsToLowercase() {
|
||||||
assertThat(getGroupEmailAddressForContactType(
|
assertThat(getGroupEmailAddressForContactType(
|
||||||
"SomeRegistrar",
|
"SomeRegistrar",
|
||||||
RegistrarContact.Type.ADMIN,
|
RegistrarContact.Type.ADMIN,
|
||||||
|
@ -87,7 +83,7 @@ public class SyncGroupMembersActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_getGroupEmailAddressForContactType_convertsNonAlphanumericChars() {
|
void test_getGroupEmailAddressForContactType_convertsNonAlphanumericChars() {
|
||||||
assertThat(getGroupEmailAddressForContactType(
|
assertThat(getGroupEmailAddressForContactType(
|
||||||
"Weird.ಠ_ಠRegistrar",
|
"Weird.ಠ_ಠRegistrar",
|
||||||
MARKETING,
|
MARKETING,
|
||||||
|
@ -96,7 +92,7 @@ public class SyncGroupMembersActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_doPost_noneModified() {
|
void test_doPost_noneModified() {
|
||||||
persistResource(
|
persistResource(
|
||||||
loadRegistrar("NewRegistrar").asBuilder().setContactsRequireSyncing(false).build());
|
loadRegistrar("NewRegistrar").asBuilder().setContactsRequireSyncing(false).build());
|
||||||
persistResource(
|
persistResource(
|
||||||
|
@ -109,7 +105,7 @@ public class SyncGroupMembersActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_doPost_syncsNewContact() throws Exception {
|
void test_doPost_syncsNewContact() throws Exception {
|
||||||
runAction();
|
runAction();
|
||||||
verify(connection).addMemberToGroup(
|
verify(connection).addMemberToGroup(
|
||||||
"newregistrar-primary-contacts@domain-registry.example",
|
"newregistrar-primary-contacts@domain-registry.example",
|
||||||
|
@ -121,7 +117,7 @@ public class SyncGroupMembersActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_doPost_removesOldContact() throws Exception {
|
void test_doPost_removesOldContact() throws Exception {
|
||||||
when(connection.getMembersOfGroup("newregistrar-primary-contacts@domain-registry.example"))
|
when(connection.getMembersOfGroup("newregistrar-primary-contacts@domain-registry.example"))
|
||||||
.thenReturn(ImmutableSet.of("defunct@example.com", "janedoe@theregistrar.com"));
|
.thenReturn(ImmutableSet.of("defunct@example.com", "janedoe@theregistrar.com"));
|
||||||
runAction();
|
runAction();
|
||||||
|
@ -132,7 +128,7 @@ public class SyncGroupMembersActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_doPost_removesAllContactsFromGroup() throws Exception {
|
void test_doPost_removesAllContactsFromGroup() throws Exception {
|
||||||
when(connection.getMembersOfGroup("newregistrar-primary-contacts@domain-registry.example"))
|
when(connection.getMembersOfGroup("newregistrar-primary-contacts@domain-registry.example"))
|
||||||
.thenReturn(ImmutableSet.of("defunct@example.com", "janedoe@theregistrar.com"));
|
.thenReturn(ImmutableSet.of("defunct@example.com", "janedoe@theregistrar.com"));
|
||||||
ofy().deleteWithoutBackup()
|
ofy().deleteWithoutBackup()
|
||||||
|
@ -148,7 +144,7 @@ public class SyncGroupMembersActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_doPost_addsAndRemovesContacts_acrossMultipleRegistrars() throws Exception {
|
void test_doPost_addsAndRemovesContacts_acrossMultipleRegistrars() throws Exception {
|
||||||
when(connection.getMembersOfGroup("newregistrar-primary-contacts@domain-registry.example"))
|
when(connection.getMembersOfGroup("newregistrar-primary-contacts@domain-registry.example"))
|
||||||
.thenReturn(ImmutableSet.of("defunct@example.com", "janedoe@theregistrar.com"));
|
.thenReturn(ImmutableSet.of("defunct@example.com", "janedoe@theregistrar.com"));
|
||||||
when(connection.getMembersOfGroup("newregistrar-marketing-contacts@domain-registry.example"))
|
when(connection.getMembersOfGroup("newregistrar-marketing-contacts@domain-registry.example"))
|
||||||
|
@ -196,7 +192,7 @@ public class SyncGroupMembersActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_doPost_gracefullyHandlesExceptionForSingleRegistrar() throws Exception {
|
void test_doPost_gracefullyHandlesExceptionForSingleRegistrar() throws Exception {
|
||||||
when(connection.getMembersOfGroup("newregistrar-primary-contacts@domain-registry.example"))
|
when(connection.getMembersOfGroup("newregistrar-primary-contacts@domain-registry.example"))
|
||||||
.thenReturn(ImmutableSet.of());
|
.thenReturn(ImmutableSet.of());
|
||||||
when(connection.getMembersOfGroup("theregistrar-primary-contacts@domain-registry.example"))
|
when(connection.getMembersOfGroup("theregistrar-primary-contacts@domain-registry.example"))
|
||||||
|
@ -215,7 +211,7 @@ public class SyncGroupMembersActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_doPost_retriesOnTransientException() throws Exception {
|
void test_doPost_retriesOnTransientException() throws Exception {
|
||||||
doThrow(IOException.class)
|
doThrow(IOException.class)
|
||||||
.doNothing()
|
.doNothing()
|
||||||
.when(connection)
|
.when(connection)
|
||||||
|
|
|
@ -40,22 +40,18 @@ import google.registry.request.HttpException.InternalServerErrorException;
|
||||||
import google.registry.testing.AppEngineRule;
|
import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.InOrder;
|
import org.mockito.InOrder;
|
||||||
|
|
||||||
/** Unit tests for {@link UpdateSnapshotViewAction}. */
|
/** Unit tests for {@link UpdateSnapshotViewAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class UpdateSnapshotViewActionTest {
|
public class UpdateSnapshotViewActionTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
public final AppEngineRule appEngine = AppEngineRule.builder().withTaskQueue().build();
|
||||||
.withTaskQueue()
|
|
||||||
.build();
|
|
||||||
private final CheckedBigquery checkedBigquery = mock(CheckedBigquery.class);
|
private final CheckedBigquery checkedBigquery = mock(CheckedBigquery.class);
|
||||||
private final Bigquery bigquery = mock(Bigquery.class);
|
private final Bigquery bigquery = mock(Bigquery.class);
|
||||||
private final Bigquery.Datasets bigqueryDatasets = mock(Bigquery.Datasets.class);
|
private final Bigquery.Datasets bigqueryDatasets = mock(Bigquery.Datasets.class);
|
||||||
|
@ -66,8 +62,8 @@ public class UpdateSnapshotViewActionTest {
|
||||||
|
|
||||||
private UpdateSnapshotViewAction action;
|
private UpdateSnapshotViewAction action;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() throws Exception {
|
void beforeEach() throws Exception {
|
||||||
when(checkedBigquery.ensureDataSetExists(anyString(), anyString())).thenReturn(bigquery);
|
when(checkedBigquery.ensureDataSetExists(anyString(), anyString())).thenReturn(bigquery);
|
||||||
when(bigquery.datasets()).thenReturn(bigqueryDatasets);
|
when(bigquery.datasets()).thenReturn(bigqueryDatasets);
|
||||||
when(bigqueryDatasets.insert(anyString(), any(Dataset.class)))
|
when(bigqueryDatasets.insert(anyString(), any(Dataset.class)))
|
||||||
|
@ -86,7 +82,7 @@ public class UpdateSnapshotViewActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_createViewUpdateTask() {
|
void testSuccess_createViewUpdateTask() {
|
||||||
getQueue(QUEUE)
|
getQueue(QUEUE)
|
||||||
.add(
|
.add(
|
||||||
createViewUpdateTask(
|
createViewUpdateTask(
|
||||||
|
@ -103,7 +99,7 @@ public class UpdateSnapshotViewActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_doPost() throws Exception {
|
void testSuccess_doPost() throws Exception {
|
||||||
action.run();
|
action.run();
|
||||||
|
|
||||||
InOrder factoryOrder = inOrder(checkedBigquery);
|
InOrder factoryOrder = inOrder(checkedBigquery);
|
||||||
|
@ -126,7 +122,7 @@ public class UpdateSnapshotViewActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_bigqueryConnectionThrowsError() throws Exception {
|
void testFailure_bigqueryConnectionThrowsError() throws Exception {
|
||||||
when(bigqueryTables.update(anyString(), anyString(), anyString(), any(Table.class)))
|
when(bigqueryTables.update(anyString(), anyString(), anyString(), any(Table.class)))
|
||||||
.thenThrow(new IOException("I'm sorry Dave, I can't let you do that"));
|
.thenThrow(new IOException("I'm sorry Dave, I can't let you do that"));
|
||||||
InternalServerErrorException thrown =
|
InternalServerErrorException thrown =
|
||||||
|
|
|
@ -49,21 +49,17 @@ import google.registry.testing.AppEngineRule;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
|
||||||
/** Unit tests for {@link UploadDatastoreBackupAction}. */
|
/** Unit tests for {@link UploadDatastoreBackupAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class UploadDatastoreBackupActionTest {
|
public class UploadDatastoreBackupActionTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
public final AppEngineRule appEngine = AppEngineRule.builder().withTaskQueue().build();
|
||||||
.withTaskQueue()
|
|
||||||
.build();
|
|
||||||
private final CheckedBigquery checkedBigquery = mock(CheckedBigquery.class);
|
private final CheckedBigquery checkedBigquery = mock(CheckedBigquery.class);
|
||||||
private final Bigquery bigquery = mock(Bigquery.class);
|
private final Bigquery bigquery = mock(Bigquery.class);
|
||||||
private final Bigquery.Jobs bigqueryJobs = mock(Bigquery.Jobs.class);
|
private final Bigquery.Jobs bigqueryJobs = mock(Bigquery.Jobs.class);
|
||||||
|
@ -74,8 +70,8 @@ public class UploadDatastoreBackupActionTest {
|
||||||
private final BigqueryPollJobEnqueuer bigqueryPollEnqueuer = mock(BigqueryPollJobEnqueuer.class);
|
private final BigqueryPollJobEnqueuer bigqueryPollEnqueuer = mock(BigqueryPollJobEnqueuer.class);
|
||||||
private UploadDatastoreBackupAction action;
|
private UploadDatastoreBackupAction action;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() throws Exception {
|
void beforeEach() throws Exception {
|
||||||
when(checkedBigquery.ensureDataSetExists("Project-Id", BACKUP_DATASET)).thenReturn(bigquery);
|
when(checkedBigquery.ensureDataSetExists("Project-Id", BACKUP_DATASET)).thenReturn(bigquery);
|
||||||
when(bigquery.jobs()).thenReturn(bigqueryJobs);
|
when(bigquery.jobs()).thenReturn(bigqueryJobs);
|
||||||
when(bigqueryJobs.insert(eq("Project-Id"), any(Job.class))).thenReturn(bigqueryJobsInsert);
|
when(bigqueryJobs.insert(eq("Project-Id"), any(Job.class))).thenReturn(bigqueryJobsInsert);
|
||||||
|
@ -92,7 +88,7 @@ public class UploadDatastoreBackupActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_enqueueLoadTask() {
|
void testSuccess_enqueueLoadTask() {
|
||||||
enqueueUploadBackupTask("id12345", "gs://bucket/path", ImmutableSet.of("one", "two", "three"));
|
enqueueUploadBackupTask("id12345", "gs://bucket/path", ImmutableSet.of("one", "two", "three"));
|
||||||
assertTasksEnqueued(
|
assertTasksEnqueued(
|
||||||
QUEUE,
|
QUEUE,
|
||||||
|
@ -105,7 +101,7 @@ public class UploadDatastoreBackupActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_doPost() throws Exception {
|
void testSuccess_doPost() throws Exception {
|
||||||
action.run();
|
action.run();
|
||||||
|
|
||||||
// Verify that checkedBigquery was called in a way that would create the dataset if it didn't
|
// Verify that checkedBigquery was called in a way that would create the dataset if it didn't
|
||||||
|
@ -187,7 +183,7 @@ public class UploadDatastoreBackupActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_doPost_bigqueryThrowsException() throws Exception {
|
void testFailure_doPost_bigqueryThrowsException() throws Exception {
|
||||||
when(bigqueryJobsInsert.execute()).thenThrow(new IOException("The Internet has gone missing"));
|
when(bigqueryJobsInsert.execute()).thenThrow(new IOException("The Internet has gone missing"));
|
||||||
InternalServerErrorException thrown =
|
InternalServerErrorException thrown =
|
||||||
assertThrows(InternalServerErrorException.class, action::run);
|
assertThrows(InternalServerErrorException.class, action::run);
|
||||||
|
@ -197,7 +193,7 @@ public class UploadDatastoreBackupActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testgetBackupInfoFileForKind() {
|
void testgetBackupInfoFileForKind() {
|
||||||
assertThat(
|
assertThat(
|
||||||
getBackupInfoFileForKind(
|
getBackupInfoFileForKind(
|
||||||
"gs://BucketName/2018-11-11T00:00:00_12345", "AllocationToken"))
|
"gs://BucketName/2018-11-11T00:00:00_12345", "AllocationToken"))
|
||||||
|
|
|
@ -29,25 +29,20 @@ import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.junit.MockitoJUnit;
|
|
||||||
import org.mockito.junit.MockitoRule;
|
|
||||||
|
|
||||||
/** Unit tests for {@link DatastoreAdmin}. */
|
/** Unit tests for {@link DatastoreAdmin}. */
|
||||||
@RunWith(JUnit4.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class DatastoreAdminTest {
|
class DatastoreAdminTest {
|
||||||
|
|
||||||
private static final String AUTH_HEADER_PREFIX = "Bearer ";
|
private static final String AUTH_HEADER_PREFIX = "Bearer ";
|
||||||
private static final String ACCESS_TOKEN = "MyAccessToken";
|
private static final String ACCESS_TOKEN = "MyAccessToken";
|
||||||
private static final ImmutableList<String> KINDS =
|
private static final ImmutableList<String> KINDS =
|
||||||
ImmutableList.of("Registry", "Registrar", "DomainBase");
|
ImmutableList.of("Registry", "Registrar", "DomainBase");
|
||||||
|
|
||||||
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
|
|
||||||
|
|
||||||
private DatastoreAdmin datastoreAdmin;
|
private DatastoreAdmin datastoreAdmin;
|
||||||
|
|
||||||
private static HttpRequest simulateSendRequest(HttpRequest httpRequest) {
|
private static HttpRequest simulateSendRequest(HttpRequest httpRequest) {
|
||||||
|
@ -75,8 +70,8 @@ public class DatastoreAdminTest {
|
||||||
return Optional.of(outputStream.toString(StandardCharsets.UTF_8.name()));
|
return Optional.of(outputStream.toString(StandardCharsets.UTF_8.name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
void beforeEach() {
|
||||||
Date oneHourLater = new Date(System.currentTimeMillis() + 3_600_000);
|
Date oneHourLater = new Date(System.currentTimeMillis() + 3_600_000);
|
||||||
GoogleCredentials googleCredentials = GoogleCredentials
|
GoogleCredentials googleCredentials = GoogleCredentials
|
||||||
.create(new AccessToken(ACCESS_TOKEN, oneHourLater));
|
.create(new AccessToken(ACCESS_TOKEN, oneHourLater));
|
||||||
|
@ -92,7 +87,7 @@ public class DatastoreAdminTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExport() throws IOException {
|
void testExport() throws IOException {
|
||||||
DatastoreAdmin.Export export = datastoreAdmin.export("gs://mybucket/path", KINDS);
|
DatastoreAdmin.Export export = datastoreAdmin.export("gs://mybucket/path", KINDS);
|
||||||
HttpRequest httpRequest = export.buildHttpRequest();
|
HttpRequest httpRequest = export.buildHttpRequest();
|
||||||
assertThat(httpRequest.getUrl().toString())
|
assertThat(httpRequest.getUrl().toString())
|
||||||
|
@ -109,7 +104,7 @@ public class DatastoreAdminTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetOperation() throws IOException {
|
void testGetOperation() throws IOException {
|
||||||
DatastoreAdmin.Get get =
|
DatastoreAdmin.Get get =
|
||||||
datastoreAdmin.get("projects/MyCloudProject/operations/ASAzNjMwOTEyNjUJ");
|
datastoreAdmin.get("projects/MyCloudProject/operations/ASAzNjMwOTEyNjUJ");
|
||||||
HttpRequest httpRequest = get.buildHttpRequest();
|
HttpRequest httpRequest = get.buildHttpRequest();
|
||||||
|
@ -124,7 +119,7 @@ public class DatastoreAdminTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListOperations_all() throws IOException {
|
void testListOperations_all() throws IOException {
|
||||||
DatastoreAdmin.ListOperations listOperations = datastoreAdmin.listAll();
|
DatastoreAdmin.ListOperations listOperations = datastoreAdmin.listAll();
|
||||||
HttpRequest httpRequest = listOperations.buildHttpRequest();
|
HttpRequest httpRequest = listOperations.buildHttpRequest();
|
||||||
assertThat(httpRequest.getUrl().toString())
|
assertThat(httpRequest.getUrl().toString())
|
||||||
|
@ -137,7 +132,7 @@ public class DatastoreAdminTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListOperations_filterByStartTime() throws IOException {
|
void testListOperations_filterByStartTime() throws IOException {
|
||||||
DatastoreAdmin.ListOperations listOperations =
|
DatastoreAdmin.ListOperations listOperations =
|
||||||
datastoreAdmin.list("metadata.common.startTime>\"2018-10-31T00:00:00.0Z\"");
|
datastoreAdmin.list("metadata.common.startTime>\"2018-10-31T00:00:00.0Z\"");
|
||||||
HttpRequest httpRequest = listOperations.buildHttpRequest();
|
HttpRequest httpRequest = listOperations.buildHttpRequest();
|
||||||
|
@ -153,7 +148,7 @@ public class DatastoreAdminTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListOperations_filterByState() throws IOException {
|
void testListOperations_filterByState() throws IOException {
|
||||||
// TODO(weiminyu): consider adding a method to DatastoreAdmin to support query by state.
|
// TODO(weiminyu): consider adding a method to DatastoreAdmin to support query by state.
|
||||||
DatastoreAdmin.ListOperations listOperations =
|
DatastoreAdmin.ListOperations listOperations =
|
||||||
datastoreAdmin.list("metadata.common.state=PROCESSING");
|
datastoreAdmin.list("metadata.common.state=PROCESSING");
|
||||||
|
|
|
@ -22,23 +22,20 @@ import com.google.api.client.json.jackson2.JacksonFactory;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import google.registry.testing.TestDataHelper;
|
import google.registry.testing.TestDataHelper;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for the instantiation, marshalling and unmarshalling of {@link EntityFilter}. */
|
/** Unit tests for the instantiation, marshalling and unmarshalling of {@link EntityFilter}. */
|
||||||
@RunWith(JUnit4.class)
|
class EntityFilterTest {
|
||||||
public class EntityFilterTest {
|
|
||||||
|
|
||||||
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
|
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntityFilter_create_nullKinds() {
|
void testEntityFilter_create_nullKinds() {
|
||||||
assertThrows(NullPointerException.class, () -> new EntityFilter(null));
|
assertThrows(NullPointerException.class, () -> new EntityFilter(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntityFilter_marshall() throws IOException {
|
void testEntityFilter_marshall() throws IOException {
|
||||||
EntityFilter entityFilter =
|
EntityFilter entityFilter =
|
||||||
new EntityFilter(ImmutableList.of("Registry", "Registrar", "DomainBase"));
|
new EntityFilter(ImmutableList.of("Registry", "Registrar", "DomainBase"));
|
||||||
assertThat(JSON_FACTORY.toString(entityFilter))
|
assertThat(JSON_FACTORY.toString(entityFilter))
|
||||||
|
@ -46,7 +43,7 @@ public class EntityFilterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntityFilter_unmarshall() throws IOException {
|
void testEntityFilter_unmarshall() throws IOException {
|
||||||
EntityFilter entityFilter = loadJson("entity_filter.json", EntityFilter.class);
|
EntityFilter entityFilter = loadJson("entity_filter.json", EntityFilter.class);
|
||||||
assertThat(entityFilter.getKinds())
|
assertThat(entityFilter.getKinds())
|
||||||
.containsExactly("Registry", "Registrar", "DomainBase")
|
.containsExactly("Registry", "Registrar", "DomainBase")
|
||||||
|
@ -54,13 +51,13 @@ public class EntityFilterTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntityFilter_unmarshall_noKinds() throws IOException {
|
void testEntityFilter_unmarshall_noKinds() throws IOException {
|
||||||
EntityFilter entityFilter = JSON_FACTORY.fromString("{}", EntityFilter.class);
|
EntityFilter entityFilter = JSON_FACTORY.fromString("{}", EntityFilter.class);
|
||||||
assertThat(entityFilter.getKinds()).isEmpty();
|
assertThat(entityFilter.getKinds()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntityFilter_unmarshall_emptyKinds() throws IOException {
|
void testEntityFilter_unmarshall_emptyKinds() throws IOException {
|
||||||
EntityFilter entityFilter = JSON_FACTORY.fromString("{ \"kinds\" : [] }", EntityFilter.class);
|
EntityFilter entityFilter = JSON_FACTORY.fromString("{ \"kinds\" : [] }", EntityFilter.class);
|
||||||
assertThat(entityFilter.getKinds()).isEmpty();
|
assertThat(entityFilter.getKinds()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,17 +27,15 @@ import google.registry.testing.TestDataHelper;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for unmarshalling {@link Operation} and its member types. */
|
/** Unit tests for unmarshalling {@link Operation} and its member types. */
|
||||||
@RunWith(JUnit4.class)
|
class OperationTest {
|
||||||
public class OperationTest {
|
|
||||||
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
|
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCommonMetadata_unmarshall() throws IOException {
|
void testCommonMetadata_unmarshall() throws IOException {
|
||||||
CommonMetadata commonMetadata = loadJson("common_metadata.json", CommonMetadata.class);
|
CommonMetadata commonMetadata = loadJson("common_metadata.json", CommonMetadata.class);
|
||||||
assertThat(commonMetadata.getState()).isEqualTo("SUCCESSFUL");
|
assertThat(commonMetadata.getState()).isEqualTo("SUCCESSFUL");
|
||||||
assertThat(commonMetadata.getOperationType()).isEqualTo("EXPORT_ENTITIES");
|
assertThat(commonMetadata.getOperationType()).isEqualTo("EXPORT_ENTITIES");
|
||||||
|
@ -47,14 +45,14 @@ public class OperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProgress_unmarshall() throws IOException {
|
void testProgress_unmarshall() throws IOException {
|
||||||
Progress progress = loadJson("progress.json", Progress.class);
|
Progress progress = loadJson("progress.json", Progress.class);
|
||||||
assertThat(progress.getWorkCompleted()).isEqualTo(51797);
|
assertThat(progress.getWorkCompleted()).isEqualTo(51797);
|
||||||
assertThat(progress.getWorkEstimated()).isEqualTo(54513);
|
assertThat(progress.getWorkEstimated()).isEqualTo(54513);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMetadata_unmarshall() throws IOException {
|
void testMetadata_unmarshall() throws IOException {
|
||||||
Metadata metadata = loadJson("metadata.json", Metadata.class);
|
Metadata metadata = loadJson("metadata.json", Metadata.class);
|
||||||
assertThat(metadata.getCommonMetadata().getOperationType()).isEqualTo("EXPORT_ENTITIES");
|
assertThat(metadata.getCommonMetadata().getOperationType()).isEqualTo("EXPORT_ENTITIES");
|
||||||
assertThat(metadata.getCommonMetadata().getState()).isEqualTo("SUCCESSFUL");
|
assertThat(metadata.getCommonMetadata().getState()).isEqualTo("SUCCESSFUL");
|
||||||
|
@ -67,7 +65,7 @@ public class OperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOperation_unmarshall() throws IOException {
|
void testOperation_unmarshall() throws IOException {
|
||||||
Operation operation = loadJson("operation.json", Operation.class);
|
Operation operation = loadJson("operation.json", Operation.class);
|
||||||
assertThat(operation.getName())
|
assertThat(operation.getName())
|
||||||
.startsWith("projects/domain-registry-alpha/operations/ASAzNjMwOTEyNjUJ");
|
.startsWith("projects/domain-registry-alpha/operations/ASAzNjMwOTEyNjUJ");
|
||||||
|
@ -86,7 +84,7 @@ public class OperationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOperationList_unmarshall() throws IOException {
|
void testOperationList_unmarshall() throws IOException {
|
||||||
Operation.OperationList operationList =
|
Operation.OperationList operationList =
|
||||||
loadJson("operation_list.json", Operation.OperationList.class);
|
loadJson("operation_list.json", Operation.OperationList.class);
|
||||||
assertThat(operationList.toList()).hasSize(2);
|
assertThat(operationList.toList()).hasSize(2);
|
||||||
|
|
|
@ -33,14 +33,12 @@ import com.google.common.collect.ImmutableMap;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link SheetSynchronizer}. */
|
/** Unit tests for {@link SheetSynchronizer}. */
|
||||||
@RunWith(JUnit4.class)
|
class SheetSynchronizerTest {
|
||||||
public class SheetSynchronizerTest {
|
|
||||||
private final SheetSynchronizer sheetSynchronizer = new SheetSynchronizer();
|
private final SheetSynchronizer sheetSynchronizer = new SheetSynchronizer();
|
||||||
private final Sheets sheetsService = mock(Sheets.class);
|
private final Sheets sheetsService = mock(Sheets.class);
|
||||||
private final Sheets.Spreadsheets spreadsheets = mock(Sheets.Spreadsheets.class);
|
private final Sheets.Spreadsheets spreadsheets = mock(Sheets.Spreadsheets.class);
|
||||||
|
@ -56,8 +54,8 @@ public class SheetSynchronizerTest {
|
||||||
private List<List<Object>> existingSheet;
|
private List<List<Object>> existingSheet;
|
||||||
private ImmutableList<ImmutableMap<String, String>> data;
|
private ImmutableList<ImmutableMap<String, String>> data;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() throws Exception {
|
void beforeEach() throws Exception {
|
||||||
sheetSynchronizer.sheetsService = sheetsService;
|
sheetSynchronizer.sheetsService = sheetsService;
|
||||||
when(sheetsService.spreadsheets()).thenReturn(spreadsheets);
|
when(sheetsService.spreadsheets()).thenReturn(spreadsheets);
|
||||||
when(spreadsheets.values()).thenReturn(values);
|
when(spreadsheets.values()).thenReturn(values);
|
||||||
|
@ -88,7 +86,7 @@ public class SheetSynchronizerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSynchronize_dataAndSheetEmpty_doNothing() throws Exception {
|
void testSynchronize_dataAndSheetEmpty_doNothing() throws Exception {
|
||||||
existingSheet.add(createRow("a", "b"));
|
existingSheet.add(createRow("a", "b"));
|
||||||
sheetSynchronizer.synchronize("aSheetId", data);
|
sheetSynchronizer.synchronize("aSheetId", data);
|
||||||
verifyNoInteractions(appendReq);
|
verifyNoInteractions(appendReq);
|
||||||
|
@ -97,7 +95,7 @@ public class SheetSynchronizerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSynchronize_differentValues_updatesValues() throws Exception {
|
void testSynchronize_differentValues_updatesValues() throws Exception {
|
||||||
existingSheet.add(createRow("a", "b"));
|
existingSheet.add(createRow("a", "b"));
|
||||||
existingSheet.add(createRow("diffVal1l", "diffVal2"));
|
existingSheet.add(createRow("diffVal1l", "diffVal2"));
|
||||||
data = ImmutableList.of(ImmutableMap.of("a", "val1", "b", "val2"));
|
data = ImmutableList.of(ImmutableMap.of("a", "val1", "b", "val2"));
|
||||||
|
@ -116,7 +114,7 @@ public class SheetSynchronizerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSynchronize_unknownFields_doesntUpdate() throws Exception {
|
void testSynchronize_unknownFields_doesntUpdate() throws Exception {
|
||||||
existingSheet.add(createRow("a", "c", "b"));
|
existingSheet.add(createRow("a", "c", "b"));
|
||||||
existingSheet.add(createRow("diffVal1", "sameVal", "diffVal2"));
|
existingSheet.add(createRow("diffVal1", "sameVal", "diffVal2"));
|
||||||
data = ImmutableList.of(ImmutableMap.of("a", "val1", "b", "val2", "d", "val3"));
|
data = ImmutableList.of(ImmutableMap.of("a", "val1", "b", "val2", "d", "val3"));
|
||||||
|
@ -135,7 +133,7 @@ public class SheetSynchronizerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSynchronize_notFullRow_getsPadded() throws Exception {
|
void testSynchronize_notFullRow_getsPadded() throws Exception {
|
||||||
existingSheet.add(createRow("a", "c", "b"));
|
existingSheet.add(createRow("a", "c", "b"));
|
||||||
existingSheet.add(createRow("diffVal1", "diffVal2"));
|
existingSheet.add(createRow("diffVal1", "diffVal2"));
|
||||||
data = ImmutableList.of(ImmutableMap.of("a", "val1", "b", "paddedVal", "d", "val3"));
|
data = ImmutableList.of(ImmutableMap.of("a", "val1", "b", "paddedVal", "d", "val3"));
|
||||||
|
@ -154,12 +152,12 @@ public class SheetSynchronizerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSynchronize_moreData_appendsValues() throws Exception {
|
void testSynchronize_moreData_appendsValues() throws Exception {
|
||||||
existingSheet.add(createRow("a", "b"));
|
existingSheet.add(createRow("a", "b"));
|
||||||
existingSheet.add(createRow("diffVal1", "diffVal2"));
|
existingSheet.add(createRow("diffVal1", "diffVal2"));
|
||||||
data = ImmutableList.of(
|
data =
|
||||||
ImmutableMap.of("a", "val1", "b", "val2"),
|
ImmutableList.of(
|
||||||
ImmutableMap.of("a", "val3", "b", "val4"));
|
ImmutableMap.of("a", "val1", "b", "val2"), ImmutableMap.of("a", "val3", "b", "val4"));
|
||||||
sheetSynchronizer.synchronize("aSheetId", data);
|
sheetSynchronizer.synchronize("aSheetId", data);
|
||||||
|
|
||||||
verifyNoInteractions(clearReq);
|
verifyNoInteractions(clearReq);
|
||||||
|
@ -168,8 +166,7 @@ public class SheetSynchronizerTest {
|
||||||
List<List<Object>> updatedVals = newArrayList();
|
List<List<Object>> updatedVals = newArrayList();
|
||||||
updatedVals.add(createRow("val1", "val2"));
|
updatedVals.add(createRow("val1", "val2"));
|
||||||
expectedRequest.setData(
|
expectedRequest.setData(
|
||||||
newArrayList(
|
newArrayList(new ValueRange().setRange("Registrars!A2").setValues(updatedVals)));
|
||||||
new ValueRange().setRange("Registrars!A2").setValues(updatedVals)));
|
|
||||||
expectedRequest.setValueInputOption("RAW");
|
expectedRequest.setValueInputOption("RAW");
|
||||||
verify(values).batchUpdate("aSheetId", expectedRequest);
|
verify(values).batchUpdate("aSheetId", expectedRequest);
|
||||||
|
|
||||||
|
@ -180,7 +177,7 @@ public class SheetSynchronizerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSynchronize_lessData_clearsValues() throws Exception {
|
void testSynchronize_lessData_clearsValues() throws Exception {
|
||||||
existingSheet.add(createRow("a", "b"));
|
existingSheet.add(createRow("a", "b"));
|
||||||
existingSheet.add(createRow("val1", "val2"));
|
existingSheet.add(createRow("val1", "val2"));
|
||||||
existingSheet.add(createRow("diffVal3", "diffVal4"));
|
existingSheet.add(createRow("diffVal3", "diffVal4"));
|
||||||
|
|
|
@ -29,17 +29,14 @@ import google.registry.testing.FakeResponse;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link SyncRegistrarsSheetAction}. */
|
/** Unit tests for {@link SyncRegistrarsSheetAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class SyncRegistrarsSheetActionTest {
|
public class SyncRegistrarsSheetActionTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
AppEngineRule.builder().withDatastoreAndCloudSql().withTaskQueue().build();
|
||||||
|
|
||||||
|
@ -54,8 +51,8 @@ public class SyncRegistrarsSheetActionTest {
|
||||||
action.run();
|
action.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void beforeEach() {
|
||||||
action = new SyncRegistrarsSheetAction();
|
action = new SyncRegistrarsSheetAction();
|
||||||
action.response = response;
|
action.response = response;
|
||||||
action.syncRegistrarsSheet = syncRegistrarsSheet;
|
action.syncRegistrarsSheet = syncRegistrarsSheet;
|
||||||
|
@ -64,14 +61,14 @@ public class SyncRegistrarsSheetActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPost_withoutParamsOrSystemProperty_dropsTask() {
|
void testPost_withoutParamsOrSystemProperty_dropsTask() {
|
||||||
runAction(null, null);
|
runAction(null, null);
|
||||||
assertThat(response.getPayload()).startsWith("MISSINGNO");
|
assertThat(response.getPayload()).startsWith("MISSINGNO");
|
||||||
verifyNoInteractions(syncRegistrarsSheet);
|
verifyNoInteractions(syncRegistrarsSheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPost_withoutParams_runsSyncWithDefaultIdAndChecksIfModified() throws Exception {
|
void testPost_withoutParams_runsSyncWithDefaultIdAndChecksIfModified() throws Exception {
|
||||||
when(syncRegistrarsSheet.wereRegistrarsModified()).thenReturn(true);
|
when(syncRegistrarsSheet.wereRegistrarsModified()).thenReturn(true);
|
||||||
runAction("jazz", null);
|
runAction("jazz", null);
|
||||||
assertThat(response.getStatus()).isEqualTo(200);
|
assertThat(response.getStatus()).isEqualTo(200);
|
||||||
|
@ -83,7 +80,7 @@ public class SyncRegistrarsSheetActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPost_noModificationsToRegistrarEntities_doesNothing() {
|
void testPost_noModificationsToRegistrarEntities_doesNothing() {
|
||||||
when(syncRegistrarsSheet.wereRegistrarsModified()).thenReturn(false);
|
when(syncRegistrarsSheet.wereRegistrarsModified()).thenReturn(false);
|
||||||
runAction("NewRegistrar", null);
|
runAction("NewRegistrar", null);
|
||||||
assertThat(response.getPayload()).startsWith("NOTMODIFIED");
|
assertThat(response.getPayload()).startsWith("NOTMODIFIED");
|
||||||
|
@ -92,7 +89,7 @@ public class SyncRegistrarsSheetActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPost_overrideId_runsSyncWithCustomIdAndDoesNotCheckModified() throws Exception {
|
void testPost_overrideId_runsSyncWithCustomIdAndDoesNotCheckModified() throws Exception {
|
||||||
runAction(null, "foobar");
|
runAction(null, "foobar");
|
||||||
assertThat(response.getPayload()).startsWith("OK");
|
assertThat(response.getPayload()).startsWith("OK");
|
||||||
verify(syncRegistrarsSheet).run(eq("foobar"));
|
verify(syncRegistrarsSheet).run(eq("foobar"));
|
||||||
|
@ -100,7 +97,7 @@ public class SyncRegistrarsSheetActionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPost_failToAquireLock_servletDoesNothingAndReturns() {
|
void testPost_failToAquireLock_servletDoesNothingAndReturns() {
|
||||||
action.lockHandler = new FakeLockHandler(false);
|
action.lockHandler = new FakeLockHandler(false);
|
||||||
runAction(null, "foobar");
|
runAction(null, "foobar");
|
||||||
assertThat(response.getPayload()).startsWith("LOCKED");
|
assertThat(response.getPayload()).startsWith("LOCKED");
|
||||||
|
|
|
@ -43,27 +43,23 @@ import google.registry.testing.DatastoreHelper;
|
||||||
import google.registry.testing.FakeClock;
|
import google.registry.testing.FakeClock;
|
||||||
import google.registry.testing.InjectRule;
|
import google.registry.testing.InjectRule;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Captor;
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnit;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.mockito.junit.MockitoRule;
|
|
||||||
|
|
||||||
/** Unit tests for {@link SyncRegistrarsSheet}. */
|
/** Unit tests for {@link SyncRegistrarsSheet}. */
|
||||||
@RunWith(JUnit4.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class SyncRegistrarsSheetTest {
|
public class SyncRegistrarsSheetTest {
|
||||||
|
|
||||||
@Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastoreAndCloudSql().build();
|
||||||
|
|
||||||
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
@Rule public final InjectRule inject = new InjectRule();
|
|
||||||
|
|
||||||
|
|
||||||
@Captor private ArgumentCaptor<ImmutableList<ImmutableMap<String, String>>> rowsCaptor;
|
@Captor private ArgumentCaptor<ImmutableList<ImmutableMap<String, String>>> rowsCaptor;
|
||||||
@Mock private SheetSynchronizer sheetSynchronizer;
|
@Mock private SheetSynchronizer sheetSynchronizer;
|
||||||
|
@ -77,8 +73,8 @@ public class SyncRegistrarsSheetTest {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void beforeEach() {
|
||||||
inject.setStaticField(Ofy.class, "clock", clock);
|
inject.setStaticField(Ofy.class, "clock", clock);
|
||||||
createTld("example");
|
createTld("example");
|
||||||
// Remove Registrar entities created by AppEngineRule.
|
// Remove Registrar entities created by AppEngineRule.
|
||||||
|
@ -86,12 +82,12 @@ public class SyncRegistrarsSheetTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_wereRegistrarsModified_noRegistrars_returnsFalse() {
|
void test_wereRegistrarsModified_noRegistrars_returnsFalse() {
|
||||||
assertThat(newSyncRegistrarsSheet().wereRegistrarsModified()).isFalse();
|
assertThat(newSyncRegistrarsSheet().wereRegistrarsModified()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_wereRegistrarsModified_atDifferentCursorTimes() {
|
void test_wereRegistrarsModified_atDifferentCursorTimes() {
|
||||||
persistNewRegistrar("SomeRegistrar", "Some Registrar Inc.", Registrar.Type.REAL, 8L);
|
persistNewRegistrar("SomeRegistrar", "Some Registrar Inc.", Registrar.Type.REAL, 8L);
|
||||||
persistResource(Cursor.createGlobal(SYNC_REGISTRAR_SHEET, clock.nowUtc().minusHours(1)));
|
persistResource(Cursor.createGlobal(SYNC_REGISTRAR_SHEET, clock.nowUtc().minusHours(1)));
|
||||||
assertThat(newSyncRegistrarsSheet().wereRegistrarsModified()).isTrue();
|
assertThat(newSyncRegistrarsSheet().wereRegistrarsModified()).isTrue();
|
||||||
|
@ -100,7 +96,7 @@ public class SyncRegistrarsSheetTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun() throws Exception {
|
void testRun() throws Exception {
|
||||||
DateTime beforeExecution = clock.nowUtc();
|
DateTime beforeExecution = clock.nowUtc();
|
||||||
persistResource(new Registrar.Builder()
|
persistResource(new Registrar.Builder()
|
||||||
.setClientId("anotherregistrar")
|
.setClientId("anotherregistrar")
|
||||||
|
@ -329,7 +325,7 @@ public class SyncRegistrarsSheetTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRun_missingValues_stillWorks() throws Exception {
|
void testRun_missingValues_stillWorks() throws Exception {
|
||||||
persistNewRegistrar("SomeRegistrar", "Some Registrar", Registrar.Type.REAL, 8L);
|
persistNewRegistrar("SomeRegistrar", "Some Registrar", Registrar.Type.REAL, 8L);
|
||||||
|
|
||||||
newSyncRegistrarsSheet().run("foobar");
|
newSyncRegistrarsSheet().run("foobar");
|
||||||
|
|
|
@ -50,15 +50,11 @@ import java.util.Optional;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.junit.MockitoJUnit;
|
|
||||||
import org.mockito.junit.MockitoRule;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.mockito.junit.jupiter.MockitoSettings;
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
import org.mockito.quality.Strictness;
|
import org.mockito.quality.Strictness;
|
||||||
|
@ -86,19 +82,16 @@ public abstract class MapreduceTestCase<T> {
|
||||||
private final PipelineServlet pipelineServlet = new PipelineServlet();
|
private final PipelineServlet pipelineServlet = new PipelineServlet();
|
||||||
private LocalTaskQueue taskQueue;
|
private LocalTaskQueue taskQueue;
|
||||||
|
|
||||||
@RegisterExtension @Rule
|
@RegisterExtension
|
||||||
public final AppEngineRule appEngine =
|
public final AppEngineRule appEngine =
|
||||||
AppEngineRule.builder().withDatastoreAndCloudSql().withLocalModules().withTaskQueue().build();
|
AppEngineRule.builder().withDatastoreAndCloudSql().withLocalModules().withTaskQueue().build();
|
||||||
|
|
||||||
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
|
|
||||||
|
|
||||||
private AppEngineServiceUtils appEngineServiceUtils;
|
private AppEngineServiceUtils appEngineServiceUtils;
|
||||||
|
|
||||||
@Mock ModulesService modulesService;
|
@Mock ModulesService modulesService;
|
||||||
|
|
||||||
@Before
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void beforeEachMapreduceTestCase() {
|
||||||
taskQueue = LocalTaskQueueTestConfig.getLocalTaskQueue();
|
taskQueue = LocalTaskQueueTestConfig.getLocalTaskQueue();
|
||||||
ApiProxyLocal proxy = (ApiProxyLocal) ApiProxy.getDelegate();
|
ApiProxyLocal proxy = (ApiProxyLocal) ApiProxy.getDelegate();
|
||||||
// Creating files is not allowed in some test execution environments, so don't.
|
// Creating files is not allowed in some test execution environments, so don't.
|
||||||
|
|
|
@ -45,18 +45,15 @@ import java.util.Map;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Tests for {@link GenerateZoneFilesAction}.*/
|
/** Tests for {@link GenerateZoneFilesAction}. */
|
||||||
@RunWith(JUnit4.class)
|
class GenerateZoneFilesActionTest extends MapreduceTestCase<GenerateZoneFilesAction> {
|
||||||
public class GenerateZoneFilesActionTest extends MapreduceTestCase<GenerateZoneFilesAction> {
|
|
||||||
|
|
||||||
private final GcsService gcsService = createGcsService();
|
private final GcsService gcsService = createGcsService();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerate() throws Exception {
|
void testGenerate() throws Exception {
|
||||||
DateTime now = DateTime.now(DateTimeZone.UTC).withTimeAtStartOfDay();
|
DateTime now = DateTime.now(DateTimeZone.UTC).withTimeAtStartOfDay();
|
||||||
createTlds("tld", "com");
|
createTlds("tld", "com");
|
||||||
|
|
||||||
|
|
|
@ -41,15 +41,12 @@ import google.registry.model.ofy.CommitLogMutation;
|
||||||
import google.registry.testing.FakeResponse;
|
import google.registry.testing.FakeResponse;
|
||||||
import google.registry.testing.mapreduce.MapreduceTestCase;
|
import google.registry.testing.mapreduce.MapreduceTestCase;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Tests for {@link KillAllCommitLogsAction}.*/
|
/** Tests for {@link KillAllCommitLogsAction}. */
|
||||||
@RunWith(JUnit4.class)
|
class KillAllCommitLogsActionTest extends MapreduceTestCase<KillAllCommitLogsAction> {
|
||||||
public class KillAllCommitLogsActionTest extends MapreduceTestCase<KillAllCommitLogsAction> {
|
|
||||||
|
|
||||||
static final ImmutableList<Class<? extends ImmutableObject>> AFFECTED_TYPES =
|
private static final ImmutableList<Class<? extends ImmutableObject>> AFFECTED_TYPES =
|
||||||
ImmutableList.of(
|
ImmutableList.of(
|
||||||
CommitLogBucket.class,
|
CommitLogBucket.class,
|
||||||
CommitLogCheckpoint.class,
|
CommitLogCheckpoint.class,
|
||||||
|
@ -66,7 +63,7 @@ public class KillAllCommitLogsActionTest extends MapreduceTestCase<KillAllCommit
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKill() throws Exception {
|
void testKill() throws Exception {
|
||||||
int nextContactId = 5432;
|
int nextContactId = 5432;
|
||||||
for (String tld : asList("tld1", "tld2")) {
|
for (String tld : asList("tld1", "tld2")) {
|
||||||
createTld(tld);
|
createTld(tld);
|
||||||
|
|
|
@ -53,15 +53,12 @@ import google.registry.testing.mapreduce.MapreduceTestCase;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import org.joda.money.CurrencyUnit;
|
import org.joda.money.CurrencyUnit;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Tests for {@link KillAllEppResourcesAction}.*/
|
/** Tests for {@link KillAllEppResourcesAction}. */
|
||||||
@RunWith(JUnit4.class)
|
class KillAllEppResourcesActionTest extends MapreduceTestCase<KillAllEppResourcesAction> {
|
||||||
public class KillAllEppResourcesActionTest extends MapreduceTestCase<KillAllEppResourcesAction> {
|
|
||||||
|
|
||||||
static final ImmutableSet<String> AFFECTED_KINDS =
|
private static final ImmutableSet<String> AFFECTED_KINDS =
|
||||||
Stream.of(
|
Stream.of(
|
||||||
EppResourceIndex.class,
|
EppResourceIndex.class,
|
||||||
ForeignKeyContactIndex.class,
|
ForeignKeyContactIndex.class,
|
||||||
|
@ -86,7 +83,7 @@ public class KillAllEppResourcesActionTest extends MapreduceTestCase<KillAllEppR
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKill() throws Exception {
|
void testKill() throws Exception {
|
||||||
createTld("tld1");
|
createTld("tld1");
|
||||||
createTld("tld2");
|
createTld("tld2");
|
||||||
for (EppResource resource : asList(
|
for (EppResource resource : asList(
|
||||||
|
|
|
@ -35,26 +35,23 @@ import google.registry.tools.server.RefreshDnsForAllDomainsAction.RefreshDnsForA
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
|
||||||
/** Unit tests for {@link RefreshDnsForAllDomainsAction}. */
|
/** Unit tests for {@link RefreshDnsForAllDomainsAction}. */
|
||||||
@RunWith(JUnit4.class)
|
|
||||||
public class RefreshDnsForAllDomainsActionTest
|
public class RefreshDnsForAllDomainsActionTest
|
||||||
extends MapreduceTestCase<RefreshDnsForAllDomainsAction> {
|
extends MapreduceTestCase<RefreshDnsForAllDomainsAction> {
|
||||||
|
|
||||||
@Rule public final InjectRule inject = new InjectRule();
|
@RegisterExtension public final InjectRule inject = new InjectRule();
|
||||||
|
|
||||||
private final DnsQueue dnsQueue = mock(DnsQueue.class);
|
private final DnsQueue dnsQueue = mock(DnsQueue.class);
|
||||||
private DnsQueue origDnsQueue;
|
private DnsQueue origDnsQueue;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() {
|
void beforeEach() {
|
||||||
origDnsQueue = RefreshDnsForAllDomainsActionMapper.setDnsQueueForTest(dnsQueue);
|
origDnsQueue = RefreshDnsForAllDomainsActionMapper.setDnsQueueForTest(dnsQueue);
|
||||||
|
|
||||||
action = new RefreshDnsForAllDomainsAction();
|
action = new RefreshDnsForAllDomainsAction();
|
||||||
|
@ -67,8 +64,8 @@ public class RefreshDnsForAllDomainsActionTest
|
||||||
createTld("bar");
|
createTld("bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void restoreDnsQueue() {
|
void afterEach() {
|
||||||
assertThat(RefreshDnsForAllDomainsActionMapper.setDnsQueueForTest(origDnsQueue))
|
assertThat(RefreshDnsForAllDomainsActionMapper.setDnsQueueForTest(origDnsQueue))
|
||||||
.isEqualTo(dnsQueue);
|
.isEqualTo(dnsQueue);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +76,7 @@ public class RefreshDnsForAllDomainsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_runAction_successfullyEnqueuesDnsRefreshes() throws Exception {
|
void test_runAction_successfullyEnqueuesDnsRefreshes() throws Exception {
|
||||||
persistActiveDomain("foo.bar");
|
persistActiveDomain("foo.bar");
|
||||||
persistActiveDomain("low.bar");
|
persistActiveDomain("low.bar");
|
||||||
action.tlds = ImmutableSet.of("bar");
|
action.tlds = ImmutableSet.of("bar");
|
||||||
|
@ -89,7 +86,7 @@ public class RefreshDnsForAllDomainsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_runAction_smearsOutDnsRefreshes() throws Exception {
|
void test_runAction_smearsOutDnsRefreshes() throws Exception {
|
||||||
persistActiveDomain("foo.bar");
|
persistActiveDomain("foo.bar");
|
||||||
persistActiveDomain("low.bar");
|
persistActiveDomain("low.bar");
|
||||||
action.tlds = ImmutableSet.of("bar");
|
action.tlds = ImmutableSet.of("bar");
|
||||||
|
@ -102,7 +99,7 @@ public class RefreshDnsForAllDomainsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_runAction_doesntRefreshDeletedDomain() throws Exception {
|
void test_runAction_doesntRefreshDeletedDomain() throws Exception {
|
||||||
persistActiveDomain("foo.bar");
|
persistActiveDomain("foo.bar");
|
||||||
persistDeletedDomain("deleted.bar", DateTime.now(UTC).minusYears(1));
|
persistDeletedDomain("deleted.bar", DateTime.now(UTC).minusYears(1));
|
||||||
action.tlds = ImmutableSet.of("bar");
|
action.tlds = ImmutableSet.of("bar");
|
||||||
|
@ -112,7 +109,7 @@ public class RefreshDnsForAllDomainsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_runAction_ignoresDomainsOnOtherTlds() throws Exception {
|
void test_runAction_ignoresDomainsOnOtherTlds() throws Exception {
|
||||||
createTld("baz");
|
createTld("baz");
|
||||||
persistActiveDomain("foo.bar");
|
persistActiveDomain("foo.bar");
|
||||||
persistActiveDomain("low.bar");
|
persistActiveDomain("low.bar");
|
||||||
|
@ -125,7 +122,7 @@ public class RefreshDnsForAllDomainsActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_smearMinutesMustBeSpecified() {
|
void test_smearMinutesMustBeSpecified() {
|
||||||
action.tlds = ImmutableSet.of("bar");
|
action.tlds = ImmutableSet.of("bar");
|
||||||
action.smearMinutes = 0;
|
action.smearMinutes = 0;
|
||||||
IllegalArgumentException thrown =
|
IllegalArgumentException thrown =
|
||||||
|
|
|
@ -28,21 +28,17 @@ import google.registry.model.domain.DomainBase;
|
||||||
import google.registry.model.reporting.HistoryEntry;
|
import google.registry.model.reporting.HistoryEntry;
|
||||||
import google.registry.testing.FakeResponse;
|
import google.registry.testing.FakeResponse;
|
||||||
import google.registry.testing.mapreduce.MapreduceTestCase;
|
import google.registry.testing.mapreduce.MapreduceTestCase;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.junit.runners.JUnit4;
|
|
||||||
|
|
||||||
/** Unit tests for {@link ResaveAllHistoryEntriesAction}. */
|
/** Unit tests for {@link ResaveAllHistoryEntriesAction}. */
|
||||||
@RunWith(JUnit4.class)
|
class ResaveAllHistoryEntriesActionTest extends MapreduceTestCase<ResaveAllHistoryEntriesAction> {
|
||||||
public class ResaveAllHistoryEntriesActionTest
|
|
||||||
extends MapreduceTestCase<ResaveAllHistoryEntriesAction> {
|
|
||||||
|
|
||||||
private static final DatastoreService datastoreService =
|
private static final DatastoreService datastoreService =
|
||||||
DatastoreServiceFactory.getDatastoreService();
|
DatastoreServiceFactory.getDatastoreService();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() {
|
void beforeEach() {
|
||||||
action = new ResaveAllHistoryEntriesAction();
|
action = new ResaveAllHistoryEntriesAction();
|
||||||
action.mrRunner = makeDefaultRunner();
|
action.mrRunner = makeDefaultRunner();
|
||||||
action.response = new FakeResponse();
|
action.response = new FakeResponse();
|
||||||
|
@ -54,7 +50,7 @@ public class ResaveAllHistoryEntriesActionTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_mapreduceSuccessfullyResavesEntity() throws Exception {
|
void test_mapreduceSuccessfullyResavesEntity() throws Exception {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
DomainBase domain = persistActiveDomain("test.tld");
|
DomainBase domain = persistActiveDomain("test.tld");
|
||||||
ContactResource contact = persistActiveContact("humanBeing");
|
ContactResource contact = persistActiveContact("humanBeing");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue