Skip to content

Commit

Permalink
8326503: [11u] java/net/HttpURLConnection/HttpURLConnectionExpectCont…
Browse files Browse the repository at this point in the history
…inueTest.java fail because of package org.junit.jupiter.api does not exist

Reviewed-by: sgehwolf
  • Loading branch information
antbob authored and jerboaa committed Feb 26, 2024
1 parent 8dc2892 commit 93c5f7c
Showing 1 changed file with 48 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
* @run junit/othervm HttpURLConnectionExpectContinueTest
*/

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -44,32 +43,31 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.Assert.assertTrue;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class HttpURLConnectionExpectContinueTest {

class Control {
private static class Control {
volatile ServerSocket serverSocket = null;
volatile boolean stop = false;
volatile boolean respondWith100Continue = false;
volatile boolean write100ContinueTwice = false;
volatile String response = null;
}

private Thread serverThread = null;
private volatile Control control;
private static Thread serverThread = null;
private static volatile Control control;
static final Logger logger;

static {
control = new Control();
logger = Logger.getLogger("sun.net.www.protocol.http.HttpURLConnection");
logger.setLevel(Level.ALL);
Logger.getLogger("").getHandlers()[0].setLevel(Level.ALL);
}

@BeforeAll
public void startServerSocket() throws Exception {
Control control = this.control = new Control();
@BeforeClass
public static void startServerSocket() throws Exception {

control.serverSocket = new ServerSocket();
control.serverSocket.setReuseAddress(true);
Expand Down Expand Up @@ -170,9 +168,8 @@ public void startServerSocket() throws Exception {
serverThread.start();
}

@AfterAll
public void stopServerSocket() throws Exception {
Control control = this.control;
@AfterClass
public static void stopServerSocket() throws Exception {
control.stop = true;
control.serverSocket.close();
serverThread.join();
Expand All @@ -181,7 +178,6 @@ public void stopServerSocket() throws Exception {
@Test
public void testNonChunkedRequestAndNoExpect100ContinueResponse() throws Exception {
String body = "testNonChunkedRequestAndNoExpect100ContinueResponse";
Control control = this.control;
control.response = "HTTP/1.1 200 OK\r\n" +
"Connection: close\r\n" +
"Content-Length: " + body.length() + "\r\n" +
Expand All @@ -198,16 +194,15 @@ public void testNonChunkedRequestAndNoExpect100ContinueResponse() throws Excepti
int responseCode = connection.getResponseCode();
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
System.err.println("response body: " + responseBody);
assertTrue(responseCode == 200,
String.format("Expected 200 response, instead received %s", responseCode));
assertTrue(body.equals(responseBody),
String.format("Expected response %s, instead received %s", body, responseBody));
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
responseCode == 200);
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
body.equals(responseBody));
}

@Test
public void testNonChunkedRequestWithExpect100ContinueResponse() throws Exception {
String body = "testNonChunkedRequestWithExpect100ContinueResponse";
Control control = this.control;
control.response = "HTTP/1.1 200 OK\r\n" +
"Connection: close\r\n" +
"Content-Length: " + body.length() + "\r\n" +
Expand All @@ -224,16 +219,15 @@ public void testNonChunkedRequestWithExpect100ContinueResponse() throws Exceptio
int responseCode = connection.getResponseCode();
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
System.err.println("response body: " + responseBody);
assertTrue(responseCode == 200,
String.format("Expected 200 response, instead received %s", responseCode));
assertTrue(body.equals(responseBody),
String.format("Expected response %s, instead received %s", body, responseBody));
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
responseCode == 200);
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
body.equals(responseBody));
}

@Test
public void testNonChunkedRequestWithDoubleExpect100ContinueResponse() throws Exception {
String body = "testNonChunkedRequestWithDoubleExpect100ContinueResponse";
Control control = this.control;
control.response = "HTTP/1.1 200 OK\r\n" +
"Connection: close\r\n" +
"Content-Length: " + body.length() + "\r\n" +
Expand All @@ -250,16 +244,15 @@ public void testNonChunkedRequestWithDoubleExpect100ContinueResponse() throws Ex
int responseCode = connection.getResponseCode();
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
System.err.println("response body: " + responseBody);
assertTrue(responseCode == 200,
String.format("Expected 200 response, instead received %s", responseCode));
assertTrue(body.equals(responseBody),
String.format("Expected response %s, instead received %s", body, responseBody));
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
responseCode == 200);
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
body.equals(responseBody));
}

@Test
public void testChunkedRequestAndNoExpect100ContinueResponse() throws Exception {
String body = "testChunkedRequestAndNoExpect100ContinueResponse";
Control control = this.control;
control.response = "HTTP/1.1 200 OK\r\n" +
"Connection: close\r\n" +
"Content-Length: " + body.length() + "\r\n" +
Expand All @@ -277,16 +270,15 @@ public void testChunkedRequestAndNoExpect100ContinueResponse() throws Exception
int responseCode = connection.getResponseCode();
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
System.err.println("response body: " + responseBody);
assertTrue(responseCode == 200,
String.format("Expected 200 response, instead received %s", responseCode));
assertTrue(body.equals(responseBody),
String.format("Expected response %s, instead received %s", body, responseBody));
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
responseCode == 200);
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
body.equals(responseBody));
}

@Test
public void testChunkedRequestWithExpect100ContinueResponse() throws Exception {
String body = "testChunkedRequestWithExpect100ContinueResponse";
Control control = this.control;
control.response = "HTTP/1.1 200 OK\r\n" +
"Connection: close\r\n" +
"Content-Length: " + body.length() + "\r\n" +
Expand All @@ -304,16 +296,15 @@ public void testChunkedRequestWithExpect100ContinueResponse() throws Exception {
int responseCode = connection.getResponseCode();
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
System.err.println("response body: " + responseBody);
assertTrue(responseCode == 200,
String.format("Expected 200 response, instead received %s", responseCode));
assertTrue(body.equals(responseBody),
String.format("Expected response %s, instead received %s", body, responseBody));
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
responseCode == 200);
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
body.equals(responseBody));
}

@Test
public void testChunkedRequestWithDoubleExpect100ContinueResponse() throws Exception {
String body = "testChunkedRequestWithDoubleExpect100ContinueResponse";
Control control = this.control;
control.response = "HTTP/1.1 200 OK\r\n" +
"Connection: close\r\n" +
"Content-Length: " + body.length() + "\r\n" +
Expand All @@ -331,16 +322,15 @@ public void testChunkedRequestWithDoubleExpect100ContinueResponse() throws Excep
int responseCode = connection.getResponseCode();
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
System.err.println("response body: " + responseBody);
assertTrue(responseCode == 200,
String.format("Expected 200 response, instead received %s", responseCode));
assertTrue(body.equals(responseBody),
String.format("Expected response %s, instead received %s", body, responseBody));
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
responseCode == 200);
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
body.equals(responseBody));
}

@Test
public void testFixedLengthRequestAndNoExpect100ContinueResponse() throws Exception {
String body = "testFixedLengthRequestAndNoExpect100ContinueResponse";
Control control = this.control;
control.response = "HTTP/1.1 200 OK\r\n" +
"Connection: close\r\n" +
"Content-Length: " + body.length() + "\r\n" +
Expand All @@ -358,16 +348,15 @@ public void testFixedLengthRequestAndNoExpect100ContinueResponse() throws Except
int responseCode = connection.getResponseCode();
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
System.err.println("response body: " + responseBody);
assertTrue(responseCode == 200,
String.format("Expected 200 response, instead received %s", responseCode));
assertTrue(body.equals(responseBody),
String.format("Expected response %s, instead received %s", body, responseBody));
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
responseCode == 200);
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
body.equals(responseBody));
}

@Test
public void testFixedLengthRequestWithExpect100ContinueResponse() throws Exception {
String body = "testFixedLengthRequestWithExpect100ContinueResponse";
Control control = this.control;
control.response = "HTTP/1.1 200 OK\r\n" +
"Connection: close\r\n" +
"Content-Length: " + body.length() + "\r\n" +
Expand All @@ -385,16 +374,15 @@ public void testFixedLengthRequestWithExpect100ContinueResponse() throws Excepti
int responseCode = connection.getResponseCode();
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
System.err.println("response body: " + responseBody);
assertTrue(responseCode == 200,
String.format("Expected 200 response, instead received %s", responseCode));
assertTrue(body.equals(responseBody),
String.format("Expected response %s, instead received %s", body, responseBody));
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
responseCode == 200);
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
body.equals(responseBody));
}

@Test
public void testFixedLengthRequestWithDoubleExpect100ContinueResponse() throws Exception {
String body = "testFixedLengthRequestWithDoubleExpect100ContinueResponse";
Control control = this.control;
control.response = "HTTP/1.1 200 OK\r\n" +
"Connection: close\r\n" +
"Content-Length: " + body.length() + "\r\n" +
Expand All @@ -412,10 +400,10 @@ public void testFixedLengthRequestWithDoubleExpect100ContinueResponse() throws E
int responseCode = connection.getResponseCode();
String responseBody = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8).strip();
System.err.println("response body: " + responseBody);
assertTrue(responseCode == 200,
String.format("Expected 200 response, instead received %s", responseCode));
assertTrue(body.equals(responseBody),
String.format("Expected response %s, instead received %s", body, responseBody));
assertTrue(String.format("Expected 200 response, instead received %s", responseCode),
responseCode == 200);
assertTrue(String.format("Expected response %s, instead received %s", body, responseBody),
body.equals(responseBody));
}

// Creates a connection with all the common settings used in each test
Expand Down

1 comment on commit 93c5f7c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.