mirror of
https://github.com/google/nomulus.git
synced 2025-07-24 03:30:46 +02:00
Simplify some of the RDAP Action classes
Overriding getter methods to change values is a bit overkill when these values are static (don't change based on internal state). Just setting them in the base class' constructor is simpler. Also, we can read the PATH of an Action based on the Annotation instead returning it manually for each Action. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=246135754
This commit is contained in:
parent
99aeedc598
commit
90c53152bf
21 changed files with 81 additions and 204 deletions
|
@ -17,6 +17,7 @@ package google.registry.rdap;
|
|||
import static com.google.common.net.HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.request.Action.Method.GET;
|
||||
import static google.registry.request.Action.Method.HEAD;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.TestDataHelper.loadFile;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
@ -29,6 +30,7 @@ import google.registry.rdap.RdapMetrics.SearchType;
|
|||
import google.registry.rdap.RdapMetrics.WildcardType;
|
||||
import google.registry.rdap.RdapSearchResults.IncompletenessWarningType;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.auth.Auth;
|
||||
import java.util.Optional;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Before;
|
||||
|
@ -41,29 +43,19 @@ import org.junit.runners.JUnit4;
|
|||
public class RdapActionBaseTest extends RdapActionBaseTestCase<RdapActionBaseTest.RdapTestAction> {
|
||||
|
||||
public RdapActionBaseTest() {
|
||||
super(RdapTestAction.class, RdapTestAction.PATH);
|
||||
super(RdapTestAction.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dummy RdapActionBase subclass used for testing.
|
||||
*/
|
||||
/** Dummy RdapActionBase subclass used for testing. */
|
||||
@Action(
|
||||
service = Action.Service.PUBAPI,
|
||||
path = "/rdap/test/",
|
||||
method = {GET, HEAD},
|
||||
auth = Auth.AUTH_PUBLIC_ANONYMOUS)
|
||||
public static class RdapTestAction extends RdapActionBase {
|
||||
|
||||
public static final String PATH = "/rdap/test/";
|
||||
|
||||
@Override
|
||||
public String getHumanReadableObjectTypeName() {
|
||||
return "human-readable string";
|
||||
}
|
||||
|
||||
@Override
|
||||
public EndpointType getEndpointType() {
|
||||
return EndpointType.HELP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionPath() {
|
||||
return PATH;
|
||||
public RdapTestAction() {
|
||||
super("human-readable string", EndpointType.HELP);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -90,7 +82,7 @@ public class RdapActionBaseTest extends RdapActionBaseTestCase<RdapActionBaseTes
|
|||
@Before
|
||||
public void setUp() {
|
||||
createTld("thing");
|
||||
action.fullServletPath = "http://myserver.example.com" + RdapTestAction.PATH;
|
||||
action.fullServletPath = "http://myserver.example.com" + actionPath;
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -188,7 +180,7 @@ public class RdapActionBaseTest extends RdapActionBaseTestCase<RdapActionBaseTes
|
|||
|
||||
@Test
|
||||
public void testUnformatted() {
|
||||
action.requestPath = RdapTestAction.PATH + "no.thing";
|
||||
action.requestPath = actionPath + "no.thing";
|
||||
action.requestMethod = GET;
|
||||
action.run();
|
||||
assertThat(response.getPayload())
|
||||
|
@ -197,7 +189,7 @@ public class RdapActionBaseTest extends RdapActionBaseTestCase<RdapActionBaseTes
|
|||
|
||||
@Test
|
||||
public void testFormatted() {
|
||||
action.requestPath = RdapTestAction.PATH + "no.thing?formatOutput=true";
|
||||
action.requestPath = actionPath + "no.thing?formatOutput=true";
|
||||
action.requestMethod = GET;
|
||||
action.formatOutputParam = Optional.of(true);
|
||||
action.run();
|
||||
|
|
|
@ -27,6 +27,7 @@ import com.google.appengine.api.users.User;
|
|||
import com.google.common.collect.ImmutableSetMultimap;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.Actions;
|
||||
import google.registry.request.auth.AuthLevel;
|
||||
import google.registry.request.auth.AuthResult;
|
||||
import google.registry.request.auth.AuthenticatedRegistrarAccessor;
|
||||
|
@ -79,9 +80,9 @@ public class RdapActionBaseTestCase<A extends RdapActionBase> {
|
|||
protected final String actionPath;
|
||||
protected final Class<A> rdapActionClass;
|
||||
|
||||
protected RdapActionBaseTestCase(Class<A> rdapActionClass, String actionPath) {
|
||||
protected RdapActionBaseTestCase(Class<A> rdapActionClass) {
|
||||
this.rdapActionClass = rdapActionClass;
|
||||
this.actionPath = actionPath;
|
||||
this.actionPath = Actions.getPathForAction(rdapActionClass);
|
||||
}
|
||||
|
||||
@Before
|
||||
|
|
|
@ -59,7 +59,7 @@ import org.junit.runners.JUnit4;
|
|||
public class RdapDomainActionTest extends RdapActionBaseTestCase<RdapDomainAction> {
|
||||
|
||||
public RdapDomainActionTest() {
|
||||
super(RdapDomainAction.class, RdapDomainAction.PATH);
|
||||
super(RdapDomainAction.class);
|
||||
}
|
||||
|
||||
@Before
|
||||
|
|
|
@ -71,7 +71,7 @@ import org.junit.runners.JUnit4;
|
|||
public class RdapDomainSearchActionTest extends RdapSearchActionTestCase<RdapDomainSearchAction> {
|
||||
|
||||
public RdapDomainSearchActionTest() {
|
||||
super(RdapDomainSearchAction.class, RdapDomainSearchAction.PATH);
|
||||
super(RdapDomainSearchAction.class);
|
||||
}
|
||||
|
||||
private Registrar registrar;
|
||||
|
@ -96,7 +96,7 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase<RdapDom
|
|||
|
||||
private Object generateActualJson(
|
||||
RequestType requestType, String paramValue, String cursor) {
|
||||
action.requestPath = RdapDomainSearchAction.PATH;
|
||||
action.requestPath = actionPath;
|
||||
action.requestMethod = POST;
|
||||
String requestTypeParam = null;
|
||||
switch (requestType) {
|
||||
|
@ -829,7 +829,7 @@ public class RdapDomainSearchActionTest extends RdapSearchActionTestCase<RdapDom
|
|||
|
||||
@Test
|
||||
public void testInvalidPath_rejected() {
|
||||
action.requestPath = RdapDomainSearchAction.PATH + "/path";
|
||||
action.requestPath = actionPath + "/path";
|
||||
action.run();
|
||||
assertThat(response.getStatus()).isEqualTo(400);
|
||||
verifyErrorMetrics(SearchType.NONE, Optional.empty(), 400);
|
||||
|
|
|
@ -52,7 +52,7 @@ import org.junit.runners.JUnit4;
|
|||
public class RdapEntityActionTest extends RdapActionBaseTestCase<RdapEntityAction> {
|
||||
|
||||
public RdapEntityActionTest() {
|
||||
super(RdapEntityAction.class, RdapEntityAction.PATH);
|
||||
super(RdapEntityAction.class);
|
||||
}
|
||||
|
||||
private Registrar registrarLol;
|
||||
|
|
|
@ -58,7 +58,7 @@ import org.junit.runners.JUnit4;
|
|||
public class RdapEntitySearchActionTest extends RdapSearchActionTestCase<RdapEntitySearchAction> {
|
||||
|
||||
public RdapEntitySearchActionTest() {
|
||||
super(RdapEntitySearchAction.class, RdapEntitySearchAction.PATH);
|
||||
super(RdapEntitySearchAction.class);
|
||||
}
|
||||
|
||||
private enum QueryType {
|
||||
|
@ -418,7 +418,7 @@ public class RdapEntitySearchActionTest extends RdapSearchActionTestCase<RdapEnt
|
|||
|
||||
@Test
|
||||
public void testInvalidPath_rejected() {
|
||||
action.requestPath = RdapEntitySearchAction.PATH + "/path";
|
||||
action.requestPath = actionPath + "/path";
|
||||
action.run();
|
||||
assertThat(response.getStatus()).isEqualTo(400);
|
||||
verifyErrorMetrics(Optional.empty(), 400);
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.junit.Test;
|
|||
public class RdapHelpActionTest extends RdapActionBaseTestCase<RdapHelpAction> {
|
||||
|
||||
public RdapHelpActionTest() {
|
||||
super(RdapHelpAction.class, RdapHelpAction.PATH);
|
||||
super(RdapHelpAction.class);
|
||||
}
|
||||
|
||||
private Object generateExpectedJson(String name, String expectedOutputFile) {
|
||||
|
|
|
@ -45,7 +45,7 @@ import org.junit.runners.JUnit4;
|
|||
public class RdapNameserverActionTest extends RdapActionBaseTestCase<RdapNameserverAction> {
|
||||
|
||||
public RdapNameserverActionTest() {
|
||||
super(RdapNameserverAction.class, RdapNameserverAction.PATH);
|
||||
super(RdapNameserverAction.class);
|
||||
}
|
||||
|
||||
@Before
|
||||
|
|
|
@ -58,7 +58,7 @@ public class RdapNameserverSearchActionTest
|
|||
extends RdapSearchActionTestCase<RdapNameserverSearchAction> {
|
||||
|
||||
public RdapNameserverSearchActionTest() {
|
||||
super(RdapNameserverSearchAction.class, RdapNameserverSearchAction.PATH);
|
||||
super(RdapNameserverSearchAction.class);
|
||||
}
|
||||
|
||||
private DomainBase domainCatLol;
|
||||
|
@ -263,7 +263,7 @@ public class RdapNameserverSearchActionTest
|
|||
|
||||
@Test
|
||||
public void testInvalidPath_rejected() {
|
||||
action.requestPath = RdapDomainSearchAction.PATH + "/path";
|
||||
action.requestPath = actionPath + "/path";
|
||||
action.run();
|
||||
assertThat(response.getStatus()).isEqualTo(400);
|
||||
verifyErrorMetrics(Optional.empty(), 400);
|
||||
|
|
|
@ -30,8 +30,8 @@ import org.junit.Before;
|
|||
public class RdapSearchActionTestCase<A extends RdapSearchActionBase>
|
||||
extends RdapActionBaseTestCase<A> {
|
||||
|
||||
protected RdapSearchActionTestCase(Class<A> rdapActionClass, String path) {
|
||||
super(rdapActionClass, path);
|
||||
protected RdapSearchActionTestCase(Class<A> rdapActionClass) {
|
||||
super(rdapActionClass);
|
||||
}
|
||||
|
||||
SearchType metricSearchType = SearchType.NONE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue