mirror of
https://github.com/google/nomulus.git
synced 2025-05-01 20:47:52 +02:00
The only remaining methods on ExceptionRule after this are methods that also exist on ExpectedException, which will allow us to, in the next CL, swap out the one for the other and then run the automated refactoring to turn it all into assertThrows/expectThrows. Note that there were some assertions about root causes that couldn't easily be turned into ExpectedException invocations, so I simply converted them directly to usages of assertThrows/expectThrows. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=178623431
97 lines
2.9 KiB
Java
97 lines
2.9 KiB
Java
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package google.registry.dns;
|
|
|
|
import static google.registry.testing.DatastoreHelper.createTld;
|
|
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
|
|
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
|
|
|
import google.registry.testing.AppEngineRule;
|
|
import google.registry.testing.ExceptionRule;
|
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
|
import org.junit.Before;
|
|
import org.junit.Rule;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runners.JUnit4;
|
|
|
|
/** Unit tests for {@link DnsQueue}. */
|
|
@RunWith(JUnit4.class)
|
|
public class DnsQueueTest {
|
|
|
|
@Rule
|
|
public final AppEngineRule appEngine = AppEngineRule.builder()
|
|
.withDatastore()
|
|
.withTaskQueue()
|
|
.build();
|
|
|
|
@Rule
|
|
public final ExceptionRule thrown = new ExceptionRule();
|
|
|
|
private DnsQueue dnsQueue;
|
|
|
|
@Before
|
|
public void init() {
|
|
dnsQueue = DnsQueue.create();
|
|
dnsQueue.leaseTasksBatchSize = 10;
|
|
}
|
|
|
|
@Test
|
|
public void test_addHostRefreshTask_success() throws Exception {
|
|
createTld("tld");
|
|
dnsQueue.addHostRefreshTask("octopus.tld");
|
|
assertTasksEnqueued(
|
|
"dns-pull",
|
|
new TaskMatcher()
|
|
.param("Target-Type", "HOST")
|
|
.param("Target-Name", "octopus.tld")
|
|
.param("tld", "tld"));
|
|
}
|
|
|
|
@Test
|
|
public void test_addHostRefreshTask_failsOnUnknownTld() throws Exception {
|
|
thrown.expect(IllegalArgumentException.class);
|
|
thrown.expectMessage("octopus.notatld is not a subordinate host to a known tld");
|
|
try {
|
|
dnsQueue.addHostRefreshTask("octopus.notatld");
|
|
} finally {
|
|
assertNoTasksEnqueued("dns-pull");
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void test_addDomainRefreshTask_success() throws Exception {
|
|
createTld("tld");
|
|
dnsQueue.addDomainRefreshTask("octopus.tld");
|
|
assertTasksEnqueued(
|
|
"dns-pull",
|
|
new TaskMatcher()
|
|
.param("Target-Type", "DOMAIN")
|
|
.param("Target-Name", "octopus.tld")
|
|
.param("tld", "tld"));
|
|
}
|
|
|
|
@Test
|
|
public void test_addDomainRefreshTask_failsOnUnknownTld() throws Exception {
|
|
thrown.expect(IllegalArgumentException.class);
|
|
thrown.expectMessage("TLD notatld does not exist");
|
|
try {
|
|
dnsQueue.addDomainRefreshTask("fake.notatld");
|
|
} finally {
|
|
assertNoTasksEnqueued("dns-pull");
|
|
}
|
|
}
|
|
}
|
|
|