mirror of
https://github.com/google/nomulus.git
synced 2025-05-18 02:09:35 +02:00
Upgrade prober & proxy packages from JUnit 4 to JUnit 5 (#734)
* Upgrade prober & proxy packages from JUnit 4 to JUnit 5
This commit is contained in:
parent
090c233592
commit
e95ce30fa6
67 changed files with 358 additions and 3137 deletions
|
@ -75,10 +75,9 @@ dependencies {
|
|||
testCompile deps['com.google.monitoring-client:contrib']
|
||||
testCompile deps['com.google.truth:truth']
|
||||
testCompile deps['org.yaml:snakeyaml']
|
||||
testCompile deps['junit:junit']
|
||||
testCompile deps['org.junit.jupiter:junit-jupiter-api']
|
||||
testCompile deps['org.junit.jupiter:junit-jupiter-engine']
|
||||
testCompile deps['org.junit.vintage:junit-vintage-engine']
|
||||
testCompile deps['org.junit.jupiter:junit-jupiter-params']
|
||||
testCompile deps['org.mockito:mockito-core']
|
||||
testCompile project(path: ':common', configuration: 'testing')
|
||||
testCompile project(path: ':networking', configuration: 'testRuntime')
|
||||
|
|
|
@ -52,7 +52,7 @@ javax.inject:javax.inject:1
|
|||
javax.mail:mail:1.4
|
||||
javax.xml.bind:jaxb-api:2.3.0
|
||||
joda-time:joda-time:2.9.2
|
||||
junit:junit:4.13
|
||||
junit:junit:4.12
|
||||
net.bytebuddy:byte-buddy-agent:1.10.5
|
||||
net.bytebuddy:byte-buddy:1.10.5
|
||||
org.apache.httpcomponents:httpclient:4.5.11
|
||||
|
@ -68,7 +68,6 @@ org.junit.jupiter:junit-jupiter-engine:5.6.2
|
|||
org.junit.jupiter:junit-jupiter-params:5.6.2
|
||||
org.junit.platform:junit-platform-commons:1.6.2
|
||||
org.junit.platform:junit-platform-engine:1.6.2
|
||||
org.junit.vintage:junit-vintage-engine:5.6.2
|
||||
org.junit:junit-bom:5.6.2
|
||||
org.mockito:mockito-core:3.3.3
|
||||
org.objenesis:objenesis:2.6
|
||||
|
|
|
@ -52,7 +52,7 @@ javax.inject:javax.inject:1
|
|||
javax.mail:mail:1.4
|
||||
javax.xml.bind:jaxb-api:2.3.0
|
||||
joda-time:joda-time:2.9.2
|
||||
junit:junit:4.13
|
||||
junit:junit:4.12
|
||||
net.bytebuddy:byte-buddy-agent:1.10.5
|
||||
net.bytebuddy:byte-buddy:1.10.5
|
||||
org.apache.httpcomponents:httpclient:4.5.11
|
||||
|
@ -68,7 +68,6 @@ org.junit.jupiter:junit-jupiter-engine:5.6.2
|
|||
org.junit.jupiter:junit-jupiter-params:5.6.2
|
||||
org.junit.platform:junit-platform-commons:1.6.2
|
||||
org.junit.platform:junit-platform-engine:1.6.2
|
||||
org.junit.vintage:junit-vintage-engine:5.6.2
|
||||
org.junit:junit-bom:5.6.2
|
||||
org.mockito:mockito-core:3.3.3
|
||||
org.objenesis:objenesis:2.6
|
||||
|
|
|
@ -52,7 +52,7 @@ javax.inject:javax.inject:1
|
|||
javax.mail:mail:1.4
|
||||
javax.xml.bind:jaxb-api:2.3.0
|
||||
joda-time:joda-time:2.9.2
|
||||
junit:junit:4.13
|
||||
junit:junit:4.12
|
||||
net.bytebuddy:byte-buddy-agent:1.10.5
|
||||
net.bytebuddy:byte-buddy:1.10.5
|
||||
org.apache.httpcomponents:httpclient:4.5.11
|
||||
|
@ -68,7 +68,6 @@ org.junit.jupiter:junit-jupiter-engine:5.6.2
|
|||
org.junit.jupiter:junit-jupiter-params:5.6.2
|
||||
org.junit.platform:junit-platform-commons:1.6.2
|
||||
org.junit.platform:junit-platform-engine:1.6.2
|
||||
org.junit.vintage:junit-vintage-engine:5.6.2
|
||||
org.junit:junit-bom:5.6.2
|
||||
org.mockito:mockito-core:3.3.3
|
||||
org.objenesis:objenesis:2.6
|
||||
|
|
|
@ -52,7 +52,7 @@ javax.inject:javax.inject:1
|
|||
javax.mail:mail:1.4
|
||||
javax.xml.bind:jaxb-api:2.3.0
|
||||
joda-time:joda-time:2.9.2
|
||||
junit:junit:4.13
|
||||
junit:junit:4.12
|
||||
net.bytebuddy:byte-buddy-agent:1.10.5
|
||||
net.bytebuddy:byte-buddy:1.10.5
|
||||
org.apache.httpcomponents:httpclient:4.5.11
|
||||
|
@ -68,7 +68,6 @@ org.junit.jupiter:junit-jupiter-engine:5.6.2
|
|||
org.junit.jupiter:junit-jupiter-params:5.6.2
|
||||
org.junit.platform:junit-platform-commons:1.6.2
|
||||
org.junit.platform:junit-platform-engine:1.6.2
|
||||
org.junit.vintage:junit-vintage-engine:5.6.2
|
||||
org.junit:junit-bom:5.6.2
|
||||
org.mockito:mockito-core:3.3.3
|
||||
org.objenesis:objenesis:2.6
|
||||
|
|
|
@ -37,14 +37,11 @@ import io.netty.handler.codec.http.cookie.Cookie;
|
|||
import io.netty.handler.codec.http.cookie.DefaultCookie;
|
||||
import io.netty.util.concurrent.Promise;
|
||||
import java.security.cert.X509Certificate;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** End-to-end tests for {@link EppProtocolModule}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class EppProtocolModuleTest extends ProtocolModuleTest {
|
||||
class EppProtocolModuleTest extends ProtocolModuleTest {
|
||||
|
||||
private static final int HEADER_LENGTH = 4;
|
||||
|
||||
|
@ -59,7 +56,7 @@ public class EppProtocolModuleTest extends ProtocolModuleTest {
|
|||
|
||||
private X509Certificate certificate;
|
||||
|
||||
public EppProtocolModuleTest() {
|
||||
EppProtocolModuleTest() {
|
||||
super(TestComponent::eppHandlers);
|
||||
}
|
||||
|
||||
|
@ -119,9 +116,9 @@ public class EppProtocolModuleTest extends ProtocolModuleTest {
|
|||
return TestUtils.makeEppHttpResponse(new String(content, UTF_8), status, cookies);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
void beforeEach() throws Exception {
|
||||
testComponent = makeTestComponent(new FakeClock());
|
||||
certificate = SelfSignedCaCertificate.create().cert();
|
||||
initializeChannel(
|
||||
|
@ -135,7 +132,7 @@ public class EppProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_singleFrameInboundMessage() throws Exception {
|
||||
void testSuccess_singleFrameInboundMessage() throws Exception {
|
||||
// First inbound message is hello.
|
||||
assertThat((FullHttpRequest) channel.readInbound()).isEqualTo(makeEppHttpRequest(HELLO_BYTES));
|
||||
|
||||
|
@ -151,7 +148,7 @@ public class EppProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_SingleFrame_MultipleInboundMessages() throws Exception {
|
||||
void testSuccess_SingleFrame_MultipleInboundMessages() throws Exception {
|
||||
// First inbound message is hello.
|
||||
channel.readInbound();
|
||||
|
||||
|
@ -173,7 +170,7 @@ public class EppProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_MultipleFrames_MultipleInboundMessages() throws Exception {
|
||||
void testSuccess_MultipleFrames_MultipleInboundMessages() throws Exception {
|
||||
// First inbound message is hello.
|
||||
channel.readInbound();
|
||||
|
||||
|
@ -201,7 +198,7 @@ public class EppProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_simpleOutboundMessage() throws Exception {
|
||||
void testSuccess_simpleOutboundMessage() throws Exception {
|
||||
// First inbound message is hello.
|
||||
channel.readInbound();
|
||||
|
||||
|
@ -217,7 +214,7 @@ public class EppProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_nonOkOutboundMessage() throws Exception {
|
||||
void testFailure_nonOkOutboundMessage() throws Exception {
|
||||
// First inbound message is hello.
|
||||
channel.readInbound();
|
||||
|
||||
|
@ -239,7 +236,7 @@ public class EppProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_setAndReadCookies() throws Exception {
|
||||
void testSuccess_setAndReadCookies() throws Exception {
|
||||
// First inbound message is hello.
|
||||
channel.readInbound();
|
||||
|
||||
|
|
|
@ -19,14 +19,11 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import com.google.common.base.Joiner;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link google.registry.proxy.GcpJsonFormatter}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class GcpJsonFormatterTest {
|
||||
class GcpJsonFormatterTest {
|
||||
|
||||
private static final String LOGGER_NAME = "example.company.app.logger";
|
||||
private static final String SOURCE_CLASS_NAME = "example.company.app.component.Doer";
|
||||
|
@ -55,20 +52,20 @@ public class GcpJsonFormatterTest {
|
|||
return "\"" + content.replaceAll("\n", "\\\\n") + "\"";
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
logRecord.setLoggerName(LOGGER_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess() {
|
||||
void testSuccess() {
|
||||
String actual = formatter.format(logRecord);
|
||||
String expected = makeJson("WARNING", LOGGER_NAME, MESSAGE);
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_sourceClassAndMethod() {
|
||||
void testSuccess_sourceClassAndMethod() {
|
||||
logRecord.setSourceClassName(SOURCE_CLASS_NAME);
|
||||
logRecord.setSourceMethodName(SOURCE_METHOD_NAME);
|
||||
String actual = formatter.format(logRecord);
|
||||
|
@ -77,7 +74,7 @@ public class GcpJsonFormatterTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_multilineMessage() {
|
||||
void testSuccess_multilineMessage() {
|
||||
String multilineMessage = "First line message\nSecond line message\n";
|
||||
logRecord.setMessage(multilineMessage);
|
||||
String actual = formatter.format(logRecord);
|
||||
|
@ -86,7 +83,7 @@ public class GcpJsonFormatterTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_withCause() {
|
||||
void testSuccess_withCause() {
|
||||
Throwable throwable = new Throwable("Some reason");
|
||||
StackTraceElement[] stacktrace = {
|
||||
new StackTraceElement("class1", "method1", "file1", 5),
|
||||
|
|
|
@ -19,20 +19,17 @@ import static java.nio.charset.StandardCharsets.US_ASCII;
|
|||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** End-to-end tests for {@link HealthCheckProtocolModule}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class HealthCheckProtocolModuleTest extends ProtocolModuleTest {
|
||||
class HealthCheckProtocolModuleTest extends ProtocolModuleTest {
|
||||
|
||||
public HealthCheckProtocolModuleTest() {
|
||||
HealthCheckProtocolModuleTest() {
|
||||
super(TestComponent::healthCheckHandlers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_expectedInboundMessage() {
|
||||
void testSuccess_expectedInboundMessage() {
|
||||
// no inbound message passed along.
|
||||
assertThat(
|
||||
channel.writeInbound(
|
||||
|
@ -47,7 +44,7 @@ public class HealthCheckProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_InboundMessageTooShort() {
|
||||
void testSuccess_InboundMessageTooShort() {
|
||||
String shortRequest = "HEALTH_CHECK";
|
||||
// no inbound message passed along.
|
||||
assertThat(channel.writeInbound(Unpooled.wrappedBuffer(shortRequest.getBytes(US_ASCII))))
|
||||
|
@ -58,7 +55,7 @@ public class HealthCheckProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_InboundMessageTooLong() {
|
||||
void testSuccess_InboundMessageTooLong() {
|
||||
String longRequest = "HEALTH_CHECK_REQUEST HELLO";
|
||||
// no inbound message passed along.
|
||||
assertThat(channel.writeInbound(Unpooled.wrappedBuffer(longRequest.getBytes(US_ASCII))))
|
||||
|
@ -76,7 +73,7 @@ public class HealthCheckProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_InboundMessageNotMatch() {
|
||||
void testSuccess_InboundMessageNotMatch() {
|
||||
String invalidRequest = "HEALTH_CHECK_REQUESX";
|
||||
// no inbound message passed along.
|
||||
assertThat(channel.writeInbound(Unpooled.wrappedBuffer(invalidRequest.getBytes(US_ASCII))))
|
||||
|
|
|
@ -27,9 +27,7 @@ import io.netty.handler.codec.http.FullHttpResponse;
|
|||
import io.netty.handler.codec.http.HttpObjectAggregator;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.handler.codec.http.HttpServerCodec;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* End-to-end tests for {@link HttpsRelayProtocolModule}.
|
||||
|
@ -45,8 +43,7 @@ import org.junit.runners.JUnit4;
|
|||
* handlers that deal with HTTP protocol, but not whether the handlers converts between bytes and
|
||||
* HTTP messages correctly, which is presumed correct.
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class HttpsRelayProtocolModuleTest extends ProtocolModuleTest {
|
||||
class HttpsRelayProtocolModuleTest extends ProtocolModuleTest {
|
||||
|
||||
private static final String HOST = "test.tld";
|
||||
private static final String PATH = "/path/to/test";
|
||||
|
@ -55,7 +52,7 @@ public class HttpsRelayProtocolModuleTest extends ProtocolModuleTest {
|
|||
private final EmbeddedChannel serverChannel =
|
||||
new EmbeddedChannel(new HttpServerCodec(), new HttpObjectAggregator(512 * 1024));
|
||||
|
||||
public HttpsRelayProtocolModuleTest() {
|
||||
HttpsRelayProtocolModuleTest() {
|
||||
super(TestComponent::httpsRelayHandlers);
|
||||
}
|
||||
|
||||
|
@ -92,12 +89,12 @@ public class HttpsRelayProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_OkResponse() {
|
||||
void testSuccess_OkResponse() {
|
||||
requestAndRespondWithStatus(HttpResponseStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_NonOkResponse() {
|
||||
void testSuccess_NonOkResponse() {
|
||||
requestAndRespondWithStatus(HttpResponseStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ import java.util.function.Supplier;
|
|||
import javax.inject.Named;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
import org.junit.Before;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
/**
|
||||
* Base class for end-to-end tests of a {@link Protocol}.
|
||||
|
@ -78,9 +78,9 @@ import org.junit.Before;
|
|||
*/
|
||||
public abstract class ProtocolModuleTest {
|
||||
|
||||
protected static final ProxyConfig PROXY_CONFIG = getProxyConfig(Environment.LOCAL);
|
||||
static final ProxyConfig PROXY_CONFIG = getProxyConfig(Environment.LOCAL);
|
||||
|
||||
protected TestComponent testComponent;
|
||||
TestComponent testComponent;
|
||||
|
||||
/**
|
||||
* Default list of handler classes that are not of interest in end-to-end testing of the {@link
|
||||
|
@ -122,10 +122,10 @@ public abstract class ProtocolModuleTest {
|
|||
* Method reference to the component method that exposes the list of handler providers for the
|
||||
* specific {@link Protocol} in interest.
|
||||
*/
|
||||
protected final Function<TestComponent, ImmutableList<Provider<? extends ChannelHandler>>>
|
||||
private final Function<TestComponent, ImmutableList<Provider<? extends ChannelHandler>>>
|
||||
handlerProvidersMethod;
|
||||
|
||||
protected final ImmutableSet<Class<? extends ChannelHandler>> excludedHandlers;
|
||||
private final ImmutableSet<Class<? extends ChannelHandler>> excludedHandlers;
|
||||
|
||||
protected ProtocolModuleTest(
|
||||
Function<TestComponent, ImmutableList<Provider<? extends ChannelHandler>>>
|
||||
|
@ -149,7 +149,7 @@ public abstract class ProtocolModuleTest {
|
|||
.collect(toImmutableList());
|
||||
}
|
||||
|
||||
protected void initializeChannel(Consumer<Channel> initializer) {
|
||||
void initializeChannel(Consumer<Channel> initializer) {
|
||||
channel =
|
||||
new EmbeddedChannel(
|
||||
new ChannelInitializer<Channel>() {
|
||||
|
@ -174,8 +174,8 @@ public abstract class ProtocolModuleTest {
|
|||
.build();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void beforeEach() throws Exception {
|
||||
testComponent = makeTestComponent(new FakeClock());
|
||||
initializeChannel(this::addAllTestableHandlers);
|
||||
}
|
||||
|
@ -196,6 +196,7 @@ public abstract class ProtocolModuleTest {
|
|||
HttpsRelayProtocolModule.class
|
||||
})
|
||||
interface TestComponent {
|
||||
|
||||
@WhoisProtocol
|
||||
ImmutableList<Provider<? extends ChannelHandler>> whoisHandlers();
|
||||
|
||||
|
|
|
@ -21,19 +21,16 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||
|
||||
import com.beust.jcommander.ParameterException;
|
||||
import google.registry.proxy.ProxyConfig.Environment;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link ProxyModule}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class ProxyModuleTest {
|
||||
class ProxyModuleTest {
|
||||
|
||||
private static final ProxyConfig PROXY_CONFIG = getProxyConfig(LOCAL);
|
||||
private final ProxyModule proxyModule = new ProxyModule();
|
||||
|
||||
@Test
|
||||
public void testSuccess_parseArgs_defaultArgs() {
|
||||
void testSuccess_parseArgs_defaultArgs() {
|
||||
String[] args = {};
|
||||
proxyModule.parse(args);
|
||||
assertThat(proxyModule.provideWhoisPort(PROXY_CONFIG)).isEqualTo(PROXY_CONFIG.whois.port);
|
||||
|
@ -49,7 +46,7 @@ public class ProxyModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_parseArgs_loggingInProduction() {
|
||||
void testFailure_parseArgs_loggingInProduction() {
|
||||
String[] args = {"--env", "production", "--log"};
|
||||
IllegalArgumentException e =
|
||||
assertThrows(
|
||||
|
@ -63,7 +60,7 @@ public class ProxyModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_parseArgs_wrongArguments() {
|
||||
void testFailure_parseArgs_wrongArguments() {
|
||||
String[] args = {"--wrong_flag", "some_value"};
|
||||
ParameterException thrown =
|
||||
assertThrows(ParameterException.class, () -> proxyModule.parse(args));
|
||||
|
@ -71,56 +68,56 @@ public class ProxyModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_parseArgs_log() {
|
||||
void testSuccess_parseArgs_log() {
|
||||
String[] args = {"--log"};
|
||||
proxyModule.parse(args);
|
||||
assertThat(proxyModule.log).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_parseArgs_customWhoisPort() {
|
||||
void testSuccess_parseArgs_customWhoisPort() {
|
||||
String[] args = {"--whois", "12345"};
|
||||
proxyModule.parse(args);
|
||||
assertThat(proxyModule.provideWhoisPort(PROXY_CONFIG)).isEqualTo(12345);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_parseArgs_customEppPort() {
|
||||
void testSuccess_parseArgs_customEppPort() {
|
||||
String[] args = {"--epp", "22222"};
|
||||
proxyModule.parse(args);
|
||||
assertThat(proxyModule.provideEppPort(PROXY_CONFIG)).isEqualTo(22222);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_parseArgs_customHealthCheckPort() {
|
||||
void testSuccess_parseArgs_customHealthCheckPort() {
|
||||
String[] args = {"--health_check", "23456"};
|
||||
proxyModule.parse(args);
|
||||
assertThat(proxyModule.provideHealthCheckPort(PROXY_CONFIG)).isEqualTo(23456);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_parseArgs_customhttpWhoisPort() {
|
||||
void testSuccess_parseArgs_customhttpWhoisPort() {
|
||||
String[] args = {"--http_whois", "12121"};
|
||||
proxyModule.parse(args);
|
||||
assertThat(proxyModule.provideHttpWhoisProtocol(PROXY_CONFIG)).isEqualTo(12121);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_parseArgs_customhttpsWhoisPort() {
|
||||
void testSuccess_parseArgs_customhttpsWhoisPort() {
|
||||
String[] args = {"--https_whois", "21212"};
|
||||
proxyModule.parse(args);
|
||||
assertThat(proxyModule.provideHttpsWhoisProtocol(PROXY_CONFIG)).isEqualTo(21212);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_parseArgs_customEnvironment() {
|
||||
void testSuccess_parseArgs_customEnvironment() {
|
||||
String[] args = {"--env", "ALpHa"};
|
||||
proxyModule.parse(args);
|
||||
assertThat(proxyModule.provideEnvironment()).isEqualTo(Environment.ALPHA);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_parseArgs_wrongEnvironment() {
|
||||
void testFailure_parseArgs_wrongEnvironment() {
|
||||
String[] args = {"--env", "beta"};
|
||||
ParameterException e = assertThrows(ParameterException.class, () -> proxyModule.parse(args));
|
||||
assertThat(e).hasMessageThat().contains("Invalid value for --env parameter");
|
||||
|
|
|
@ -28,9 +28,7 @@ import io.netty.handler.codec.http.FullHttpResponse;
|
|||
import io.netty.handler.codec.http.HttpClientCodec;
|
||||
import io.netty.handler.codec.http.HttpObjectAggregator;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* End-to-end tests for {@link WebWhoisProtocolsModule}.
|
||||
|
@ -49,8 +47,7 @@ import org.junit.runners.JUnit4;
|
|||
* <p>Only the HTTP redirect protocol is tested as both protocols share the same handlers except for
|
||||
* those that are excluded ({@code SslServerInitializer}, {@code WebWhoisRedirectHandler}).
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class WebWhoisProtocolsModuleTest extends ProtocolModuleTest {
|
||||
class WebWhoisProtocolsModuleTest extends ProtocolModuleTest {
|
||||
|
||||
private static final String HOST = "test.tld";
|
||||
private static final String PATH = "/path/to/test";
|
||||
|
@ -58,7 +55,7 @@ public class WebWhoisProtocolsModuleTest extends ProtocolModuleTest {
|
|||
private final EmbeddedChannel clientChannel =
|
||||
new EmbeddedChannel(new HttpClientCodec(), new HttpObjectAggregator(512 * 1024));
|
||||
|
||||
public WebWhoisProtocolsModuleTest() {
|
||||
WebWhoisProtocolsModuleTest() {
|
||||
super(TestComponent::httpWhoisHandlers);
|
||||
}
|
||||
|
||||
|
@ -98,12 +95,12 @@ public class WebWhoisProtocolsModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_OkResponse() {
|
||||
void testSuccess_OkResponse() {
|
||||
requestAndRespondWithStatus(HttpResponseStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_NonOkResponse() {
|
||||
void testSuccess_NonOkResponse() {
|
||||
requestAndRespondWithStatus(HttpResponseStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,20 +31,17 @@ import io.netty.handler.codec.http.FullHttpResponse;
|
|||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** End-to-end tests for {@link WhoisProtocolModule}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class WhoisProtocolModuleTest extends ProtocolModuleTest {
|
||||
class WhoisProtocolModuleTest extends ProtocolModuleTest {
|
||||
|
||||
public WhoisProtocolModuleTest() {
|
||||
WhoisProtocolModuleTest() {
|
||||
super(TestComponent::whoisHandlers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_singleFrameInboundMessage() {
|
||||
void testSuccess_singleFrameInboundMessage() {
|
||||
String inputString = "test.tld\r\n";
|
||||
// Inbound message processed and passed along.
|
||||
assertThat(channel.writeInbound(Unpooled.wrappedBuffer(inputString.getBytes(US_ASCII))))
|
||||
|
@ -64,7 +61,7 @@ public class WhoisProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_noNewlineInboundMessage() {
|
||||
void testSuccess_noNewlineInboundMessage() {
|
||||
String inputString = "test.tld";
|
||||
// No newline encountered, no message formed.
|
||||
assertThat(channel.writeInbound(Unpooled.wrappedBuffer(inputString.getBytes(US_ASCII))))
|
||||
|
@ -73,7 +70,7 @@ public class WhoisProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_multiFrameInboundMessage() {
|
||||
void testSuccess_multiFrameInboundMessage() {
|
||||
String frame1 = "test";
|
||||
String frame2 = "1.tld";
|
||||
String frame3 = "\r\nte";
|
||||
|
@ -113,7 +110,7 @@ public class WhoisProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_inboundMessageTooLong() {
|
||||
void testSuccess_inboundMessageTooLong() {
|
||||
String inputString = Stream.generate(() -> "x").limit(513).collect(joining()) + "\r\n";
|
||||
// Nothing gets propagated further.
|
||||
assertThat(channel.writeInbound(Unpooled.wrappedBuffer(inputString.getBytes(US_ASCII))))
|
||||
|
@ -123,7 +120,7 @@ public class WhoisProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_parseSingleOutboundHttpResponse() {
|
||||
void testSuccess_parseSingleOutboundHttpResponse() {
|
||||
String outputString = "line1\r\nline2\r\n";
|
||||
FullHttpResponse response = makeWhoisHttpResponse(outputString, HttpResponseStatus.OK);
|
||||
// Http response parsed and passed along.
|
||||
|
@ -136,7 +133,7 @@ public class WhoisProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_parseOnlyFirstFromMultipleOutboundHttpResponse() {
|
||||
void testFailure_parseOnlyFirstFromMultipleOutboundHttpResponse() {
|
||||
String outputString1 = "line1\r\nline2\r\n";
|
||||
String outputString2 = "line3\r\nline4\r\nline5\r\n";
|
||||
FullHttpResponse response1 = makeWhoisHttpResponse(outputString1, HttpResponseStatus.OK);
|
||||
|
@ -151,7 +148,7 @@ public class WhoisProtocolModuleTest extends ProtocolModuleTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_outboundResponseStatusNotOK() {
|
||||
void testFailure_outboundResponseStatusNotOK() {
|
||||
String outputString = "line1\r\nline2\r\n";
|
||||
FullHttpResponse response = makeWhoisHttpResponse(outputString, HttpResponseStatus.BAD_REQUEST);
|
||||
EncoderException thrown =
|
||||
|
|
|
@ -40,14 +40,11 @@ import io.netty.handler.codec.http.FullHttpResponse;
|
|||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link BackendMetricsHandler}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class BackendMetricsHandlerTest {
|
||||
class BackendMetricsHandlerTest {
|
||||
|
||||
private static final String HOST = "host.tld";
|
||||
private static final String CLIENT_CERT_HASH = "blah12345";
|
||||
|
@ -75,8 +72,8 @@ public class BackendMetricsHandlerTest {
|
|||
|
||||
private EmbeddedChannel channel;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
EmbeddedChannel frontendChannel = new EmbeddedChannel();
|
||||
frontendChannel.attr(PROTOCOL_KEY).set(frontendProtocol);
|
||||
frontendChannel.attr(CLIENT_CERTIFICATE_HASH_KEY).set(CLIENT_CERT_HASH);
|
||||
|
@ -93,7 +90,7 @@ public class BackendMetricsHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_outbound_wrongType() {
|
||||
void testFailure_outbound_wrongType() {
|
||||
Object request = new Object();
|
||||
IllegalArgumentException e =
|
||||
assertThrows(IllegalArgumentException.class, () -> channel.writeOutbound(request));
|
||||
|
@ -101,7 +98,7 @@ public class BackendMetricsHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_inbound_wrongType() {
|
||||
void testFailure_inbound_wrongType() {
|
||||
Object response = new Object();
|
||||
IllegalArgumentException e =
|
||||
assertThrows(IllegalArgumentException.class, () -> channel.writeInbound(response));
|
||||
|
@ -109,7 +106,7 @@ public class BackendMetricsHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_oneRequest() {
|
||||
void testSuccess_oneRequest() {
|
||||
FullHttpRequest request = makeHttpPostRequest("some content", HOST, "/");
|
||||
// outbound message passed to the next handler.
|
||||
assertThat(channel.writeOutbound(request)).isTrue();
|
||||
|
@ -120,7 +117,7 @@ public class BackendMetricsHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_oneRequest_oneResponse() {
|
||||
void testSuccess_oneRequest_oneResponse() {
|
||||
FullHttpRequest request = makeHttpPostRequest("some request", HOST, "/");
|
||||
FullHttpResponse response = makeHttpResponse("some response", HttpResponseStatus.OK);
|
||||
// outbound message passed to the next handler.
|
||||
|
@ -139,7 +136,7 @@ public class BackendMetricsHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_badResponse() {
|
||||
void testSuccess_badResponse() {
|
||||
FullHttpRequest request = makeHttpPostRequest("some request", HOST, "/");
|
||||
FullHttpResponse response =
|
||||
makeHttpResponse("some bad response", HttpResponseStatus.BAD_REQUEST);
|
||||
|
@ -161,7 +158,7 @@ public class BackendMetricsHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_responseBeforeRequest() {
|
||||
void testFailure_responseBeforeRequest() {
|
||||
FullHttpResponse response = makeHttpResponse("phantom response", HttpResponseStatus.OK);
|
||||
IllegalStateException e =
|
||||
assertThrows(IllegalStateException.class, () -> channel.writeInbound(response));
|
||||
|
@ -169,7 +166,7 @@ public class BackendMetricsHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_pipelinedResponses() {
|
||||
void testSuccess_pipelinedResponses() {
|
||||
FullHttpRequest request1 = makeHttpPostRequest("request 1", HOST, "/");
|
||||
FullHttpResponse response1 = makeHttpResponse("response 1", HttpResponseStatus.OK);
|
||||
FullHttpRequest request2 = makeHttpPostRequest("request 22", HOST, "/");
|
||||
|
|
|
@ -38,14 +38,11 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
|||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link EppQuotaHandler} */
|
||||
@RunWith(JUnit4.class)
|
||||
public class EppQuotaHandlerTest {
|
||||
class EppQuotaHandlerTest {
|
||||
|
||||
private final QuotaManager quotaManager = mock(QuotaManager.class);
|
||||
private final FrontendMetrics metrics = mock(FrontendMetrics.class);
|
||||
|
@ -73,14 +70,14 @@ public class EppQuotaHandlerTest {
|
|||
.build());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
channel.attr(CLIENT_CERTIFICATE_HASH_KEY).set(clientCertHash);
|
||||
setProtocol(channel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_quotaGrantedAndReturned() {
|
||||
void testSuccess_quotaGrantedAndReturned() {
|
||||
when(quotaManager.acquireQuota(QuotaRequest.create(clientCertHash)))
|
||||
.thenReturn(QuotaResponse.create(true, clientCertHash, now));
|
||||
|
||||
|
@ -104,7 +101,7 @@ public class EppQuotaHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_quotaNotGranted() {
|
||||
void testFailure_quotaNotGranted() {
|
||||
when(quotaManager.acquireQuota(QuotaRequest.create(clientCertHash)))
|
||||
.thenReturn(QuotaResponse.create(false, clientCertHash, now));
|
||||
OverQuotaException e =
|
||||
|
@ -119,7 +116,7 @@ public class EppQuotaHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_twoChannels_twoUserIds() {
|
||||
void testSuccess_twoChannels_twoUserIds() {
|
||||
// Set up another user.
|
||||
final EppQuotaHandler otherHandler = new EppQuotaHandler(quotaManager, metrics);
|
||||
final EmbeddedChannel otherChannel = new EmbeddedChannel(otherHandler);
|
||||
|
@ -147,7 +144,7 @@ public class EppQuotaHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_twoChannels_sameUserIds() {
|
||||
void testSuccess_twoChannels_sameUserIds() {
|
||||
// Set up another channel for the same user.
|
||||
final EppQuotaHandler otherHandler = new EppQuotaHandler(quotaManager, metrics);
|
||||
final EmbeddedChannel otherChannel = new EmbeddedChannel(otherHandler);
|
||||
|
|
|
@ -44,14 +44,11 @@ import io.netty.handler.codec.http.cookie.Cookie;
|
|||
import io.netty.handler.codec.http.cookie.DefaultCookie;
|
||||
import io.netty.util.concurrent.Promise;
|
||||
import java.security.cert.X509Certificate;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link EppServiceHandler}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class EppServiceHandlerTest {
|
||||
class EppServiceHandlerTest {
|
||||
|
||||
private static final String HELLO =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
|
||||
|
@ -112,8 +109,8 @@ public class EppServiceHandlerTest {
|
|||
cookies);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void beforeEach() throws Exception {
|
||||
clientCertificate = SelfSignedCaCertificate.create().cert();
|
||||
channel = setUpNewChannel(eppServiceHandler);
|
||||
}
|
||||
|
@ -132,7 +129,7 @@ public class EppServiceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_connectionMetrics_oneConnection() throws Exception {
|
||||
void testSuccess_connectionMetrics_oneConnection() throws Exception {
|
||||
setHandshakeSuccess();
|
||||
String certHash = getCertificateHash(clientCertificate);
|
||||
assertThat(channel.isActive()).isTrue();
|
||||
|
@ -141,7 +138,7 @@ public class EppServiceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_connectionMetrics_twoConnections_sameClient() throws Exception {
|
||||
void testSuccess_connectionMetrics_twoConnections_sameClient() throws Exception {
|
||||
setHandshakeSuccess();
|
||||
String certHash = getCertificateHash(clientCertificate);
|
||||
assertThat(channel.isActive()).isTrue();
|
||||
|
@ -165,7 +162,7 @@ public class EppServiceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_connectionMetrics_twoConnections_differentClients() throws Exception {
|
||||
void testSuccess_connectionMetrics_twoConnections_differentClients() throws Exception {
|
||||
setHandshakeSuccess();
|
||||
String certHash = getCertificateHash(clientCertificate);
|
||||
assertThat(channel.isActive()).isTrue();
|
||||
|
@ -191,7 +188,7 @@ public class EppServiceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_sendHelloUponHandshakeSuccess() throws Exception {
|
||||
void testSuccess_sendHelloUponHandshakeSuccess() throws Exception {
|
||||
// Nothing to pass to the next handler.
|
||||
assertThat((Object) channel.readInbound()).isNull();
|
||||
setHandshakeSuccess();
|
||||
|
@ -204,7 +201,7 @@ public class EppServiceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_disconnectUponHandshakeFailure() throws Exception {
|
||||
void testSuccess_disconnectUponHandshakeFailure() throws Exception {
|
||||
// Nothing to pass to the next handler.
|
||||
assertThat((Object) channel.readInbound()).isNull();
|
||||
setHandshakeFailure();
|
||||
|
@ -212,7 +209,7 @@ public class EppServiceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_sendRequestToNextHandler() throws Exception {
|
||||
void testSuccess_sendRequestToNextHandler() throws Exception {
|
||||
setHandshakeSuccess();
|
||||
// First inbound message is hello.
|
||||
channel.readInbound();
|
||||
|
@ -226,7 +223,7 @@ public class EppServiceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_sendResponseToNextHandler() throws Exception {
|
||||
void testSuccess_sendResponseToNextHandler() throws Exception {
|
||||
setHandshakeSuccess();
|
||||
String content = "<epp>stuff</epp>";
|
||||
channel.writeOutbound(makeEppHttpResponse(content, HttpResponseStatus.OK));
|
||||
|
@ -238,7 +235,7 @@ public class EppServiceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_sendResponseToNextHandler_andDisconnect() throws Exception {
|
||||
void testSuccess_sendResponseToNextHandler_andDisconnect() throws Exception {
|
||||
setHandshakeSuccess();
|
||||
String content = "<epp>stuff</epp>";
|
||||
HttpResponse response = makeEppHttpResponse(content, HttpResponseStatus.OK);
|
||||
|
@ -253,7 +250,7 @@ public class EppServiceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_disconnectOnNonOKResponseStatus() throws Exception {
|
||||
void testFailure_disconnectOnNonOKResponseStatus() throws Exception {
|
||||
setHandshakeSuccess();
|
||||
String content = "<epp>stuff</epp>";
|
||||
EncoderException thrown =
|
||||
|
@ -269,7 +266,7 @@ public class EppServiceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_setCookies() throws Exception {
|
||||
void testSuccess_setCookies() throws Exception {
|
||||
setHandshakeSuccess();
|
||||
// First inbound message is hello.
|
||||
channel.readInbound();
|
||||
|
@ -291,7 +288,7 @@ public class EppServiceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_updateCookies() throws Exception {
|
||||
void testSuccess_updateCookies() throws Exception {
|
||||
setHandshakeSuccess();
|
||||
// First inbound message is hello.
|
||||
channel.readInbound();
|
||||
|
|
|
@ -32,14 +32,11 @@ import io.netty.channel.ChannelInitializer;
|
|||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link FrontendMetricsHandler}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class FrontendMetricsHandlerTest {
|
||||
class FrontendMetricsHandlerTest {
|
||||
|
||||
private static final String CLIENT_CERT_HASH = "blah12345";
|
||||
private static final String PROTOCOL_NAME = "frontend protocol";
|
||||
|
@ -58,8 +55,8 @@ public class FrontendMetricsHandlerTest {
|
|||
|
||||
private EmbeddedChannel channel;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
channel =
|
||||
new EmbeddedChannel(
|
||||
new ChannelInitializer<EmbeddedChannel>() {
|
||||
|
@ -73,7 +70,7 @@ public class FrontendMetricsHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_oneRequest() {
|
||||
void testSuccess_oneRequest() {
|
||||
// Inbound message passed to the next handler.
|
||||
Object request = new Object();
|
||||
assertThat(channel.writeInbound(request)).isTrue();
|
||||
|
@ -82,7 +79,7 @@ public class FrontendMetricsHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_oneRequest_oneResponse() {
|
||||
void testSuccess_oneRequest_oneResponse() {
|
||||
Object request = new Object();
|
||||
Object response = new Object();
|
||||
// Inbound message passed to the next handler.
|
||||
|
@ -98,7 +95,7 @@ public class FrontendMetricsHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_responseBeforeRequest() {
|
||||
void testFailure_responseBeforeRequest() {
|
||||
Object response = new Object();
|
||||
IllegalStateException e =
|
||||
assertThrows(IllegalStateException.class, () -> channel.writeOutbound(response));
|
||||
|
@ -106,7 +103,7 @@ public class FrontendMetricsHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_pipelinedResponses() {
|
||||
void testSuccess_pipelinedResponses() {
|
||||
Object request1 = new Object();
|
||||
Object response1 = new Object();
|
||||
Object request2 = new Object();
|
||||
|
|
|
@ -20,13 +20,10 @@ import static java.nio.charset.StandardCharsets.US_ASCII;
|
|||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link HealthCheckHandler}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class HealthCheckHandlerTest {
|
||||
class HealthCheckHandlerTest {
|
||||
|
||||
private static final String CHECK_REQ = "REQUEST";
|
||||
private static final String CHECK_RES = "RESPONSE";
|
||||
|
@ -36,7 +33,7 @@ public class HealthCheckHandlerTest {
|
|||
private final EmbeddedChannel channel = new EmbeddedChannel(healthCheckHandler);
|
||||
|
||||
@Test
|
||||
public void testSuccess_ResponseSent() {
|
||||
void testSuccess_ResponseSent() {
|
||||
ByteBuf input = Unpooled.wrappedBuffer(CHECK_REQ.getBytes(US_ASCII));
|
||||
// No inbound message passed to the next handler.
|
||||
assertThat(channel.writeInbound(input)).isFalse();
|
||||
|
@ -46,7 +43,7 @@ public class HealthCheckHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_IgnoreUnrecognizedRequest() {
|
||||
void testSuccess_IgnoreUnrecognizedRequest() {
|
||||
String unrecognizedInput = "1234567";
|
||||
ByteBuf input = Unpooled.wrappedBuffer(unrecognizedInput.getBytes(US_ASCII));
|
||||
// No inbound message passed to the next handler.
|
||||
|
|
|
@ -21,13 +21,10 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
|||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link ProxyProtocolHandler}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class ProxyProtocolHandlerTest {
|
||||
class ProxyProtocolHandlerTest {
|
||||
|
||||
private static final String HEADER_TEMPLATE = "PROXY TCP%d %s %s %s %s\r\n";
|
||||
|
||||
|
@ -37,7 +34,7 @@ public class ProxyProtocolHandlerTest {
|
|||
private String header;
|
||||
|
||||
@Test
|
||||
public void testSuccess_proxyHeaderPresent_singleFrame() {
|
||||
void testSuccess_proxyHeaderPresent_singleFrame() {
|
||||
header = String.format(HEADER_TEMPLATE, 4, "172.0.0.1", "255.255.255.255", "234", "123");
|
||||
String message = "some message";
|
||||
// Header processed, rest of the message passed along.
|
||||
|
@ -50,7 +47,7 @@ public class ProxyProtocolHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_proxyHeaderUnknownSource_singleFrame() {
|
||||
void testSuccess_proxyHeaderUnknownSource_singleFrame() {
|
||||
header = "PROXY UNKNOWN\r\n";
|
||||
String message = "some message";
|
||||
// Header processed, rest of the message passed along.
|
||||
|
@ -63,7 +60,7 @@ public class ProxyProtocolHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_proxyHeaderPresent_multipleFrames() {
|
||||
void testSuccess_proxyHeaderPresent_multipleFrames() {
|
||||
header = String.format(HEADER_TEMPLATE, 4, "172.0.0.1", "255.255.255.255", "234", "123");
|
||||
String frame1 = header.substring(0, 4);
|
||||
String frame2 = header.substring(4, 7);
|
||||
|
@ -85,7 +82,7 @@ public class ProxyProtocolHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_proxyHeaderPresent_singleFrame_ipv6() {
|
||||
void testSuccess_proxyHeaderPresent_singleFrame_ipv6() {
|
||||
header =
|
||||
String.format(HEADER_TEMPLATE, 6, "2001:db8:0:1:1:1:1:1", "0:0:0:0:0:0:0:1", "234", "123");
|
||||
String message = "some message";
|
||||
|
@ -99,7 +96,7 @@ public class ProxyProtocolHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_proxyHeaderNotPresent_singleFrame() {
|
||||
void testSuccess_proxyHeaderNotPresent_singleFrame() {
|
||||
String message = "some message";
|
||||
// No header present, rest of the message passed along.
|
||||
assertThat(channel.writeInbound(Unpooled.wrappedBuffer(message.getBytes(UTF_8)))).isTrue();
|
||||
|
@ -110,7 +107,7 @@ public class ProxyProtocolHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_proxyHeaderNotPresent_multipleFrames() {
|
||||
void testSuccess_proxyHeaderNotPresent_multipleFrames() {
|
||||
String frame1 = "som";
|
||||
String frame2 = "e mess";
|
||||
String frame3 = "age\nis not";
|
||||
|
|
|
@ -25,14 +25,11 @@ import google.registry.proxy.Protocol.BackendProtocol;
|
|||
import google.registry.proxy.Protocol.FrontendProtocol;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import java.util.ArrayDeque;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link RelayHandler}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class RelayHandlerTest {
|
||||
class RelayHandlerTest {
|
||||
|
||||
private static final class ExpectedType {}
|
||||
|
||||
|
@ -56,8 +53,8 @@ public class RelayHandlerTest {
|
|||
.build();
|
||||
private final BackendProtocol backendProtocol = frontendProtocol.relayProtocol();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
inboundChannel.attr(RELAY_CHANNEL_KEY).set(outboundChannel);
|
||||
inboundChannel.attr(RELAY_BUFFER_KEY).set(new ArrayDeque<>());
|
||||
inboundChannel.attr(PROTOCOL_KEY).set(frontendProtocol);
|
||||
|
@ -65,7 +62,7 @@ public class RelayHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_relayInboundMessageOfExpectedType() {
|
||||
void testSuccess_relayInboundMessageOfExpectedType() {
|
||||
ExpectedType inboundMessage = new ExpectedType();
|
||||
// Relay handler intercepted the message, no further inbound message.
|
||||
assertThat(inboundChannel.writeInbound(inboundMessage)).isFalse();
|
||||
|
@ -75,7 +72,7 @@ public class RelayHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_ignoreInboundMessageOfOtherType() {
|
||||
void testSuccess_ignoreInboundMessageOfOtherType() {
|
||||
OtherType inboundMessage = new OtherType();
|
||||
// Relay handler ignores inbound message of other types, the inbound message is passed along.
|
||||
assertThat(inboundChannel.writeInbound(inboundMessage)).isTrue();
|
||||
|
@ -85,7 +82,7 @@ public class RelayHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_frontClosed() {
|
||||
void testSuccess_frontClosed() {
|
||||
inboundChannel.attr(RELAY_BUFFER_KEY).set(null);
|
||||
inboundChannel.attr(PROTOCOL_KEY).set(backendProtocol);
|
||||
outboundChannel.attr(PROTOCOL_KEY).set(frontendProtocol);
|
||||
|
@ -101,7 +98,7 @@ public class RelayHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_backendClosed_enqueueBuffer() {
|
||||
void testSuccess_backendClosed_enqueueBuffer() {
|
||||
ExpectedType inboundMessage = new ExpectedType();
|
||||
// Outbound channel (backend) is closed.
|
||||
outboundChannel.finish();
|
||||
|
@ -114,7 +111,7 @@ public class RelayHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_channelRead_relayNotSet() {
|
||||
void testSuccess_channelRead_relayNotSet() {
|
||||
ExpectedType inboundMessage = new ExpectedType();
|
||||
inboundChannel.attr(RELAY_CHANNEL_KEY).set(null);
|
||||
// Nothing to read.
|
||||
|
|
|
@ -24,13 +24,10 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
|||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.FullHttpResponse;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link WebWhoisRedirectHandler}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class WebWhoisRedirectHandlerTest {
|
||||
class WebWhoisRedirectHandlerTest {
|
||||
|
||||
private static final String REDIRECT_HOST = "www.example.com";
|
||||
private static final String TARGET_HOST = "whois.nic.tld";
|
||||
|
@ -62,7 +59,7 @@ public class WebWhoisRedirectHandlerTest {
|
|||
// HTTP redirect tests.
|
||||
|
||||
@Test
|
||||
public void testSuccess_http_methodNotAllowed() {
|
||||
void testSuccess_http_methodNotAllowed() {
|
||||
setupChannel(false);
|
||||
request = makeHttpPostRequest("", TARGET_HOST, "/");
|
||||
// No inbound message passed to the next handler.
|
||||
|
@ -74,7 +71,7 @@ public class WebWhoisRedirectHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_http_badHost() {
|
||||
void testSuccess_http_badHost() {
|
||||
setupChannel(false);
|
||||
request = makeHttpGetRequest("", "/");
|
||||
// No inbound message passed to the next handler.
|
||||
|
@ -86,7 +83,7 @@ public class WebWhoisRedirectHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_http_noHost() {
|
||||
void testSuccess_http_noHost() {
|
||||
setupChannel(false);
|
||||
request = makeHttpGetRequest("", "/");
|
||||
request.headers().remove("host");
|
||||
|
@ -99,7 +96,7 @@ public class WebWhoisRedirectHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_http_healthCheck() {
|
||||
void testSuccess_http_healthCheck() {
|
||||
setupChannel(false);
|
||||
request = makeHttpPostRequest("", TARGET_HOST, "/");
|
||||
// No inbound message passed to the next handler.
|
||||
|
@ -111,7 +108,7 @@ public class WebWhoisRedirectHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_http_redirectToHttps() {
|
||||
void testSuccess_http_redirectToHttps() {
|
||||
setupChannel(false);
|
||||
request = makeHttpGetRequest(TARGET_HOST, "/");
|
||||
// No inbound message passed to the next handler.
|
||||
|
@ -125,7 +122,7 @@ public class WebWhoisRedirectHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_http_redirectToHttps_hostAndPort() {
|
||||
void testSuccess_http_redirectToHttps_hostAndPort() {
|
||||
setupChannel(false);
|
||||
request = makeHttpGetRequest(TARGET_HOST + ":80", "/");
|
||||
// No inbound message passed to the next handler.
|
||||
|
@ -139,7 +136,7 @@ public class WebWhoisRedirectHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_http_redirectToHttps_noKeepAlive() {
|
||||
void testSuccess_http_redirectToHttps_noKeepAlive() {
|
||||
setupChannel(false);
|
||||
request = makeHttpGetRequest(TARGET_HOST, "/");
|
||||
request.headers().set("connection", "close");
|
||||
|
@ -156,7 +153,7 @@ public class WebWhoisRedirectHandlerTest {
|
|||
// HTTPS redirect tests.
|
||||
|
||||
@Test
|
||||
public void testSuccess_https_methodNotAllowed() {
|
||||
void testSuccess_https_methodNotAllowed() {
|
||||
setupChannel(true);
|
||||
request = makeHttpPostRequest("", TARGET_HOST, "/");
|
||||
// No inbound message passed to the next handler.
|
||||
|
@ -168,7 +165,7 @@ public class WebWhoisRedirectHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_https_badHost() {
|
||||
void testSuccess_https_badHost() {
|
||||
setupChannel(true);
|
||||
request = makeHttpGetRequest("", "/");
|
||||
// No inbound message passed to the next handler.
|
||||
|
@ -180,7 +177,7 @@ public class WebWhoisRedirectHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_https_noHost() {
|
||||
void testSuccess_https_noHost() {
|
||||
setupChannel(true);
|
||||
request = makeHttpGetRequest("", "/");
|
||||
request.headers().remove("host");
|
||||
|
@ -193,7 +190,7 @@ public class WebWhoisRedirectHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_https_healthCheck() {
|
||||
void testSuccess_https_healthCheck() {
|
||||
setupChannel(true);
|
||||
request = makeHttpGetRequest("health-check.invalid", "/");
|
||||
// No inbound message passed to the next handler.
|
||||
|
@ -205,7 +202,7 @@ public class WebWhoisRedirectHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_https_redirectToDestination() {
|
||||
void testSuccess_https_redirectToDestination() {
|
||||
setupChannel(true);
|
||||
request = makeHttpGetRequest(TARGET_HOST, "/");
|
||||
// No inbound message passed to the next handler.
|
||||
|
@ -218,7 +215,7 @@ public class WebWhoisRedirectHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_https_redirectToDestination_noKeepAlive() {
|
||||
void testSuccess_https_redirectToDestination_noKeepAlive() {
|
||||
setupChannel(true);
|
||||
request = makeHttpGetRequest(TARGET_HOST, "/");
|
||||
request.headers().set("connection", "close");
|
||||
|
|
|
@ -37,14 +37,11 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
|||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link WhoisQuotaHandler} */
|
||||
@RunWith(JUnit4.class)
|
||||
public class WhoisQuotaHandlerTest {
|
||||
class WhoisQuotaHandlerTest {
|
||||
|
||||
private final QuotaManager quotaManager = mock(QuotaManager.class);
|
||||
private final FrontendMetrics metrics = mock(FrontendMetrics.class);
|
||||
|
@ -72,14 +69,14 @@ public class WhoisQuotaHandlerTest {
|
|||
.build());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
channel.attr(REMOTE_ADDRESS_KEY).set(remoteAddress);
|
||||
setProtocol(channel);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_quotaGranted() {
|
||||
void testSuccess_quotaGranted() {
|
||||
when(quotaManager.acquireQuota(QuotaRequest.create(remoteAddress)))
|
||||
.thenReturn(QuotaResponse.create(true, remoteAddress, now));
|
||||
|
||||
|
@ -99,7 +96,7 @@ public class WhoisQuotaHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_quotaNotGranted() {
|
||||
void testFailure_quotaNotGranted() {
|
||||
when(quotaManager.acquireQuota(QuotaRequest.create(remoteAddress)))
|
||||
.thenReturn(QuotaResponse.create(false, remoteAddress, now));
|
||||
OverQuotaException e =
|
||||
|
@ -110,7 +107,7 @@ public class WhoisQuotaHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_twoChannels_twoUserIds() {
|
||||
void testSuccess_twoChannels_twoUserIds() {
|
||||
// Set up another user.
|
||||
final WhoisQuotaHandler otherHandler = new WhoisQuotaHandler(quotaManager, metrics);
|
||||
final EmbeddedChannel otherChannel = new EmbeddedChannel(otherHandler);
|
||||
|
@ -138,7 +135,7 @@ public class WhoisQuotaHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_oneUser_rateLimited() {
|
||||
void testSuccess_oneUser_rateLimited() {
|
||||
// Set up another channel for the same user.
|
||||
final WhoisQuotaHandler otherHandler = new WhoisQuotaHandler(quotaManager, metrics);
|
||||
final EmbeddedChannel otherChannel = new EmbeddedChannel(otherHandler);
|
||||
|
|
|
@ -34,14 +34,11 @@ import io.netty.handler.codec.EncoderException;
|
|||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.FullHttpResponse;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link WhoisServiceHandler}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class WhoisServiceHandlerTest {
|
||||
class WhoisServiceHandlerTest {
|
||||
|
||||
private static final String RELAY_HOST = "www.example.tld";
|
||||
private static final String RELAY_PATH = "/test";
|
||||
|
@ -56,22 +53,22 @@ public class WhoisServiceHandlerTest {
|
|||
new WhoisServiceHandler(RELAY_HOST, RELAY_PATH, () -> ACCESS_TOKEN, metrics);
|
||||
private EmbeddedChannel channel;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
// Need to reset metrics for each test method, since they are static fields on the class and
|
||||
// shared between each run.
|
||||
channel = new EmbeddedChannel(whoisServiceHandler);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_connectionMetrics_oneChannel() {
|
||||
void testSuccess_connectionMetrics_oneChannel() {
|
||||
assertThat(channel.isActive()).isTrue();
|
||||
verify(metrics).registerActiveConnection(PROTOCOL, CLIENT_HASH, channel);
|
||||
verifyNoMoreInteractions(metrics);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_ConnectionMetrics_twoConnections() {
|
||||
void testSuccess_ConnectionMetrics_twoConnections() {
|
||||
assertThat(channel.isActive()).isTrue();
|
||||
verify(metrics).registerActiveConnection(PROTOCOL, CLIENT_HASH, channel);
|
||||
|
||||
|
@ -88,7 +85,7 @@ public class WhoisServiceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_fireInboundHttpRequest() {
|
||||
void testSuccess_fireInboundHttpRequest() {
|
||||
ByteBuf inputBuffer = Unpooled.wrappedBuffer(QUERY_CONTENT.getBytes(US_ASCII));
|
||||
FullHttpRequest expectedRequest =
|
||||
makeWhoisHttpRequest(QUERY_CONTENT, RELAY_HOST, RELAY_PATH, ACCESS_TOKEN);
|
||||
|
@ -102,7 +99,7 @@ public class WhoisServiceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_parseOutboundHttpResponse() {
|
||||
void testSuccess_parseOutboundHttpResponse() {
|
||||
String outputString = "line1\r\nline2\r\n";
|
||||
FullHttpResponse outputResponse = makeWhoisHttpResponse(outputString, HttpResponseStatus.OK);
|
||||
// output data passed to next handler
|
||||
|
@ -115,7 +112,7 @@ public class WhoisServiceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_OutboundHttpResponseNotOK() {
|
||||
void testFailure_OutboundHttpResponseNotOK() {
|
||||
String outputString = "line1\r\nline2\r\n";
|
||||
FullHttpResponse outputResponse =
|
||||
makeWhoisHttpResponse(outputString, HttpResponseStatus.BAD_REQUEST);
|
||||
|
|
|
@ -24,14 +24,11 @@ import io.netty.handler.codec.http.FullHttpRequest;
|
|||
import io.netty.handler.codec.http.FullHttpResponse;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link BackendMetrics}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class BackendMetricsTest {
|
||||
class BackendMetricsTest {
|
||||
|
||||
private final String host = "host.tld";
|
||||
private final String certHash = "blah12345";
|
||||
|
@ -39,13 +36,13 @@ public class BackendMetricsTest {
|
|||
|
||||
private final BackendMetrics metrics = new BackendMetrics();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
metrics.resetMetrics();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_oneRequest() {
|
||||
void testSuccess_oneRequest() {
|
||||
String content = "some content";
|
||||
FullHttpRequest request = makeHttpPostRequest(content, host, "/");
|
||||
metrics.requestSent(protocol, certHash, request.content().readableBytes());
|
||||
|
@ -64,7 +61,7 @@ public class BackendMetricsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_multipleRequests() {
|
||||
void testSuccess_multipleRequests() {
|
||||
String content1 = "some content";
|
||||
String content2 = "some other content";
|
||||
FullHttpRequest request1 = makeHttpPostRequest(content1, host, "/");
|
||||
|
@ -87,7 +84,7 @@ public class BackendMetricsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_oneResponse() {
|
||||
void testSuccess_oneResponse() {
|
||||
String content = "some response";
|
||||
FullHttpResponse response = makeHttpResponse(content, HttpResponseStatus.OK);
|
||||
metrics.responseReceived(protocol, certHash, response, Duration.millis(5));
|
||||
|
@ -109,7 +106,7 @@ public class BackendMetricsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_multipleResponses() {
|
||||
void testSuccess_multipleResponses() {
|
||||
String content1 = "some response";
|
||||
String content2 = "other response";
|
||||
String content3 = "a very bad response";
|
||||
|
@ -142,7 +139,7 @@ public class BackendMetricsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_oneRequest_oneResponse() {
|
||||
void testSuccess_oneRequest_oneResponse() {
|
||||
String requestContent = "some request";
|
||||
String responseContent = "the only response";
|
||||
FullHttpRequest request = makeHttpPostRequest(requestContent, host, "/");
|
||||
|
|
|
@ -20,26 +20,23 @@ import static com.google.monitoring.metrics.contrib.LongMetricSubject.assertThat
|
|||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.DefaultChannelId;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link FrontendMetrics}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class FrontendMetricsTest {
|
||||
class FrontendMetricsTest {
|
||||
|
||||
private static final String PROTOCOL = "some protocol";
|
||||
private static final String CERT_HASH = "abc_blah_1134zdf";
|
||||
private final FrontendMetrics metrics = new FrontendMetrics();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
metrics.resetMetrics();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_oneConnection() {
|
||||
void testSuccess_oneConnection() {
|
||||
EmbeddedChannel channel = new EmbeddedChannel();
|
||||
metrics.registerActiveConnection(PROTOCOL, CERT_HASH, channel);
|
||||
assertThat(channel.isActive()).isTrue();
|
||||
|
@ -62,7 +59,7 @@ public class FrontendMetricsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_twoConnections_sameClient() {
|
||||
void testSuccess_twoConnections_sameClient() {
|
||||
EmbeddedChannel channel1 = new EmbeddedChannel();
|
||||
EmbeddedChannel channel2 = new EmbeddedChannel(DefaultChannelId.newInstance());
|
||||
|
||||
|
@ -111,7 +108,7 @@ public class FrontendMetricsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_twoConnections_differentClients() {
|
||||
void testSuccess_twoConnections_differentClients() {
|
||||
EmbeddedChannel channel1 = new EmbeddedChannel();
|
||||
EmbeddedChannel channel2 = new EmbeddedChannel(DefaultChannelId.newInstance());
|
||||
String certHash2 = "blahblah_lol_234";
|
||||
|
@ -167,7 +164,7 @@ public class FrontendMetricsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_registerQuotaRejections() {
|
||||
void testSuccess_registerQuotaRejections() {
|
||||
String otherCertHash = "foobar1234X";
|
||||
String remoteAddress = "127.0.0.1";
|
||||
String otherProtocol = "other protocol";
|
||||
|
|
|
@ -36,14 +36,11 @@ import java.net.HttpURLConnection;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Function;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link MetricParameters}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class MetricParametersTest {
|
||||
class MetricParametersTest {
|
||||
|
||||
private static final HashMap<String, String> RESULTS = new HashMap<>();
|
||||
|
||||
|
@ -71,8 +68,8 @@ public class MetricParametersTest {
|
|||
return new ByteArrayInputStream(input.getBytes(UTF_8));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void beforeEach() throws Exception {
|
||||
fakeEnvVarMap.put(NAMESPACE_ID_ENV, "some-namespace");
|
||||
fakeEnvVarMap.put(POD_ID_ENV, "some-pod");
|
||||
fakeEnvVarMap.put(CONTAINER_NAME_ENV, "some-container");
|
||||
|
@ -97,26 +94,26 @@ public class MetricParametersTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess() {
|
||||
void testSuccess() {
|
||||
assertThat(metricParameters.makeLabelsMap()).isEqualTo(ImmutableMap.copyOf(RESULTS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_missingEnvVar() {
|
||||
void testSuccess_missingEnvVar() {
|
||||
fakeEnvVarMap.remove(POD_ID_ENV);
|
||||
RESULTS.put("pod_id", "");
|
||||
assertThat(metricParameters.makeLabelsMap()).isEqualTo(ImmutableMap.copyOf(RESULTS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_malformedZone() throws Exception {
|
||||
void testSuccess_malformedZone() throws Exception {
|
||||
when(zoneConnection.getInputStream()).thenReturn(makeInputStreamFromString("some-zone"));
|
||||
RESULTS.put("zone", "");
|
||||
assertThat(metricParameters.makeLabelsMap()).isEqualTo(ImmutableMap.copyOf(RESULTS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_errorResponseCode() throws Exception {
|
||||
void testSuccess_errorResponseCode() throws Exception {
|
||||
when(projectIdConnection.getResponseCode()).thenReturn(404);
|
||||
when(projectIdConnection.getErrorStream())
|
||||
.thenReturn(makeInputStreamFromString("some error message"));
|
||||
|
@ -125,7 +122,7 @@ public class MetricParametersTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_connectionError() throws Exception {
|
||||
void testSuccess_connectionError() throws Exception {
|
||||
InputStream fakeInputStream = mock(InputStream.class);
|
||||
when(projectIdConnection.getInputStream()).thenReturn(fakeInputStream);
|
||||
when(fakeInputStream.read(any(byte[].class), anyInt(), anyInt()))
|
||||
|
|
|
@ -20,14 +20,11 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||
|
||||
import google.registry.proxy.ProxyConfig.Quota;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
/** Unit Tests for {@link QuotaConfig} */
|
||||
@RunWith(JUnit4.class)
|
||||
public class QuotaConfigTest {
|
||||
class QuotaConfigTest {
|
||||
|
||||
private QuotaConfig quotaConfig;
|
||||
|
||||
|
@ -47,7 +44,7 @@ public class QuotaConfigTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_regularConfig() {
|
||||
void testSuccess_regularConfig() {
|
||||
quotaConfig = loadQuotaConfig("quota_config_regular.yaml");
|
||||
assertThat(quotaConfig.getRefreshPeriod()).isEqualTo(Duration.standardHours(1));
|
||||
validateQuota("abc", 10, 60);
|
||||
|
@ -56,7 +53,7 @@ public class QuotaConfigTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_onlyDefault() {
|
||||
void testSuccess_onlyDefault() {
|
||||
quotaConfig = loadQuotaConfig("quota_config_default.yaml");
|
||||
assertThat(quotaConfig.getRefreshPeriod()).isEqualTo(Duration.standardHours(1));
|
||||
validateQuota("abc", 100, 60);
|
||||
|
@ -65,14 +62,14 @@ public class QuotaConfigTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_noRefresh_noRefill() {
|
||||
void testSuccess_noRefresh_noRefill() {
|
||||
quotaConfig = loadQuotaConfig("quota_config_no_refresh_no_refill.yaml");
|
||||
assertThat(quotaConfig.getRefreshPeriod()).isEqualTo(Duration.ZERO);
|
||||
assertThat(quotaConfig.getRefillPeriod("no_match")).isEqualTo(Duration.ZERO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_getTokenAmount_throwsOnUnlimitedTokens() {
|
||||
void testFailure_getTokenAmount_throwsOnUnlimitedTokens() {
|
||||
quotaConfig = loadQuotaConfig("quota_config_unlimited_tokens.yaml");
|
||||
assertThat(quotaConfig.hasUnlimitedTokens("some_user")).isTrue();
|
||||
IllegalStateException e =
|
||||
|
@ -83,7 +80,7 @@ public class QuotaConfigTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_duplicateUserId() {
|
||||
void testFailure_duplicateUserId() {
|
||||
IllegalArgumentException e =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> loadQuotaConfig("quota_config_duplicate.yaml"));
|
||||
|
|
|
@ -29,13 +29,10 @@ import google.registry.proxy.quota.TokenStore.TimestampedInteger;
|
|||
import google.registry.testing.FakeClock;
|
||||
import java.util.concurrent.Future;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link QuotaManager}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class QuotaManagerTest {
|
||||
class QuotaManagerTest {
|
||||
|
||||
private static final String USER_ID = "theUser";
|
||||
|
||||
|
@ -48,7 +45,7 @@ public class QuotaManagerTest {
|
|||
private QuotaResponse response;
|
||||
|
||||
@Test
|
||||
public void testSuccess_requestApproved() {
|
||||
void testSuccess_requestApproved() {
|
||||
when(tokenStore.take(anyString())).thenReturn(TimestampedInteger.create(1, clock.nowUtc()));
|
||||
|
||||
request = QuotaRequest.create(USER_ID);
|
||||
|
@ -59,7 +56,7 @@ public class QuotaManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_requestDenied() {
|
||||
void testSuccess_requestDenied() {
|
||||
when(tokenStore.take(anyString())).thenReturn(TimestampedInteger.create(0, clock.nowUtc()));
|
||||
|
||||
request = QuotaRequest.create(USER_ID);
|
||||
|
@ -70,7 +67,7 @@ public class QuotaManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_rebate() throws Exception {
|
||||
void testSuccess_rebate() throws Exception {
|
||||
DateTime grantedTokenRefillTime = clock.nowUtc();
|
||||
response = QuotaResponse.create(true, USER_ID, grantedTokenRefillTime);
|
||||
QuotaRebate rebate = QuotaRebate.create(response);
|
||||
|
|
|
@ -33,15 +33,12 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
/** Unit tests for {@link TokenStore}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class TokenStoreTest {
|
||||
class TokenStoreTest {
|
||||
|
||||
private final QuotaConfig quotaConfig = mock(QuotaConfig.class);
|
||||
private final FakeClock clock = new FakeClock();
|
||||
|
@ -89,8 +86,8 @@ public class TokenStoreTest {
|
|||
});
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
when(quotaConfig.getRefreshPeriod()).thenReturn(Duration.standardSeconds(60));
|
||||
when(quotaConfig.getRefillPeriod(user)).thenReturn(Duration.standardSeconds(10));
|
||||
when(quotaConfig.getTokenAmount(user)).thenReturn(3);
|
||||
|
@ -99,7 +96,7 @@ public class TokenStoreTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_take() {
|
||||
void testSuccess_take() {
|
||||
// Take 3 tokens one by one.
|
||||
DateTime refillTime = clock.nowUtc();
|
||||
assertTake(1, 2, refillTime);
|
||||
|
@ -118,13 +115,13 @@ public class TokenStoreTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_put_entryDoesNotExist() {
|
||||
void testSuccess_put_entryDoesNotExist() {
|
||||
tokenStore.put(user, clock.nowUtc());
|
||||
assertThat(tokenStore.getTokenForTests(user)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_put() {
|
||||
void testSuccess_put() {
|
||||
DateTime refillTime = clock.nowUtc();
|
||||
|
||||
// Initialize the entry.
|
||||
|
@ -148,7 +145,7 @@ public class TokenStoreTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_takeAndPut() {
|
||||
void testSuccess_takeAndPut() {
|
||||
DateTime refillTime = clock.nowUtc();
|
||||
|
||||
// Take 1 token.
|
||||
|
@ -168,7 +165,7 @@ public class TokenStoreTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_multipleUsers() {
|
||||
void testSuccess_multipleUsers() {
|
||||
DateTime refillTime1 = clock.nowUtc();
|
||||
DateTime refillTime2 = clock.nowUtc();
|
||||
|
||||
|
@ -196,7 +193,7 @@ public class TokenStoreTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_refresh() {
|
||||
void testSuccess_refresh() {
|
||||
DateTime refillTime1 = clock.nowUtc();
|
||||
assertTake(user, 1, 2, refillTime1);
|
||||
|
||||
|
@ -214,7 +211,7 @@ public class TokenStoreTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_unlimitedQuota() {
|
||||
void testSuccess_unlimitedQuota() {
|
||||
when(quotaConfig.hasUnlimitedTokens(user)).thenReturn(true);
|
||||
for (int i = 0; i < 10000; ++i) {
|
||||
assertTake(1, SENTINEL_UNLIMITED_TOKENS, clock.nowUtc());
|
||||
|
@ -225,7 +222,7 @@ public class TokenStoreTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_noRefill() {
|
||||
void testSuccess_noRefill() {
|
||||
when(quotaConfig.getRefillPeriod(user)).thenReturn(Duration.ZERO);
|
||||
DateTime refillTime = clock.nowUtc();
|
||||
assertTake(1, 2, refillTime);
|
||||
|
@ -236,7 +233,7 @@ public class TokenStoreTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_noRefresh() {
|
||||
void testSuccess_noRefresh() {
|
||||
when(quotaConfig.getRefreshPeriod()).thenReturn(Duration.ZERO);
|
||||
DateTime refillTime = clock.nowUtc();
|
||||
assertTake(1, 2, refillTime);
|
||||
|
@ -246,7 +243,7 @@ public class TokenStoreTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_concurrency() throws Exception {
|
||||
void testSuccess_concurrency() throws Exception {
|
||||
ExecutorService executor = Executors.newWorkStealingPool();
|
||||
final DateTime time1 = clock.nowUtc();
|
||||
submitAndWaitForTasks(
|
||||
|
@ -297,7 +294,7 @@ public class TokenStoreTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_scheduleRefresh() throws Exception {
|
||||
void testSuccess_scheduleRefresh() throws Exception {
|
||||
when(quotaConfig.getRefreshPeriod()).thenReturn(Duration.standardSeconds(5));
|
||||
|
||||
tokenStore.scheduleRefresh();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue