mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
Switch to constructor injection in a few actions
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=232552406
This commit is contained in:
parent
927e8bbd73
commit
29d3ad8052
5 changed files with 49 additions and 50 deletions
|
@ -38,11 +38,22 @@ import javax.inject.Inject;
|
|||
auth = Auth.AUTH_INTERNAL_ONLY)
|
||||
public final class RefreshDnsAction implements Runnable {
|
||||
|
||||
@Inject Clock clock;
|
||||
@Inject DnsQueue dnsQueue;
|
||||
@Inject @Parameter("domainOrHostName") String domainOrHostName;
|
||||
@Inject @Parameter("type") TargetType type;
|
||||
@Inject RefreshDnsAction() {}
|
||||
private final Clock clock;
|
||||
private final DnsQueue dnsQueue;
|
||||
private final String domainOrHostName;
|
||||
private final TargetType type;
|
||||
|
||||
@Inject
|
||||
RefreshDnsAction(
|
||||
@Parameter("domainOrHostName") String domainOrHostName,
|
||||
@Parameter("type") TargetType type,
|
||||
Clock clock,
|
||||
DnsQueue dnsQueue) {
|
||||
this.domainOrHostName = domainOrHostName;
|
||||
this.type = type;
|
||||
this.clock = clock;
|
||||
this.dnsQueue = dnsQueue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -58,9 +58,14 @@ public class DeleteEntityAction implements Runnable {
|
|||
public static final String PATH = "/_dr/admin/deleteEntity";
|
||||
public static final String PARAM_RAW_KEYS = "rawKeys";
|
||||
|
||||
@Inject @Parameter(PARAM_RAW_KEYS) String rawKeys;
|
||||
@Inject Response response;
|
||||
@Inject DeleteEntityAction() {}
|
||||
private final String rawKeys;
|
||||
private final Response response;
|
||||
|
||||
@Inject
|
||||
DeleteEntityAction(@Parameter(PARAM_RAW_KEYS) String rawKeys, Response response) {
|
||||
this.rawKeys = rawKeys;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -41,20 +41,14 @@ import org.junit.runners.JUnit4;
|
|||
public class RefreshDnsActionTest {
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.withTaskQueue()
|
||||
.build();
|
||||
public final AppEngineRule appEngine =
|
||||
AppEngineRule.builder().withDatastore().withTaskQueue().build();
|
||||
|
||||
private final DnsQueue dnsQueue = mock(DnsQueue.class);
|
||||
private final FakeClock clock = new FakeClock();
|
||||
|
||||
private void run(TargetType type, String name) {
|
||||
RefreshDnsAction action = new RefreshDnsAction();
|
||||
action.clock = clock;
|
||||
action.domainOrHostName = name;
|
||||
action.type = type;
|
||||
action.dnsQueue = dnsQueue;
|
||||
action.run();
|
||||
new RefreshDnsAction(name, type, clock, dnsQueue).run();
|
||||
}
|
||||
|
||||
@Before
|
||||
|
|
|
@ -60,7 +60,10 @@ public final class FakeResponse implements Response {
|
|||
|
||||
@Override
|
||||
public void setContentType(MediaType contentType) {
|
||||
checkArgument(payload.isEmpty(), "setContentType must be called before setPayload");
|
||||
checkArgument(
|
||||
payload.isEmpty(),
|
||||
"setContentType must be called before setPayload; payload is: %s",
|
||||
payload);
|
||||
this.contentType = checkNotNull(contentType);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ import google.registry.model.registry.label.ReservedList;
|
|||
import google.registry.request.HttpException.BadRequestException;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.FakeResponse;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -36,34 +35,23 @@ import org.junit.runners.JUnit4;
|
|||
@RunWith(JUnit4.class)
|
||||
public class DeleteEntityActionTest {
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||
FakeResponse response = new FakeResponse();
|
||||
DeleteEntityAction action = new DeleteEntityAction();
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
action.response = response;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_deleteSingleRawEntitySuccessfully() {
|
||||
Entity entity = new Entity("single", "raw");
|
||||
getDatastoreService().put(entity);
|
||||
action.rawKeys = KeyFactory.keyToString(entity.getKey());
|
||||
action.run();
|
||||
assertThat(response.getPayload())
|
||||
.isEqualTo("Deleted 1 raw entities and 0 registered entities");
|
||||
new DeleteEntityAction(KeyFactory.keyToString(entity.getKey()), response).run();
|
||||
assertThat(response.getPayload()).isEqualTo("Deleted 1 raw entities and 0 registered entities");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_deleteSingleRegisteredEntitySuccessfully() {
|
||||
ReservedList ofyEntity = new ReservedList.Builder().setName("foo").build();
|
||||
ofy().saveWithoutBackup().entity(ofyEntity).now();
|
||||
action.rawKeys = KeyFactory.keyToString(create(ofyEntity).getRaw());
|
||||
action.run();
|
||||
assertThat(response.getPayload())
|
||||
.isEqualTo("Deleted 0 raw entities and 1 registered entities");
|
||||
new DeleteEntityAction(KeyFactory.keyToString(create(ofyEntity).getRaw()), response).run();
|
||||
assertThat(response.getPayload()).isEqualTo("Deleted 0 raw entities and 1 registered entities");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -71,10 +59,8 @@ public class DeleteEntityActionTest {
|
|||
Entity entity = new Entity("single", "raw");
|
||||
entity.setIndexedProperty("^d", "UnregType");
|
||||
getDatastoreService().put(entity);
|
||||
action.rawKeys = KeyFactory.keyToString(entity.getKey());
|
||||
action.run();
|
||||
assertThat(response.getPayload())
|
||||
.isEqualTo("Deleted 1 raw entities and 0 registered entities");
|
||||
new DeleteEntityAction(KeyFactory.keyToString(entity.getKey()), response).run();
|
||||
assertThat(response.getPayload()).isEqualTo("Deleted 1 raw entities and 0 registered entities");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -85,18 +71,17 @@ public class DeleteEntityActionTest {
|
|||
ReservedList ofyEntity = new ReservedList.Builder().setName("registered").build();
|
||||
ofy().saveWithoutBackup().entity(ofyEntity).now();
|
||||
String ofyKey = KeyFactory.keyToString(create(ofyEntity).getRaw());
|
||||
action.rawKeys = String.format("%s,%s", rawKey, ofyKey);
|
||||
action.run();
|
||||
assertThat(response.getPayload())
|
||||
.isEqualTo("Deleted 1 raw entities and 1 registered entities");
|
||||
new DeleteEntityAction(String.format("%s,%s", rawKey, ofyKey), response).run();
|
||||
assertThat(response.getPayload()).isEqualTo("Deleted 1 raw entities and 1 registered entities");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_deleteNonExistentEntityRepliesWithError() {
|
||||
Entity entity = new Entity("not", "here");
|
||||
String rawKey = KeyFactory.keyToString(entity.getKey());
|
||||
action.rawKeys = rawKey;
|
||||
BadRequestException thrown = assertThrows(BadRequestException.class, action::run);
|
||||
BadRequestException thrown =
|
||||
assertThrows(
|
||||
BadRequestException.class, () -> new DeleteEntityAction(rawKey, response).run());
|
||||
assertThat(thrown).hasMessageThat().contains("Could not find entity with key " + rawKey);
|
||||
}
|
||||
|
||||
|
@ -105,10 +90,11 @@ public class DeleteEntityActionTest {
|
|||
ReservedList ofyEntity = new ReservedList.Builder().setName("first_registered").build();
|
||||
ofy().saveWithoutBackup().entity(ofyEntity).now();
|
||||
String ofyKey = KeyFactory.keyToString(create(ofyEntity).getRaw());
|
||||
Entity entity = new Entity("non", "existent");
|
||||
String rawKey = KeyFactory.keyToString(entity.getKey());
|
||||
action.rawKeys = String.format("%s,%s", ofyKey, rawKey);
|
||||
BadRequestException thrown = assertThrows(BadRequestException.class, action::run);
|
||||
String rawKey = KeyFactory.keyToString(new Entity("non", "existent").getKey());
|
||||
BadRequestException thrown =
|
||||
assertThrows(
|
||||
BadRequestException.class,
|
||||
() -> new DeleteEntityAction(String.format("%s,%s", ofyKey, rawKey), response).run());
|
||||
assertThat(thrown).hasMessageThat().contains("Could not find entity with key " + rawKey);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue