mirror of
https://github.com/google/nomulus.git
synced 2025-07-22 10:46:10 +02:00
Centralize RDAP test initialization and login
All RDAP actions inherit from a common RdapActionBase class. All RDAP search actions inherit from a comman RdapSearchActionBase class, which inherits from RdapActionBase Each of the base classes has @Before initialization needed for the tests, as well as utility functions (such as login and logout). Currently, these were copied in all test classes. Instead, we created a similar test inheritance tree to centralize the initialization and place common utility functions. This way, the @Before of every test only needs to initialize the variables new to the specific action, making the code somewhat clearer. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=217856844
This commit is contained in:
parent
b254269d2f
commit
3a3b0b738a
45 changed files with 456 additions and 758 deletions
|
@ -25,11 +25,8 @@ import static google.registry.testing.FullFieldsTestEntityHelper.makeHistoryEntr
|
|||
import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrar;
|
||||
import static google.registry.testing.FullFieldsTestEntityHelper.makeRegistrarContacts;
|
||||
import static google.registry.testing.TestDataHelper.loadFile;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.appengine.api.users.User;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -37,7 +34,6 @@ import google.registry.model.contact.ContactResource;
|
|||
import google.registry.model.domain.DomainBase;
|
||||
import google.registry.model.domain.Period;
|
||||
import google.registry.model.host.HostResource;
|
||||
import google.registry.model.ofy.Ofy;
|
||||
import google.registry.model.registrar.Registrar;
|
||||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
|
@ -46,61 +42,28 @@ 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.AuthLevel;
|
||||
import google.registry.request.auth.AuthResult;
|
||||
import google.registry.request.auth.UserAuthInfo;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeResponse;
|
||||
import google.registry.testing.InjectRule;
|
||||
import google.registry.ui.server.registrar.AuthenticatedRegistrarAccessor;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joda.time.DateTime;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@link RdapDomainAction}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class RdapDomainActionTest {
|
||||
public class RdapDomainActionTest extends RdapActionBaseTestCase<RdapDomainAction> {
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
private final FakeResponse response = new FakeResponse();
|
||||
private final FakeClock clock = new FakeClock(DateTime.parse("2000-01-01TZ"));
|
||||
private final AuthenticatedRegistrarAccessor registrarAccessor =
|
||||
mock(AuthenticatedRegistrarAccessor.class);
|
||||
private final RdapMetrics rdapMetrics = mock(RdapMetrics.class);
|
||||
|
||||
private RdapDomainAction action;
|
||||
|
||||
private static final AuthResult AUTH_RESULT =
|
||||
AuthResult.create(
|
||||
AuthLevel.USER,
|
||||
UserAuthInfo.create(new User("rdap.user@user.com", "gmail.com", "12345"), false));
|
||||
|
||||
private static final AuthResult AUTH_RESULT_ADMIN =
|
||||
AuthResult.create(
|
||||
AuthLevel.USER,
|
||||
UserAuthInfo.create(new User("rdap.user@google.com", "gmail.com", "12345"), true));
|
||||
public RdapDomainActionTest() {
|
||||
super(RdapDomainAction.class, RdapDomainAction.PATH);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
inject.setStaticField(Ofy.class, "clock", clock);
|
||||
// lol
|
||||
createTld("lol");
|
||||
Registrar registrarLol = persistResource(makeRegistrar(
|
||||
|
@ -265,35 +228,6 @@ public class RdapDomainActionTest {
|
|||
Period.create(1, Period.Unit.YEARS),
|
||||
"deleted",
|
||||
clock.nowUtc().minusMonths(6)));
|
||||
|
||||
action = new RdapDomainAction();
|
||||
action.clock = clock;
|
||||
action.requestMethod = Action.Method.GET;
|
||||
action.fullServletPath = "https://example.com/rdap";
|
||||
action.response = response;
|
||||
action.registrarParam = Optional.empty();
|
||||
action.includeDeletedParam = Optional.empty();
|
||||
action.formatOutputParam = Optional.empty();
|
||||
action.rdapJsonFormatter = RdapTestHelper.getTestRdapJsonFormatter();
|
||||
action.rdapWhoisServer = null;
|
||||
action.registrarAccessor = registrarAccessor;
|
||||
action.authResult = AUTH_RESULT;
|
||||
action.rdapMetrics = rdapMetrics;
|
||||
}
|
||||
|
||||
private void login(String clientId) {
|
||||
when(registrarAccessor.guessClientId()).thenReturn(clientId);
|
||||
}
|
||||
|
||||
private void loginAsAdmin() {
|
||||
when(registrarAccessor.guessClientId()).thenReturn("irrelevant");
|
||||
action.authResult = AUTH_RESULT_ADMIN;
|
||||
}
|
||||
|
||||
private Object generateActualJson(String domainName) {
|
||||
action.requestPath = RdapDomainAction.PATH + domainName;
|
||||
action.run();
|
||||
return JSONValue.parse(response.getPayload());
|
||||
}
|
||||
|
||||
private Object generateExpectedJson(
|
||||
|
@ -400,7 +334,7 @@ public class RdapDomainActionTest {
|
|||
builder,
|
||||
false,
|
||||
RdapTestHelper.createNotices(
|
||||
"https://example.com/rdap/",
|
||||
"https://example.tld/rdap/",
|
||||
(contactRoids == null)
|
||||
? RdapTestHelper.ContactNoticeType.DOMAIN
|
||||
: RdapTestHelper.ContactNoticeType.NONE,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue