Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions test/jdk/java/net/httpclient/http2/BadHeadersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* with bad header fields.
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.httpclient.test.lib.http2.Http2TestServer jdk.test.lib.net.SimpleSSLContext
* @run testng/othervm -Djdk.internal.httpclient.debug=true BadHeadersTest
* @run junit/othervm -Djdk.internal.httpclient.debug=true BadHeadersTest
*/

import jdk.internal.net.http.common.HttpHeadersBuilder;
Expand All @@ -38,10 +38,10 @@
import jdk.internal.net.http.frame.HeadersFrame;
import jdk.internal.net.http.frame.Http2Frame;
import jdk.test.lib.net.SimpleSSLContext;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import java.io.IOException;
Expand All @@ -61,6 +61,7 @@
import java.util.Map.Entry;
import java.util.concurrent.ExecutionException;
import java.util.function.BiFunction;

import jdk.httpclient.test.lib.http2.Http2TestServer;
import jdk.httpclient.test.lib.http2.Http2TestExchange;
import jdk.httpclient.test.lib.http2.Http2TestExchangeImpl;
Expand All @@ -69,8 +70,9 @@
import jdk.httpclient.test.lib.http2.Http2TestServerConnection;
import static java.util.List.of;
import static java.util.Map.entry;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

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

SSLContext sslContext;
Http2TestServer http2TestServer; // HTTP/2 ( h2c )
Http2TestServer https2TestServer; // HTTP/2 ( h2 )
String http2URI;
String https2URI;
private static SSLContext sslContext;
private static Http2TestServer http2TestServer; // HTTP/2 ( h2c )
private static Http2TestServer https2TestServer; // HTTP/2 ( h2 )
private static String http2URI;
private static String https2URI;

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

@DataProvider(name = "variants")
public Object[][] variants() {
static Object[][] variants() {
return new Object[][] {
{ http2URI, false, oneContinuation },
{ https2URI, false, oneContinuation },
Expand All @@ -142,8 +143,8 @@ public Object[][] variants() {
};
}


@Test(dataProvider = "variants")
@ParameterizedTest
@MethodSource("variants")
void test(String uri,
boolean sameClient,
BiFunction<Integer,List<ByteBuffer>,List<Http2Frame>> headerFramesSupplier)
Expand Down Expand Up @@ -172,7 +173,8 @@ void test(String uri,
}
}

@Test(dataProvider = "variants")
@ParameterizedTest
@MethodSource("variants")
void testAsync(String uri,
boolean sameClient,
BiFunction<Integer,List<ByteBuffer>,List<Http2Frame>> headerFramesSupplier)
Expand Down Expand Up @@ -211,8 +213,7 @@ void testAsync(String uri,
// sync with implementation.
static void assertDetailMessage(Throwable throwable, int iterationIndex) {
try {
assertTrue(throwable instanceof ProtocolException,
"Expected ProtocolException, got " + throwable);
assertInstanceOf(ProtocolException.class, throwable, "Expected ProtocolException, got " + throwable);
assertTrue(throwable.getMessage().contains("malformed response"),
"Expected \"malformed response\" in: " + throwable.getMessage());

Expand All @@ -239,8 +240,8 @@ static void assertDetailMessage(Throwable throwable, int iterationIndex) {
}
}

@BeforeTest
public void setup() throws Exception {
@BeforeAll
static void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
Expand All @@ -264,8 +265,8 @@ public void setup() throws Exception {
https2TestServer.start();
}

@AfterTest
public void teardown() throws Exception {
@AfterAll
static void teardown() throws Exception {
http2TestServer.stop();
https2TestServer.stop();
}
Expand Down
27 changes: 13 additions & 14 deletions test/jdk/java/net/httpclient/http2/BadPushPromiseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
* @bug 8354276
* @library /test/lib /test/jdk/java/net/httpclient/lib
* @build jdk.test.lib.net.SimpleSSLContext jdk.httpclient.test.lib.http2.Http2TestServer
* @run testng/othervm
* @run junit/othervm
* -Djdk.internal.httpclient.debug=true
* -Djdk.httpclient.HttpClient.log=errors,requests,responses,trace
* BadPushPromiseTest
*/

import jdk.httpclient.test.lib.common.HttpServerAdapters;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand All @@ -59,7 +59,7 @@
import static java.net.http.HttpClient.Version.HTTP_2;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.List.of;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

public class BadPushPromiseTest {

Expand All @@ -73,11 +73,11 @@ public class BadPushPromiseTest {

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

HttpServerAdapters.HttpTestServer server;
URI uri;
static HttpServerAdapters.HttpTestServer server;
static URI uri;

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

@AfterTest
public void teardown() {
@AfterAll
static void teardown() {
server.stop();
}

/*
* Malformed push promise headers should kill the connection
*/
@Test
public void test() throws Exception {
void test() {
HttpClient client = HttpClient.newHttpClient();

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

if (iterationIndex == 0) { // unknown
assertTrue(throwable.getMessage().contains("Unknown pseudo-header"),
Expand Down
7 changes: 3 additions & 4 deletions test/jdk/java/net/httpclient/http2/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* jdk.test.lib.Asserts
* jdk.test.lib.Utils
* jdk.test.lib.net.SimpleSSLContext
* @run testng/othervm -Djdk.httpclient.HttpClient.log=ssl,requests,responses,errors BasicTest
* @run junit/othervm -Djdk.httpclient.HttpClient.log=ssl,requests,responses,errors BasicTest
*/

import java.io.IOException;
Expand All @@ -53,14 +53,13 @@
import jdk.httpclient.test.lib.http2.Http2TestExchange;
import jdk.httpclient.test.lib.http2.Http2EchoHandler;
import jdk.test.lib.net.SimpleSSLContext;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import static java.net.http.HttpClient.Version.HTTP_2;
import static jdk.test.lib.Asserts.assertFileContentsEqual;
import static jdk.test.lib.Utils.createTempFile;
import static jdk.test.lib.Utils.createTempFileOfSize;

@Test
public class BasicTest {

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

@Test
public static void test() throws Exception {
void test() throws Exception {
try {
initialize();
warmup(false);
Expand Down
Loading