mirror of
https://github.com/google/nomulus.git
synced 2025-08-04 00:42:12 +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
|
@ -14,26 +14,39 @@
|
|||
|
||||
package google.registry.rdap;
|
||||
|
||||
import static google.registry.rdap.RdapAuthorization.Role.PUBLIC;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
import google.registry.rdap.RdapMetrics.EndpointType;
|
||||
import google.registry.rdap.RdapMetrics.SearchType;
|
||||
import google.registry.rdap.RdapMetrics.WildcardType;
|
||||
import google.registry.rdap.RdapSearchResults.IncompletenessWarningType;
|
||||
import google.registry.request.Action;
|
||||
import java.util.Optional;
|
||||
import org.junit.Before;
|
||||
|
||||
public class RdapSearchActionTestCase {
|
||||
/** Common unit test code for actions inheriting {@link RdapSearchActionBase}. */
|
||||
public class RdapSearchActionTestCase<A extends RdapSearchActionBase>
|
||||
extends RdapActionBaseTestCase<A> {
|
||||
|
||||
protected RdapSearchActionTestCase(Class<A> rdapActionClass, String path) {
|
||||
super(rdapActionClass, path);
|
||||
}
|
||||
|
||||
RdapAuthorization.Role metricRole = PUBLIC;
|
||||
SearchType metricSearchType = SearchType.NONE;
|
||||
WildcardType metricWildcardType = WildcardType.INVALID;
|
||||
int metricPrefixLength = 0;
|
||||
int metricStatusCode = SC_OK;
|
||||
final RdapMetrics rdapMetrics = mock(RdapMetrics.class);
|
||||
|
||||
@Before
|
||||
public void initRdapSearchActionTestCase() {
|
||||
action.parameterMap = ImmutableListMultimap.of();
|
||||
action.cursorTokenParam = Optional.empty();
|
||||
action.rdapResultSetMaxSize = 4;
|
||||
action.requestUrl = "https://example.tld" + actionPath;
|
||||
action.requestPath = actionPath;
|
||||
}
|
||||
|
||||
void rememberWildcardType(String queryString) {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue