From fc77e3e9a2bedd3cefc98ca28516eb85ceefe2e5 Mon Sep 17 00:00:00 2001 From: Daniel Fuchs Date: Thu, 5 Mar 2026 11:12:33 +0000 Subject: [PATCH] 8378599: Refactor tests under test/jdk/java/net/httpclient/whitebox from TestNG to JUnit Reviewed-by: vyazici, syan --- .../httpclient/whitebox/AltSvcFrameTest.java | 36 +++--- .../whitebox/AltSvcRegistryTest.java | 21 +-- .../AuthenticationFilterTestDriver.java | 4 +- .../whitebox/DefaultProxyDriver.java | 4 +- .../httpclient/whitebox/DemandTestDriver.java | 4 +- .../httpclient/whitebox/FlowTestDriver.java | 4 +- .../whitebox/FramesDecoderTestDriver.java | 4 +- .../whitebox/Http1HeaderParserTestDriver.java | 4 +- .../whitebox/MinimalFutureTestDriver.java | 4 +- .../whitebox/RawChannelTestDriver.java | 6 +- .../whitebox/SSLEchoTubeTestDriver.java | 4 +- .../whitebox/SSLFlowDelegateTestDriver.java | 4 +- .../whitebox/SSLTubeTestDriver.java | 4 +- .../whitebox/SelectorTestDriver.java | 4 +- .../whitebox/WindowControllerTestDriver.java | 4 +- .../whitebox/WrapperTestDriver.java | 4 +- .../net/http/AbstractSSLTubeTest.java | 6 +- .../net/http/AuthenticationFilterTest.java | 61 ++++----- .../jdk/internal/net/http/DefaultProxy.java | 33 ++--- .../jdk/internal/net/http/FlowTest.java | 16 +-- .../net/http/Http1HeaderParserTest.java | 47 +++---- .../jdk/internal/net/http/RawChannelTest.java | 11 +- .../internal/net/http/SSLEchoTubeTest.java | 6 +- .../net/http/SSLFlowDelegateTest.java | 75 +++++------ .../jdk/internal/net/http/SSLTubeTest.java | 14 +- .../jdk/internal/net/http/SelectorTest.java | 6 +- .../net/http/WindowControllerTest.java | 121 +++++++++--------- .../jdk/internal/net/http/WrapperTest.java | 7 +- .../internal/net/http/common/DemandTest.java | 63 +++++---- .../net/http/common/MinimalFutureTest.java | 15 +-- .../net/http/frame/FramesDecoderTest.java | 32 ++--- 31 files changed, 324 insertions(+), 304 deletions(-) diff --git a/test/jdk/java/net/httpclient/whitebox/AltSvcFrameTest.java b/test/jdk/java/net/httpclient/whitebox/AltSvcFrameTest.java index 589e5409044..b9e5f2d58fe 100644 --- a/test/jdk/java/net/httpclient/whitebox/AltSvcFrameTest.java +++ b/test/jdk/java/net/httpclient/whitebox/AltSvcFrameTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -48,17 +48,19 @@ import jdk.internal.net.http.HttpClientAccess; import jdk.internal.net.http.common.HttpHeadersBuilder; import jdk.internal.net.http.frame.AltSvcFrame; import jdk.test.lib.net.SimpleSSLContext; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; import static java.net.http.HttpResponse.BodyHandlers.ofString; import static jdk.internal.net.http.AltServicesRegistry.AltService; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /* * @test - * @summary This test verifies alt-svc registry updation for frames + * @summary This test verifies alt-svc registry updating for frames * @library /test/lib /test/jdk/java/net/httpclient/lib * @build java.net.http/jdk.internal.net.http.HttpClientAccess * jdk.httpclient.test.lib.http2.Http2TestServer @@ -82,7 +84,7 @@ import static org.testng.Assert.assertTrue; * java.base/sun.net.www.http * java.base/sun.net.www * java.base/sun.net - * @run testng/othervm + * @run junit/othervm * -Dtest.requiresHost=true * -Djdk.httpclient.HttpClient.log=headers * -Djdk.internal.httpclient.disableHostnameVerification @@ -90,7 +92,6 @@ import static org.testng.Assert.assertTrue; * AltSvcFrameTest */ - public class AltSvcFrameTest { private static final String IGNORED_HOST = "www.should-be-ignored.com"; @@ -109,18 +110,23 @@ public class AltSvcFrameTest { static HttpClient client; private static final SSLContext server = SimpleSSLContext.findSSLContext(); - @BeforeTest - public void setUp() throws Exception { + @BeforeAll + public static void setUp() throws Exception { getRegistry(); https2Server = new Http2TestServer("localhost", true, server); https2Server.addHandler(new AltSvcFrameTestHandler(), "/"); https2Server.setExchangeSupplier(AltSvcFrameTest.CFTHttp2TestExchange::new); https2Server.start(); https2URI = "https://" + https2Server.serverAuthority() + "/"; - - } + @AfterAll + public static void tearDown() { + if (client != null) client.close(); + if (https2Server != null) https2Server.stop(); + } + + static AltServicesRegistry getRegistry() { client = HttpClient.newBuilder() .sslContext(server) @@ -139,7 +145,7 @@ public class AltSvcFrameTest { .GET() .build(); HttpResponse response = client.send(request, ofString()); - assertEquals(response.statusCode(), 200, "unexpected response code"); + assertEquals(200, response.statusCode(), "unexpected response code"); final List services = registry.lookup(URI.create(https2URI), "h3").toList(); System.out.println("Alt services in registry for " + https2URI + " = " + services); final boolean hasExpectedAltSvc = services.stream().anyMatch( @@ -158,7 +164,7 @@ public class AltSvcFrameTest { .GET() .build(); HttpResponse response = client.send(request, ofString()); - assertEquals(response.statusCode(), 200, "unexpected response code"); + assertEquals(200, response.statusCode(), "unexpected response code"); final List services = registry.lookup( URI.create(FOO_BAR_ORIGIN), "h3").toList(); System.out.println("Alt services in registry for " + FOO_BAR_ORIGIN + " = " + services); diff --git a/test/jdk/java/net/httpclient/whitebox/AltSvcRegistryTest.java b/test/jdk/java/net/httpclient/whitebox/AltSvcRegistryTest.java index b853f715415..682082ba9f8 100644 --- a/test/jdk/java/net/httpclient/whitebox/AltSvcRegistryTest.java +++ b/test/jdk/java/net/httpclient/whitebox/AltSvcRegistryTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,8 +26,6 @@ import jdk.internal.net.http.AltServicesRegistry; import jdk.test.lib.net.SimpleSSLContext; import jdk.httpclient.test.lib.common.HttpServerAdapters; import jdk.httpclient.test.lib.http2.Http2TestServer; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; import javax.net.ssl.SSLContext; import java.io.IOException; @@ -46,6 +44,10 @@ import java.util.concurrent.Executors; import static jdk.internal.net.http.AltServicesRegistry.AltService; import static java.net.http.HttpResponse.BodyHandlers.ofString; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + /* * @test * @summary This test verifies alt-svc registry updates @@ -73,7 +75,7 @@ import static java.net.http.HttpResponse.BodyHandlers.ofString; * java.base/sun.net.www * java.base/sun.net * java.base/jdk.internal.util - * @run testng/othervm + * @run junit/othervm * -Dtest.requiresHost=true * -Djdk.httpclient.HttpClient.log=headers * -Djdk.internal.httpclient.disableHostnameVerification @@ -81,7 +83,6 @@ import static java.net.http.HttpResponse.BodyHandlers.ofString; * AltSvcRegistryTest */ - public class AltSvcRegistryTest implements HttpServerAdapters { static HttpTestServer https2Server; @@ -89,8 +90,8 @@ public class AltSvcRegistryTest implements HttpServerAdapters { static HttpClient client; private static final SSLContext server = SimpleSSLContext.findSSLContext(); - @BeforeTest - public void setUp() throws Exception { + @BeforeAll + public static void setUp() throws Exception { getRegistry(); final ExecutorService executor = Executors.newCachedThreadPool(); https2Server = HttpServerAdapters.HttpTestServer.of( @@ -98,8 +99,12 @@ public class AltSvcRegistryTest implements HttpServerAdapters { https2Server.addHandler(new AltSvcRegistryTestHandler("https", https2Server), "/"); https2Server.start(); https2URI = "https://" + https2Server.serverAuthority() + "/"; + } - + @AfterAll + public static void tearDown() { + if (client != null) client.close(); + if (https2Server != null) https2Server.stop(); } static AltServicesRegistry getRegistry() { diff --git a/test/jdk/java/net/httpclient/whitebox/AuthenticationFilterTestDriver.java b/test/jdk/java/net/httpclient/whitebox/AuthenticationFilterTestDriver.java index e932455e409..5808c380593 100644 --- a/test/jdk/java/net/httpclient/whitebox/AuthenticationFilterTestDriver.java +++ b/test/jdk/java/net/httpclient/whitebox/AuthenticationFilterTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,5 +24,5 @@ /* * @test * @modules java.net.http/jdk.internal.net.http - * @run testng java.net.http/jdk.internal.net.http.AuthenticationFilterTest + * @run junit java.net.http/jdk.internal.net.http.AuthenticationFilterTest */ diff --git a/test/jdk/java/net/httpclient/whitebox/DefaultProxyDriver.java b/test/jdk/java/net/httpclient/whitebox/DefaultProxyDriver.java index 5c18fd84a0f..54127855386 100644 --- a/test/jdk/java/net/httpclient/whitebox/DefaultProxyDriver.java +++ b/test/jdk/java/net/httpclient/whitebox/DefaultProxyDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,7 +27,7 @@ * @summary Verifies that the HTTP Client, by default, uses the system-wide * proxy selector, and that that selector supports the standard HTTP proxy * system properties. - * @run testng/othervm + * @run junit/othervm * -Dhttp.proxyHost=foo.proxy.com * -Dhttp.proxyPort=9876 * -Dhttp.nonProxyHosts=*.direct.com diff --git a/test/jdk/java/net/httpclient/whitebox/DemandTestDriver.java b/test/jdk/java/net/httpclient/whitebox/DemandTestDriver.java index ea442878261..c8b793a289c 100644 --- a/test/jdk/java/net/httpclient/whitebox/DemandTestDriver.java +++ b/test/jdk/java/net/httpclient/whitebox/DemandTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,5 +24,5 @@ /* * @test * @modules java.net.http/jdk.internal.net.http.common - * @run testng java.net.http/jdk.internal.net.http.common.DemandTest + * @run junit java.net.http/jdk.internal.net.http.common.DemandTest */ diff --git a/test/jdk/java/net/httpclient/whitebox/FlowTestDriver.java b/test/jdk/java/net/httpclient/whitebox/FlowTestDriver.java index c24a733db3b..4468b5d6eb6 100644 --- a/test/jdk/java/net/httpclient/whitebox/FlowTestDriver.java +++ b/test/jdk/java/net/httpclient/whitebox/FlowTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,5 +25,5 @@ * @test * @compile/module=java.net.http ../../../../../../lib/jdk/test/lib/net/SimpleSSLContext.java * @modules java.net.http/jdk.internal.net.http - * @run testng/timeout=480 java.net.http/jdk.internal.net.http.FlowTest + * @run junit/timeout=480 java.net.http/jdk.internal.net.http.FlowTest */ diff --git a/test/jdk/java/net/httpclient/whitebox/FramesDecoderTestDriver.java b/test/jdk/java/net/httpclient/whitebox/FramesDecoderTestDriver.java index 9b3c8878669..7edc555d8a6 100644 --- a/test/jdk/java/net/httpclient/whitebox/FramesDecoderTestDriver.java +++ b/test/jdk/java/net/httpclient/whitebox/FramesDecoderTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,7 +25,7 @@ * @test * @bug 8195823 * @modules java.net.http/jdk.internal.net.http.frame - * @run testng/othervm + * @run junit/othervm * -Djdk.internal.httpclient.debug=true * java.net.http/jdk.internal.net.http.frame.FramesDecoderTest */ diff --git a/test/jdk/java/net/httpclient/whitebox/Http1HeaderParserTestDriver.java b/test/jdk/java/net/httpclient/whitebox/Http1HeaderParserTestDriver.java index b18142601a5..f3b9d410b51 100644 --- a/test/jdk/java/net/httpclient/whitebox/Http1HeaderParserTestDriver.java +++ b/test/jdk/java/net/httpclient/whitebox/Http1HeaderParserTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,5 +25,5 @@ * @test * @bug 8195138 * @modules java.net.http/jdk.internal.net.http - * @run testng java.net.http/jdk.internal.net.http.Http1HeaderParserTest + * @run junit java.net.http/jdk.internal.net.http.Http1HeaderParserTest */ diff --git a/test/jdk/java/net/httpclient/whitebox/MinimalFutureTestDriver.java b/test/jdk/java/net/httpclient/whitebox/MinimalFutureTestDriver.java index 316ca29e2a6..90fe6816adc 100644 --- a/test/jdk/java/net/httpclient/whitebox/MinimalFutureTestDriver.java +++ b/test/jdk/java/net/httpclient/whitebox/MinimalFutureTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,5 +24,5 @@ /* * @test * @modules java.net.http/jdk.internal.net.http.common - * @run testng java.net.http/jdk.internal.net.http.common.MinimalFutureTest + * @run junit java.net.http/jdk.internal.net.http.common.MinimalFutureTest */ diff --git a/test/jdk/java/net/httpclient/whitebox/RawChannelTestDriver.java b/test/jdk/java/net/httpclient/whitebox/RawChannelTestDriver.java index ab44fba5ecd..7ca448b7892 100644 --- a/test/jdk/java/net/httpclient/whitebox/RawChannelTestDriver.java +++ b/test/jdk/java/net/httpclient/whitebox/RawChannelTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,10 +25,10 @@ * @test * @bug 8151299 8164704 * @modules java.net.http/jdk.internal.net.http - * @run testng/othervm java.net.http/jdk.internal.net.http.RawChannelTest + * @run junit/othervm java.net.http/jdk.internal.net.http.RawChannelTest */ // use -// @run testng/othervm -Dseed=6434511950803022575 +// @run junit/othervm -Dseed=6434511950803022575 // java.net.http/jdk.internal.net.http.RawChannelTest // to reproduce a failure with a particular seed (e.g. 6434511950803022575) // if this test is observed failing with that seed diff --git a/test/jdk/java/net/httpclient/whitebox/SSLEchoTubeTestDriver.java b/test/jdk/java/net/httpclient/whitebox/SSLEchoTubeTestDriver.java index d641513b298..b4b3e59326d 100644 --- a/test/jdk/java/net/httpclient/whitebox/SSLEchoTubeTestDriver.java +++ b/test/jdk/java/net/httpclient/whitebox/SSLEchoTubeTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,7 +25,7 @@ * @test * @compile/module=java.net.http ../../../../../../lib/jdk/test/lib/net/SimpleSSLContext.java * @modules java.net.http/jdk.internal.net.http - * @run testng/othervm + * @run junit/othervm * -Djdk.internal.httpclient.debug=true * java.net.http/jdk.internal.net.http.SSLEchoTubeTest */ diff --git a/test/jdk/java/net/httpclient/whitebox/SSLFlowDelegateTestDriver.java b/test/jdk/java/net/httpclient/whitebox/SSLFlowDelegateTestDriver.java index a49f53a844a..cb8e9801ca8 100644 --- a/test/jdk/java/net/httpclient/whitebox/SSLFlowDelegateTestDriver.java +++ b/test/jdk/java/net/httpclient/whitebox/SSLFlowDelegateTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,7 +28,7 @@ * downReader doesn't request any * @compile/module=java.net.http ../../../../../../lib/jdk/test/lib/net/SimpleSSLContext.java * @modules java.net.http/jdk.internal.net.http - * @run testng/othervm -Djdk.internal.httpclient.debug=true + * @run junit/othervm -Djdk.internal.httpclient.debug=true * -Djavax.net.debug=ssl:handshake * java.net.http/jdk.internal.net.http.SSLFlowDelegateTest */ diff --git a/test/jdk/java/net/httpclient/whitebox/SSLTubeTestDriver.java b/test/jdk/java/net/httpclient/whitebox/SSLTubeTestDriver.java index b1994777b14..2c73de26648 100644 --- a/test/jdk/java/net/httpclient/whitebox/SSLTubeTestDriver.java +++ b/test/jdk/java/net/httpclient/whitebox/SSLTubeTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,7 +25,7 @@ * @test * @compile/module=java.net.http ../../../../../../lib/jdk/test/lib/net/SimpleSSLContext.java * @modules java.net.http/jdk.internal.net.http - * @run testng/othervm + * @run junit/othervm * -Djdk.internal.httpclient.debug=true * java.net.http/jdk.internal.net.http.SSLTubeTest */ diff --git a/test/jdk/java/net/httpclient/whitebox/SelectorTestDriver.java b/test/jdk/java/net/httpclient/whitebox/SelectorTestDriver.java index 226e644e903..54d66d04cff 100644 --- a/test/jdk/java/net/httpclient/whitebox/SelectorTestDriver.java +++ b/test/jdk/java/net/httpclient/whitebox/SelectorTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,5 +25,5 @@ * @test * @bug 8151299 8164704 * @modules java.net.http/jdk.internal.net.http - * @run testng java.net.http/jdk.internal.net.http.SelectorTest + * @run junit java.net.http/jdk.internal.net.http.SelectorTest */ diff --git a/test/jdk/java/net/httpclient/whitebox/WindowControllerTestDriver.java b/test/jdk/java/net/httpclient/whitebox/WindowControllerTestDriver.java index 7943bfceaa0..16ac4aaefb8 100644 --- a/test/jdk/java/net/httpclient/whitebox/WindowControllerTestDriver.java +++ b/test/jdk/java/net/httpclient/whitebox/WindowControllerTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,5 +26,5 @@ * @bug 8207960 * @modules java.net.http/jdk.internal.net.http * @summary Non-negative WINDOW_UPDATE increments may leave the stream window size negative - * @run testng/othervm java.net.http/jdk.internal.net.http.WindowControllerTest + * @run junit/othervm java.net.http/jdk.internal.net.http.WindowControllerTest */ diff --git a/test/jdk/java/net/httpclient/whitebox/WrapperTestDriver.java b/test/jdk/java/net/httpclient/whitebox/WrapperTestDriver.java index 7ea2b07e3a7..dfc808ff68b 100644 --- a/test/jdk/java/net/httpclient/whitebox/WrapperTestDriver.java +++ b/test/jdk/java/net/httpclient/whitebox/WrapperTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,5 +24,5 @@ /* * @test * @modules java.net.http/jdk.internal.net.http - * @run testng java.net.http/jdk.internal.net.http.WrapperTest + * @run junit java.net.http/jdk.internal.net.http.WrapperTest */ diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AbstractSSLTubeTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AbstractSSLTubeTest.java index 944f8ae0872..699b537c980 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AbstractSSLTubeTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AbstractSSLTubeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,17 +26,13 @@ package jdk.internal.net.http; import jdk.internal.net.http.common.FlowTube; import jdk.internal.net.http.common.SSLTube; import jdk.internal.net.http.common.Utils; -import org.testng.annotations.Test; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLParameters; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.nio.ByteBuffer; import java.util.List; -import java.util.StringTokenizer; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AuthenticationFilterTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AuthenticationFilterTest.java index 415caeb1196..2e9672e4725 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AuthenticationFilterTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AuthenticationFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,9 +24,6 @@ package jdk.internal.net.http; import jdk.internal.net.http.common.HttpHeadersBuilder; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import org.testng.annotations.AfterClass; import java.lang.ref.Reference; import java.net.Authenticator; @@ -55,12 +52,15 @@ import static java.util.stream.Collectors.joining; import static java.net.http.HttpClient.Version.HTTP_1_1; import static java.net.http.HttpClient.Version.HTTP_2; import static java.net.http.HttpClient.Builder.NO_PROXY; -import static org.testng.Assert.*; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import static org.junit.jupiter.api.Assertions.*; public class AuthenticationFilterTest { - @DataProvider(name = "uris") - public Object[][] responses() { + public static Object[][] responses() { return new Object[][] { { "http://foo.com", HTTP_1_1, null }, { "http://foo.com", HTTP_2, null }, @@ -135,7 +135,8 @@ public class AuthenticationFilterTest { return s == null || s.isEmpty(); } - @Test(dataProvider = "uris") + @ParameterizedTest + @MethodSource("responses") public void testAuthentication(String uri, Version v, String proxy) throws Exception { String test = format("testAuthentication: {\"%s\", %s, \"%s\"}", uri, v, proxy); try { @@ -146,8 +147,8 @@ public class AuthenticationFilterTest { } } - @AfterClass - public void printDiagnostic() { + @AfterAll + public static void printDiagnostic() { if (FAILED.isEmpty()) { out.println("All tests passed"); return; @@ -183,7 +184,7 @@ public class AuthenticationFilterTest { HttpClientImpl client = facade.impl; AuthenticationFilter filter = new AuthenticationFilter(); - assertEquals(authenticator.COUNTER.get(), 0); + assertEquals(0, authenticator.COUNTER.get()); // Creates the first HttpRequestImpl, and call filter.request() with // it. The expectation is that the filter will not add any credentials, @@ -202,7 +203,7 @@ public class AuthenticationFilterTest { HttpHeaders hdrs = req.getSystemHeadersBuilder().build(); assertFalse(hdrs.firstValue(authorization(true)).isPresent()); assertFalse(hdrs.firstValue(authorization(false)).isPresent()); - assertEquals(authenticator.COUNTER.get(), 0); + assertEquals(0, authenticator.COUNTER.get()); // Creates the Response to the first request, and call filter.response // with it. That response has a 401 or 407 status code. @@ -221,9 +222,9 @@ public class AuthenticationFilterTest { out.println("Checking filter's response to " + unauthorized + " from " + uri); - assertTrue(next != null, "next should not be null"); + assertNotNull(next, "next should not be null"); String[] up = check(reqURI, next.getSystemHeadersBuilder().build(), proxy); - assertEquals(authenticator.COUNTER.get(), 1); + assertEquals(1, authenticator.COUNTER.get()); // Now simulate a new successful exchange to get the credentials in the cache // We first call filter.request with the request that was previously @@ -241,8 +242,8 @@ public class AuthenticationFilterTest { HttpHeaders h = HttpHeaders.of(Collections.emptyMap(), ACCEPT_ALL); response = new Response(next, exchange,h, null, 200, v); next = filter.response(response); - assertTrue(next == null, "next should be null"); - assertEquals(authenticator.COUNTER.get(), 1); + assertNull(next, "next should be null"); + assertEquals(1, authenticator.COUNTER.get()); // Now verify that the cache is used for the next request to the same server. // We're going to create a request to the same server by appending "/bar" to @@ -270,7 +271,7 @@ public class AuthenticationFilterTest { + " with proxy " + req2.proxy()); String[] up2 = check(reqURI, req2.getSystemHeadersBuilder().build(), proxy); assertTrue(Arrays.deepEquals(up, up2), format("%s:%s != %s:%s", up2[0], up2[1], up[0], up[1])); - assertEquals(authenticator.COUNTER.get(), 1); + assertEquals(1, authenticator.COUNTER.get()); // Now verify that the cache is not used if we send a request to a different server. // We're going to append ".bar" to the original request host name, and feed that @@ -316,7 +317,7 @@ public class AuthenticationFilterTest { java.util.stream.Stream.of(getAuthorization(h3, false)) .collect(joining(":"))); assertFalse(h3.firstValue(authorization(false)).isPresent()); - assertEquals(authenticator.COUNTER.get(), 1); + assertEquals(1, authenticator.COUNTER.get()); // Now we will verify that credentials for proxies are not used for servers and // conversely. @@ -365,7 +366,7 @@ public class AuthenticationFilterTest { String[] up4 = check(reqURI, h4, proxy); assertTrue(Arrays.deepEquals(up, up4), format("%s:%s != %s:%s", up4[0], up4[1], up[0], up[1])); } - assertEquals(authenticator.COUNTER.get(), 1); + assertEquals(1, authenticator.COUNTER.get()); if (proxy != null) { // Now if we were using a proxy, we're going to send the same request than @@ -380,7 +381,7 @@ public class AuthenticationFilterTest { MultiExchange multi5 = new MultiExchange(origReq5, req5, client, HttpResponse.BodyHandlers.replacing(null), null); out.println("Simulating new request to " + reqURI + " with a proxy " + req5.proxy()); - assertTrue(req5.proxy() == null, "req5.proxy() should be null"); + assertNull(req5.proxy(), "req5.proxy() should be null"); Exchange exchange5 = new Exchange<>(req5, multi5); filter.request(req5, multi5); out.println("Check that filter has not added server credentials from cache for " @@ -398,7 +399,7 @@ public class AuthenticationFilterTest { java.util.stream.Stream.of(getAuthorization(h5, true)) .collect(joining(":"))); assertFalse(h5.firstValue(authorization(true)).isPresent()); - assertEquals(authenticator.COUNTER.get(), 1); + assertEquals(1, authenticator.COUNTER.get()); // Now simulate a 401 response from the server HttpHeadersBuilder headers5Builder = new HttpHeadersBuilder(); @@ -410,11 +411,11 @@ public class AuthenticationFilterTest { out.println("Simulating " + unauthorized + " response from " + uri); HttpRequestImpl next5 = filter.response(response5); - assertEquals(authenticator.COUNTER.get(), 2); + assertEquals(2, authenticator.COUNTER.get()); out.println("Checking filter's response to " + unauthorized + " from " + uri); - assertTrue(next5 != null, "next5 should not be null"); + assertNotNull(next5, "next5 should not be null"); String[] up5 = check(reqURI, next5.getSystemHeadersBuilder().build(), null); // now simulate a 200 response from the server @@ -423,7 +424,7 @@ public class AuthenticationFilterTest { h = HttpHeaders.of(Map.of(), ACCEPT_ALL); response5 = new Response(next5, exchange5, h, null, 200, v); filter.response(response5); - assertEquals(authenticator.COUNTER.get(), 2); + assertEquals(2, authenticator.COUNTER.get()); // now send the request again, with proxy this time, and it should have both // server auth and proxy auth @@ -433,7 +434,7 @@ public class AuthenticationFilterTest { MultiExchange multi6 = new MultiExchange(origReq6, req6, client, HttpResponse.BodyHandlers.replacing(null), null); out.println("Simulating new request to " + reqURI + " with a proxy " + req6.proxy()); - assertTrue(req6.proxy() != null, "req6.proxy() should not be null"); + assertNotNull(req6.proxy(), "req6.proxy() should not be null"); Exchange exchange6 = new Exchange<>(req6, multi6); filter.request(req6, multi6); out.println("Check that filter has added server credentials from cache for " @@ -444,7 +445,7 @@ public class AuthenticationFilterTest { + reqURI + " (proxy: " + req6.proxy() + ")"); String[] up6 = check(reqURI, h6, proxy); assertTrue(Arrays.deepEquals(up, up6), format("%s:%s != %s:%s", up6[0], up6[1], up[0], up[1])); - assertEquals(authenticator.COUNTER.get(), 2); + assertEquals(2, authenticator.COUNTER.get()); } if (proxy == null && uri.contains("x/y/z")) { @@ -456,7 +457,7 @@ public class AuthenticationFilterTest { MultiExchange multi7 = new MultiExchange(origReq7, req7, client, HttpResponse.BodyHandlers.replacing(null), null); out.println("Simulating new request to " + reqURI7 + " with a proxy " + req7.proxy()); - assertTrue(req7.proxy() == null, "req7.proxy() should be null"); + assertNull(req7.proxy(), "req7.proxy() should be null"); Exchange exchange7 = new Exchange<>(req7, multi7); filter.request(req7, multi7); out.println("Check that filter has not added server credentials from cache for " @@ -475,7 +476,7 @@ public class AuthenticationFilterTest { java.util.stream.Stream.of(getAuthorization(h7, true)) .collect(joining(":"))); assertFalse(h7.firstValue(authorization(true)).isPresent()); - assertEquals(authenticator.COUNTER.get(), 1); + assertEquals(1, authenticator.COUNTER.get()); } @@ -516,7 +517,7 @@ public class AuthenticationFilterTest { out.println("user:password: " + u + ":" + p); String protocol = proxy != null ? "http" : reqURI.getScheme(); String expectedUser = "u." + protocol; - assertEquals(u, expectedUser); + assertEquals(expectedUser, u); String host = proxy == null ? reqURI.getHost() : proxy.substring(0, proxy.lastIndexOf(':')); int port = proxy == null ? reqURI.getPort() @@ -524,7 +525,7 @@ public class AuthenticationFilterTest { String expectedPw = concat(requestorType(proxy!=null), "basic", protocol, host, port, "earth", reqURI.toURL()); - assertEquals(p, expectedPw); + assertEquals(expectedPw, p); return new String[] {u, p}; } diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/DefaultProxy.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/DefaultProxy.java index 96d08ae2c34..819b02e7fc7 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/DefaultProxy.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/DefaultProxy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,8 +29,9 @@ import java.net.ProxySelector; import java.net.URI; import java.net.http.HttpClient; import java.util.List; -import org.testng.annotations.Test; -import static org.testng.Assert.assertEquals; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; public class DefaultProxy { @@ -42,7 +43,7 @@ public class DefaultProxy { public void testDefault() { ProxySelector ps = getProxySelector(); System.out.println("HttpClientImpl proxySelector:" + ps); - assertEquals(ps, ProxySelector.getDefault()); + assertEquals(ProxySelector.getDefault(), ps); } // From the test driver @@ -56,21 +57,21 @@ public class DefaultProxy { URI uri = URI.create("http://foo.com/example.html"); List plist = ps.select(uri); System.out.println("proxy list for " + uri + " : " + plist); - assertEquals(plist.size(), 1); + assertEquals(1, plist.size()); Proxy proxy = plist.get(0); - assertEquals(proxy.type(), Proxy.Type.HTTP); + assertEquals(Proxy.Type.HTTP, proxy.type()); InetSocketAddress expectedAddr = InetSocketAddress.createUnresolved("foo.proxy.com", 9876); - assertEquals(proxy.address(), expectedAddr); + assertEquals(expectedAddr, proxy.address()); // nonProxyHosts uri = URI.create("http://foo.direct.com/example.html"); plist = ps.select(uri); System.out.println("proxy list for " + uri + " : " + plist); - assertEquals(plist.size(), 1); + assertEquals(1, plist.size()); proxy = plist.get(0); - assertEquals(proxy.type(), Proxy.Type.DIRECT); - assertEquals(proxy.address(), null); + assertEquals(Proxy.Type.DIRECT, proxy.type()); + assertEquals(null, proxy.address()); } // From the test driver @@ -83,21 +84,21 @@ public class DefaultProxy { URI uri = URI.create("https://foo.com/example.html"); List plist = ps.select(uri); System.out.println("proxy list for " + uri + " : " + plist); - assertEquals(plist.size(), 1); + assertEquals(1, plist.size()); Proxy proxy = plist.get(0); - assertEquals(proxy.type(), Proxy.Type.HTTP); + assertEquals(Proxy.Type.HTTP, proxy.type()); InetSocketAddress expectedAddr = InetSocketAddress.createUnresolved("secure.proxy.com", 5443); - assertEquals(proxy.address(), expectedAddr); + assertEquals(expectedAddr, proxy.address()); // nonProxyHosts uri = URI.create("https://foo.direct.com/example.html"); plist = ps.select(uri); System.out.println("proxy list for " + uri + " : " + plist); - assertEquals(plist.size(), 1); + assertEquals(1, plist.size()); proxy = plist.get(0); - assertEquals(proxy.type(), Proxy.Type.DIRECT); - assertEquals(proxy.address(), null); + assertEquals(Proxy.Type.DIRECT, proxy.type()); + assertEquals(null, proxy.address()); } } diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/FlowTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/FlowTest.java index 3e9e967c061..cd05196b653 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/FlowTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/FlowTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,8 +32,6 @@ import java.net.InetSocketAddress; import java.net.Socket; import java.nio.ByteBuffer; import java.util.List; -import java.util.Random; -import java.util.StringTokenizer; import java.util.concurrent.BlockingQueue; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; @@ -47,10 +45,10 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import javax.net.ssl.*; import jdk.internal.net.http.common.Utils; -import org.testng.annotations.Test; import jdk.internal.net.http.common.SSLFlowDelegate; -@Test +import org.junit.jupiter.api.Test; + public class FlowTest extends AbstractRandomTest { private final SubmissionPublisher> srcPublisher; @@ -241,7 +239,7 @@ public class FlowTest extends AbstractRandomTest { private void clientReader() { try { InputStream is = clientSock.getInputStream(); - final int bufsize = FlowTest.randomRange(512, 16 * 1024); + final int bufsize = AbstractRandomTest.randomRange(512, 16 * 1024); println("clientReader: bufsize = " + bufsize); while (true) { byte[] buf = new byte[bufsize]; @@ -315,8 +313,8 @@ public class FlowTest extends AbstractRandomTest { private final AtomicInteger loopCount = new AtomicInteger(); public String monitor() { - return "serverLoopback: loopcount = " + loopCount.toString() - + " clientRead: count = " + readCount.toString(); + return "serverLoopback: loopcount = " + loopCount.get() + + " clientRead: count = " + readCount.get(); } // thread2 @@ -324,7 +322,7 @@ public class FlowTest extends AbstractRandomTest { try { InputStream is = serverSock.getInputStream(); OutputStream os = serverSock.getOutputStream(); - final int bufsize = FlowTest.randomRange(512, 16 * 1024); + final int bufsize = AbstractRandomTest.randomRange(512, 16 * 1024); println("serverLoopback: bufsize = " + bufsize); byte[] bb = new byte[bufsize]; while (true) { diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/Http1HeaderParserTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/Http1HeaderParserTest.java index 9bde9109095..a4c7b76aba8 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/Http1HeaderParserTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/Http1HeaderParserTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,22 +36,22 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.IntStream; import sun.net.www.MessageHeader; -import org.testng.annotations.Test; -import org.testng.annotations.DataProvider; import static java.lang.System.out; import static java.lang.String.format; import static java.nio.charset.StandardCharsets.ISO_8859_1; import static java.nio.charset.StandardCharsets.US_ASCII; import static java.util.stream.Collectors.toList; -import static org.testng.Assert.*; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import static org.junit.jupiter.api.Assertions.*; // Mostly verifies the "new" Http1HeaderParser returns the same results as the // tried and tested sun.net.www.MessageHeader. public class Http1HeaderParserTest { - @DataProvider(name = "responses") - public Object[][] responses() { + public static Object[][] responses() { List responses = new ArrayList<>(); String[] basic = @@ -316,7 +316,8 @@ public class Http1HeaderParserTest { } - @Test(dataProvider = "responses") + @ParameterizedTest + @MethodSource("responses") public void verifyHeaders(String respString) throws Exception { System.out.println("\ntesting:\n\t" + respString .replace("\r\n", "") @@ -339,7 +340,7 @@ public class Http1HeaderParserTest { String statusLine1 = messageHeaderMap.get(null).get(0); String statusLine2 = decoder.statusLine(); if (statusLine1.startsWith("HTTP")) {// skip the case where MH's messes up the status-line - assertEquals(statusLine2, statusLine1, "Status-line not equal"); + assertEquals(statusLine1, statusLine2, "Status-line not equal"); } else { assertTrue(statusLine2.startsWith("HTTP/1."), "Status-line not HTTP/1."); } @@ -356,7 +357,7 @@ public class Http1HeaderParserTest { assertHeadersEqual(messageHeaderMap, decoderMap1, "messageHeaderMap not equal to decoderMap1"); - assertEquals(availableBytes, b.remaining(), + assertEquals(b.remaining(), availableBytes, String.format("stream available (%d) not equal to remaining (%d)", availableBytes, b.remaining())); // byte at a time @@ -366,14 +367,13 @@ public class Http1HeaderParserTest { .collect(toList()); while (decoder.parse(buffers.remove(0)) != true); Map> decoderMap2 = decoder.headers().map(); - assertEquals(availableBytes, buffers.size(), + assertEquals(buffers.size(), availableBytes, "stream available not equals to remaining buffers"); - assertEquals(decoderMap1, decoderMap2, "decoder maps not equal"); + assertEquals(decoderMap2, decoderMap1, "decoder maps not equal"); } - @DataProvider(name = "errors") - public Object[][] errors() { + public static Object[][] errors() { List responses = new ArrayList<>(); // These responses are parsed, somewhat, by MessageHeaders but give @@ -451,12 +451,15 @@ public class Http1HeaderParserTest { return responses.stream().map(p -> new Object[] { p }).toArray(Object[][]::new); } - @Test(dataProvider = "errors", expectedExceptions = ProtocolException.class) + @ParameterizedTest + @MethodSource("errors") public void errors(String respString) throws ProtocolException { - byte[] bytes = respString.getBytes(US_ASCII); - Http1HeaderParser decoder = new Http1HeaderParser(); - ByteBuffer b = ByteBuffer.wrap(bytes); - decoder.parse(b); + assertThrows(ProtocolException.class, () -> { + byte[] bytes = respString.getBytes(US_ASCII); + Http1HeaderParser decoder = new Http1HeaderParser(); + ByteBuffer b = ByteBuffer.wrap(bytes); + decoder.parse(b); + }); } void assertHeadersEqual(Map> expected, @@ -466,7 +469,7 @@ public class Http1HeaderParserTest { if (expected.equals(actual)) return; - assertEquals(expected.size(), actual.size(), + assertEquals(actual.size(), expected.size(), format("%s. Expected size %d, actual size %s. %nexpected= %s,%n actual=%s.", msg, expected.size(), actual.size(), mapToString(expected), mapToString(actual))); @@ -479,7 +482,7 @@ public class Http1HeaderParserTest { if (key.equalsIgnoreCase(other.getKey())) { found = true; List otherValues = other.getValue(); - assertEquals(values.size(), otherValues.size(), + assertEquals(otherValues.size(), values.size(), format("%s. Expected list size %d, actual size %s", msg, values.size(), otherValues.size())); if (!(values.containsAll(otherValues) && otherValues.containsAll(values))) @@ -508,11 +511,11 @@ public class Http1HeaderParserTest { public static void main(String... args) throws Exception { Http1HeaderParserTest test = new Http1HeaderParserTest(); int count = 0; - for (Object[] objs : test.responses()) { + for (Object[] objs : Http1HeaderParserTest.responses()) { out.println("Testing " + count++ + ", " + objs[0]); test.verifyHeaders((String) objs[0]); } - for (Object[] objs : test.errors()) { + for (Object[] objs : Http1HeaderParserTest.errors()) { out.println("Testing " + count++ + ", " + objs[0]); try { test.errors((String) objs[0]); diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java index f6bcdcb4d33..62ca237d2f1 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -47,10 +47,11 @@ import java.net.http.HttpResponse; import java.util.concurrent.atomic.AtomicReference; import jdk.internal.net.http.websocket.RawChannel; -import org.testng.annotations.Test; import static java.net.http.HttpResponse.BodyHandlers.discarding; import static java.util.concurrent.TimeUnit.SECONDS; -import static org.testng.Assert.assertEquals; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; /* * This test exercises mechanics of _independent_ reads and writes on the @@ -222,8 +223,8 @@ public class RawChannelTest { closeChannel(chan); }); exit.await(); // All done, we need to compare results: - assertEquals(clientRead.get(), serverWritten.get()); - assertEquals(serverRead.get(), clientWritten.get()); + assertEquals(serverWritten.get(), clientRead.get()); + assertEquals(clientWritten.get(), serverRead.get()); Throwable serverError = testServer.failed.get(); if (serverError != null) { throw new AssertionError("TestServer failed: " diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLEchoTubeTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLEchoTubeTest.java index 2884b74eee5..4316a46a25c 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLEchoTubeTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLEchoTubeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,7 +28,6 @@ import jdk.internal.net.http.common.FlowTube; import jdk.internal.net.http.common.SSLTube; import jdk.internal.net.http.common.SequentialScheduler; import jdk.internal.net.http.common.Utils; -import org.testng.annotations.Test; import java.io.IOException; import java.nio.ByteBuffer; @@ -44,7 +43,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; -@Test +import org.junit.jupiter.api.Test; + public class SSLEchoTubeTest extends AbstractSSLTubeTest { @Test diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLFlowDelegateTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLFlowDelegateTest.java index 6b031bdfa58..32511de173b 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLFlowDelegateTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLFlowDelegateTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -58,10 +58,11 @@ import jdk.internal.net.http.common.Logger; import jdk.internal.net.http.common.SSLFlowDelegate; import jdk.internal.net.http.common.SubscriberWrapper; import jdk.internal.net.http.common.Utils; -import org.testng.Assert; -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 static org.junit.jupiter.api.Assertions.*; // jtreg test definition for this test resides in SSLFlowDelegateTestDriver.java public class SSLFlowDelegateTest { @@ -70,38 +71,38 @@ public class SSLFlowDelegateTest { private static final Random random = new Random(); private static final byte DATA_BYTE = (byte) random.nextInt(); - private ExecutorService executor; - private SSLParameters sslParams; - private SSLServerSocket sslServerSocket; - private SSLEngine clientEngine; - private CompletableFuture testCompletion; + private static ExecutorService executor; + private static SSLParameters sslParams; + private static SSLServerSocket sslServerSocket; + private static SSLEngine clientEngine; + private static CompletableFuture testCompletion; - @BeforeTest - public void beforeTest() throws Exception { - this.executor = Executors.newCachedThreadPool(); - this.testCompletion = new CompletableFuture<>(); + @BeforeAll + public static void beforeTest() throws Exception { + executor = Executors.newCachedThreadPool(); + testCompletion = new CompletableFuture<>(); final SSLParameters sp = new SSLParameters(); sp.setApplicationProtocols(new String[]{ALPN}); - this.sslParams = sp; + sslParams = sp; var sslContext = SimpleSSLContextWhiteboxAdapter.findSSLContext(); - this.sslServerSocket = startServer(sslContext); - println(debugTag, "Server started at " + this.sslServerSocket.getInetAddress() + ":" - + this.sslServerSocket.getLocalPort()); + sslServerSocket = startServer(sslContext); + println(debugTag, "Server started at " + sslServerSocket.getInetAddress() + ":" + + sslServerSocket.getLocalPort()); - this.clientEngine = createClientEngine(sslContext); + clientEngine = createClientEngine(sslContext); } - @AfterTest - public void afterTest() throws Exception { - if (this.sslServerSocket != null) { - println(debugTag, "Closing server socket " + this.sslServerSocket); - this.sslServerSocket.close(); + @AfterAll + public static void afterTest() throws Exception { + if (sslServerSocket != null) { + println(debugTag, "Closing server socket " + sslServerSocket); + sslServerSocket.close(); } - if (this.executor != null) { - println(debugTag, "Shutting down the executor " + this.executor); - this.executor.shutdownNow(); + if (executor != null) { + println(debugTag, "Shutting down the executor " + executor); + executor.shutdownNow(); } } @@ -117,30 +118,30 @@ public class SSLFlowDelegateTest { } } - private SSLServerSocket createSSLServerSocket( + private static SSLServerSocket createSSLServerSocket( final SSLContext ctx, final InetSocketAddress bindAddr) throws IOException { final SSLServerSocketFactory fac = ctx.getServerSocketFactory(); final SSLServerSocket sslServerSocket = (SSLServerSocket) fac.createServerSocket(); sslServerSocket.setReuseAddress(false); - sslServerSocket.setSSLParameters(this.sslParams); + sslServerSocket.setSSLParameters(sslParams); sslServerSocket.bind(bindAddr); return sslServerSocket; } - private SSLServerSocket startServer(final SSLContext ctx) throws Exception { + private static SSLServerSocket startServer(final SSLContext ctx) throws Exception { final SSLServerSocket sslServerSocket = createSSLServerSocket(ctx, new InetSocketAddress(InetAddress.getLoopbackAddress(), 0)); final Runnable serverResponsePusher = new ServerResponsePusher(sslServerSocket, - this.testCompletion); + testCompletion); final Thread serverThread = new Thread(serverResponsePusher, "serverResponsePusher"); // start the thread which will accept() a socket connection and send data over it serverThread.start(); return sslServerSocket; } - private SSLEngine createClientEngine(final SSLContext ctx) { + private static SSLEngine createClientEngine(final SSLContext ctx) { final SSLEngine clientEngine = ctx.createSSLEngine(); - clientEngine.setSSLParameters(this.sslParams); + clientEngine.setSSLParameters(sslParams); clientEngine.setUseClientMode(true); return clientEngine; } @@ -170,7 +171,7 @@ public class SSLFlowDelegateTest { // in various places in this test. If the "testCompletion" completes before // the "soleExpectedAppData" completes (typically due to some exception), // then we complete the "soleExpectedAppData" too. - this.testCompletion.whenComplete((r, t) -> { + testCompletion.whenComplete((r, t) -> { if (soleExpectedAppData.isDone()) { return; } @@ -221,7 +222,7 @@ public class SSLFlowDelegateTest { println(debugTag, "Waiting for handshake to complete"); final String negotiatedALPN = sslFlowDelegate.alpn().join(); println(debugTag, "handshake completed, with negotiated ALPN: " + negotiatedALPN); - Assert.assertEquals(negotiatedALPN, ALPN, "unexpected ALPN negotiated"); + assertEquals(ALPN, negotiatedALPN, "unexpected ALPN negotiated"); try { // now wait for the initial (and the only) chunk of application data to be // received by the AppResponseReceiver @@ -254,7 +255,7 @@ public class SSLFlowDelegateTest { private void failTest(final CompletionException ce) { final Throwable cause = ce.getCause(); - Assert.fail(cause.getMessage() == null ? "test failed" : cause.getMessage(), cause); + fail(cause.getMessage() == null ? "test failed" : cause.getMessage(), cause); } // uses reflection to get hold of the SSLFlowDelegate.reader.outputQ member field, @@ -288,7 +289,7 @@ public class SSLFlowDelegateTest { } println(debugTag, "num unsolicited bytes so far = " + numUnsolicitated); } - Assert.assertEquals(numUnsolicitated, 0, + assertEquals(0, numUnsolicitated, "SSLFlowDelegate has accumulated " + numUnsolicitated + " unsolicited bytes"); } diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLTubeTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLTubeTest.java index ac6a235b8e2..bb8d583e07b 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLTubeTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SSLTubeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,7 +26,6 @@ package jdk.internal.net.http; import jdk.internal.net.http.common.FlowTube; import jdk.internal.net.http.common.SSLFlowDelegate; import jdk.internal.net.http.common.Utils; -import org.testng.annotations.Test; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLParameters; @@ -51,7 +50,8 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.SubmissionPublisher; import java.util.concurrent.atomic.AtomicInteger; -@Test +import org.junit.jupiter.api.Test; + public class SSLTubeTest extends AbstractSSLTubeTest { @Test @@ -125,7 +125,7 @@ public class SSLTubeTest extends AbstractSSLTubeTest { private void clientReader() { try { InputStream is = clientSock.getInputStream(); - final int bufsize = randomRange(512, 16 * 1024); + final int bufsize = AbstractRandomTest.randomRange(512, 16 * 1024); System.out.println("clientReader: bufsize = " + bufsize); while (true) { byte[] buf = new byte[bufsize]; @@ -137,7 +137,7 @@ public class SSLTubeTest extends AbstractSSLTubeTest { allBytesReceived.await(); System.out.println("clientReader: closing publisher"); publisher.close(); - sleep(2000); + AbstractSSLTubeTest.sleep(2000); Utils.close(is, clientSock); return; } @@ -206,13 +206,13 @@ public class SSLTubeTest extends AbstractSSLTubeTest { try { InputStream is = serverSock.getInputStream(); OutputStream os = serverSock.getOutputStream(); - final int bufsize = randomRange(512, 16 * 1024); + final int bufsize = AbstractRandomTest.randomRange(512, 16 * 1024); System.out.println("serverLoopback: bufsize = " + bufsize); byte[] bb = new byte[bufsize]; while (true) { int n = is.read(bb); if (n == -1) { - sleep(2000); + AbstractSSLTubeTest.sleep(2000); is.close(); os.close(); serverSock.close(); diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SelectorTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SelectorTest.java index 5b8da3b9979..3027df0436e 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SelectorTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SelectorTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,20 +31,20 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; import java.net.http.HttpClient; import java.net.http.HttpResponse; -import org.testng.annotations.Test; import jdk.internal.net.http.websocket.RawChannel; import static java.lang.System.out; import static java.nio.charset.StandardCharsets.US_ASCII; import static java.util.concurrent.TimeUnit.SECONDS; import static java.net.http.HttpResponse.BodyHandlers.discarding; +import org.junit.jupiter.api.Test; + /** * Whitebox test of selector mechanics. Currently only a simple test * setting one read and one write event is done. It checks that the * write event occurs first, followed by the read event and then no * further events occur despite the conditions actually still existing. */ -@Test public class SelectorTest { AtomicInteger counter = new AtomicInteger(); diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/WindowControllerTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/WindowControllerTest.java index 0a94f471575..5df3b4227e6 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/WindowControllerTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/WindowControllerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,92 +23,93 @@ package jdk.internal.net.http; -import org.testng.annotations.Test; import static jdk.internal.net.http.frame.SettingsFrame.DEFAULT_INITIAL_WINDOW_SIZE; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertThrows; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class WindowControllerTest { @Test public void testConnectionWindowOverflow() { WindowController wc = new WindowController(); - assertEquals(wc.connectionWindowSize(), DEFAULT_INITIAL_WINDOW_SIZE); - assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false); - assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false); - assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false); - assertEquals(wc.connectionWindowSize(), DEFAULT_INITIAL_WINDOW_SIZE); + assertEquals(DEFAULT_INITIAL_WINDOW_SIZE, wc.connectionWindowSize()); + assertEquals(false, wc.increaseConnectionWindow(Integer.MAX_VALUE)); + assertEquals(false, wc.increaseConnectionWindow(Integer.MAX_VALUE)); + assertEquals(false, wc.increaseConnectionWindow(Integer.MAX_VALUE)); + assertEquals(DEFAULT_INITIAL_WINDOW_SIZE, wc.connectionWindowSize()); wc.registerStream(1, DEFAULT_INITIAL_WINDOW_SIZE); wc.tryAcquire(DEFAULT_INITIAL_WINDOW_SIZE - 1, 1, null); - assertEquals(wc.connectionWindowSize(), 1); - assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false); - assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false); - assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false); - assertEquals(wc.connectionWindowSize(), 1); + assertEquals(1, wc.connectionWindowSize()); + assertEquals(false, wc.increaseConnectionWindow(Integer.MAX_VALUE)); + assertEquals(false, wc.increaseConnectionWindow(Integer.MAX_VALUE)); + assertEquals(false, wc.increaseConnectionWindow(Integer.MAX_VALUE)); + assertEquals(1, wc.connectionWindowSize()); wc.increaseConnectionWindow(Integer.MAX_VALUE - 1 -1); - assertEquals(wc.connectionWindowSize(), Integer.MAX_VALUE - 1); - assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false); - assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false); - assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false); - assertEquals(wc.connectionWindowSize(), Integer.MAX_VALUE - 1); + assertEquals(Integer.MAX_VALUE - 1, wc.connectionWindowSize()); + assertEquals(false, wc.increaseConnectionWindow(Integer.MAX_VALUE)); + assertEquals(false, wc.increaseConnectionWindow(Integer.MAX_VALUE)); + assertEquals(false, wc.increaseConnectionWindow(Integer.MAX_VALUE)); + assertEquals(Integer.MAX_VALUE - 1, wc.connectionWindowSize()); wc.increaseConnectionWindow(1); - assertEquals(wc.connectionWindowSize(), Integer.MAX_VALUE); - assertEquals(wc.increaseConnectionWindow(1), false); - assertEquals(wc.increaseConnectionWindow(100), false); - assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false); - assertEquals(wc.connectionWindowSize(), Integer.MAX_VALUE); + assertEquals(Integer.MAX_VALUE, wc.connectionWindowSize()); + assertEquals(false, wc.increaseConnectionWindow(1)); + assertEquals(false, wc.increaseConnectionWindow(100)); + assertEquals(false, wc.increaseConnectionWindow(Integer.MAX_VALUE)); + assertEquals(Integer.MAX_VALUE, wc.connectionWindowSize()); } @Test public void testStreamWindowOverflow() { WindowController wc = new WindowController(); wc.registerStream(1, DEFAULT_INITIAL_WINDOW_SIZE); - assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 1), false); - assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 1), false); - assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 1), false); + assertEquals(false, wc.increaseStreamWindow(Integer.MAX_VALUE, 1)); + assertEquals(false, wc.increaseStreamWindow(Integer.MAX_VALUE, 1)); + assertEquals(false, wc.increaseStreamWindow(Integer.MAX_VALUE, 1)); wc.registerStream(3, DEFAULT_INITIAL_WINDOW_SIZE); - assertEquals(wc.increaseStreamWindow(100, 3), true); - assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 3), false); - assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 3), false); + assertEquals(true, wc.increaseStreamWindow(100, 3)); + assertEquals(false, wc.increaseStreamWindow(Integer.MAX_VALUE, 3)); + assertEquals(false, wc.increaseStreamWindow(Integer.MAX_VALUE, 3)); wc.registerStream(5, 0); - assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 5), true); - assertEquals(wc.increaseStreamWindow(1, 5), false); - assertEquals(wc.increaseStreamWindow(1, 5), false); - assertEquals(wc.increaseStreamWindow(10, 5), false); + assertEquals(true, wc.increaseStreamWindow(Integer.MAX_VALUE, 5)); + assertEquals(false, wc.increaseStreamWindow(1, 5)); + assertEquals(false, wc.increaseStreamWindow(1, 5)); + assertEquals(false, wc.increaseStreamWindow(10, 5)); wc.registerStream(7, -1); - assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 7), true); - assertEquals(wc.increaseStreamWindow(1, 7), true); - assertEquals(wc.increaseStreamWindow(1, 7), false); - assertEquals(wc.increaseStreamWindow(10, 7), false); + assertEquals(true, wc.increaseStreamWindow(Integer.MAX_VALUE, 7)); + assertEquals(true, wc.increaseStreamWindow(1, 7)); + assertEquals(false, wc.increaseStreamWindow(1, 7)); + assertEquals(false, wc.increaseStreamWindow(10, 7)); wc.registerStream(9, -1); - assertEquals(wc.increaseStreamWindow(1, 9), true); - assertEquals(wc.increaseStreamWindow(1, 9), true); - assertEquals(wc.increaseStreamWindow(1, 9), true); - assertEquals(wc.increaseStreamWindow(10, 9), true); - assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 9), false); + assertEquals(true, wc.increaseStreamWindow(1, 9)); + assertEquals(true, wc.increaseStreamWindow(1, 9)); + assertEquals(true, wc.increaseStreamWindow(1, 9)); + assertEquals(true, wc.increaseStreamWindow(10, 9)); + assertEquals(false, wc.increaseStreamWindow(Integer.MAX_VALUE, 9)); wc.registerStream(11, -10); - assertEquals(wc.increaseStreamWindow(1, 11), true); - assertEquals(wc.increaseStreamWindow(1, 11), true); - assertEquals(wc.increaseStreamWindow(1, 11), true); - assertEquals(wc.increaseStreamWindow(1, 11), true); - assertEquals(wc.increaseStreamWindow(1, 11), true); - assertEquals(wc.increaseStreamWindow(1, 11), true); - assertEquals(wc.increaseStreamWindow(1, 11), true); - assertEquals(wc.increaseStreamWindow(1, 11), true); - assertEquals(wc.increaseStreamWindow(1, 11), true); - assertEquals(wc.increaseStreamWindow(1, 11), true); - assertEquals(wc.increaseStreamWindow(1, 11), true); - assertEquals(wc.streamWindowSize(11), 1); - assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 11), false); - assertEquals(wc.streamWindowSize(11), 1); + assertEquals(true, wc.increaseStreamWindow(1, 11)); + assertEquals(true, wc.increaseStreamWindow(1, 11)); + assertEquals(true, wc.increaseStreamWindow(1, 11)); + assertEquals(true, wc.increaseStreamWindow(1, 11)); + assertEquals(true, wc.increaseStreamWindow(1, 11)); + assertEquals(true, wc.increaseStreamWindow(1, 11)); + assertEquals(true, wc.increaseStreamWindow(1, 11)); + assertEquals(true, wc.increaseStreamWindow(1, 11)); + assertEquals(true, wc.increaseStreamWindow(1, 11)); + assertEquals(true, wc.increaseStreamWindow(1, 11)); + assertEquals(true, wc.increaseStreamWindow(1, 11)); + assertEquals(1, wc.streamWindowSize(11)); + assertEquals(false, wc.increaseStreamWindow(Integer.MAX_VALUE, 11)); + assertEquals(1, wc.streamWindowSize(11)); } @Test @@ -125,9 +126,9 @@ public class WindowControllerTest { wc.tryAcquire(51, 5 , null); wc.adjustActiveStreams(-200); - assertEquals(wc.streamWindowSize(1), -149); - assertEquals(wc.streamWindowSize(3), -150); - assertEquals(wc.streamWindowSize(5), -151); + assertEquals(-149, wc.streamWindowSize(1)); + assertEquals(-150, wc.streamWindowSize(3)); + assertEquals(-151, wc.streamWindowSize(5)); } static final Class IE = InternalError.class; diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/WrapperTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/WrapperTest.java index 6dad2cc75b5..bc69c425678 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/WrapperTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/WrapperTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,11 +27,10 @@ import java.nio.ByteBuffer; import java.util.LinkedList; import java.util.List; import java.util.concurrent.*; -import java.util.concurrent.atomic.*; -import org.testng.annotations.Test; import jdk.internal.net.http.common.SubscriberWrapper; -@Test +import org.junit.jupiter.api.Test; + public class WrapperTest { static final int LO_PRI = 1; static final int HI_PRI = 2; diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/common/DemandTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/common/DemandTest.java index 4ea604fd488..1ea72f472e9 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/common/DemandTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/common/DemandTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,15 +23,16 @@ package jdk.internal.net.http.common; -import org.testng.annotations.Test; - import java.util.concurrent.CountDownLatch; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.atomic.AtomicReference; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; public class DemandTest { @@ -59,53 +60,61 @@ public class DemandTest { public void test03() { Demand d = new Demand(); d.increase(3); - assertEquals(d.decreaseAndGet(3), 3); + assertEquals(3, d.decreaseAndGet(3)); } @Test public void test04() { Demand d = new Demand(); d.increase(3); - assertEquals(d.decreaseAndGet(5), 3); + assertEquals(3, d.decreaseAndGet(5)); } @Test public void test05() { Demand d = new Demand(); d.increase(7); - assertEquals(d.decreaseAndGet(4), 4); + assertEquals(4, d.decreaseAndGet(4)); } @Test public void test06() { Demand d = new Demand(); - assertEquals(d.decreaseAndGet(3), 0); + assertEquals(0, d.decreaseAndGet(3)); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test07() { - Demand d = new Demand(); - d.increase(0); + assertThrows(IllegalArgumentException.class, () -> { + Demand d = new Demand(); + d.increase(0); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test08() { - Demand d = new Demand(); - d.increase(-1); + assertThrows(IllegalArgumentException.class, () -> { + Demand d = new Demand(); + d.increase(-1); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test09() { - Demand d = new Demand(); - d.increase(10); - d.decreaseAndGet(0); + assertThrows(IllegalArgumentException.class, () -> { + Demand d = new Demand(); + d.increase(10); + d.decreaseAndGet(0); + }); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test public void test10() { - Demand d = new Demand(); - d.increase(13); - d.decreaseAndGet(-3); + assertThrows(IllegalArgumentException.class, () -> { + Demand d = new Demand(); + d.increase(13); + d.decreaseAndGet(-3); + }); } @Test @@ -169,7 +178,7 @@ public class DemandTest { assertTrue(d.isFulfilled()); } - @Test(invocationCount = 32) + @Test public void test15() throws InterruptedException { int N = Math.max(2, Runtime.getRuntime().availableProcessors() + 1); int M = ((N + 1) * N) / 2; // 1 + 2 + 3 + ... N @@ -187,7 +196,7 @@ public class DemandTest { error.compareAndSet(null, e); } try { - assertEquals(d.decreaseAndGet(j), j); + assertEquals(j, d.decreaseAndGet(j)); } catch (Throwable t) { error.compareAndSet(null, t); } finally { @@ -197,6 +206,6 @@ public class DemandTest { } stop.await(); assertTrue(d.isFulfilled()); - assertEquals(error.get(), null); + assertNull(error.get()); } } diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/common/MinimalFutureTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/common/MinimalFutureTest.java index 01798a645a2..2c33f6f0018 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/common/MinimalFutureTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/common/MinimalFutureTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,19 +23,19 @@ package jdk.internal.net.http.common; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import static org.testng.Assert.assertThrows; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import static org.junit.jupiter.api.Assertions.assertThrows; public class MinimalFutureTest { - @Test(dataProvider = "futures") + @ParameterizedTest + @MethodSource("futures") public void test(CompletableFuture mf) { ExecutorService executor = Executors.newSingleThreadExecutor(); try { @@ -134,8 +134,7 @@ public class MinimalFutureTest { } - @DataProvider(name = "futures") - public Object[][] futures() { + public static Object[][] futures() { MinimalFuture mf = new MinimalFuture<>(); mf.completeExceptionally(new Throwable()); diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/frame/FramesDecoderTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/frame/FramesDecoderTest.java index 3db439d1c00..e8acc95c1d2 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/frame/FramesDecoderTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/frame/FramesDecoderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,15 +27,15 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; -import org.testng.Assert; -import org.testng.annotations.Test; import static java.lang.System.out; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.testng.Assert.*; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; public class FramesDecoderTest { - abstract class TestFrameProcessor implements FramesDecoder.FrameProcessor { + abstract static class TestFrameProcessor implements FramesDecoder.FrameProcessor { protected volatile int count; public int numberOfFramesDecoded() { return count; } } @@ -69,17 +69,17 @@ public class FramesDecoderTest { assertTrue(frame instanceof DataFrame); DataFrame dataFrame = (DataFrame) frame; List list = dataFrame.getData(); - assertEquals(list.size(), 1); + assertEquals(1, list.size()); ByteBuffer data = list.get(0); byte[] bytes = new byte[data.remaining()]; data.get(bytes); if (count == 0) { - assertEquals(new String(bytes, UTF_8), "XXXX"); + assertEquals("XXXX", new String(bytes, UTF_8)); out.println("First data received:" + data); - assertEquals(data.position(), data.limit()); // since bytes read - assertEquals(data.limit(), data.capacity()); + assertEquals(data.limit(), data.position()); // since bytes read + assertEquals(data.capacity(), data.limit()); } else { - assertEquals(new String(bytes, UTF_8), "YYYY"); + assertEquals("YYYY", new String(bytes, UTF_8)); out.println("Second data received:" + data); } count++; @@ -89,7 +89,7 @@ public class FramesDecoderTest { out.println("Sending " + combined + " to decoder: "); decoder.decode(combined); - Assert.assertEquals(testFrameProcessor.numberOfFramesDecoded(), 2); + assertEquals(2, testFrameProcessor.numberOfFramesDecoded()); } @@ -119,15 +119,15 @@ public class FramesDecoderTest { assertTrue(frame instanceof DataFrame); DataFrame dataFrame = (DataFrame) frame; List list = dataFrame.getData(); - assertEquals(list.size(), 1); + assertEquals(1, list.size()); ByteBuffer data = list.get(0); byte[] bytes = new byte[data.remaining()]; data.get(bytes); - assertEquals(new String(bytes, UTF_8), "XXXX"); + assertEquals("XXXX", new String(bytes, UTF_8)); out.println("First data received:" + data); - assertEquals(data.position(), data.limit()); // since bytes read + assertEquals(data.limit(), data.position()); // since bytes read //assertNotEquals(data.limit(), data.capacity()); - assertEquals(data.capacity(), 1024 - 9 /*frame header*/); + assertEquals(1024 - 9 /*frame header*/, data.capacity()); count++; } }; @@ -135,6 +135,6 @@ public class FramesDecoderTest { out.println("Sending " + combined + " to decoder: "); decoder.decode(combined); - Assert.assertEquals(testFrameProcessor.numberOfFramesDecoded(), 1); + assertEquals(1, testFrameProcessor.numberOfFramesDecoded()); } }