diff --git a/test/jdk/sun/net/ext/ExtendedSocketOptionsTest.java b/test/jdk/sun/net/ext/ExtendedSocketOptionsTest.java index d42d780db9d..af9345953b8 100644 --- a/test/jdk/sun/net/ext/ExtendedSocketOptionsTest.java +++ b/test/jdk/sun/net/ext/ExtendedSocketOptionsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 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 @@ -21,8 +21,7 @@ * questions. */ -import org.testng.Assert; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Collections; @@ -33,6 +32,10 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; + /** * @test * @bug 8260366 @@ -40,11 +43,11 @@ import java.util.concurrent.Future; * jdk.net.ExtendedSocketOptions doesn't lead to a deadlock * @modules java.base/sun.net.ext:open * jdk.net - * @run testng/othervm ExtendedSocketOptionsTest - * @run testng/othervm ExtendedSocketOptionsTest - * @run testng/othervm ExtendedSocketOptionsTest - * @run testng/othervm ExtendedSocketOptionsTest - * @run testng/othervm ExtendedSocketOptionsTest + * @run junit/othervm ${test.main.class} + * @run junit/othervm ${test.main.class} + * @run junit/othervm ${test.main.class} + * @run junit/othervm ${test.main.class} + * @run junit/othervm ${test.main.class} */ public class ExtendedSocketOptionsTest { @@ -83,13 +86,13 @@ public class ExtendedSocketOptionsTest { // check that the sun.net.ext.ExtendedSocketOptions#getInstance() does indeed return // the registered instance final Object extSocketOptions = callSunNetExtSocketOptionsGetInstance(); - Assert.assertNotNull(extSocketOptions, "sun.net.ext.ExtendedSocketOptions#getInstance()" + + assertNotNull(extSocketOptions, "sun.net.ext.ExtendedSocketOptions#getInstance()" + " unexpectedly returned null"); // now verify that each call to getInstance(), either in the tasks or here, returned the exact // same instance of ExtendedSocketOptions - Assert.assertEquals(2, GetInstanceTask.extendedSocketOptionsInstances.size()); + assertEquals(2, GetInstanceTask.extendedSocketOptionsInstances.size()); for (final Object inst : GetInstanceTask.extendedSocketOptionsInstances) { - Assert.assertSame(inst, extSocketOptions, "sun.net.ext.ExtendedSocketOptions#getInstance()" + + assertSame(extSocketOptions, inst, "sun.net.ext.ExtendedSocketOptions#getInstance()" + " returned different instances"); } } diff --git a/test/jdk/sun/net/spi/DefaultProxySelectorTest.java b/test/jdk/sun/net/spi/DefaultProxySelectorTest.java index 5fdff96f5f2..d070d843fee 100644 --- a/test/jdk/sun/net/spi/DefaultProxySelectorTest.java +++ b/test/jdk/sun/net/spi/DefaultProxySelectorTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 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 @@ -21,18 +21,19 @@ * questions. */ -import org.testng.Assert; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import sun.net.spi.DefaultProxySelector; import java.net.ProxySelector; import java.net.URI; +import static org.junit.jupiter.api.Assertions.assertThrows; + /** * @test * @bug 6563286 6797318 8177648 * @summary Tests sun.net.spi.DefaultProxySelector#select(URI) - * @run testng DefaultProxySelectorTest + * @run junit ${test.main.class} * @modules java.base/sun.net.spi:+open */ public class DefaultProxySelectorTest { @@ -44,12 +45,7 @@ public class DefaultProxySelectorTest { @Test public void testIllegalArgForNull() { final ProxySelector selector = new DefaultProxySelector(); - try { - selector.select(null); - Assert.fail("select() was expected to fail for null URI"); - } catch (IllegalArgumentException iae) { - // expected - } + assertThrows(IllegalArgumentException.class, () -> selector.select(null)); } /** @@ -61,12 +57,11 @@ public class DefaultProxySelectorTest { @Test public void testIllegalArgForNoHost() throws Exception { final ProxySelector selector = new DefaultProxySelector(); - assertFailsWithIAE(selector, new URI("http", "/test", null)); - assertFailsWithIAE(selector, new URI("https", "/test2", null)); - assertFailsWithIAE(selector, new URI("ftp", "/test3", null)); + assertThrows(IllegalArgumentException.class, () -> selector.select(new URI("http", "/test", null))); + assertThrows(IllegalArgumentException.class, () -> selector.select(new URI("https", "/test2", null))); + assertThrows(IllegalArgumentException.class, () -> selector.select(new URI("ftp", "/test3", null))); } - /** * Tests that {@link DefaultProxySelector} throws a {@link IllegalArgumentException} * for URIs that don't have protocol/scheme information @@ -76,15 +71,6 @@ public class DefaultProxySelectorTest { @Test public void testIllegalArgForNoScheme() throws Exception { final ProxySelector selector = new DefaultProxySelector(); - assertFailsWithIAE(selector, new URI(null, "/test", null)); - } - - private static void assertFailsWithIAE(final ProxySelector selector, final URI uri) { - try { - selector.select(uri); - Assert.fail("select() was expected to fail for URI " + uri); - } catch (IllegalArgumentException iae) { - // expected - } + assertThrows(IllegalArgumentException.class, () -> selector.select(new URI(null, "/test", null))); } } diff --git a/test/jdk/sun/net/www/MessageHeaderTest.java b/test/jdk/sun/net/www/MessageHeaderTest.java index 903e805f5f4..6928173df67 100644 --- a/test/jdk/sun/net/www/MessageHeaderTest.java +++ b/test/jdk/sun/net/www/MessageHeaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 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,16 +25,17 @@ * @test * @bug 8003948 8133686 * @modules java.base/sun.net.www - * @run testng MessageHeaderTest + * @run junit ${test.main.class} */ import java.io.*; import java.util.*; -import org.testng.Assert; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import sun.net.www.MessageHeader; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class MessageHeaderTest { /* This test checks to see if the MessageHeader.getHeaders method returns headers with the same value field in the order they were added @@ -53,12 +54,12 @@ public class MessageHeaderTest { var actualHeaders = testHeader.getHeaders().get("test"); - Assert.assertEquals(expectedHeaders, actualHeaders, String.format(errorMessageTemplate, expectedHeaders.toString(), actualHeaders.toString())); + assertEquals(expectedHeaders, actualHeaders, String.format(errorMessageTemplate, expectedHeaders.toString(), actualHeaders.toString())); } @Test public void ntlmNegotiateTest () throws Exception { - String expected[] = { + String[] expected = { "{null: HTTP/1.1 200 Ok}{Foo: bar}{Bar: foo}{WWW-Authenticate: NTLM sdsds}", "{null: HTTP/1.1 200 Ok}{Foo: bar}{Bar: foo}{WWW-Authenticate: }", "{null: HTTP/1.1 200 Ok}{Foo: bar}{Bar: foo}{WWW-Authenticate: NTLM sdsds}", @@ -90,8 +91,8 @@ public class MessageHeaderTest { boolean result = h.filterNTLMResponses("WWW-Authenticate"); String after = h.toString(); after = after.substring(after.indexOf('{')); - Assert.assertEquals(expected[i], after, i + " expected != after"); - Assert.assertEquals(result, expectedResult[i], i + " result != expectedResult"); + assertEquals(expected[i], after, i + " expected != after"); + assertEquals(expectedResult[i], result, i + " result != expectedResult"); } } } diff --git a/test/jdk/sun/net/www/http/KeepAliveStreamCleaner/KeepAliveStreamCleanerTestDriver.java b/test/jdk/sun/net/www/http/KeepAliveStreamCleaner/KeepAliveStreamCleanerTestDriver.java index 5f66aff365e..bf7553acf62 100644 --- a/test/jdk/sun/net/www/http/KeepAliveStreamCleaner/KeepAliveStreamCleanerTestDriver.java +++ b/test/jdk/sun/net/www/http/KeepAliveStreamCleaner/KeepAliveStreamCleanerTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 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,5 +26,5 @@ * @bug 8255124 * @summary Tests that KeepAliveStreamCleaner run does not throw an IllegalMonitorState Exception. * @modules java.base/sun.net.www.http - * @run testng java.base/sun.net.www.http.KeepAliveStreamCleanerTest + * @run junit java.base/sun.net.www.http.KeepAliveStreamCleanerTest */ diff --git a/test/jdk/sun/net/www/http/KeepAliveStreamCleaner/java.base/sun/net/www/http/KeepAliveStreamCleanerTest.java b/test/jdk/sun/net/www/http/KeepAliveStreamCleaner/java.base/sun/net/www/http/KeepAliveStreamCleanerTest.java index b4bc638099d..d927e0a8029 100644 --- a/test/jdk/sun/net/www/http/KeepAliveStreamCleaner/java.base/sun/net/www/http/KeepAliveStreamCleanerTest.java +++ b/test/jdk/sun/net/www/http/KeepAliveStreamCleaner/java.base/sun/net/www/http/KeepAliveStreamCleanerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 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 @@ -23,9 +23,9 @@ package sun.net.www.http; -import org.testng.annotations.Test; -@Test +import org.junit.jupiter.api.Test; + public class KeepAliveStreamCleanerTest { /* diff --git a/test/jdk/sun/net/www/http/RequestMethodCheck/RequestMethodEquality.java b/test/jdk/sun/net/www/http/RequestMethodCheck/RequestMethodEquality.java index 290248989d8..364bafd0749 100644 --- a/test/jdk/sun/net/www/http/RequestMethodCheck/RequestMethodEquality.java +++ b/test/jdk/sun/net/www/http/RequestMethodCheck/RequestMethodEquality.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 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 @@ -30,17 +30,16 @@ * @modules java.base/sun.net.www.http * java.base/sun.net.www.protocol.http * @build java.base/sun.net.www.http.HttpClientAccess - * @run testng/othervm RequestMethodEquality + * @run junit/othervm ${test.main.class} */ import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; import jdk.test.lib.net.URIBuilder; -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 sun.net.www.http.HttpClient; import sun.net.www.http.HttpClientAccess; import sun.net.www.http.KeepAliveCache; @@ -52,21 +51,23 @@ import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URL; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + public class RequestMethodEquality { private static final String TEST_CONTEXT = "/reqmethodtest"; - private HttpServer server; - private CustomHandler handler; - private HttpClientAccess httpClientAccess; + private static HttpServer server; + private static CustomHandler handler; + private static HttpClientAccess httpClientAccess; - @BeforeTest - public void setup() throws Exception { + @BeforeAll + public static void setup() throws Exception { handler = new CustomHandler(); server = createServer(handler); httpClientAccess = new HttpClientAccess(); } - @AfterTest - public void tearDown() throws Exception { + @AfterAll + public static void tearDown() throws Exception { if (server != null) { server.stop(0); } @@ -111,7 +112,7 @@ public class RequestMethodEquality { // If both connectTimeout values are equal, it means the test retrieved the same broken // HttpClient from the cache and is trying to re-use it. - Assert.assertNotEquals(originalConnectTimeout, cachedConnectTimeout, "Both connectTimeout values are equal.\nThis means the test is reusing a broken HttpClient rather than creating a new one."); + assertNotEquals(originalConnectTimeout, cachedConnectTimeout, "Both connectTimeout values are equal.\nThis means the test is reusing a broken HttpClient rather than creating a new one."); } finally { if (conn != null) { conn.disconnect(); diff --git a/test/jdk/sun/net/www/protocol/file/DirPermissionDenied.java b/test/jdk/sun/net/www/protocol/file/DirPermissionDenied.java index 0e3f9e86c4e..b6d8790bb5b 100644 --- a/test/jdk/sun/net/www/protocol/file/DirPermissionDenied.java +++ b/test/jdk/sun/net/www/protocol/file/DirPermissionDenied.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ * @library /test/lib * @build DirPermissionDenied jdk.test.lib.process.* * jdk.test.lib.util.FileUtils - * @run testng DirPermissionDenied + * @run junit ${test.main.class} */ import java.io.IOException; @@ -41,9 +41,10 @@ import java.nio.file.Paths; import jdk.test.lib.process.ProcessTools; import jdk.test.lib.util.FileUtils; -import org.testng.annotations.AfterTest; -import org.testng.annotations.Test; -import org.testng.annotations.BeforeTest; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + public class DirPermissionDenied { private static final Path TEST_DIR = Paths.get( "DirPermissionDeniedDirectory"); @@ -79,8 +80,8 @@ public class DirPermissionDenied { } } - @BeforeTest - public void setup() throws Throwable { + @BeforeAll + public static void setup() throws Throwable { // mkdir and chmod "333" Files.createDirectories(TEST_DIR); ProcessTools.executeCommand("chmod", "333", TEST_DIR.toString()) @@ -89,8 +90,8 @@ public class DirPermissionDenied { .shouldHaveExitValue(0); } - @AfterTest - public void tearDown() throws Throwable { + @AfterAll + public static void tearDown() throws Throwable { // add read permission to ensure the dir removable ProcessTools.executeCommand("chmod", "733", TEST_DIR.toString()) .outputTo(System.out) diff --git a/test/jdk/sun/net/www/protocol/http/HttpHeaderParserTest.java b/test/jdk/sun/net/www/protocol/http/HttpHeaderParserTest.java index 245cd49d518..ad3b3fa3722 100644 --- a/test/jdk/sun/net/www/protocol/http/HttpHeaderParserTest.java +++ b/test/jdk/sun/net/www/protocol/http/HttpHeaderParserTest.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 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,13 +28,12 @@ * @library /test/lib * @summary Sanity check that HttpHeaderParser works same as MessageHeader * @modules java.base/sun.net.www java.base/sun.net.www.protocol.http:open - * @run testng/othervm HttpHeaderParserTest + * @run junit/othervm ${test.main.class} */ import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -45,20 +44,21 @@ import java.util.concurrent.atomic.AtomicInteger; 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 org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import jdk.test.lib.net.HttpHeaderParser; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import sun.net.www.MessageHeader; public class HttpHeaderParserTest { - @DataProvider(name = "responses") - public Object[][] responses() { + public static List responses() { List responses = new ArrayList<>(); - - String[] basic = - { "HTTP/1.1 200 OK\r\n\r\n", + List basic = List.of( + "HTTP/1.1 200 OK\r\n\r\n", "HTTP/1.1 200 OK\r\n" + "Date: Mon, 15 Jan 2001 12:18:21 GMT\r\n" + @@ -142,11 +142,11 @@ public class HttpHeaderParserTest { "Vary: Host,Accept-Encoding,User-Agent\r\n" + "X-Mod-Pagespeed: 1.12.34.2-0\r\n" + "Connection: keep-alive\r\n\r\n" - }; - Arrays.stream(basic).forEach(responses::add); + ); + responses.addAll(basic); // add some tests where some of the CRLF are replaced // by a single LF - Arrays.stream(basic) + basic.stream() .map(HttpHeaderParserTest::mixedCRLF) .forEach(responses::add); @@ -211,8 +211,8 @@ public class HttpHeaderParserTest { responses.add(mixedCRLF(template).replace("$NEWLINE", newLineChar)); } - String[] bad = // much of this is to retain parity with legacy MessageHeaders - { "HTTP/1.1 200 OK\r\n" + + List bad = List.of( // much of this is to retain parity with legacy MessageHeaders + "HTTP/1.1 200 OK\r\n" + "Connection:\r\n\r\n", // empty value, no body "HTTP/1.1 200 OK\r\n" + @@ -258,12 +258,11 @@ public class HttpHeaderParserTest { "HTTP/1.0 404 Not Found\r\n" + "header-without-colon\r\n\r\n" + - "SOMEBODY", + "SOMEBODY" - }; - Arrays.stream(bad).forEach(responses::add); - - return responses.stream().map(p -> new Object[] { p }).toArray(Object[][]::new); + ); + responses.addAll(bad); + return responses; } static final AtomicInteger index = new AtomicInteger(); @@ -318,8 +317,8 @@ public class HttpHeaderParserTest { return res.toString(); } - - @Test(dataProvider = "responses") + @ParameterizedTest + @MethodSource("responses") public void verifyHeaders(String respString) throws Exception { System.out.println("\ntesting:\n\t" + respString .replace("\r\n", "") @@ -344,7 +343,7 @@ public class HttpHeaderParserTest { String statusLine1 = messageHeaderMap.get(null).get(0); String statusLine2 = decoder.getRequestDetails(); 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."); } @@ -366,91 +365,86 @@ public class HttpHeaderParserTest { availableBytes, headerStream.available())); } - @DataProvider(name = "errors") - public Object[][] errors() { - List responses = new ArrayList<>(); - + public static List errors() { // These responses are parsed, somewhat, by MessageHeaders but give // nonsensible results. They, correctly, fail with the Http1HeaderParser. - String[] bad = - {// "HTTP/1.1 402 Payment Required\r\n" + - // "Content-Length: 65\r\n\r", // missing trailing LF //TODO: incomplete + List responses = List.of( + // "HTTP/1.1 402 Payment Required\r\n" + + // "Content-Length: 65\r\n\r", // missing trailing LF //TODO: incomplete - "HTTP/1.1 402 Payment Required\r\n" + - "Content-Length: 65\r\n\rT\r\n\r\nGGGGGG", + "HTTP/1.1 402 Payment Required\r\n" + + "Content-Length: 65\r\n\rT\r\n\r\nGGGGGG", - "HTTP/1.1 200OK\r\n\rT", + "HTTP/1.1 200OK\r\n\rT", - "HTTP/1.1 200OK\rT", + "HTTP/1.1 200OK\rT", - "HTTP/1.0 FOO\r\n", + "HTTP/1.0 FOO\r\n", - "HTTP/1.1 BAR\r\n", + "HTTP/1.1 BAR\r\n", - "HTTP/1.1 +99\r\n", + "HTTP/1.1 +99\r\n", - "HTTP/1.1 -22\r\n", + "HTTP/1.1 -22\r\n", - "HTTP/1.1 -20 \r\n", + "HTTP/1.1 -20 \r\n", + "HTTP/1.1 200 OK\r\n" + + "X-fo\u00ffo: foo\r\n" + // invalid char in name + "Content-Length: 5\r\n" + + "Content-Type: text/html; charset=UTF-8\r\n\r\n" + + "XXXXX", + + "HTTP/1.1 200 OK\r\n" + "HTTP/1.1 200 OK\r\n" + - "X-fo\u00ffo: foo\r\n" + // invalid char in name - "Content-Length: 5\r\n" + - "Content-Type: text/html; charset=UTF-8\r\n\r\n" + - "XXXXX", + "X-foo : bar\r\n" + // trim space after name + "Content-Length: 5\r\n" + + "Content-Type: text/html; charset=UTF-8\r\n\r\n" + + "XXXXX", - "HTTP/1.1 200 OK\r\n" + - "HTTP/1.1 200 OK\r\n" + - "X-foo : bar\r\n" + // trim space after name - "Content-Length: 5\r\n" + - "Content-Type: text/html; charset=UTF-8\r\n\r\n" + - "XXXXX", + "HTTP/1.1 200 OK\r\n" + + " X-foo: bar\r\n" + // trim space before name + "Content-Length: 5\r\n" + + "Content-Type: text/html; charset=UTF-8\r\n\r\n" + + "XXXXX", - "HTTP/1.1 200 OK\r\n" + - " X-foo: bar\r\n" + // trim space before name - "Content-Length: 5\r\n" + - "Content-Type: text/html; charset=UTF-8\r\n\r\n" + - "XXXXX", + "HTTP/1.1 200 OK\r\n" + + "X foo: bar\r\n" + // invalid space in name + "Content-Length: 5\r\n" + + "Content-Type: text/html; charset=UTF-8\r\n\r\n" + + "XXXXX", - "HTTP/1.1 200 OK\r\n" + - "X foo: bar\r\n" + // invalid space in name - "Content-Length: 5\r\n" + - "Content-Type: text/html; charset=UTF-8\r\n\r\n" + - "XXXXX", + "HTTP/1.1 200 OK\r\n" + + "Content-Length: 5\r\n" + + "Content Type: text/html; charset=UTF-8\r\n\r\n" + // invalid space in name + "XXXXX", - "HTTP/1.1 200 OK\r\n" + - "Content-Length: 5\r\n" + - "Content Type: text/html; charset=UTF-8\r\n\r\n" + // invalid space in name - "XXXXX", + "HTTP/1.1 200 OK\r\n" + + "Conte\r" + + " nt-Length: 9\r\n" + // fold results in space in header name + "Content-Type: text/html; charset=UTF-8\r\n\r\n" + + "XXXXX", - "HTTP/1.1 200 OK\r\n" + - "Conte\r" + - " nt-Length: 9\r\n" + // fold results in space in header name - "Content-Type: text/html; charset=UTF-8\r\n\r\n" + - "XXXXX", + "HTTP/1.1 200 OK\r\n" + + " : no header\r\n" + // all blank header-name (not fold) + "Content-Length: 65\r\n\r\n" + + "XXXXX", - "HTTP/1.1 200 OK\r\n" + - " : no header\r\n" + // all blank header-name (not fold) - "Content-Length: 65\r\n\r\n" + - "XXXXX", + "HTTP/1.1 200 OK\r\n" + + " \t : no header\r\n" + // all blank header-name (not fold) + "Content-Length: 65\r\n\r\n" + + "XXXXX"); - "HTTP/1.1 200 OK\r\n" + - " \t : no header\r\n" + // all blank header-name (not fold) - "Content-Length: 65\r\n\r\n" + - "XXXXX", - - }; - Arrays.stream(bad).forEach(responses::add); - - return responses.stream().map(p -> new Object[] { p }).toArray(Object[][]::new); + return responses; } - @Test(dataProvider = "errors", expectedExceptions = IOException.class) + @ParameterizedTest + @MethodSource("errors") public void errors(String respString) throws IOException { byte[] bytes = respString.getBytes(US_ASCII); HttpHeaderParser decoder = new HttpHeaderParser(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - decoder.parse(bais); + assertThrows(IOException.class, () -> decoder.parse(bais)); } void assertHeadersEqual(Map> expected, @@ -477,7 +471,7 @@ public class HttpHeaderParserTest { format("%s. Expected list size %d, actual size %s", msg, values.size(), otherValues.size())); if (!(values.containsAll(otherValues) && otherValues.containsAll(values))) - assertTrue(false, format("Lists are unequal [%s] [%s]", values, otherValues)); + fail(format("Lists are unequal [%s] [%s]", values, otherValues)); break; } } diff --git a/test/jdk/sun/net/www/protocol/http/TestTransparentNTLM.java b/test/jdk/sun/net/www/protocol/http/TestTransparentNTLM.java index 0df834765c8..1c2262ba8e2 100644 --- a/test/jdk/sun/net/www/protocol/http/TestTransparentNTLM.java +++ b/test/jdk/sun/net/www/protocol/http/TestTransparentNTLM.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2019, 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 @@ -28,18 +28,18 @@ * and is used only when the relevant property is set. * @requires os.family == "windows" * @library /test/lib - * @run testng/othervm + * @run junit/othervm * -Dtest.auth.succeed=false * TestTransparentNTLM - * @run testng/othervm + * @run junit/othervm * -Djdk.http.ntlm.transparentAuth=allHosts * -Dtest.auth.succeed=true * TestTransparentNTLM - * @run testng/othervm + * @run junit/othervm * -Djdk.http.ntlm.transparentAuth=blahblah * -Dtest.auth.succeed=false * TestTransparentNTLM - * @run testng/othervm + * @run junit/othervm * -Djdk.http.ntlm.transparentAuth=trustedHosts * -Dtest.auth.succeed=false * TestTransparentNTLM @@ -57,21 +57,21 @@ import java.net.ServerSocket; import java.net.Socket; import java.net.URL; import jdk.test.lib.net.URIBuilder; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; -import org.testng.SkipException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + import static java.lang.System.out; import static java.net.Proxy.NO_PROXY; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class TestTransparentNTLM { - boolean succeed; // true if authentication is expected to succeed - Server server; - URL url; + static boolean succeed; // true if authentication is expected to succeed + static Server server; + static URL url; @Test public void testNTLM() throws IOException { @@ -81,11 +81,11 @@ public class TestTransparentNTLM { out.println("received: " + respCode); if (succeed) { - assertEquals(respCode, HttpURLConnection.HTTP_OK); + assertEquals(HttpURLConnection.HTTP_OK, respCode); String body = new String(uc.getInputStream().readAllBytes(), UTF_8); out.println("received body: " + body); } else { - assertEquals(respCode, HttpURLConnection.HTTP_UNAUTHORIZED); + assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, respCode); } } @@ -169,8 +169,8 @@ public class TestTransparentNTLM { } } - @BeforeTest - public void setup() throws Exception { + @BeforeAll + public static void setup() throws Exception { succeed = System.getProperty("test.auth.succeed").equals("true"); if (succeed) out.println("Expect client to succeed, with 200 Ok"); @@ -187,8 +187,8 @@ public class TestTransparentNTLM { .toURL(); } - @AfterTest - public void teardown() throws Exception { + @AfterAll + public static void teardown() throws Exception { server.close(); server.join(); } diff --git a/test/jdk/sun/net/www/protocol/jar/MultiReleaseJarURLConnection.java b/test/jdk/sun/net/www/protocol/jar/MultiReleaseJarURLConnection.java index f113e7d3fcd..3be7dd5bd98 100644 --- a/test/jdk/sun/net/www/protocol/jar/MultiReleaseJarURLConnection.java +++ b/test/jdk/sun/net/www/protocol/jar/MultiReleaseJarURLConnection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2025, 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,7 +31,7 @@ * @build CreateMultiReleaseTestJars * jdk.test.lib.util.JarBuilder * jdk.test.lib.compiler.Compiler - * @run testng MultiReleaseJarURLConnection + * @run junit ${test.main.class} */ import java.io.IOException; @@ -59,22 +59,27 @@ import java.util.jar.JarFile; import com.sun.net.httpserver.HttpServer; import com.sun.net.httpserver.SimpleFileServer; import jdk.test.lib.net.URIBuilder; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -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 static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class MultiReleaseJarURLConnection { - String userdir = System.getProperty("user.dir", "."); - String unversioned = userdir + "/unversioned.jar"; - String unsigned = userdir + "/multi-release.jar"; - String signed = userdir + "/signed-multi-release.jar"; - HttpServer server; - ExecutorService executor; + static String userdir = System.getProperty("user.dir", "."); + static String unversioned = userdir + "/unversioned.jar"; + static String unsigned = userdir + "/multi-release.jar"; + static String signed = userdir + "/signed-multi-release.jar"; + static HttpServer server; + static ExecutorService executor; - @BeforeClass - public void initialize() throws Exception { + @BeforeAll + public static void initialize() throws Exception { CreateMultiReleaseTestJars creator = new CreateMultiReleaseTestJars(); creator.compileEntries(); creator.buildUnversionedJar(); @@ -87,8 +92,8 @@ public class MultiReleaseJarURLConnection { server.start(); } - @AfterClass - public void close() throws IOException { + @AfterAll + public static void close() throws IOException { // Windows requires server to stop before file is deleted if (server != null) server.stop(0); @@ -99,8 +104,7 @@ public class MultiReleaseJarURLConnection { Files.delete(Paths.get(signed)); } - @DataProvider(name = "data") - public Object[][] createData() { + public static Object[][] createData() { return new Object[][]{ {"unversioned", unversioned}, {"unsigned", unsigned}, @@ -108,20 +112,21 @@ public class MultiReleaseJarURLConnection { }; } - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("createData") public void testRuntimeVersioning(String style, String file) throws Exception { String urlFile = "jar:file:" + file + "!/"; String baseUrlEntry = urlFile + "version/Version.java"; String rtreturn = "return " + Runtime.version().major(); - Assert.assertTrue(readAndCompare(new URL(baseUrlEntry), "return 8")); + assertTrue(readAndCompare(new URL(baseUrlEntry), "return 8")); // #runtime is "magic" for a multi-release jar, but not for unversioned jar - Assert.assertTrue(readAndCompare(new URL(baseUrlEntry + "#runtime"), + assertTrue(readAndCompare(new URL(baseUrlEntry + "#runtime"), style.equals("unversioned") ? "return 8" : rtreturn)); // #fragment or any other fragment is not magic - Assert.assertTrue(readAndCompare(new URL(baseUrlEntry + "#fragment"), "return 8")); + assertTrue(readAndCompare(new URL(baseUrlEntry + "#fragment"), "return 8")); // cached entities not affected - Assert.assertTrue(readAndCompare(new URL(baseUrlEntry), "return 8")); + assertTrue(readAndCompare(new URL(baseUrlEntry), "return 8")); // the following tests will not work with unversioned jars if (style.equals("unversioned")) @@ -130,13 +135,14 @@ public class MultiReleaseJarURLConnection { // direct access to versioned entry String versUrlEntry = urlFile + "META-INF/versions/" + Runtime.version().major() + "/version/Version.java"; - Assert.assertTrue(readAndCompare(new URL(versUrlEntry), rtreturn)); + assertTrue(readAndCompare(new URL(versUrlEntry), rtreturn)); // adding any fragment does not change things - Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#runtime"), rtreturn)); - Assert.assertTrue(readAndCompare(new URL(versUrlEntry + "#fragment"), rtreturn)); + assertTrue(readAndCompare(new URL(versUrlEntry + "#runtime"), rtreturn)); + assertTrue(readAndCompare(new URL(versUrlEntry + "#fragment"), rtreturn)); } - @Test(dataProvider = "data") + @ParameterizedTest + @MethodSource("createData") public void testCachedJars(String style, String file) throws Exception { String urlFile = "jar:file:" + file + "!/"; @@ -150,28 +156,27 @@ public class MultiReleaseJarURLConnection { JarFile runtimeJar = juc.getJarFile(); Runtime.Version runtime = runtimeJar.getVersion(); if (style.equals("unversioned")) { - Assert.assertEquals(root, runtime); + assertEquals(root, runtime); } else { - Assert.assertNotEquals(root, runtime); + assertNotEquals(root, runtime); } juc = (JarURLConnection) rootUrl.openConnection(); JarFile jar = juc.getJarFile(); - Assert.assertEquals(jar.getVersion(), root); - Assert.assertEquals(jar, rootJar); + assertEquals(root, jar.getVersion()); + assertEquals(rootJar, jar); juc = (JarURLConnection) runtimeUrl.openConnection(); jar = juc.getJarFile(); - Assert.assertEquals(jar.getVersion(), runtime); - Assert.assertEquals(jar, runtimeJar); + assertEquals(runtime, jar.getVersion()); + assertEquals(runtimeJar, jar); rootJar.close(); runtimeJar.close(); jar.close(); // probably not needed } - @DataProvider(name = "resourcedata") - public Object[][] createResourceData() throws Exception { + public static Object[][] createResourceData() throws Exception { return new Object[][]{ {"unversioned", Paths.get(unversioned).toUri().toURL()}, {"unsigned", Paths.get(unsigned).toUri().toURL()}, @@ -189,7 +194,8 @@ public class MultiReleaseJarURLConnection { }; } - @Test(dataProvider = "resourcedata") + @ParameterizedTest + @MethodSource("createResourceData") public void testResources(String style, URL url) throws Throwable { // System.out.println(" testing " + style + " url: " + url); URL[] urls = {url}; @@ -199,30 +205,28 @@ public class MultiReleaseJarURLConnection { // verify we are loading a runtime versioned class MethodType mt = MethodType.methodType(int.class); MethodHandle mh = MethodHandles.lookup().findVirtual(vcls, "getVersion", mt); - Assert.assertEquals((int)mh.invoke(vcls.newInstance()), - style.equals("unversioned") ? 8 : Runtime.version().major()); - + assertEquals(style.equals("unversioned") ? 8 : Runtime.version().major(), (int)mh.invoke(vcls.newInstance())); // now get a resource and verify that we don't have a fragment attached Enumeration vclsUrlEnum = cldr.getResources("version/Version.class"); - Assert.assertTrue(vclsUrlEnum.hasMoreElements()); + assertTrue(vclsUrlEnum.hasMoreElements()); URL vclsUrls[] = new URL[] { vcls.getResource("/version/Version.class"), vcls.getResource("Version.class"), cldr.getResource("version/Version.class"), vclsUrlEnum.nextElement() }; - Assert.assertFalse(vclsUrlEnum.hasMoreElements()); + assertFalse(vclsUrlEnum.hasMoreElements()); for (URL vclsUrl : vclsUrls) { String fragment = vclsUrl.getRef(); - Assert.assertNull(fragment); + assertNull(fragment); // and verify that the url is a reified pointer to the runtime entry String rep = vclsUrl.toString(); //System.out.println(" getResource(\"/version/Version.class\") returned: " + rep); if (style.equals("http")) { - Assert.assertTrue(rep.startsWith("jar:http:")); + assertTrue(rep.startsWith("jar:http:")); } else { - Assert.assertTrue(rep.startsWith("jar:file:")); + assertTrue(rep.startsWith("jar:file:")); } String suffix; if (style.equals("unversioned")) { @@ -231,7 +235,7 @@ public class MultiReleaseJarURLConnection { suffix = ".jar!/META-INF/versions/" + Runtime.version().major() + "/version/Version.class"; } - Assert.assertTrue(rep.endsWith(suffix)); + assertTrue(rep.endsWith(suffix)); } cldr.close(); } diff --git a/test/jdk/sun/net/www/protocol/jrt/Basic.java b/test/jdk/sun/net/www/protocol/jrt/Basic.java index 785920b4a4d..272d82bd4d6 100644 --- a/test/jdk/sun/net/www/protocol/jrt/Basic.java +++ b/test/jdk/sun/net/www/protocol/jrt/Basic.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 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,21 +24,25 @@ /** * @test * @summary Basic test of jimage protocol handler - * @run testng Basic + * @run junit ${test.main.class} */ +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + import java.io.IOException; import java.net.URL; import java.net.URLConnection; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import static org.testng.Assert.*; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + public class Basic { - @DataProvider(name = "urls") - public Object[][] urls() { + public static Object[][] urls() { Object[][] data = { {"jrt:/java.base/java/lang/Object.class", true}, // Valid resource with and without percent-encoding. @@ -67,7 +71,8 @@ public class Basic { return data; } - @Test(dataProvider = "urls") + @ParameterizedTest + @MethodSource("urls") public void testConnect(String urlString, boolean exists) throws Exception { URL url = new URL(urlString); URLConnection uc = url.openConnection(); @@ -79,32 +84,35 @@ public class Basic { } } - @Test(dataProvider = "urls") + @ParameterizedTest + @MethodSource("urls") public void testInputStream(String urlString, boolean exists) throws Exception { URL url = new URL(urlString); URLConnection uc = url.openConnection(); try { int b = uc.getInputStream().read(); - assertTrue(b != -1); + assertNotEquals(-1, b); if (!exists) fail("IOException expected"); } catch (IOException ioe) { if (exists) fail("IOException not expected"); } } - @Test(dataProvider = "urls") + @ParameterizedTest + @MethodSource("urls") public void testContentLength(String urlString, boolean exists) throws Exception { URL url = new URL(urlString); int len = url.openConnection().getContentLength(); assertTrue((exists && len > 0) || (!exists && len == -1)); } - @Test(dataProvider = "urls") + @ParameterizedTest + @MethodSource("urls") public void testGetContent(String urlString, boolean exists) throws Exception { URL url = new URL(urlString); try { Object obj = url.getContent(); - assertTrue(obj != null); + assertNotNull(obj); if (!exists) fail("IOException expected"); } catch (IOException ioe) { if (exists) fail("IOException not expected");