mirror of
https://github.com/google/nomulus.git
synced 2025-07-20 09:46:03 +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
|
@ -48,10 +48,9 @@ dependencies {
|
|||
|
||||
testCompile deps['com.google.monitoring-client:contrib']
|
||||
testCompile deps['com.google.truth:truth']
|
||||
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')
|
||||
|
|
|
@ -47,7 +47,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
|
||||
|
@ -63,7 +63,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
|
||||
|
|
|
@ -47,7 +47,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
|
||||
|
@ -63,7 +63,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
|
||||
|
|
|
@ -47,7 +47,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
|
||||
|
@ -63,7 +63,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
|
||||
|
|
|
@ -47,7 +47,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
|
||||
|
@ -63,7 +63,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
|
||||
|
|
|
@ -92,12 +92,14 @@ public class EppMessage {
|
|||
@VisibleForTesting
|
||||
public static final String XPASS_EXPRESSION =
|
||||
String.format("//eppns:result[@code>='%s'][@code<'%s']", 1000, 2000);
|
||||
|
||||
/**
|
||||
* Expression that expresses a result code in the {@link EppResponseMessage} that means failure.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public static final String XFAIL_EXPRESSION =
|
||||
String.format("//eppns:result[@code>='%s'][@code<'%s']", 2000, 3000);
|
||||
|
||||
// "Security" errors from RFC 5730, plus the error we get when we end
|
||||
// up no longer logged (see b/28196510).
|
||||
// 2002 "Command use error"
|
||||
|
|
|
@ -37,10 +37,8 @@ import io.netty.channel.Channel;
|
|||
import io.netty.channel.ChannelPromise;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
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.Mockito;
|
||||
|
||||
/**
|
||||
|
@ -56,8 +54,7 @@ import org.mockito.Mockito;
|
|||
* UnrecoverableStateException}, using mocks of the steps or actions, as the sequences are run using
|
||||
* the main thread (with {@link EmbeddedChannel}).
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class ProbingSequenceTest {
|
||||
class ProbingSequenceTest {
|
||||
|
||||
private static final String PROTOCOL_NAME = "PROTOCOL";
|
||||
private static final String MESSAGE_NAME = "MESSAGE";
|
||||
|
@ -100,8 +97,8 @@ public class ProbingSequenceTest {
|
|||
/** Default mock {@link Clock} passed into each {@link ProbingSequence} tested */
|
||||
private Clock clock = new FakeClock();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
// To avoid a NullPointerException, we must have a protocol return persistent connection as
|
||||
// false.
|
||||
doReturn(true).when(mockProtocol).persistentConnection();
|
||||
|
@ -124,7 +121,7 @@ public class ProbingSequenceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSequenceBasicConstruction_Success() {
|
||||
void testSequenceBasicConstruction_Success() {
|
||||
ProbingStep firstStep = Mockito.mock(ProbingStep.class);
|
||||
ProbingStep secondStep = Mockito.mock(ProbingStep.class);
|
||||
ProbingStep thirdStep = Mockito.mock(ProbingStep.class);
|
||||
|
@ -149,7 +146,7 @@ public class ProbingSequenceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSequenceAdvancedConstruction_Success() {
|
||||
void testSequenceAdvancedConstruction_Success() {
|
||||
ProbingStep firstStep = Mockito.mock(ProbingStep.class);
|
||||
ProbingStep secondStep = Mockito.mock(ProbingStep.class);
|
||||
ProbingStep thirdStep = Mockito.mock(ProbingStep.class);
|
||||
|
@ -175,7 +172,7 @@ public class ProbingSequenceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRunStep_Success() throws UndeterminedStateException {
|
||||
void testRunStep_Success() throws UndeterminedStateException {
|
||||
// Always returns a succeeded future on call to mockAction. Also advances the FakeClock by
|
||||
// standard LATENCY to check right latency is recorded.
|
||||
doAnswer(
|
||||
|
@ -229,7 +226,7 @@ public class ProbingSequenceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRunLoop_Success() throws UndeterminedStateException {
|
||||
void testRunLoop_Success() throws UndeterminedStateException {
|
||||
// Always returns a succeeded future on call to mockAction. Also advances the FakeClock by
|
||||
// standard LATENCY to check right latency is recorded.
|
||||
doAnswer(
|
||||
|
@ -367,7 +364,7 @@ public class ProbingSequenceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRunStep_FailureRunning() throws UndeterminedStateException {
|
||||
void testRunStep_FailureRunning() throws UndeterminedStateException {
|
||||
// Returns a failed future when calling the generated mock action. Also advances FakeClock by
|
||||
// LATENCY in order to check right latency is recorded.
|
||||
doAnswer(
|
||||
|
@ -402,7 +399,7 @@ public class ProbingSequenceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testRunStep_FailureGenerating() throws UndeterminedStateException {
|
||||
void testRunStep_FailureGenerating() throws UndeterminedStateException {
|
||||
// Mock first step throws an error when generating the first action, and advances the clock
|
||||
// by LATENCY.
|
||||
doAnswer(
|
||||
|
|
|
@ -17,24 +17,18 @@ package google.registry.monitoring.blackbox.handler;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import google.registry.monitoring.blackbox.exception.EppClientException;
|
||||
import google.registry.monitoring.blackbox.exception.FailureException;
|
||||
import google.registry.monitoring.blackbox.exception.UndeterminedStateException;
|
||||
import google.registry.monitoring.blackbox.message.EppRequestMessage;
|
||||
import google.registry.monitoring.blackbox.message.EppResponseMessage;
|
||||
import google.registry.monitoring.blackbox.util.EppUtils;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import java.io.IOException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameter;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import java.util.stream.Stream;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link EppActionHandler} and {@link EppMessageHandler} as well as integration
|
||||
|
@ -44,8 +38,7 @@ import org.xml.sax.SAXException;
|
|||
* of {@link EppResponseMessage}s with corresponding {@link EppRequestMessage} sent down channel
|
||||
* pipeline.
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class EppActionHandlerTest {
|
||||
class EppActionHandlerTest {
|
||||
|
||||
private static final String USER_ID = "TEST_ID";
|
||||
private static final String USER_PASSWORD = "TEST_PASSWORD";
|
||||
|
@ -54,94 +47,74 @@ public class EppActionHandlerTest {
|
|||
private static final String DOMAIN_NAME = "TEST_DOMAIN_NAME.test";
|
||||
private static final String SERVER_ID = "TEST_SERVER_ID";
|
||||
|
||||
@Parameter(0)
|
||||
public EppRequestMessage message;
|
||||
|
||||
private EmbeddedChannel channel;
|
||||
private EppActionHandler actionHandler = new EppActionHandler();
|
||||
private EppMessageHandler messageHandler = new EppMessageHandler(EppUtils.getGreetingResponse());
|
||||
|
||||
// We test all relevant EPP actions
|
||||
@Parameters(name = "{0}")
|
||||
public static EppRequestMessage[] data() {
|
||||
return new EppRequestMessage[] {
|
||||
EppUtils.getHelloMessage(EppUtils.getGreetingResponse()),
|
||||
EppUtils.getLoginMessage(EppUtils.getSuccessResponse(), USER_ID, USER_PASSWORD),
|
||||
EppUtils.getCreateMessage(EppUtils.getSuccessResponse()),
|
||||
EppUtils.getCreateMessage(EppUtils.getFailureResponse()),
|
||||
EppUtils.getDeleteMessage(EppUtils.getSuccessResponse()),
|
||||
EppUtils.getDeleteMessage(EppUtils.getFailureResponse()),
|
||||
EppUtils.getLogoutMessage(EppUtils.getSuccessResponse()),
|
||||
EppUtils.getCheckMessage(EppUtils.getDomainExistsResponse()),
|
||||
EppUtils.getCheckMessage(EppUtils.getDomainNotExistsResponse())
|
||||
};
|
||||
@SuppressWarnings("unused")
|
||||
static Stream<Arguments> provideTestCombinations() {
|
||||
return Stream.of(
|
||||
EppUtils.getHelloMessage(EppUtils.getGreetingResponse()),
|
||||
EppUtils.getLoginMessage(EppUtils.getSuccessResponse(), USER_ID, USER_PASSWORD),
|
||||
EppUtils.getCreateMessage(EppUtils.getSuccessResponse()),
|
||||
EppUtils.getCreateMessage(EppUtils.getFailureResponse()),
|
||||
EppUtils.getDeleteMessage(EppUtils.getSuccessResponse()),
|
||||
EppUtils.getDeleteMessage(EppUtils.getFailureResponse()),
|
||||
EppUtils.getLogoutMessage(EppUtils.getSuccessResponse()),
|
||||
EppUtils.getCheckMessage(EppUtils.getDomainExistsResponse()),
|
||||
EppUtils.getCheckMessage(EppUtils.getDomainNotExistsResponse()))
|
||||
.map(Arguments::of);
|
||||
}
|
||||
|
||||
/** Setup main three handlers to be used in pipeline. */
|
||||
@Before
|
||||
public void setup() throws EppClientException {
|
||||
private void setupRequestAndChannels(EppRequestMessage message, ChannelHandler... handlers)
|
||||
throws Exception {
|
||||
message.modifyMessage(USER_CLIENT_TRID, DOMAIN_NAME);
|
||||
}
|
||||
|
||||
private void setupEmbeddedChannel(ChannelHandler... handlers) {
|
||||
channel = new EmbeddedChannel(handlers);
|
||||
}
|
||||
|
||||
private Document getResponse(EppResponseMessage response, boolean fail, String clTrid)
|
||||
throws IOException, EppClientException {
|
||||
if (response.name().equals("greeting")) {
|
||||
if (fail) {
|
||||
return EppUtils.getBasicResponse(true, clTrid, SERVER_ID);
|
||||
} else {
|
||||
return EppUtils.getGreeting();
|
||||
}
|
||||
} else if (response.name().equals("domainExists")) {
|
||||
return EppUtils.getDomainCheck(!fail, clTrid, SERVER_ID, DOMAIN_NAME);
|
||||
|
||||
} else if (response.name().equals("domainNotExists")) {
|
||||
return EppUtils.getDomainCheck(fail, clTrid, SERVER_ID, DOMAIN_NAME);
|
||||
|
||||
} else if (response.name().equals("success")) {
|
||||
return EppUtils.getBasicResponse(!fail, clTrid, SERVER_ID);
|
||||
|
||||
} else {
|
||||
return EppUtils.getBasicResponse(fail, clTrid, SERVER_ID);
|
||||
throws Exception {
|
||||
switch (response.name()) {
|
||||
case "greeting":
|
||||
if (fail) {
|
||||
return EppUtils.getBasicResponse(true, clTrid, SERVER_ID);
|
||||
} else {
|
||||
return EppUtils.getGreeting();
|
||||
}
|
||||
case "domainExists":
|
||||
return EppUtils.getDomainCheck(!fail, clTrid, SERVER_ID, DOMAIN_NAME);
|
||||
case "domainNotExists":
|
||||
return EppUtils.getDomainCheck(fail, clTrid, SERVER_ID, DOMAIN_NAME);
|
||||
case "success":
|
||||
return EppUtils.getBasicResponse(!fail, clTrid, SERVER_ID);
|
||||
default:
|
||||
return EppUtils.getBasicResponse(fail, clTrid, SERVER_ID);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicAction_Success_Embedded()
|
||||
throws SAXException, IOException, EppClientException, FailureException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideTestCombinations")
|
||||
void testBasicAction_Success_Embedded(EppRequestMessage message) throws Exception {
|
||||
// We simply use an embedded channel in this instance
|
||||
setupEmbeddedChannel(actionHandler);
|
||||
|
||||
setupRequestAndChannels(message, actionHandler);
|
||||
ChannelFuture future = actionHandler.getFinishedFuture();
|
||||
|
||||
EppResponseMessage response = message.getExpectedResponse();
|
||||
|
||||
response.getDocument(
|
||||
EppUtils.docToByteBuf(getResponse(message.getExpectedResponse(), false, USER_CLIENT_TRID)));
|
||||
|
||||
channel.writeInbound(response);
|
||||
|
||||
ChannelFuture unusedFuture = future.syncUninterruptibly();
|
||||
|
||||
assertThat(future.isSuccess()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicAction_FailCode_Embedded()
|
||||
throws SAXException, IOException, EppClientException, FailureException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideTestCombinations")
|
||||
void testBasicAction_FailCode_Embedded(EppRequestMessage message) throws Exception {
|
||||
// We simply use an embedded channel in this instance
|
||||
setupEmbeddedChannel(actionHandler);
|
||||
|
||||
setupRequestAndChannels(message, actionHandler);
|
||||
ChannelFuture future = actionHandler.getFinishedFuture();
|
||||
|
||||
EppResponseMessage response = message.getExpectedResponse();
|
||||
|
||||
response.getDocument(
|
||||
EppUtils.docToByteBuf(getResponse(message.getExpectedResponse(), true, USER_CLIENT_TRID)));
|
||||
|
||||
channel.writeInbound(response);
|
||||
|
||||
assertThrows(
|
||||
|
@ -151,19 +124,15 @@ public class EppActionHandlerTest {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicAction_FailTRID_Embedded()
|
||||
throws SAXException, IOException, EppClientException, FailureException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideTestCombinations")
|
||||
void testBasicAction_FailTRID_Embedded(EppRequestMessage message) throws Exception {
|
||||
// We simply use an embedded channel in this instance
|
||||
setupEmbeddedChannel(actionHandler);
|
||||
|
||||
setupRequestAndChannels(message, actionHandler);
|
||||
ChannelFuture future = actionHandler.getFinishedFuture();
|
||||
|
||||
EppResponseMessage response = message.getExpectedResponse();
|
||||
|
||||
response.getDocument(
|
||||
EppUtils.docToByteBuf(getResponse(message.getExpectedResponse(), false, FAILURE_TRID)));
|
||||
|
||||
channel.writeInbound(response);
|
||||
|
||||
if (message.getExpectedResponse().name().equals("greeting")) {
|
||||
|
@ -178,32 +147,26 @@ public class EppActionHandlerTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegratedAction_Success_Embedded()
|
||||
throws IOException, SAXException, UndeterminedStateException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideTestCombinations")
|
||||
void testIntegratedAction_Success_Embedded(EppRequestMessage message) throws Exception {
|
||||
// We simply use an embedded channel in this instance
|
||||
setupEmbeddedChannel(messageHandler, actionHandler);
|
||||
|
||||
setupRequestAndChannels(message, messageHandler, actionHandler);
|
||||
ChannelFuture future = actionHandler.getFinishedFuture();
|
||||
channel.writeOutbound(message);
|
||||
|
||||
channel.writeInbound(
|
||||
EppUtils.docToByteBuf(getResponse(message.getExpectedResponse(), false, USER_CLIENT_TRID)));
|
||||
|
||||
ChannelFuture unusedFuture = future.syncUninterruptibly();
|
||||
|
||||
assertThat(future.isSuccess()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegratedAction_FailCode_Embedded()
|
||||
throws IOException, SAXException, UndeterminedStateException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideTestCombinations")
|
||||
void testIntegratedAction_FailCode_Embedded(EppRequestMessage message) throws Exception {
|
||||
// We simply use an embedded channel in this instance
|
||||
setupEmbeddedChannel(messageHandler, actionHandler);
|
||||
|
||||
setupRequestAndChannels(message, messageHandler, actionHandler);
|
||||
ChannelFuture future = actionHandler.getFinishedFuture();
|
||||
channel.writeOutbound(message);
|
||||
|
||||
channel.writeInbound(
|
||||
EppUtils.docToByteBuf(getResponse(message.getExpectedResponse(), true, USER_CLIENT_TRID)));
|
||||
|
||||
|
@ -214,15 +177,13 @@ public class EppActionHandlerTest {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegratedAction_FailTRID_Embedded()
|
||||
throws IOException, SAXException, UndeterminedStateException {
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideTestCombinations")
|
||||
void testIntegratedAction_FailTRID_Embedded(EppRequestMessage message) throws Exception {
|
||||
// We simply use an embedded channel in this instance
|
||||
setupEmbeddedChannel(messageHandler, actionHandler);
|
||||
|
||||
setupRequestAndChannels(message, messageHandler, actionHandler);
|
||||
ChannelFuture future = actionHandler.getFinishedFuture();
|
||||
channel.writeOutbound(message);
|
||||
|
||||
channel.writeInbound(
|
||||
EppUtils.docToByteBuf(getResponse(message.getExpectedResponse(), false, FAILURE_TRID)));
|
||||
|
||||
|
|
|
@ -38,9 +38,7 @@ import io.netty.channel.nio.NioEventLoopGroup;
|
|||
import io.netty.handler.codec.http.FullHttpResponse;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import javax.inject.Provider;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link WebWhoisActionHandler}.
|
||||
|
@ -48,8 +46,7 @@ import org.junit.runners.JUnit4;
|
|||
* <p>Attempts to test how well {@link WebWhoisActionHandler} works when responding to all possible
|
||||
* types of responses
|
||||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class WebWhoisActionHandlerTest {
|
||||
class WebWhoisActionHandlerTest {
|
||||
|
||||
private static final int HTTP_PORT = 80;
|
||||
private static final String HTTP_REDIRECT = "http://";
|
||||
|
@ -105,7 +102,7 @@ public class WebWhoisActionHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBasic_responseOk() {
|
||||
void testBasic_responseOk() {
|
||||
// setup
|
||||
setup("", null, true);
|
||||
setupChannel(initialProtocol);
|
||||
|
@ -126,7 +123,7 @@ public class WebWhoisActionHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBasic_responseFailure_badRequest() {
|
||||
void testBasic_responseFailure_badRequest() {
|
||||
// setup
|
||||
setup("", null, false);
|
||||
setupChannel(initialProtocol);
|
||||
|
@ -152,7 +149,7 @@ public class WebWhoisActionHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testBasic_responseFailure_badURL() {
|
||||
void testBasic_responseFailure_badURL() {
|
||||
// setup
|
||||
setup("", null, false);
|
||||
setupChannel(initialProtocol);
|
||||
|
@ -179,7 +176,7 @@ public class WebWhoisActionHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testAdvanced_redirect() {
|
||||
void testAdvanced_redirect() {
|
||||
// Sets up EventLoopGroup with 1 thread to be blocking.
|
||||
EventLoopGroup group = new NioEventLoopGroup(1);
|
||||
|
||||
|
|
|
@ -29,23 +29,21 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
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.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class EppMessageTest {
|
||||
/** Unit tests for {@link EppMessage}. */
|
||||
class EppMessageTest {
|
||||
|
||||
private Document xmlDoc = null;
|
||||
private Document greeting = null;
|
||||
private DocumentBuilder builder = null;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void beforeEach() throws Exception {
|
||||
String xmlString =
|
||||
"<epp>"
|
||||
+ "<textAndAttr myAttr1='1'>text1</textAndAttr>"
|
||||
|
@ -64,7 +62,7 @@ public class EppMessageTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void xmlDocToStringSuccess() throws Exception {
|
||||
void xmlDocToStringSuccess() throws Exception {
|
||||
Document xml = builder.newDocument();
|
||||
Element doc = xml.createElement("doc");
|
||||
Element title = xml.createElement("title");
|
||||
|
@ -88,7 +86,7 @@ public class EppMessageTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void xmlDoctoByteArraySuccess() throws Exception {
|
||||
void xmlDoctoByteArraySuccess() throws Exception {
|
||||
Document xml = builder.newDocument();
|
||||
Element doc = xml.createElement("doc");
|
||||
Element title = xml.createElement("title");
|
||||
|
@ -112,12 +110,12 @@ public class EppMessageTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void eppValidateSuccess() throws Exception {
|
||||
void eppValidateSuccess() throws Exception {
|
||||
EppMessage.eppValidate(greeting);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eppValidateFail() {
|
||||
void eppValidateFail() {
|
||||
assertThrows(SAXException.class, () -> EppMessage.eppValidate(xmlDoc));
|
||||
}
|
||||
|
||||
|
@ -127,7 +125,7 @@ public class EppMessageTest {
|
|||
* actual (greeting) respoonse.
|
||||
*/
|
||||
@Test
|
||||
public void verifyResponseSuccess() throws Exception {
|
||||
void verifyResponseSuccess() throws Exception {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add("epp");
|
||||
list.add("//textAndAttr[@myAttr1='1'] | //textAndAttr[child::text()='text1']");
|
||||
|
@ -139,7 +137,7 @@ public class EppMessageTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void verifyEppResponseSuccess() throws Exception {
|
||||
void verifyEppResponseSuccess() throws Exception {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add("*");
|
||||
list.add("/eppns:epp");
|
||||
|
@ -151,7 +149,7 @@ public class EppMessageTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void verifyResponseMissingTextFail() {
|
||||
void verifyResponseMissingTextFail() {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add("epp");
|
||||
list.add("//textAndAttr[child::text()='text2']");
|
||||
|
@ -160,7 +158,7 @@ public class EppMessageTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void verifyResponseMissingAttrFail() {
|
||||
void verifyResponseMissingAttrFail() {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add("epp");
|
||||
list.add("//textAndAttr/@myAttr2");
|
||||
|
@ -169,7 +167,7 @@ public class EppMessageTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void verifyResponseSplitTextAttrFail() {
|
||||
void verifyResponseSplitTextAttrFail() {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add("epp");
|
||||
list.add("//textAndAttrSplitRepeated[@myAttr3='3'][child::text()='text3']");
|
||||
|
@ -178,7 +176,7 @@ public class EppMessageTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getEppDocFromTemplateTest() throws Exception {
|
||||
void getEppDocFromTemplateTest() throws Exception {
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
replaceMap.put("//eppns:expectedClTRID", "ABC-1234-CBA");
|
||||
replaceMap.put("//domainns:name", "foo");
|
||||
|
@ -189,7 +187,7 @@ public class EppMessageTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getEppDocFromTemplateTestFail() {
|
||||
void getEppDocFromTemplateTestFail() {
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
replaceMap.put("//eppns:create", "ABC-1234-CBA");
|
||||
replaceMap.put("//domainns:name", "foo");
|
||||
|
@ -199,7 +197,7 @@ public class EppMessageTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void checkValidDomainName() {
|
||||
void checkValidDomainName() {
|
||||
String domainName = "good.tld";
|
||||
assertThat(domainName.matches(EppMessage.VALID_SLD_LABEL_REGEX)).isTrue();
|
||||
domainName = "good.tld.";
|
||||
|
|
|
@ -19,14 +19,11 @@ import static com.google.monitoring.metrics.contrib.LongMetricSubject.assertThat
|
|||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import google.registry.monitoring.blackbox.metric.MetricsCollector.ResponseType;
|
||||
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 MetricsCollector}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class MetricsCollectorTest {
|
||||
class MetricsCollectorTest {
|
||||
|
||||
private final String requestName = "request";
|
||||
private final String responseName = "response";
|
||||
|
@ -34,13 +31,13 @@ public class MetricsCollectorTest {
|
|||
|
||||
private final MetricsCollector metrics = new MetricsCollector();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
metrics.resetMetric();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneRecord() {
|
||||
void testOneRecord() {
|
||||
metrics.recordResult(protocol, requestName, responseName, ResponseType.SUCCESS, 100);
|
||||
|
||||
assertThat(MetricsCollector.responsesCounter)
|
||||
|
@ -56,7 +53,7 @@ public class MetricsCollectorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleRecords_sameStatus() {
|
||||
void testMultipleRecords_sameStatus() {
|
||||
metrics.recordResult(protocol, requestName, responseName, ResponseType.FAILURE, 100);
|
||||
metrics.recordResult(protocol, requestName, responseName, ResponseType.FAILURE, 200);
|
||||
|
||||
|
@ -77,7 +74,7 @@ public class MetricsCollectorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleRecords_differentStatus() {
|
||||
void testMultipleRecords_differentStatus() {
|
||||
metrics.recordResult(protocol, requestName, responseName, ResponseType.SUCCESS, 100);
|
||||
metrics.recordResult(protocol, requestName, responseName, ResponseType.FAILURE, 200);
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public class TestServer {
|
|||
this(new NioEventLoopGroup(1), localAddress, handlers);
|
||||
}
|
||||
|
||||
public TestServer(
|
||||
private TestServer(
|
||||
EventLoopGroup eventLoopGroup,
|
||||
LocalAddress localAddress,
|
||||
ImmutableList<? extends ChannelHandler> handlers) {
|
||||
|
@ -108,7 +108,7 @@ public class TestServer {
|
|||
* @param destinationInput - Server will send back an {@link HttpResponseStatus} OK response
|
||||
* when receiving a request with this host location
|
||||
*/
|
||||
public RedirectHandler(String redirectInput, String destinationInput, String destinationPath) {
|
||||
RedirectHandler(String redirectInput, String destinationInput, String destinationPath) {
|
||||
this.redirectInput = redirectInput;
|
||||
this.destinationInput = destinationInput;
|
||||
this.destinationPath = destinationPath;
|
||||
|
|
|
@ -20,14 +20,11 @@ import google.registry.monitoring.blackbox.exception.UndeterminedStateException;
|
|||
import google.registry.monitoring.blackbox.message.EppRequestMessage;
|
||||
import google.registry.monitoring.blackbox.util.EppUtils;
|
||||
import io.netty.channel.Channel;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
/** Unit Tests for each {@link Token} subtype (just {@link WebWhoisToken} for now) */
|
||||
@RunWith(JUnit4.class)
|
||||
public class EppTokenTest {
|
||||
class EppTokenTest {
|
||||
|
||||
private static String TEST_HOST = "host";
|
||||
private static String TEST_TLD = "tld";
|
||||
|
@ -36,7 +33,7 @@ public class EppTokenTest {
|
|||
private EppToken transientEppToken = new EppToken.Transient(TEST_TLD, TEST_HOST);
|
||||
|
||||
@Test
|
||||
public void testMessageModificationSuccess_PersistentToken() throws UndeterminedStateException {
|
||||
void testMessageModificationSuccess_PersistentToken() throws UndeterminedStateException {
|
||||
|
||||
EppRequestMessage originalMessage = EppUtils.getCreateMessage(EppUtils.getSuccessResponse());
|
||||
String domainName = persistentEppToken.getCurrentDomainName();
|
||||
|
@ -51,7 +48,7 @@ public class EppTokenTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMessageModificationSuccess_TransientToken() throws UndeterminedStateException {
|
||||
void testMessageModificationSuccess_TransientToken() throws UndeterminedStateException {
|
||||
|
||||
EppRequestMessage originalMessage = EppUtils.getCreateMessage(EppUtils.getSuccessResponse());
|
||||
String domainName = transientEppToken.getCurrentDomainName();
|
||||
|
@ -66,7 +63,7 @@ public class EppTokenTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testNext_persistentToken() {
|
||||
void testNext_persistentToken() {
|
||||
String domainName = persistentEppToken.getCurrentDomainName();
|
||||
Channel mockChannel = Mockito.mock(Channel.class);
|
||||
persistentEppToken.setChannel(mockChannel);
|
||||
|
@ -78,7 +75,7 @@ public class EppTokenTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testNext_transientToken() {
|
||||
void testNext_transientToken() {
|
||||
String domainName = transientEppToken.getCurrentDomainName();
|
||||
Channel mockChannel = Mockito.mock(Channel.class);
|
||||
transientEppToken.setChannel(mockChannel);
|
||||
|
|
|
@ -19,13 +19,10 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.monitoring.blackbox.exception.UndeterminedStateException;
|
||||
import google.registry.monitoring.blackbox.message.HttpRequestMessage;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit Tests for {@link WebWhoisToken} */
|
||||
@RunWith(JUnit4.class)
|
||||
public class WebWhoisTokenTest {
|
||||
class WebWhoisTokenTest {
|
||||
|
||||
private static final String PREFIX = "whois.nic.";
|
||||
private static final String HOST = "starter";
|
||||
|
@ -35,10 +32,10 @@ public class WebWhoisTokenTest {
|
|||
private final ImmutableList<String> testDomains =
|
||||
ImmutableList.of(FIRST_TLD, SECOND_TLD, THIRD_TLD);
|
||||
|
||||
public Token webToken = new WebWhoisToken(testDomains);
|
||||
private Token webToken = new WebWhoisToken(testDomains);
|
||||
|
||||
@Test
|
||||
public void testMessageModification() throws UndeterminedStateException {
|
||||
void testMessageModification() throws UndeterminedStateException {
|
||||
// creates Request message with header
|
||||
HttpRequestMessage message = new HttpRequestMessage();
|
||||
message.headers().set("host", HOST);
|
||||
|
@ -49,13 +46,13 @@ public class WebWhoisTokenTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testHostOfToken() {
|
||||
void testHostOfToken() {
|
||||
assertThat(webToken.host()).isEqualTo(PREFIX + FIRST_TLD);
|
||||
assertThat(webToken.host()).isEqualTo(PREFIX + FIRST_TLD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNextToken() {
|
||||
void testNextToken() {
|
||||
assertThat(webToken.host()).isEqualTo(PREFIX + FIRST_TLD);
|
||||
webToken = webToken.next();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue