Skip to content

Commit 7fe71a7

Browse files
author
Mahendra Chhipa
committed
8318662: Refactor some jdk/java/net/httpclient/http2 tests to JUnit
Reviewed-by: dfuchs
1 parent 52a923f commit 7fe71a7

File tree

5 files changed

+103
-128
lines changed

5 files changed

+103
-128
lines changed

test/jdk/java/net/httpclient/http2/BadHeadersTest.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* with bad header fields.
3030
* @library /test/lib /test/jdk/java/net/httpclient/lib
3131
* @build jdk.httpclient.test.lib.http2.Http2TestServer jdk.test.lib.net.SimpleSSLContext
32-
* @run testng/othervm -Djdk.internal.httpclient.debug=true BadHeadersTest
32+
* @run junit/othervm -Djdk.internal.httpclient.debug=true BadHeadersTest
3333
*/
3434

3535
import jdk.internal.net.http.common.HttpHeadersBuilder;
@@ -38,10 +38,10 @@
3838
import jdk.internal.net.http.frame.HeadersFrame;
3939
import jdk.internal.net.http.frame.Http2Frame;
4040
import jdk.test.lib.net.SimpleSSLContext;
41-
import org.testng.annotations.AfterTest;
42-
import org.testng.annotations.BeforeTest;
43-
import org.testng.annotations.DataProvider;
44-
import org.testng.annotations.Test;
41+
import org.junit.jupiter.api.AfterAll;
42+
import org.junit.jupiter.api.BeforeAll;
43+
import org.junit.jupiter.params.ParameterizedTest;
44+
import org.junit.jupiter.params.provider.MethodSource;
4545
import javax.net.ssl.SSLContext;
4646
import javax.net.ssl.SSLSession;
4747
import java.io.IOException;
@@ -61,6 +61,7 @@
6161
import java.util.Map.Entry;
6262
import java.util.concurrent.ExecutionException;
6363
import java.util.function.BiFunction;
64+
6465
import jdk.httpclient.test.lib.http2.Http2TestServer;
6566
import jdk.httpclient.test.lib.http2.Http2TestExchange;
6667
import jdk.httpclient.test.lib.http2.Http2TestExchangeImpl;
@@ -69,8 +70,9 @@
6970
import jdk.httpclient.test.lib.http2.Http2TestServerConnection;
7071
import static java.util.List.of;
7172
import static java.util.Map.entry;
72-
import static org.testng.Assert.assertTrue;
73-
import static org.testng.Assert.fail;
73+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
74+
import static org.junit.jupiter.api.Assertions.assertTrue;
75+
import static org.junit.jupiter.api.Assertions.fail;
7476

7577
// Code copied from ContinuationFrameTest
7678
public class BadHeadersTest {
@@ -85,11 +87,11 @@ public class BadHeadersTest {
8587
of(entry("hello", "world!"), entry(":status", "200")) // Pseudo header is not the first one
8688
);
8789

88-
SSLContext sslContext;
89-
Http2TestServer http2TestServer; // HTTP/2 ( h2c )
90-
Http2TestServer https2TestServer; // HTTP/2 ( h2 )
91-
String http2URI;
92-
String https2URI;
90+
private static SSLContext sslContext;
91+
private static Http2TestServer http2TestServer; // HTTP/2 ( h2c )
92+
private static Http2TestServer https2TestServer; // HTTP/2 ( h2 )
93+
private static String http2URI;
94+
private static String https2URI;
9395

9496
/**
9597
* A function that returns a list of 1) one HEADERS frame ( with an empty
@@ -127,8 +129,7 @@ public class BadHeadersTest {
127129
return frames;
128130
};
129131

130-
@DataProvider(name = "variants")
131-
public Object[][] variants() {
132+
static Object[][] variants() {
132133
return new Object[][] {
133134
{ http2URI, false, oneContinuation },
134135
{ https2URI, false, oneContinuation },
@@ -142,8 +143,8 @@ public Object[][] variants() {
142143
};
143144
}
144145

145-
146-
@Test(dataProvider = "variants")
146+
@ParameterizedTest
147+
@MethodSource("variants")
147148
void test(String uri,
148149
boolean sameClient,
149150
BiFunction<Integer,List<ByteBuffer>,List<Http2Frame>> headerFramesSupplier)
@@ -172,7 +173,8 @@ void test(String uri,
172173
}
173174
}
174175

175-
@Test(dataProvider = "variants")
176+
@ParameterizedTest
177+
@MethodSource("variants")
176178
void testAsync(String uri,
177179
boolean sameClient,
178180
BiFunction<Integer,List<ByteBuffer>,List<Http2Frame>> headerFramesSupplier)
@@ -211,8 +213,7 @@ void testAsync(String uri,
211213
// sync with implementation.
212214
static void assertDetailMessage(Throwable throwable, int iterationIndex) {
213215
try {
214-
assertTrue(throwable instanceof ProtocolException,
215-
"Expected ProtocolException, got " + throwable);
216+
assertInstanceOf(ProtocolException.class, throwable, "Expected ProtocolException, got " + throwable);
216217
assertTrue(throwable.getMessage().contains("malformed response"),
217218
"Expected \"malformed response\" in: " + throwable.getMessage());
218219

@@ -239,8 +240,8 @@ static void assertDetailMessage(Throwable throwable, int iterationIndex) {
239240
}
240241
}
241242

242-
@BeforeTest
243-
public void setup() throws Exception {
243+
@BeforeAll
244+
static void setup() throws Exception {
244245
sslContext = new SimpleSSLContext().get();
245246
if (sslContext == null)
246247
throw new AssertionError("Unexpected null sslContext");
@@ -264,8 +265,8 @@ public void setup() throws Exception {
264265
https2TestServer.start();
265266
}
266267

267-
@AfterTest
268-
public void teardown() throws Exception {
268+
@AfterAll
269+
static void teardown() throws Exception {
269270
http2TestServer.stop();
270271
https2TestServer.stop();
271272
}

test/jdk/java/net/httpclient/http2/BadPushPromiseTest.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@
2626
* @bug 8354276
2727
* @library /test/lib /test/jdk/java/net/httpclient/lib
2828
* @build jdk.test.lib.net.SimpleSSLContext jdk.httpclient.test.lib.http2.Http2TestServer
29-
* @run testng/othervm
29+
* @run junit/othervm
3030
* -Djdk.internal.httpclient.debug=true
3131
* -Djdk.httpclient.HttpClient.log=errors,requests,responses,trace
3232
* BadPushPromiseTest
3333
*/
3434

3535
import jdk.httpclient.test.lib.common.HttpServerAdapters;
36-
import org.testng.annotations.AfterTest;
37-
import org.testng.annotations.BeforeTest;
38-
import org.testng.annotations.Test;
36+
import org.junit.jupiter.api.AfterAll;
37+
import org.junit.jupiter.api.BeforeAll;
38+
import org.junit.jupiter.api.Test;
3939

4040
import java.io.ByteArrayInputStream;
4141
import java.io.IOException;
@@ -59,7 +59,7 @@
5959
import static java.net.http.HttpClient.Version.HTTP_2;
6060
import static java.nio.charset.StandardCharsets.UTF_8;
6161
import static java.util.List.of;
62-
import static org.testng.Assert.*;
62+
import static org.junit.jupiter.api.Assertions.*;
6363

6464
public class BadPushPromiseTest {
6565

@@ -73,11 +73,11 @@ public class BadPushPromiseTest {
7373

7474
static final String MAIN_RESPONSE_BODY = "the main response body";
7575

76-
HttpServerAdapters.HttpTestServer server;
77-
URI uri;
76+
static HttpServerAdapters.HttpTestServer server;
77+
static URI uri;
7878

79-
@BeforeTest
80-
public void setup() throws Exception {
79+
@BeforeAll
80+
static void setup() throws Exception {
8181
server = HttpServerAdapters.HttpTestServer.create(HTTP_2);
8282
HttpServerAdapters.HttpTestHandler handler = new ServerPushHandler(MAIN_RESPONSE_BODY);
8383
server.addHandler(handler, "/");
@@ -87,16 +87,16 @@ public void setup() throws Exception {
8787
uri = new URI("http://" + authority + "/foo/a/b/c");
8888
}
8989

90-
@AfterTest
91-
public void teardown() {
90+
@AfterAll
91+
static void teardown() {
9292
server.stop();
9393
}
9494

9595
/*
9696
* Malformed push promise headers should kill the connection
9797
*/
9898
@Test
99-
public void test() throws Exception {
99+
void test() {
100100
HttpClient client = HttpClient.newHttpClient();
101101

102102
for (int i=0; i< BAD_HEADERS.size(); i++) {
@@ -123,8 +123,7 @@ public void test() throws Exception {
123123
// sync with implementation.
124124
static void assertDetailMessage(Throwable throwable, int iterationIndex) {
125125
try {
126-
assertTrue(throwable instanceof ProtocolException,
127-
"Expected ProtocolException, got " + throwable);
126+
assertInstanceOf(ProtocolException.class, throwable, "Expected ProtocolException, got " + throwable);
128127

129128
if (iterationIndex == 0) { // unknown
130129
assertTrue(throwable.getMessage().contains("Unknown pseudo-header"),

test/jdk/java/net/httpclient/http2/BasicTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* jdk.test.lib.Asserts
3333
* jdk.test.lib.Utils
3434
* jdk.test.lib.net.SimpleSSLContext
35-
* @run testng/othervm -Djdk.httpclient.HttpClient.log=ssl,requests,responses,errors BasicTest
35+
* @run junit/othervm -Djdk.httpclient.HttpClient.log=ssl,requests,responses,errors BasicTest
3636
*/
3737

3838
import java.io.IOException;
@@ -53,14 +53,13 @@
5353
import jdk.httpclient.test.lib.http2.Http2TestExchange;
5454
import jdk.httpclient.test.lib.http2.Http2EchoHandler;
5555
import jdk.test.lib.net.SimpleSSLContext;
56-
import org.testng.annotations.Test;
56+
import org.junit.jupiter.api.Test;
5757

5858
import static java.net.http.HttpClient.Version.HTTP_2;
5959
import static jdk.test.lib.Asserts.assertFileContentsEqual;
6060
import static jdk.test.lib.Utils.createTempFile;
6161
import static jdk.test.lib.Utils.createTempFileOfSize;
6262

63-
@Test
6463
public class BasicTest {
6564

6665
private static final String TEMP_FILE_PREFIX =
@@ -127,7 +126,7 @@ public void handle(Http2TestExchange exchange) throws IOException {
127126
}
128127

129128
@Test
130-
public static void test() throws Exception {
129+
void test() throws Exception {
131130
try {
132131
initialize();
133132
warmup(false);

0 commit comments

Comments
 (0)