For objects of class type, use a variable whose value is a
pointer to the class, initialized to nullptr. Provide an
diff --git a/doc/hotspot-style.md b/doc/hotspot-style.md
index c8f0f72b814..26549e3ca02 100644
--- a/doc/hotspot-style.md
+++ b/doc/hotspot-style.md
@@ -954,7 +954,7 @@ destructors at exit can lead to problems.
Some of the approaches used in HotSpot to avoid dynamic initialization
include:
-* Use the `Deferred` class template. Add a call to its initialization
+* Use the `DeferredStatic` class template. Add a call to its initialization
function at an appropriate place during VM initialization. The underlying
object is never destroyed.
diff --git a/make/Bundles.gmk b/make/Bundles.gmk
index cf3b77e4e52..0b324e7e3f3 100644
--- a/make/Bundles.gmk
+++ b/make/Bundles.gmk
@@ -125,13 +125,6 @@ define SetupBundleFileBody
&& $(TAR) cf - -$(TAR_INCLUDE_PARAM) $$($1_$$d_LIST_FILE) \
$(TAR_IGNORE_EXIT_VALUE) ) \
| ( $(CD) $(SUPPORT_OUTPUTDIR)/bundles/$1/$$($1_SUBDIR) && $(TAR) xf - )$$(NEWLINE) )
- # Rename stripped pdb files
- ifeq ($(call isTargetOs, windows)+$(SHIP_DEBUG_SYMBOLS), true+public)
- for f in `$(FIND) $(SUPPORT_OUTPUTDIR)/bundles/$1/$$($1_SUBDIR) -name "*.stripped.pdb"`; do \
- $(ECHO) Renaming $$$${f} to $$$${f%stripped.pdb}pdb $(LOG_INFO); \
- $(MV) $$$${f} $$$${f%stripped.pdb}pdb; \
- done
- endif
# Unzip any zipped debuginfo files
ifeq ($$($1_UNZIP_DEBUGINFO), true)
for f in `$(FIND) $(SUPPORT_OUTPUTDIR)/bundles/$1/$$($1_SUBDIR) -name "*.diz"`; do \
@@ -192,96 +185,30 @@ endif
ifneq ($(filter product-bundles% legacy-bundles, $(MAKECMDGOALS)), )
- SYMBOLS_EXCLUDE_PATTERN := %.debuginfo %.diz %.map
-
- # There may be files with spaces in the names, so use ShellFindFiles
- # explicitly.
+ # There may be files with spaces in the names, so use ShellFindFiles explicitly.
ALL_JDK_FILES := $(call ShellFindFiles, $(JDK_IMAGE_DIR))
- ifneq ($(JDK_IMAGE_DIR), $(JDK_SYMBOLS_IMAGE_DIR))
- ALL_JDK_SYMBOLS_FILES := $(call ShellFindFiles, $(JDK_SYMBOLS_IMAGE_DIR))
- else
- ALL_JDK_SYMBOLS_FILES := $(ALL_JDK_FILES)
- endif
ifneq ($(JDK_IMAGE_DIR), $(JDK_DEMOS_IMAGE_DIR))
ALL_JDK_DEMOS_FILES := $(call ShellFindFiles, $(JDK_DEMOS_IMAGE_DIR))
else
ALL_JDK_DEMOS_FILES := $(ALL_JDK_FILES)
endif
- # Create special filter rules when dealing with unzipped .dSYM directories on
- # macosx
- ifeq ($(call isTargetOs, macosx), true)
- ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), false)
- JDK_SYMBOLS_EXCLUDE_PATTERN := $(addprefix %, \
- $(call containing, .dSYM/, $(patsubst $(JDK_IMAGE_DIR)/%, %, \
- $(ALL_JDK_SYMBOLS_FILES))))
- endif
- endif
-
- # Create special filter rules when dealing with debug symbols on windows
- ifeq ($(call isTargetOs, windows), true)
- ifeq ($(SHIP_DEBUG_SYMBOLS), )
- JDK_SYMBOLS_EXCLUDE_PATTERN := %.pdb
- else
- ifeq ($(SHIP_DEBUG_SYMBOLS), public)
- JDK_SYMBOLS_EXCLUDE_PATTERN := \
- $(filter-out \
- %.stripped.pdb, \
- $(filter %.pdb, $(ALL_JDK_FILES)) \
- )
- endif
- endif
- endif
-
JDK_BUNDLE_FILES := \
$(filter-out \
- $(JDK_SYMBOLS_EXCLUDE_PATTERN) \
$(JDK_EXTRA_EXCLUDES) \
- $(SYMBOLS_EXCLUDE_PATTERN) \
$(JDK_IMAGE_HOMEDIR)/demo/% \
, \
$(ALL_JDK_FILES) \
)
- JDK_SYMBOLS_BUNDLE_FILES := \
- $(filter-out \
- %.stripped.pdb, \
- $(call FindFiles, $(SYMBOLS_IMAGE_DIR)) \
- )
+ JDK_SYMBOLS_BUNDLE_FILES := $(call FindFiles, $(SYMBOLS_IMAGE_DIR))
TEST_DEMOS_BUNDLE_FILES := $(filter $(JDK_DEMOS_IMAGE_HOMEDIR)/demo/%, \
$(ALL_JDK_DEMOS_FILES))
ALL_JRE_FILES := $(call ShellFindFiles, $(JRE_IMAGE_DIR))
- # Create special filter rules when dealing with unzipped .dSYM directories on
- # macosx
- ifeq ($(OPENJDK_TARGET_OS), macosx)
- ifeq ($(ZIP_EXTERNAL_DEBUG_SYMBOLS), false)
- JRE_SYMBOLS_EXCLUDE_PATTERN := $(addprefix %, \
- $(call containing, .dSYM/, $(patsubst $(JRE_IMAGE_DIR)/%, %, $(ALL_JRE_FILES))))
- endif
- endif
-
- # Create special filter rules when dealing with debug symbols on windows
- ifeq ($(call isTargetOs, windows), true)
- ifeq ($(SHIP_DEBUG_SYMBOLS), )
- JRE_SYMBOLS_EXCLUDE_PATTERN := %.pdb
- else
- ifeq ($(SHIP_DEBUG_SYMBOLS), public)
- JRE_SYMBOLS_EXCLUDE_PATTERN := \
- $(filter-out \
- %.stripped.pdb, \
- $(filter %.pdb, $(ALL_JRE_FILES)) \
- )
- endif
- endif
- endif
-
- JRE_BUNDLE_FILES := $(filter-out \
- $(JRE_SYMBOLS_EXCLUDE_PATTERN) \
- $(SYMBOLS_EXCLUDE_PATTERN), \
- $(ALL_JRE_FILES))
+ JRE_BUNDLE_FILES := $(ALL_JRE_FILES)
ifeq ($(MACOSX_CODESIGN_MODE), hardened)
# Macosx release build and code signing available.
diff --git a/make/CreateJmods.gmk b/make/CreateJmods.gmk
index 3280b24924a..32f107b6bb6 100644
--- a/make/CreateJmods.gmk
+++ b/make/CreateJmods.gmk
@@ -218,10 +218,14 @@ ifeq ($(call isTargetOs, windows), true)
ifeq ($(SHIP_DEBUG_SYMBOLS), )
JMOD_FLAGS += --exclude '**{_the.*,_*.marker*,*.diz,*.pdb,*.map}'
else
- JMOD_FLAGS += --exclude '**{_the.*,_*.marker*,*.diz,*.map}'
+ JMOD_FLAGS += --exclude '**{_the.*,_*.marker*,*.map}'
endif
else
- JMOD_FLAGS += --exclude '**{_the.*,_*.marker*,*.diz,*.debuginfo,*.dSYM/**,*.dSYM}'
+ ifeq ($(SHIP_DEBUG_SYMBOLS), )
+ JMOD_FLAGS += --exclude '**{_the.*,_*.marker*,*.diz,*.debuginfo,*.dSYM/**,*.dSYM}'
+ else
+ JMOD_FLAGS += --exclude '**{_the.*,_*.marker*}'
+ endif
endif
# Unless we are creating a very large module, use the small tool JVM options
diff --git a/make/Docs.gmk b/make/Docs.gmk
index b105e1d8683..a8d40e078e2 100644
--- a/make/Docs.gmk
+++ b/make/Docs.gmk
@@ -93,16 +93,19 @@ JAVADOC_DISABLED_DOCLINT_WARNINGS := missing
JAVADOC_DISABLED_DOCLINT_PACKAGES := org.w3c.* javax.smartcardio
# The initial set of options for javadoc
+# -XDaccessInternalAPI is a temporary workaround, see 8373909
JAVADOC_OPTIONS := -use -keywords -notimestamp \
-serialwarn -encoding utf-8 -docencoding utf-8 -breakiterator \
-splitIndex --system none -javafx --expand-requires transitive \
- --override-methods=summary
+ --override-methods=summary \
+ -XDaccessInternalAPI
# The reference options must stay stable to allow for comparisons across the
# development cycle.
REFERENCE_OPTIONS := -XDignore.symbol.file=true -use -keywords -notimestamp \
-serialwarn -encoding utf-8 -breakiterator -splitIndex --system none \
- -html5 -javafx --expand-requires transitive
+ -html5 -javafx --expand-requires transitive \
+ -XDaccessInternalAPI
# Should we add DRAFT stamps to the generated javadoc?
ifeq ($(VERSION_IS_GA), true)
diff --git a/make/Images.gmk b/make/Images.gmk
index c5877e44c22..89c0a834477 100644
--- a/make/Images.gmk
+++ b/make/Images.gmk
@@ -282,29 +282,33 @@ else
endif
CMDS_TARGET_SUBDIR := bin
-# Param 1 - either JDK or JRE
+# Copy debug info files into symbols bundle.
+# In case of Windows and --with-external-symbols-in-bundles=public, take care to remove *.stripped.pdb files
SetupCopyDebuginfo = \
$(foreach m, $(ALL_$1_MODULES), \
+ $(eval dbgfiles := $(call FindDebuginfoFiles, $(SUPPORT_OUTPUTDIR)/modules_libs/$m)) \
+ $(eval dbgfiles := $(if $(filter true+public,$(call isTargetOs,windows)+$(SHIP_DEBUG_SYMBOLS)), \
+ $(filter-out %.stripped.pdb,$(dbgfiles)),$(dbgfiles)) \
+ ) \
$(eval $(call SetupCopyFiles, COPY_$1_LIBS_DEBUGINFO_$m, \
SRC := $(SUPPORT_OUTPUTDIR)/modules_libs/$m, \
DEST := $($1_IMAGE_DIR)/$(LIBS_TARGET_SUBDIR), \
- FILES := $(call FindDebuginfoFiles, \
- $(SUPPORT_OUTPUTDIR)/modules_libs/$m), \
+ FILES := $(dbgfiles), \
)) \
$(eval $1_TARGETS += $$(COPY_$1_LIBS_DEBUGINFO_$m)) \
+ $(eval dbgfiles := $(call FindDebuginfoFiles, $(SUPPORT_OUTPUTDIR)/modules_cmds/$m)) \
+ $(eval dbgfiles := $(if $(filter true+public,$(call isTargetOs,windows)+$(SHIP_DEBUG_SYMBOLS)), \
+ $(filter-out %.stripped.pdb,$(dbgfiles)),$(dbgfiles)) \
+ ) \
$(eval $(call SetupCopyFiles, COPY_$1_CMDS_DEBUGINFO_$m, \
SRC := $(SUPPORT_OUTPUTDIR)/modules_cmds/$m, \
DEST := $($1_IMAGE_DIR)/$(CMDS_TARGET_SUBDIR), \
- FILES := $(call FindDebuginfoFiles, \
- $(SUPPORT_OUTPUTDIR)/modules_cmds/$m), \
+ FILES := $(dbgfiles), \
)) \
$(eval $1_TARGETS += $$(COPY_$1_CMDS_DEBUGINFO_$m)) \
)
-# No space before argument to avoid having to put $(strip ) everywhere in
-# implementation above.
-$(call SetupCopyDebuginfo,JDK)
-$(call SetupCopyDebuginfo,JRE)
+# No space before argument to avoid having to put $(strip ) everywhere in implementation above.
$(call SetupCopyDebuginfo,SYMBOLS)
################################################################################
diff --git a/make/RunTests.gmk b/make/RunTests.gmk
index 1f50b97531b..946b1332edc 100644
--- a/make/RunTests.gmk
+++ b/make/RunTests.gmk
@@ -873,7 +873,7 @@ define SetupRunJtregTestBody
$1_JTREG_BASIC_OPTIONS += -testThreadFactoryPath:$$(JTREG_TEST_THREAD_FACTORY_JAR)
$1_JTREG_BASIC_OPTIONS += -testThreadFactory:$$(JTREG_TEST_THREAD_FACTORY)
$1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$(wildcard \
- $$(addprefix $$($1_TEST_ROOT)/, ProblemList-$$(JTREG_TEST_THREAD_FACTORY).txt) \
+ $$(addprefix $$($1_TEST_ROOT)/, ProblemList-$$(JTREG_TEST_THREAD_FACTORY).txt) \
))
endif
@@ -881,8 +881,8 @@ define SetupRunJtregTestBody
AGENT := $$(LIBRARY_PREFIX)JvmtiStressAgent$$(SHARED_LIBRARY_SUFFIX)=$$(JTREG_JVMTI_STRESS_AGENT)
$1_JTREG_BASIC_OPTIONS += -javaoption:'-agentpath:$(TEST_IMAGE_DIR)/hotspot/jtreg/native/$$(AGENT)'
$1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$(wildcard \
- $$(addprefix $$($1_TEST_ROOT)/, ProblemList-jvmti-stress-agent.txt) \
- ))
+ $$(addprefix $$($1_TEST_ROOT)/, ProblemList-jvmti-stress-agent.txt) \
+ ))
endif
@@ -1092,7 +1092,7 @@ define SetupRunJtregTestBody
$$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR) \
$$($1_TEST_TMP_DIR))
$$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/jtreg, \
- $$(COV_ENVIRONMENT) $$($1_COMMAND_LINE) \
+ $$(COV_ENVIRONMENT) $$($1_COMMAND_LINE) \
)
$1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/text/stats.txt
@@ -1102,11 +1102,11 @@ define SetupRunJtregTestBody
$$(call LogWarn, Test report is stored in $$(strip \
$$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
- # Read jtreg documentation to learn on the test stats categories:
- # https://github.com/openjdk/jtreg/blob/master/src/share/doc/javatest/regtest/faq.md#what-do-all-those-numbers-in-the-test-results-line-mean
- # In jtreg, "skipped:" category accounts for tests that threw jtreg.SkippedException at runtime.
- # At the same time these tests contribute to "passed:" tests.
- # In here we don't want that and so we substract number of "skipped:" from "passed:".
+ # Read jtreg documentation to learn on the test stats categories:
+ # https://github.com/openjdk/jtreg/blob/master/src/share/doc/javatest/regtest/faq.md#what-do-all-those-numbers-in-the-test-results-line-mean
+ # In jtreg, "skipped:" category accounts for tests that threw jtreg.SkippedException at runtime.
+ # At the same time these tests contribute to "passed:" tests.
+ # In here we don't want that and so we substract number of "skipped:" from "passed:".
$$(if $$(wildcard $$($1_RESULT_FILE)), \
$$(eval $1_PASSED_AND_RUNTIME_SKIPPED := $$(shell $$(AWK) '{ gsub(/[,;]/, ""); \
diff --git a/make/RunTestsPrebuiltSpec.gmk b/make/RunTestsPrebuiltSpec.gmk
index e9fd901c9e1..5fe559eafad 100644
--- a/make/RunTestsPrebuiltSpec.gmk
+++ b/make/RunTestsPrebuiltSpec.gmk
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2017, 2025, 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
diff --git a/make/autoconf/bootcycle-spec.gmk.template b/make/autoconf/bootcycle-spec.gmk.template
index d17a95e190a..eb564f40e3f 100644
--- a/make/autoconf/bootcycle-spec.gmk.template
+++ b/make/autoconf/bootcycle-spec.gmk.template
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2025, 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
diff --git a/make/autoconf/buildjdk-spec.gmk.template b/make/autoconf/buildjdk-spec.gmk.template
index 924389b94e8..bb020842d59 100644
--- a/make/autoconf/buildjdk-spec.gmk.template
+++ b/make/autoconf/buildjdk-spec.gmk.template
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2015, 2025, 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
diff --git a/make/autoconf/compare.sh.template b/make/autoconf/compare.sh.template
index 84421035ab9..b17ddc16827 100644
--- a/make/autoconf/compare.sh.template
+++ b/make/autoconf/compare.sh.template
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2012, 2025, 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
diff --git a/make/autoconf/flags-cflags.m4 b/make/autoconf/flags-cflags.m4
index 6298bcae416..5a9fdc57c74 100644
--- a/make/autoconf/flags-cflags.m4
+++ b/make/autoconf/flags-cflags.m4
@@ -69,6 +69,23 @@ AC_DEFUN([FLAGS_SETUP_DEBUG_SYMBOLS],
# Debug prefix mapping if supported by compiler
DEBUG_PREFIX_CFLAGS=
+ UTIL_ARG_WITH(NAME: native-debug-symbols-level, TYPE: string,
+ DEFAULT: "",
+ RESULT: DEBUG_SYMBOLS_LEVEL,
+ DESC: [set the native debug symbol level (GCC and Clang only)],
+ DEFAULT_DESC: [toolchain default])
+ AC_SUBST(DEBUG_SYMBOLS_LEVEL)
+
+ if test "x${TOOLCHAIN_TYPE}" = xgcc || \
+ test "x${TOOLCHAIN_TYPE}" = xclang; then
+ DEBUG_SYMBOLS_LEVEL_FLAGS="-g"
+ if test "x${DEBUG_SYMBOLS_LEVEL}" != "x"; then
+ DEBUG_SYMBOLS_LEVEL_FLAGS="-g${DEBUG_SYMBOLS_LEVEL}"
+ FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${DEBUG_SYMBOLS_LEVEL_FLAGS}],
+ IF_FALSE: AC_MSG_ERROR("Debug info level ${DEBUG_SYMBOLS_LEVEL} is not supported"))
+ fi
+ fi
+
# Debug symbols
if test "x$TOOLCHAIN_TYPE" = xgcc; then
if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then
@@ -93,8 +110,9 @@ AC_DEFUN([FLAGS_SETUP_DEBUG_SYMBOLS],
)
fi
- CFLAGS_DEBUG_SYMBOLS="-g -gdwarf-4"
- ASFLAGS_DEBUG_SYMBOLS="-g"
+ # Debug info level should follow the debug format to be effective.
+ CFLAGS_DEBUG_SYMBOLS="-gdwarf-4 ${DEBUG_SYMBOLS_LEVEL_FLAGS}"
+ ASFLAGS_DEBUG_SYMBOLS="${DEBUG_SYMBOLS_LEVEL_FLAGS}"
elif test "x$TOOLCHAIN_TYPE" = xclang; then
if test "x$ALLOW_ABSOLUTE_PATHS_IN_OUTPUT" = "xfalse"; then
# Check if compiler supports -fdebug-prefix-map. If so, use that to make
@@ -113,8 +131,9 @@ AC_DEFUN([FLAGS_SETUP_DEBUG_SYMBOLS],
FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${GDWARF_FLAGS}],
IF_FALSE: [GDWARF_FLAGS=""])
- CFLAGS_DEBUG_SYMBOLS="-g ${GDWARF_FLAGS}"
- ASFLAGS_DEBUG_SYMBOLS="-g"
+ # Debug info level should follow the debug format to be effective.
+ CFLAGS_DEBUG_SYMBOLS="${GDWARF_FLAGS} ${DEBUG_SYMBOLS_LEVEL_FLAGS}"
+ ASFLAGS_DEBUG_SYMBOLS="${DEBUG_SYMBOLS_LEVEL_FLAGS}"
elif test "x$TOOLCHAIN_TYPE" = xmicrosoft; then
CFLAGS_DEBUG_SYMBOLS="-Z7"
fi
diff --git a/make/autoconf/flags-ldflags.m4 b/make/autoconf/flags-ldflags.m4
index b0dc565b39f..466ff1beaf4 100644
--- a/make/autoconf/flags-ldflags.m4
+++ b/make/autoconf/flags-ldflags.m4
@@ -63,7 +63,7 @@ AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER],
fi
BASIC_LDFLAGS_JVM_ONLY=""
- LDFLAGS_LTO="-flto=auto -fuse-linker-plugin -fno-strict-aliasing"
+ LDFLAGS_LTO="-flto=auto -fuse-linker-plugin -fno-strict-aliasing $DEBUG_PREFIX_CFLAGS"
LDFLAGS_CXX_PARTIAL_LINKING="$MACHINE_FLAG -r"
@@ -71,7 +71,7 @@ AC_DEFUN([FLAGS_SETUP_LDFLAGS_HELPER],
BASIC_LDFLAGS_JVM_ONLY="-mno-omit-leaf-frame-pointer -mstack-alignment=16 \
-fPIC"
- LDFLAGS_LTO="-flto=auto -fuse-linker-plugin -fno-strict-aliasing"
+ LDFLAGS_LTO="-flto=auto -fuse-linker-plugin -fno-strict-aliasing $DEBUG_PREFIX_CFLAGS"
LDFLAGS_CXX_PARTIAL_LINKING="$MACHINE_FLAG -r"
if test "x$OPENJDK_TARGET_OS" = xlinux; then
diff --git a/make/autoconf/hotspot.m4 b/make/autoconf/hotspot.m4
index 6dc46d17aa3..3adb1333fe5 100644
--- a/make/autoconf/hotspot.m4
+++ b/make/autoconf/hotspot.m4
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2025, 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
diff --git a/make/autoconf/jdk-options.m4 b/make/autoconf/jdk-options.m4
index bb188778001..87d147d4f07 100644
--- a/make/autoconf/jdk-options.m4
+++ b/make/autoconf/jdk-options.m4
@@ -316,23 +316,36 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_DEBUG_SYMBOLS],
AC_MSG_CHECKING([if we should add external native debug symbols to the shipped bundles])
AC_ARG_WITH([external-symbols-in-bundles],
[AS_HELP_STRING([--with-external-symbols-in-bundles],
- [which type of external native debug symbol information shall be shipped in product bundles (none, public, full)
- (e.g. ship full/stripped pdbs on Windows) @<:@none@:>@])])
+ [which type of external native debug symbol information shall be shipped with bundles/images (none, public, full).
+ @<:@none in release builds, full otherwise. --with-native-debug-symbols=external/zipped is a prerequisite. public is only supported on Windows@:>@])],
+ [],
+ [with_external_symbols_in_bundles=default])
if test "x$with_external_symbols_in_bundles" = x || test "x$with_external_symbols_in_bundles" = xnone ; then
AC_MSG_RESULT([no])
elif test "x$with_external_symbols_in_bundles" = xfull || test "x$with_external_symbols_in_bundles" = xpublic ; then
- if test "x$OPENJDK_TARGET_OS" != xwindows ; then
- AC_MSG_ERROR([--with-external-symbols-in-bundles currently only works on windows!])
- elif test "x$COPY_DEBUG_SYMBOLS" != xtrue ; then
- AC_MSG_ERROR([--with-external-symbols-in-bundles only works when --with-native-debug-symbols=external is used!])
- elif test "x$with_external_symbols_in_bundles" = xfull ; then
+ if test "x$COPY_DEBUG_SYMBOLS" != xtrue ; then
+ AC_MSG_ERROR([--with-external-symbols-in-bundles only works when --with-native-debug-symbols=external/zipped is used!])
+ elif test "x$with_external_symbols_in_bundles" = xpublic && test "x$OPENJDK_TARGET_OS" != xwindows ; then
+ AC_MSG_ERROR([--with-external-symbols-in-bundles=public is only supported on Windows!])
+ fi
+
+ if test "x$with_external_symbols_in_bundles" = xfull ; then
AC_MSG_RESULT([full])
SHIP_DEBUG_SYMBOLS=full
else
AC_MSG_RESULT([public])
SHIP_DEBUG_SYMBOLS=public
fi
+ elif test "x$with_external_symbols_in_bundles" = xdefault ; then
+ if test "x$DEBUG_LEVEL" = xrelease ; then
+ AC_MSG_RESULT([no (default)])
+ elif test "x$COPY_DEBUG_SYMBOLS" = xtrue ; then
+ AC_MSG_RESULT([full (default)])
+ SHIP_DEBUG_SYMBOLS=full
+ else
+ AC_MSG_RESULT([no (default, native debug symbols are not external/zipped)])
+ fi
else
AC_MSG_ERROR([$with_external_symbols_in_bundles is an unknown value for --with-external-symbols-in-bundles])
fi
diff --git a/make/autoconf/lib-bundled.m4 b/make/autoconf/lib-bundled.m4
index 3246697663c..a6266bec014 100644
--- a/make/autoconf/lib-bundled.m4
+++ b/make/autoconf/lib-bundled.m4
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2025, 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
diff --git a/make/autoconf/platform.m4 b/make/autoconf/platform.m4
index 31451d0c37f..1b247e159ac 100644
--- a/make/autoconf/platform.m4
+++ b/make/autoconf/platform.m4
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2025, 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
diff --git a/make/common/Utils.gmk b/make/common/Utils.gmk
index c0ebabca3f7..b4bb949d3ee 100644
--- a/make/common/Utils.gmk
+++ b/make/common/Utils.gmk
@@ -114,7 +114,7 @@ EscapeDollar = $(subst $$,\$$,$(subst \$$,$$,$(strip $1)))
################################################################################
# This macro works just like EscapeDollar above, but for #.
-EscapeHash = $(subst \#,\\\#,$(subst \\\#,\#,$(strip $1)))
+EscapeHash = $(subst $(HASH),\$(HASH),$(subst \$(HASH),$(HASH),$(strip $1)))
################################################################################
# This macro translates $ into $$ to protect the string from make itself.
diff --git a/make/common/native/Flags.gmk b/make/common/native/Flags.gmk
index 843701cb4db..6353b490654 100644
--- a/make/common/native/Flags.gmk
+++ b/make/common/native/Flags.gmk
@@ -229,6 +229,14 @@ define SetupLinkerFlags
# TOOLCHAIN_TYPE plus OPENJDK_TARGET_OS
ifeq ($$($1_LINK_TIME_OPTIMIZATION), true)
$1_EXTRA_LDFLAGS += $(LDFLAGS_LTO)
+ # Instruct the ld64 linker not to delete the temporary object file
+ # generated during Link Time Optimization
+ ifeq ($(call isTargetOs, macosx), true)
+ $1_EXTRA_LDFLAGS += -Wl,-object_path_lto,$$($1_OBJECT_DIR)/$$($1_NAME)_lto_helper.o
+ endif
+ ifeq ($(TOOLCHAIN_TYPE), microsoft)
+ $1_EXTRA_LDFLAGS += -LTCGOUT:$$($1_OBJECT_DIR)/$$($1_NAME).iobj
+ endif
endif
$1_EXTRA_LDFLAGS += $$($1_LDFLAGS_$(OPENJDK_TARGET_OS_TYPE)) $$($1_LDFLAGS_$(OPENJDK_TARGET_OS)) \
diff --git a/make/conf/jib-profiles.js b/make/conf/jib-profiles.js
index 795335d7c3c..93aeebc0dd6 100644
--- a/make/conf/jib-profiles.js
+++ b/make/conf/jib-profiles.js
@@ -1192,8 +1192,8 @@ var getJibProfilesDependencies = function (input, common) {
server: "jpg",
product: "jcov",
version: "3.0",
- build_number: "3",
- file: "bundles/jcov-3.0+3.zip",
+ build_number: "5",
+ file: "bundles/jcov-3.0+5.zip",
environment_name: "JCOV_HOME",
},
diff --git a/make/conf/version-numbers.conf b/make/conf/version-numbers.conf
index 977809535ba..4392d86ac33 100644
--- a/make/conf/version-numbers.conf
+++ b/make/conf/version-numbers.conf
@@ -26,17 +26,17 @@
# Default version, product, and vendor information to use,
# unless overridden by configure
-DEFAULT_VERSION_FEATURE=26
+DEFAULT_VERSION_FEATURE=27
DEFAULT_VERSION_INTERIM=0
DEFAULT_VERSION_UPDATE=0
DEFAULT_VERSION_PATCH=0
DEFAULT_VERSION_EXTRA1=0
DEFAULT_VERSION_EXTRA2=0
DEFAULT_VERSION_EXTRA3=0
-DEFAULT_VERSION_DATE=2026-03-17
-DEFAULT_VERSION_CLASSFILE_MAJOR=70 # "`$EXPR $DEFAULT_VERSION_FEATURE + 44`"
+DEFAULT_VERSION_DATE=2026-09-15
+DEFAULT_VERSION_CLASSFILE_MAJOR=71 # "`$EXPR $DEFAULT_VERSION_FEATURE + 44`"
DEFAULT_VERSION_CLASSFILE_MINOR=0
DEFAULT_VERSION_DOCS_API_SINCE=11
-DEFAULT_ACCEPTABLE_BOOT_VERSIONS="25 26"
-DEFAULT_JDK_SOURCE_TARGET_VERSION=26
+DEFAULT_ACCEPTABLE_BOOT_VERSIONS="25 26 27"
+DEFAULT_JDK_SOURCE_TARGET_VERSION=27
DEFAULT_PROMOTED_VERSION_PRE=ea
diff --git a/make/devkit/createWindowsDevkit.sh b/make/devkit/createWindowsDevkit.sh
index 7c55605c776..b21557ed498 100644
--- a/make/devkit/createWindowsDevkit.sh
+++ b/make/devkit/createWindowsDevkit.sh
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2015, 2025, 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
diff --git a/make/hotspot/lib/CompileJvm.gmk b/make/hotspot/lib/CompileJvm.gmk
index b0ea27e5081..39a549b7db0 100644
--- a/make/hotspot/lib/CompileJvm.gmk
+++ b/make/hotspot/lib/CompileJvm.gmk
@@ -151,6 +151,12 @@ JVM_STRIPFLAGS ?= $(STRIPFLAGS)
# This source set is reused so save in cache.
$(call FillFindCache, $(JVM_SRC_DIRS))
+ifeq ($(SHIP_DEBUG_SYMBOLS), full)
+ CFLAGS_SHIP_DEBUGINFO := -DSHIP_DEBUGINFO_FULL
+else ifeq ($(SHIP_DEBUG_SYMBOLS), public)
+ CFLAGS_SHIP_DEBUGINFO := -DSHIP_DEBUGINFO_PUBLIC
+endif
+
ifeq ($(call isTargetOs, windows), true)
ifeq ($(STATIC_LIBS), true)
WIN_EXPORT_FILE := $(JVM_OUTPUTDIR)/static-win-exports.def
@@ -158,10 +164,6 @@ ifeq ($(call isTargetOs, windows), true)
WIN_EXPORT_FILE := $(JVM_OUTPUTDIR)/win-exports.def
endif
- ifeq ($(SHIP_DEBUG_SYMBOLS), public)
- CFLAGS_STRIPPED_DEBUGINFO := -DHAS_STRIPPED_DEBUGINFO
- endif
-
JVM_LDFLAGS += -def:$(WIN_EXPORT_FILE)
endif
@@ -187,7 +189,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJVM, \
CFLAGS := $(JVM_CFLAGS), \
abstract_vm_version.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \
arguments.cpp_CXXFLAGS := $(CFLAGS_VM_VERSION), \
- whitebox.cpp_CXXFLAGS := $(CFLAGS_STRIPPED_DEBUGINFO), \
+ whitebox.cpp_CXXFLAGS := $(CFLAGS_SHIP_DEBUGINFO), \
DISABLED_WARNINGS_gcc := $(DISABLED_WARNINGS_gcc), \
DISABLED_WARNINGS_gcc_ad_$(HOTSPOT_TARGET_CPU_ARCH).cpp := nonnull, \
DISABLED_WARNINGS_gcc_bytecodeInterpreter.cpp := unused-label, \
diff --git a/make/jdk/src/classes/build/tools/pandocfilter/PandocFilter.java b/make/jdk/src/classes/build/tools/pandocfilter/PandocFilter.java
index ebb49613e53..9f4d84ac95b 100644
--- a/make/jdk/src/classes/build/tools/pandocfilter/PandocFilter.java
+++ b/make/jdk/src/classes/build/tools/pandocfilter/PandocFilter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, 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
diff --git a/make/jdk/src/classes/build/tools/taglet/JSpec.java b/make/jdk/src/classes/build/tools/taglet/JSpec.java
index ca45104e086..1c301e94a8a 100644
--- a/make/jdk/src/classes/build/tools/taglet/JSpec.java
+++ b/make/jdk/src/classes/build/tools/taglet/JSpec.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, 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,10 +31,9 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import java.lang.reflect.Field;
import javax.lang.model.element.Element;
-import javax.lang.model.element.PackageElement;
-import javax.lang.model.element.TypeElement;
import com.sun.source.doctree.DocTree;
import com.sun.source.doctree.LiteralTree;
@@ -160,9 +159,10 @@ public class JSpec implements Taglet {
if (m.find()) {
String chapter = m.group("chapter");
String section = m.group("section");
+ String rootParent = currentPath().replaceAll("[^/]+", "..");
- String url = String.format("%1$s/../specs/%2$s/%2$s-%3$s.html#%2$s-%3$s%4$s",
- docRoot(elem), idPrefix, chapter, section);
+ String url = String.format("%1$s/specs/%2$s/%2$s-%3$s.html#%2$s-%3$s%4$s",
+ rootParent, idPrefix, chapter, section);
sb.append(" CURRENT_PATH = null;
+
+ private String currentPath() {
+ if (CURRENT_PATH == null) {
+ try {
+ Field f = Class.forName("jdk.javadoc.internal.doclets.formats.html.HtmlDocletWriter")
+ .getField("CURRENT_PATH");
+ @SuppressWarnings("unchecked")
+ ThreadLocal tl = (ThreadLocal) f.get(null);
+ CURRENT_PATH = tl;
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException("Cannot determine current path", e);
+ }
+ }
+ return CURRENT_PATH.get();
+ }
private String expand(List extends DocTree> trees) {
return (new SimpleDocTreeVisitor() {
@@ -209,34 +225,4 @@ public class JSpec implements Taglet {
}).visit(trees, new StringBuilder()).toString();
}
- private String docRoot(Element elem) {
- switch (elem.getKind()) {
- case MODULE:
- return "..";
-
- case PACKAGE:
- PackageElement pe = (PackageElement)elem;
- String pkgPart = pe.getQualifiedName()
- .toString()
- .replace('.', '/')
- .replaceAll("[^/]+", "..");
- return pe.getEnclosingElement() != null
- ? "../" + pkgPart
- : pkgPart;
-
- case CLASS, ENUM, RECORD, INTERFACE, ANNOTATION_TYPE:
- TypeElement te = (TypeElement)elem;
- return te.getQualifiedName()
- .toString()
- .replace('.', '/')
- .replaceAll("[^/]+", "..");
-
- default:
- var enclosing = elem.getEnclosingElement();
- if (enclosing == null)
- throw new IllegalArgumentException(elem.getKind().toString());
- return docRoot(enclosing);
- }
- }
-
}
diff --git a/make/jdk/src/classes/build/tools/taglet/ToolGuide.java b/make/jdk/src/classes/build/tools/taglet/ToolGuide.java
index 72a8ab05b3b..8db2aee3092 100644
--- a/make/jdk/src/classes/build/tools/taglet/ToolGuide.java
+++ b/make/jdk/src/classes/build/tools/taglet/ToolGuide.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2025, 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,10 +31,9 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import java.lang.reflect.Field;
import javax.lang.model.element.Element;
-import javax.lang.model.element.PackageElement;
-import javax.lang.model.element.TypeElement;
import com.sun.source.doctree.DocTree;
import com.sun.source.doctree.UnknownBlockTagTree;
@@ -68,7 +67,7 @@ public class ToolGuide implements Taglet {
static final String TAG_NAME = "toolGuide";
- static final String BASE_URL = "../specs/man";
+ static final String BASE_URL = "specs/man";
static final Pattern TAG_PATTERN = Pattern.compile("(?s)(?[A-Za-z0-9]+)\\s*(?.*)$");
@@ -119,9 +118,10 @@ public class ToolGuide implements Taglet {
if (label.isEmpty()) {
label = name;
}
+ String rootParent = currentPath().replaceAll("[^/]+", "..");
String url = String.format("%s/%s/%s.html",
- docRoot(elem), BASE_URL, name);
+ rootParent, BASE_URL, name);
if (needComma) {
sb.append(",\n");
@@ -142,33 +142,21 @@ public class ToolGuide implements Taglet {
return sb.toString();
}
- private String docRoot(Element elem) {
- switch (elem.getKind()) {
- case MODULE:
- return "..";
+ private static ThreadLocal CURRENT_PATH = null;
- case PACKAGE:
- PackageElement pe = (PackageElement)elem;
- String pkgPart = pe.getQualifiedName()
- .toString()
- .replace('.', '/')
- .replaceAll("[^/]+", "..");
- return pe.getEnclosingElement() != null
- ? "../" + pkgPart
- : pkgPart;
-
- case CLASS, ENUM, RECORD, INTERFACE, ANNOTATION_TYPE:
- TypeElement te = (TypeElement)elem;
- return te.getQualifiedName()
- .toString()
- .replace('.', '/')
- .replaceAll("[^/]+", "..");
-
- default:
- var enclosing = elem.getEnclosingElement();
- if (enclosing == null)
- throw new IllegalArgumentException(elem.getKind().toString());
- return docRoot(enclosing);
+ private String currentPath() {
+ if (CURRENT_PATH == null) {
+ try {
+ Field f = Class.forName("jdk.javadoc.internal.doclets.formats.html.HtmlDocletWriter")
+ .getField("CURRENT_PATH");
+ @SuppressWarnings("unchecked")
+ ThreadLocal tl = (ThreadLocal) f.get(null);
+ CURRENT_PATH = tl;
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException("Cannot determine current path", e);
+ }
}
+ return CURRENT_PATH.get();
}
+
}
diff --git a/make/langtools/tools/propertiesparser/gen/ClassGenerator.java b/make/langtools/tools/propertiesparser/gen/ClassGenerator.java
index 247537b4676..14e8c4fb00a 100644
--- a/make/langtools/tools/propertiesparser/gen/ClassGenerator.java
+++ b/make/langtools/tools/propertiesparser/gen/ClassGenerator.java
@@ -286,7 +286,7 @@ public class ClassGenerator {
diagnosticFlags.isEmpty() ?
StubKind.DIAGNOSTIC_FLAGS_EMPTY.format() :
StubKind.DIAGNOSTIC_FLAGS_NON_EMPTY.format(diagnosticFlags),
- StubKind.LINT_CATEGORY.format("\"" + lintCategory + "\""),
+ StubKind.LINT_CATEGORY.format(toLintFieldName(lintCategory)),
"\"" + keyParts[0] + "\"",
"\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"",
javadoc);
@@ -314,7 +314,7 @@ public class ClassGenerator {
diagnosticFlags.isEmpty() ?
StubKind.DIAGNOSTIC_FLAGS_EMPTY.format() :
StubKind.DIAGNOSTIC_FLAGS_NON_EMPTY.format(diagnosticFlags),
- StubKind.LINT_CATEGORY.format("\"" + lintCategory + "\""),
+ StubKind.LINT_CATEGORY.format(toLintFieldName(lintCategory)),
"\"" + keyParts[0] + "\"",
"\"" + Stream.of(keyParts).skip(2).collect(Collectors.joining(".")) + "\"",
argNames.stream().collect(Collectors.joining(", ")));
@@ -329,6 +329,11 @@ public class ClassGenerator {
}
}
+ String toLintFieldName(String lintCategory) {
+ return lintCategory.toUpperCase()
+ .replaceAll("-", "_");
+ }
+
/**
* Form the name of a factory method/field given a resource key.
*/
diff --git a/make/langtools/tools/propertiesparser/parser/Message.java b/make/langtools/tools/propertiesparser/parser/Message.java
index fb0809fb1bd..cbd1093a161 100644
--- a/make/langtools/tools/propertiesparser/parser/Message.java
+++ b/make/langtools/tools/propertiesparser/parser/Message.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2025, 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
diff --git a/make/langtools/tools/propertiesparser/resources/templates.properties b/make/langtools/tools/propertiesparser/resources/templates.properties
index 81a9be2552c..f8ff07a878f 100644
--- a/make/langtools/tools/propertiesparser/resources/templates.properties
+++ b/make/langtools/tools/propertiesparser/resources/templates.properties
@@ -87,7 +87,7 @@ suppress.warnings=\
@SuppressWarnings("rawtypes")\n
lint.category=\
- LintCategory.get({0}).get()
+ LintCategory.{0}
diagnostic.flags.empty=\
EnumSet.noneOf(DiagnosticFlag.class)
diff --git a/make/modules/java.desktop/lib/ClientLibraries.gmk b/make/modules/java.desktop/lib/ClientLibraries.gmk
index 4cd7f5bac90..b76cb8dc4e3 100644
--- a/make/modules/java.desktop/lib/ClientLibraries.gmk
+++ b/make/modules/java.desktop/lib/ClientLibraries.gmk
@@ -164,6 +164,24 @@ ifeq ($(ENABLE_HEADLESS_ONLY), false)
ifeq ($(USE_EXTERNAL_LIBPNG), false)
LIBSPLASHSCREEN_HEADER_DIRS += libsplashscreen/libpng
+ LIBSPLASHSCREEN_CFLAGS += -DPNG_NO_MMX_CODE -DPNG_ARM_NEON_OPT=0 \
+ -DPNG_ARM_NEON_IMPLEMENTATION=0 -DPNG_LOONGARCH_LSX_OPT=0
+
+ ifeq ($(call isTargetOs, linux)+$(call isTargetCpuArch, ppc), true+true)
+ LIBSPLASHSCREEN_CFLAGS += -DPNG_POWERPC_VSX_OPT=0
+ endif
+
+ # The libpng bundled with jdk is a reduced version which does not
+ # contain .png_init_filter_functions_vsx.
+ # Therefore we need to disable PNG_POWERPC_VSX_OPT explicitly by setting
+ # it to 0. If this define is not set, it would be automatically set to 2,
+ # because
+ # "#if defined(__PPC64__) && defined(__ALTIVEC__) && defined(__VSX__)"
+ # expands to true. This would results in the fact that
+ # .png_init_filter_functions_vsx is needed in libpng.
+ ifeq ($(call isTargetOs, aix), true)
+ LIBSPLASHSCREEN_CFLAGS += -DPNG_POWERPC_VSX_OPT=0
+ endif
else
LIBSPLASHSCREEN_EXCLUDES += libpng
endif
@@ -176,25 +194,7 @@ ifeq ($(ENABLE_HEADLESS_ONLY), false)
LIBSPLASHSCREEN_STATIC_LIB_EXCLUDE_OBJS += $(LIBZIP_OBJS)
endif
- LIBSPLASHSCREEN_CFLAGS += -DSPLASHSCREEN -DPNG_NO_MMX_CODE \
- -DPNG_ARM_NEON_OPT=0 -DPNG_ARM_NEON_IMPLEMENTATION=0 \
- -DPNG_LOONGARCH_LSX_OPT=0
-
- ifeq ($(call isTargetOs, linux)+$(call isTargetCpuArch, ppc), true+true)
- LIBSPLASHSCREEN_CFLAGS += -DPNG_POWERPC_VSX_OPT=0
- endif
-
- # The external libpng submitted in the jdk is a reduced version
- # which does not contain .png_init_filter_functions_vsx.
- # Therefore we need to disable PNG_POWERPC_VSX_OPT explicitly by setting
- # it to 0. If this define is not set, it would be automatically set to 2,
- # because
- # "#if defined(__PPC64__) && defined(__ALTIVEC__) && defined(__VSX__)"
- # expands to true. This would results in the fact that
- # .png_init_filter_functions_vsx is needed in libpng.
- ifeq ($(call isTargetOs, aix), true)
- LIBSPLASHSCREEN_CFLAGS += -DPNG_POWERPC_VSX_OPT=0
- endif
+ LIBSPLASHSCREEN_CFLAGS += -DSPLASHSCREEN
ifeq ($(call isTargetOs, macosx), true)
# libsplashscreen on macosx does not use the unix code
diff --git a/make/modules/jdk.jdwp.agent/Lib.gmk b/make/modules/jdk.jdwp.agent/Lib.gmk
index 6ae053d4bec..ce58e145f59 100644
--- a/make/modules/jdk.jdwp.agent/Lib.gmk
+++ b/make/modules/jdk.jdwp.agent/Lib.gmk
@@ -54,21 +54,6 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJDWP, \
NAME := jdwp, \
OPTIMIZATION := LOW, \
CFLAGS := -DJDWP_LOGGING $(ICONV_CFLAGS), \
- DISABLED_WARNINGS_gcc_eventFilter.c := unused-variable, \
- DISABLED_WARNINGS_gcc_SDE.c := unused-function, \
- DISABLED_WARNINGS_gcc_threadControl.c := unused-but-set-variable \
- unused-variable, \
- DISABLED_WARNINGS_gcc_utf_util.c := unused-but-set-variable, \
- DISABLED_WARNINGS_clang_error_messages.c := format-nonliteral, \
- DISABLED_WARNINGS_clang_eventFilter.c := unused-variable, \
- DISABLED_WARNINGS_clang_EventRequestImpl.c := self-assign, \
- DISABLED_WARNINGS_clang_inStream.c := sometimes-uninitialized, \
- DISABLED_WARNINGS_clang_log_messages.c := format-nonliteral, \
- DISABLED_WARNINGS_clang_SDE.c := unused-function, \
- DISABLED_WARNINGS_clang_threadControl.c := unused-but-set-variable \
- unused-variable, \
- DISABLED_WARNINGS_clang_utf_util.c := unused-but-set-variable, \
- DISABLED_WARNINGS_microsoft_debugInit.c := 5287, \
LDFLAGS := $(ICONV_LDFLAGS), \
EXTRA_HEADER_DIRS := \
include \
diff --git a/make/scripts/compare-logger.sh b/make/scripts/compare-logger.sh
index 0a7d8b99f6f..930936f7ac0 100644
--- a/make/scripts/compare-logger.sh
+++ b/make/scripts/compare-logger.sh
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2012, 2025, 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
diff --git a/make/scripts/compare.sh b/make/scripts/compare.sh
index 250b5a37b9f..777db4b8242 100644
--- a/make/scripts/compare.sh
+++ b/make/scripts/compare.sh
@@ -1,6 +1,6 @@
#!/bin/bash
#
-# Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2012, 2025, 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
diff --git a/src/demo/share/java2d/J2DBench/Makefile b/src/demo/share/java2d/J2DBench/Makefile
index f8949845b4f..b5996ae4d6d 100644
--- a/src/demo/share/java2d/J2DBench/Makefile
+++ b/src/demo/share/java2d/J2DBench/Makefile
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
diff --git a/src/demo/share/java2d/J2DBench/build.xml b/src/demo/share/java2d/J2DBench/build.xml
index d48b446d0f3..748673b5fed 100644
--- a/src/demo/share/java2d/J2DBench/build.xml
+++ b/src/demo/share/java2d/J2DBench/build.xml
@@ -1,5 +1,5 @@
ERROR this file is not allowed:" + name);
+ badFileFound.set(true);
+ }
+ } else {
+ boolean allowed = allowedEndings.stream().anyMatch(name::endsWith);
+ if (! allowed) {
+ System.out.println(" --> ERROR this file is not allowed:" + name);
+ badFileFound.set(true);
+ }
+ }
+ }
+ });
+
+ return !badFileFound.get();
+ }
+}
diff --git a/test/jdk/com/sun/jdi/AfterThreadDeathTest.java b/test/jdk/com/sun/jdi/AfterThreadDeathTest.java
index 27904021442..25987de864c 100644
--- a/test/jdk/com/sun/jdi/AfterThreadDeathTest.java
+++ b/test/jdk/com/sun/jdi/AfterThreadDeathTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2025, 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
@@ -93,6 +93,7 @@ public class AfterThreadDeathTest extends TestScaffold {
println("Ok; got expected IllegalThreadStateException");
return;
} catch (Exception ee) {
+ ee.printStackTrace(System.err);
failure("FAILED: Did not get expected"
+ " IllegalThreadStateException"
+ " on a StepRequest.enable(). \n"
@@ -133,6 +134,13 @@ public class AfterThreadDeathTest extends TestScaffold {
mainThread = bpe.thread();
erm = vm().eventRequestManager();
+ /*
+ * The "main" thread will be referenced during the ThreadDeathEvent, which
+ * uses SUSPEND_NONE, so the thread might get gc'd and cause an unexpected
+ * ObjectCollectedException. Disable it from collection to prevent problems.
+ */
+ mainThread.disableCollection();
+
/*
* Set event requests
*/
diff --git a/test/jdk/com/sun/jdi/ExceptionEvents.java b/test/jdk/com/sun/jdi/ExceptionEvents.java
index de5f51c4aa2..ee9e91b4dd9 100644
--- a/test/jdk/com/sun/jdi/ExceptionEvents.java
+++ b/test/jdk/com/sun/jdi/ExceptionEvents.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2025, 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
@@ -355,7 +355,16 @@ public class ExceptionEvents extends TestScaffold {
if (event.request() == request) {
try {
System.out.print("ExceptionEvent: ");
- System.out.print("" + event.exception().referenceType().name());
+ try {
+ System.out.print("" + event.exception().referenceType().name());
+ } catch (ObjectCollectedException e) {
+ if (event.request().suspendPolicy() == EventRequest.SUSPEND_NONE) {
+ // Since the thread was not suspended, the exception object can be collected.
+ System.out.print("");
+ } else {
+ throw e;
+ }
+ }
Location loc = event.location();
System.out.print(" @ " + loc.method().name());
System.out.print(":" + loc.lineNumber());
diff --git a/test/jdk/com/sun/jndi/ldap/LdapPoolTimeoutTest.java b/test/jdk/com/sun/jndi/ldap/LdapPoolTimeoutTest.java
index 294e0f5f1a8..b47433ca16f 100644
--- a/test/jdk/com/sun/jndi/ldap/LdapPoolTimeoutTest.java
+++ b/test/jdk/com/sun/jndi/ldap/LdapPoolTimeoutTest.java
@@ -35,6 +35,8 @@ import org.testng.annotations.Test;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
+
+import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
@@ -82,14 +84,10 @@ public class LdapPoolTimeoutTest {
env.put(Context.PROVIDER_URL, "ldap://example.com:1234");
try {
- futures.add(executorService.submit(() -> { attemptConnect(env); return null; }));
- futures.add(executorService.submit(() -> { attemptConnect(env); return null; }));
- futures.add(executorService.submit(() -> { attemptConnect(env); return null; }));
- futures.add(executorService.submit(() -> { attemptConnect(env); return null; }));
- futures.add(executorService.submit(() -> { attemptConnect(env); return null; }));
- futures.add(executorService.submit(() -> { attemptConnect(env); return null; }));
- futures.add(executorService.submit(() -> { attemptConnect(env); return null; }));
- futures.add(executorService.submit(() -> { attemptConnect(env); return null; }));
+ // launch a few concurrent connection attempts
+ for (int i = 0; i < 8; i++) {
+ futures.add(executorService.submit(() -> { attemptConnect(env); return null; }));
+ }
} finally {
executorService.shutdown();
}
@@ -109,38 +107,55 @@ public class LdapPoolTimeoutTest {
private static void attemptConnect(Hashtable env) throws Exception {
try {
- LdapTimeoutTest.assertCompletion(CONNECT_MILLIS - 1000,
- 2 * CONNECT_MILLIS + TOLERANCE,
- () -> new InitialDirContext(env));
- } catch (RuntimeException e) {
- final String msg = e.getCause() == null ? e.getMessage() : e.getCause().getMessage();
- // assertCompletion may wrap a CommunicationException in an RTE
- if (msg != null &&
- (msg.contains("Network is unreachable")
- || msg.contains("No route to host")
- || msg.contains("Connection timed out"))) {
- // got the expected exception
- System.out.println("Received expected RuntimeException message: " + msg);
- } else {
- // propagate the unexpected exception
- throw e;
- }
- } catch (NamingException ex) {
- final String msg = ex.getCause() == null ? ex.getMessage() : ex.getCause().getMessage();
- if (msg != null &&
- (msg.contains("Network is unreachable")
- || msg.contains("Timed out waiting for lock")
- || msg.contains("Connect timed out")
- || msg.contains("Timeout exceeded while waiting for a connection"))) {
- // got the expected exception
- System.out.println("Received expected NamingException message: " + msg);
- } else {
- // propagate the unexpected exception
- throw ex;
- }
+ final InitialDirContext unexpectedCtx =
+ LdapTimeoutTest.assertCompletion(CONNECT_MILLIS - 1000,
+ 2 * CONNECT_MILLIS + TOLERANCE,
+ () -> new InitialDirContext(env));
+ throw new RuntimeException("InitialDirContext construction was expected to fail," +
+ " but returned " + unexpectedCtx);
} catch (Throwable t) {
- throw new RuntimeException(t);
+ final NamingException namingEx = findNamingException(t);
+ if (namingEx != null) {
+ // found the NamingException, verify it's the right reason
+ if (namingEx.getCause() instanceof SocketTimeoutException ste) {
+ // got the expected exception
+ System.out.println("Received expected SocketTimeoutException: " + ste);
+ return;
+ }
+ // rely on the exception message to verify the expected exception
+ final String msg = namingEx.getCause() == null
+ ? namingEx.getMessage()
+ : namingEx.getCause().getMessage();
+ if (msg != null &&
+ (msg.contains("Network is unreachable")
+ || msg.contains("No route to host")
+ || msg.contains("Timed out waiting for lock")
+ || msg.contains("Connect timed out")
+ || msg.contains("Timeout exceeded while waiting for a connection"))) {
+ // got the expected exception
+ System.out.println("Received expected NamingException with message: " + msg);
+ return;
+ }
+ }
+ // unexpected exception, propagate it
+ if (t instanceof Exception e) {
+ throw e;
+ } else {
+ throw new Exception(t);
+ }
}
}
+ // Find and return the NamingException from the given Throwable. Returns null if none found.
+ private static NamingException findNamingException(final Throwable t) {
+ Throwable cause = t;
+ while (cause != null) {
+ if (cause instanceof NamingException ne) {
+ return ne;
+ }
+ cause = cause.getCause();
+ }
+ return null;
+ }
+
}
diff --git a/test/jdk/com/sun/net/httpserver/BasicAuthenticatorRealm.java b/test/jdk/com/sun/net/httpserver/BasicAuthenticatorRealm.java
index 06248e950a5..85e4f93b5c9 100644
--- a/test/jdk/com/sun/net/httpserver/BasicAuthenticatorRealm.java
+++ b/test/jdk/com/sun/net/httpserver/BasicAuthenticatorRealm.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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 @@
* with HttpURLConnection and HttpClient
* @modules jdk.httpserver
* @library /test/lib
- * @run testng/othervm BasicAuthenticatorRealm
+ * @run junit/othervm BasicAuthenticatorRealm
*/
import com.sun.net.httpserver.BasicAuthenticator;
@@ -47,12 +47,20 @@ import java.net.http.HttpRequest;
import java.net.http.HttpResponse.BodyHandlers;
import jdk.test.lib.net.URIBuilder;
-import org.testng.annotations.Test;
import static java.net.http.HttpClient.Builder.NO_PROXY;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.testng.Assert.assertEquals;
+import org.junit.jupiter.api.*;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.Test;
+
+/**
+ * The second test @Order(2) must run after the first test because it
+ * sets a VM wide authenticator and the first test depends on no authenticator
+ * being set.
+ */
+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class BasicAuthenticatorRealm {
static final String REALM = "U\u00ffU@realm"; // non-ASCII char
@@ -61,7 +69,8 @@ public class BasicAuthenticatorRealm {
static final InetAddress LOOPBACK_ADDR = InetAddress.getLoopbackAddress();
@Test
- public static void testURLConnection() throws Exception {
+ @Order(1)
+ public void testURLConnection() throws Exception {
var server = HttpServer.create(new InetSocketAddress(LOOPBACK_ADDR, 0), 0);
var handler = HttpHandlers.of(200, Headers.of(), "");
var context = server.createContext("/test", handler);
@@ -73,15 +82,16 @@ public class BasicAuthenticatorRealm {
server.start();
var url = uri(server).toURL();
var connection = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
- assertEquals(connection.getResponseCode(), 401);
- assertEquals(connection.getHeaderField("WWW-Authenticate"), EXPECTED_AUTH_HEADER_VALUE);
+ assertEquals(401, connection.getResponseCode());
+ assertEquals(EXPECTED_AUTH_HEADER_VALUE, connection.getHeaderField("WWW-Authenticate"));
} finally {
server.stop(0);
}
}
@Test
- public static void testURLConnectionAuthenticated() throws Exception {
+ @Order(2)
+ public void testURLConnectionAuthenticated() throws Exception {
var server = HttpServer.create(new InetSocketAddress(LOOPBACK_ADDR, 0), 0);
var handler = HttpHandlers.of(200, Headers.of(), "foo");
var context = server.createContext("/test", handler);
@@ -94,15 +104,16 @@ public class BasicAuthenticatorRealm {
server.start();
var url = uri(server).toURL();
var connection = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
- assertEquals(connection.getResponseCode(), 200);
- assertEquals(connection.getInputStream().readAllBytes(), "foo".getBytes(UTF_8));
+ assertEquals(200, connection.getResponseCode());
+ Assertions.assertArrayEquals("foo".getBytes(UTF_8), connection.getInputStream().readAllBytes());
} finally {
server.stop(0);
}
}
@Test
- public static void testHttpClient() throws Exception {
+ @Order(3)
+ public void testHttpClient() throws Exception {
var server = HttpServer.create(new InetSocketAddress(LOOPBACK_ADDR, 0), 0);
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server)).build();
@@ -115,15 +126,16 @@ public class BasicAuthenticatorRealm {
try {
server.start();
var response = client.send(request, BodyHandlers.ofString(UTF_8));
- assertEquals(response.statusCode(), 401);
- assertEquals(response.headers().firstValue("WWW-Authenticate").orElseThrow(), EXPECTED_AUTH_HEADER_VALUE);
+ assertEquals(401, response.statusCode());
+ assertEquals(EXPECTED_AUTH_HEADER_VALUE, response.headers().firstValue("WWW-Authenticate").orElseThrow());
} finally {
server.stop(0);
}
}
@Test
- public static void testHttpClientAuthenticated() throws Exception {
+ @Order(4)
+ public void testHttpClientAuthenticated() throws Exception {
var server = HttpServer.create(new InetSocketAddress(LOOPBACK_ADDR, 0), 0);
var request = HttpRequest.newBuilder(uri(server)).build();
var handler = HttpHandlers.of(200, Headers.of(), "foo");
@@ -139,8 +151,8 @@ public class BasicAuthenticatorRealm {
try {
server.start();
var response = client.send(request, BodyHandlers.ofString(UTF_8));
- assertEquals(response.statusCode(), 200);
- assertEquals(response.body(), "foo");
+ assertEquals(200, response.statusCode());
+ assertEquals("foo", response.body());
} finally {
server.stop(0);
}
diff --git a/test/jdk/com/sun/net/httpserver/ClearTextServerSSL.java b/test/jdk/com/sun/net/httpserver/ClearTextServerSSL.java
new file mode 100644
index 00000000000..896f02b178d
--- /dev/null
+++ b/test/jdk/com/sun/net/httpserver/ClearTextServerSSL.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8373677
+ * @summary Tests for verifying that a non-SSL server can detect
+ * when a client attempts to use SSL.
+ * @library /test/lib
+ * @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.SimpleSSLContext;
+import jdk.test.lib.net.URIBuilder;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.net.ssl.SSLException;
+
+import static com.sun.net.httpserver.HttpExchange.RSPBODY_EMPTY;
+import static java.net.http.HttpClient.Builder.NO_PROXY;
+import static org.junit.jupiter.api.Assertions.*;
+
+public class ClearTextServerSSL {
+
+ static final InetAddress LOOPBACK_ADDR = InetAddress.getLoopbackAddress();
+ static final boolean ENABLE_LOGGING = true;
+ static final Logger logger = Logger.getLogger("com.sun.net.httpserver");
+
+ static final String CTXT_PATH = "/ClearTextServerSSL";
+
+ @BeforeAll
+ public static void setup() {
+ if (ENABLE_LOGGING) {
+ ConsoleHandler ch = new ConsoleHandler();
+ logger.setLevel(Level.ALL);
+ ch.setLevel(Level.ALL);
+ logger.addHandler(ch);
+ }
+ }
+
+ @Test
+ public void test() throws Exception {
+ var sslContext = SimpleSSLContext.findSSLContext();
+ var handler = new TestHandler();
+ var server = HttpServer.create(new InetSocketAddress(LOOPBACK_ADDR, 0), 0);
+ server.createContext(path(""), handler);
+ server.start();
+ try (var client = HttpClient.newBuilder()
+ .sslContext(sslContext)
+ .proxy(NO_PROXY)
+ .build()) {
+ var request = HttpRequest.newBuilder()
+ .uri(uri("http", server, path("/clear")))
+ .build();
+ var response = client.send(request, HttpResponse.BodyHandlers.ofString());
+ assertEquals(200, response.statusCode());
+ var sslRequest = HttpRequest.newBuilder()
+ .uri(uri("https", server, path("/ssl")))
+ .build();
+ Assertions.assertThrows(SSLException.class, () -> {
+ client.send(sslRequest, HttpResponse.BodyHandlers.ofString());
+ });
+ try (var socket = new Socket()) {
+ socket.connect(server.getAddress());
+ byte[] badRequest = {
+ 22, 'B', 'A', 'D', ' ',
+ '/', ' ' ,
+ 'H', 'T', 'T', 'P', '/', '1', '.', '1' };
+ socket.getOutputStream().write(badRequest);
+ socket.getOutputStream().flush();
+ var reader = new InputStreamReader(socket.getInputStream());
+ var line = reader.readAllLines();
+ Assertions.assertEquals("HTTP/1.1 400 Bad Request", line.get(0));
+ System.out.println("Got expected response:");
+ line.stream().map(l -> "\t" + l).forEach(System.out::println);
+ }
+
+ } finally {
+ server.stop(0);
+ }
+ }
+
+ // --- infra ---
+
+ static String path(String path) {
+ assert CTXT_PATH.startsWith("/");
+ assert !CTXT_PATH.endsWith("/");
+ if (path.startsWith("/")) {
+ return CTXT_PATH + path;
+ } else {
+ return CTXT_PATH + "/" + path;
+ }
+ }
+
+ static URI uri(String scheme, HttpServer server, String path) throws URISyntaxException {
+ return URIBuilder.newBuilder()
+ .scheme(scheme)
+ .loopback()
+ .port(server.getAddress().getPort())
+ .path(path)
+ .build();
+ }
+
+ /**
+ * A test handler that reads any request bytes and sends
+ * an empty 200 response
+ */
+ static class TestHandler implements HttpHandler {
+ @java.lang.Override
+ public void handle(HttpExchange exchange) throws IOException {
+ try (var reqBody = exchange.getRequestBody()) {
+ reqBody.readAllBytes();
+ exchange.sendResponseHeaders(200, RSPBODY_EMPTY);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ exchange.sendResponseHeaders(500, RSPBODY_EMPTY);
+ }
+ }
+ }
+}
diff --git a/test/jdk/com/sun/net/httpserver/CreateHttpServerTest.java b/test/jdk/com/sun/net/httpserver/CreateHttpServerTest.java
index 370bd75cf34..1fbe4e6f3d1 100644
--- a/test/jdk/com/sun/net/httpserver/CreateHttpServerTest.java
+++ b/test/jdk/com/sun/net/httpserver/CreateHttpServerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, 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,17 +25,17 @@
* @test
* @bug 8251496
* @summary summary
- * @run testng/othervm CreateHttpServerTest
+ * @run junit/othervm CreateHttpServerTest
*/
import com.sun.net.httpserver.HttpServer;
-import org.testng.annotations.Test;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
-import static org.testng.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Test;
public class CreateHttpServerTest {
@Test
diff --git a/test/jdk/com/sun/net/httpserver/DateFormatterTest.java b/test/jdk/com/sun/net/httpserver/DateFormatterTest.java
index bda3421660c..efcc96d45b0 100644
--- a/test/jdk/com/sun/net/httpserver/DateFormatterTest.java
+++ b/test/jdk/com/sun/net/httpserver/DateFormatterTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, 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
@@ -39,12 +39,13 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jdk.test.lib.net.URIBuilder;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
import static java.net.http.HttpResponse.BodyHandlers.ofString;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
+
+import org.junit.jupiter.api.AfterAll;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
/**
* @test
@@ -53,19 +54,19 @@ import static org.testng.Assert.fail;
* @modules java.net.http
* @library /test/lib
* @build DateFormatterTest
- * @run testng/othervm DateFormatterTest
+ * @run junit/othervm DateFormatterTest
*/
public class DateFormatterTest {
- private HttpServer server;
+ private static HttpServer server;
static URI httpURI;
static final Integer ITERATIONS = 10;
static String format;
static Pattern pattern;
- @BeforeTest
- public void setUp() throws IOException, URISyntaxException {
+ @BeforeAll
+ public static void setUp() throws IOException, URISyntaxException {
String days = "(Mon|Tue|Wed|Thu|Fri|Sat|Sun)(,)";
String dayNo = "(\\s\\d\\d\\s)";
String month = "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
@@ -85,8 +86,8 @@ public class DateFormatterTest {
server.start();
}
- @AfterTest
- public void cleanUp() {
+ @AfterAll
+ public static void cleanUp() {
server.stop(0);
}
diff --git a/test/jdk/com/sun/net/httpserver/FilterTest.java b/test/jdk/com/sun/net/httpserver/FilterTest.java
index 45c7ef21e8d..a5c90d2026e 100644
--- a/test/jdk/com/sun/net/httpserver/FilterTest.java
+++ b/test/jdk/com/sun/net/httpserver/FilterTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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 8267262
* @summary Tests for Filter static factory methods
- * @run testng/othervm FilterTest
+ * @run junit/othervm FilterTest
*/
import java.io.IOException;
@@ -49,11 +49,13 @@ import com.sun.net.httpserver.Filter;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-import org.testng.annotations.BeforeTest;
import static java.net.http.HttpClient.Builder.NO_PROXY;
-import static org.testng.Assert.*;
+
+import static org.junit.jupiter.api.Assertions.*;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
public class FilterTest {
@@ -64,8 +66,8 @@ public class FilterTest {
static final boolean ENABLE_LOGGING = true;
static final Logger logger = Logger.getLogger("com.sun.net.httpserver");
- @BeforeTest
- public void setup() {
+ @BeforeAll
+ public static void setup() {
if (ENABLE_LOGGING) {
ConsoleHandler ch = new ConsoleHandler();
logger.setLevel(Level.ALL);
@@ -76,14 +78,14 @@ public class FilterTest {
@Test
public void testNull() {
- expectThrows(NPE, () -> Filter.beforeHandler(null, e -> e.getResponseHeaders().set("X-Foo", "Bar")));
- expectThrows(NPE, () -> Filter.beforeHandler("Some description", null));
+ assertThrows(NPE, () -> Filter.beforeHandler(null, e -> e.getResponseHeaders().set("X-Foo", "Bar")));
+ assertThrows(NPE, () -> Filter.beforeHandler("Some description", null));
- expectThrows(NPE, () -> Filter.afterHandler("Some description", null));
- expectThrows(NPE, () -> Filter.afterHandler(null, HttpExchange::getResponseCode));
+ assertThrows(NPE, () -> Filter.afterHandler("Some description", null));
+ assertThrows(NPE, () -> Filter.afterHandler(null, HttpExchange::getResponseCode));
- expectThrows(NPE, () -> Filter.adaptRequest("Some description", null));
- expectThrows(NPE, () -> Filter.adaptRequest(null, r -> r.with("Foo", List.of("Bar"))));
+ assertThrows(NPE, () -> Filter.adaptRequest("Some description", null));
+ assertThrows(NPE, () -> Filter.adaptRequest(null, r -> r.with("Foo", List.of("Bar"))));
}
@Test
@@ -91,16 +93,15 @@ public class FilterTest {
var desc = "Some description";
var beforeFilter = Filter.beforeHandler(desc, HttpExchange::getRequestBody);
- assertEquals(desc, beforeFilter.description());
+ assertEquals(beforeFilter.description(), desc);
var afterFilter = Filter.afterHandler(desc, HttpExchange::getResponseCode);
- assertEquals(desc, afterFilter.description());
+ assertEquals(afterFilter.description(), desc);
var adaptFilter = Filter.adaptRequest(desc, r -> r.with("Foo", List.of("Bar")));
- assertEquals(desc, adaptFilter.description());
+ assertEquals(adaptFilter.description(), desc);
}
- @DataProvider
public static Object[][] throwingFilters() {
return new Object[][] {
{Filter.beforeHandler("before RE", e -> { throw new RuntimeException(); }), IOE},
@@ -111,7 +112,8 @@ public class FilterTest {
};
}
- @Test(dataProvider = "throwingFilters")
+ @ParameterizedTest
+ @MethodSource("throwingFilters")
public void testException(Filter filter, Class exception)
throws Exception
{
@@ -123,11 +125,11 @@ public class FilterTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
if (exception != null) {
- expectThrows(exception, () -> client.send(request, HttpResponse.BodyHandlers.ofString()));
+ assertThrows(exception, () -> client.send(request, HttpResponse.BodyHandlers.ofString()));
} else {
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.body(), "hello world");
+ assertEquals(200, response.statusCode());
+ assertEquals("hello world", response.body());
}
} finally {
server.stop(0);
@@ -146,9 +148,9 @@ public class FilterTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().map().size(), 3);
- assertEquals(response.headers().firstValue("x-foo").orElseThrow(), "bar");
+ assertEquals(200, response.statusCode());
+ assertEquals(3, response.headers().map().size());
+ assertEquals("bar", response.headers().firstValue("x-foo").orElseThrow());
} finally {
server.stop(0);
}
@@ -170,9 +172,9 @@ public class FilterTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().map().size(), 3);
- assertEquals(response.headers().firstValue("x-foo").orElseThrow(), "barbar");
+ assertEquals(200, response.statusCode());
+ assertEquals(3, response.headers().map().size());
+ assertEquals("barbar", response.headers().firstValue("x-foo").orElseThrow());
} finally {
server.stop(0);
}
@@ -202,9 +204,9 @@ public class FilterTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().map().size(), 3);
- assertEquals(response.headers().firstValue("x-foo").orElseThrow(), "bar");
+ assertEquals(200, response.statusCode());
+ assertEquals(3, response.headers().map().size());
+ assertEquals("bar", response.headers().firstValue("x-foo").orElseThrow());
} finally {
server.stop(0);
}
@@ -223,8 +225,8 @@ public class FilterTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.statusCode(), (int)respCode.get());
+ assertEquals(200, response.statusCode());
+ assertEquals((int)respCode.get(), response.statusCode());
} finally {
server.stop(0);
}
@@ -248,8 +250,8 @@ public class FilterTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(attr.get(), value);
+ assertEquals(200, response.statusCode());
+ assertEquals(value, attr.get());
} finally {
server.stop(0);
}
@@ -280,8 +282,8 @@ public class FilterTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.statusCode(), (int)respCode.get());
+ assertEquals(200, response.statusCode());
+ assertEquals((int)respCode.get(), response.statusCode());
} finally {
server.stop(0);
}
@@ -304,10 +306,10 @@ public class FilterTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().map().size(), 3);
- assertEquals(response.headers().firstValue("x-foo").orElseThrow(), "bar");
- assertEquals(response.statusCode(), (int)respCode.get());
+ assertEquals(200, response.statusCode());
+ assertEquals(3, response.headers().map().size());
+ assertEquals("bar", response.headers().firstValue("x-foo").orElseThrow());
+ assertEquals((int)respCode.get(), response.statusCode());
} finally {
server.stop(0);
}
@@ -326,8 +328,8 @@ public class FilterTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "foo/bar")).build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(inspectedURI.get(), URI.create("/foo/bar"));
+ assertEquals(200, response.statusCode());
+ assertEquals(URI.create("/foo/bar"), inspectedURI.get());
} finally {
server.stop(0);
}
@@ -348,9 +350,9 @@ public class FilterTest {
});
var adaptFilter = Filter.adaptRequest("Add x-foo request header", r -> {
// Confirm request state is unchanged
- assertEquals(r.getRequestHeaders(), originalExchange.getRequestHeaders());
- assertEquals(r.getRequestURI(), originalExchange.getRequestURI());
- assertEquals(r.getRequestMethod(), originalExchange.getRequestMethod());
+ assertEquals(originalExchange.getRequestHeaders(), r.getRequestHeaders());
+ assertEquals(originalExchange.getRequestURI(), r.getRequestURI());
+ assertEquals(originalExchange.getRequestMethod(), r.getRequestMethod());
return r.with("x-foo", List.of("bar"));
});
var server = HttpServer.create(new InetSocketAddress(LOOPBACK_ADDR,0), 10);
@@ -362,8 +364,8 @@ public class FilterTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.body(), "bar");
+ assertEquals(200, response.statusCode());
+ assertEquals("bar", response.body());
} finally {
server.stop(0);
}
@@ -398,22 +400,22 @@ public class FilterTest {
static class CompareStateAndEchoHandler implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
- assertEquals(exchange.getLocalAddress(), originalExchange.getLocalAddress());
- assertEquals(exchange.getRemoteAddress(), originalExchange.getRemoteAddress());
- assertEquals(exchange.getProtocol(), originalExchange.getProtocol());
- assertEquals(exchange.getPrincipal(), originalExchange.getPrincipal());
- assertEquals(exchange.getHttpContext(), originalExchange.getHttpContext());
- assertEquals(exchange.getRequestMethod(), originalExchange.getRequestMethod());
- assertEquals(exchange.getRequestURI(), originalExchange.getRequestURI());
- assertEquals(exchange.getRequestBody(), originalExchange.getRequestBody());
- assertEquals(exchange.getResponseHeaders(), originalExchange.getResponseHeaders());
- assertEquals(exchange.getResponseCode(), originalExchange.getResponseCode());
- assertEquals(exchange.getResponseBody(), originalExchange.getResponseBody());
- assertEquals(exchange.getAttribute("foo"), originalExchange.getAttribute("foo"));
+ assertEquals(originalExchange.getLocalAddress(), exchange.getLocalAddress());
+ assertEquals(originalExchange.getRemoteAddress(), exchange.getRemoteAddress());
+ assertEquals(originalExchange.getProtocol(), exchange.getProtocol());
+ assertEquals(originalExchange.getPrincipal(), exchange.getPrincipal());
+ assertEquals(originalExchange.getHttpContext(), exchange.getHttpContext());
+ assertEquals(originalExchange.getRequestMethod(), exchange.getRequestMethod());
+ assertEquals(originalExchange.getRequestURI(), exchange.getRequestURI());
+ assertEquals(originalExchange.getRequestBody(), exchange.getRequestBody());
+ assertEquals(originalExchange.getResponseHeaders(), exchange.getResponseHeaders());
+ assertEquals(originalExchange.getResponseCode(), exchange.getResponseCode());
+ assertEquals(originalExchange.getResponseBody(), exchange.getResponseBody());
+ assertEquals(originalExchange.getAttribute("foo"), exchange.getAttribute("foo"));
assertFalse(exchange.getRequestHeaders().equals(originalExchange.getRequestHeaders()));
exchange.setAttribute("foo", "barbar");
- assertEquals(exchange.getAttribute("foo"), originalExchange.getAttribute("foo"));
+ assertEquals(originalExchange.getAttribute("foo"), exchange.getAttribute("foo"));
try (InputStream is = exchange.getRequestBody();
OutputStream os = exchange.getResponseBody()) {
diff --git a/test/jdk/com/sun/net/httpserver/HeadersTest.java b/test/jdk/com/sun/net/httpserver/HeadersTest.java
index c37aba0424f..2c9ff93e179 100644
--- a/test/jdk/com/sun/net/httpserver/HeadersTest.java
+++ b/test/jdk/com/sun/net/httpserver/HeadersTest.java
@@ -29,7 +29,7 @@
* jdk.httpserver/sun.net.httpserver:+open
* @library /test/lib
* @build jdk.test.lib.net.URIBuilder
- * @run testng/othervm HeadersTest
+ * @run junit/othervm HeadersTest
*/
import java.io.IOException;
@@ -57,18 +57,20 @@ 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.annotations.DataProvider;
-import org.testng.annotations.Test;
import sun.net.httpserver.UnmodifiableHeaders;
import static java.net.http.HttpClient.Builder.NO_PROXY;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertNotSame;
-import static org.testng.Assert.assertSame;
-import static org.testng.Assert.assertThrows;
-import static org.testng.Assert.assertTrue;
+
+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.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
public class HeadersTest {
@@ -77,13 +79,13 @@ public class HeadersTest {
static final Class NPE = NullPointerException.class;
@Test
- public static void testDefaultConstructor() {
+ public void testDefaultConstructor() {
var headers = new Headers();
assertTrue(headers.isEmpty());
}
@Test
- public static void testNull() {
+ public void testNull() {
final Headers h = new Headers();
h.put("Foo", List.of("Bar"));
@@ -157,8 +159,7 @@ public class HeadersTest {
assertThrows(NPE, () -> h.set("Foo", null));
}
- @DataProvider
- public Object[][] responseHeaders() {
+ public static Object[][] responseHeaders() {
final var listWithNull = new LinkedList();
listWithNull.add(null);
return new Object[][] {
@@ -172,7 +173,8 @@ public class HeadersTest {
* Confirms HttpExchange::sendResponseHeaders throws NPE if response headers
* contain a null key or value.
*/
- @Test(dataProvider = "responseHeaders")
+ @ParameterizedTest
+ @MethodSource("responseHeaders")
public void testNullResponseHeaders(String headerKey, List headerVal)
throws Exception {
var handler = new Handler(headerKey, headerVal);
@@ -183,7 +185,7 @@ public class HeadersTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
assertThrows(IOE, () -> client.send(request, HttpResponse.BodyHandlers.ofString()));
- assertEquals(throwable.get().getClass(), NPE);
+ assertEquals(NPE, throwable.get().getClass());
assertTrue(Arrays.stream(throwable.get().getStackTrace())
.anyMatch(e -> e.getClassName().equals("sun.net.httpserver.HttpExchangeImpl")
|| e.getMethodName().equals("sendResponseHeaders")));
@@ -240,7 +242,6 @@ public class HeadersTest {
}
}
- @DataProvider
public static Object[][] headerPairs() {
final var h1 = new Headers();
final var h2 = new Headers();
@@ -259,16 +260,16 @@ public class HeadersTest {
.toArray(Object[][]::new);
}
- @Test(dataProvider = "headerPairs")
- public static void testEqualsAndHashCode(Headers h1, Headers h2) {
- // avoid testng's asserts(Map, Map) as they don't call Headers::equals
+ @ParameterizedTest
+ @MethodSource("headerPairs")
+ public void testEqualsAndHashCode(Headers h1, Headers h2) {
assertTrue(h1.equals(h2), "Headers differ");
- assertEquals(h1.hashCode(), h2.hashCode(), "hashCode differ for "
+ assertEquals(h2.hashCode(), h1.hashCode(), "hashCode differ for "
+ List.of(h1, h2));
}
@Test
- public static void testEqualsMap() {
+ public void testEqualsMap() {
final var h = new Headers();
final var m = new HashMap>();
assertTrue(h.equals(m));
@@ -277,14 +278,14 @@ public class HeadersTest {
}
@Test
- public static void testToString() {
+ public void testToString() {
final var h = new Headers();
h.put("Accept-Encoding", List.of("gzip, deflate"));
assertTrue(h.toString().equals("Headers { {Accept-encoding=[gzip, deflate]} }"));
}
@Test
- public static void testPutAll() {
+ public void testPutAll() {
final var h0 = new Headers();
final var map = new HashMap>();
map.put("a", null);
@@ -311,7 +312,7 @@ public class HeadersTest {
}
@Test
- public static void testReplaceAll() {
+ public void testReplaceAll() {
final var h1 = new Headers();
h1.put("a", List.of("1"));
h1.put("b", List.of("2"));
@@ -331,7 +332,7 @@ public class HeadersTest {
}
@Test
- public static void test1ArgConstructorNull() {
+ public void test1ArgConstructorNull() {
assertThrows(NPE, () -> new Headers(null));
{
final var m = new HashMap>();
@@ -353,35 +354,35 @@ public class HeadersTest {
}
@Test
- public static void test1ArgConstructor() {
+ public void test1ArgConstructor() {
{
var h = new Headers(new Headers());
assertTrue(h.isEmpty());
}
{
var h = new Headers(Map.of("Foo", List.of("Bar")));
- assertEquals(h.get("Foo"), List.of("Bar"));
- assertEquals(h.size(), 1);
+ assertEquals(List.of("Bar"), h.get("Foo"));
+ assertEquals(1, h.size());
}
{
var h1 = new Headers(new UnmodifiableHeaders(new Headers()));
assertTrue(h1.isEmpty());
h1.put("Foo", List.of("Bar")); // modifiable
- assertEquals(h1.get("Foo"), List.of("Bar"));
- assertEquals(h1.size(), 1);
+ assertEquals(List.of("Bar"), h1.get("Foo"));
+ assertEquals(1, h1.size());
var h2 = new Headers(h1);
- assertEquals(h2.get("Foo"), List.of("Bar"));
- assertEquals(h2.size(), 1);
+ assertEquals(List.of("Bar"), h2.get("Foo"));
+ assertEquals(1, h2.size());
- assertEquals(h1, h2);
+ assertEquals(h2, h1);
h1.set("Foo", "Barbar");
- assertNotEquals(h1, h2);
+ assertNotEquals(h2, h1);
}
}
@Test
- public static void testMutableHeaders() {
+ public void testMutableHeaders() {
{
var h = new Headers();
h.add("Foo", "Bar");
@@ -400,7 +401,7 @@ public class HeadersTest {
}
@Test
- public static void testOfNull() {
+ public void testOfNull() {
assertThrows(NPE, () -> Headers.of((String[])null));
assertThrows(NPE, () -> Headers.of(null, "Bar"));
assertThrows(NPE, () -> Headers.of("Foo", null));
@@ -426,41 +427,40 @@ public class HeadersTest {
}
@Test
- public static void testOf() {
+ public void testOf() {
final var h = Headers.of("a", "1", "b", "2");
- assertEquals(h.size(), 2);
+ assertEquals(2, h.size());
List.of("a", "b").forEach(n -> assertTrue(h.containsKey(n)));
List.of("1", "2").forEach(v -> assertTrue(h.containsValue(List.of(v))));
}
@Test
- public static void testOfEmpty() {
+ public void testOfEmpty() {
for (var h : List.of(Headers.of(), Headers.of(new String[] { }))) {
- assertEquals(h.size(), 0);
+ assertEquals(0, h.size());
assertTrue(h.isEmpty());
}
}
@Test
- public static void testOfNumberOfElements() {
+ public void testOfNumberOfElements() {
assertThrows(IAE, () -> Headers.of("a"));
assertThrows(IAE, () -> Headers.of("a", "1", "b"));
}
@Test
- public static void testOfMultipleValues() {
+ public void testOfMultipleValues() {
final var h = Headers.of("a", "1", "b", "1", "b", "2", "b", "3");
- assertEquals(h.size(), 2);
+ assertEquals(2, h.size());
List.of("a", "b").forEach(n -> assertTrue(h.containsKey(n)));
List.of(List.of("1"), List.of("1", "2", "3")).forEach(v -> assertTrue(h.containsValue(v)));
}
@Test
- public static void testNormalizeOnNull() {
+ public void testNormalizeOnNull() {
assertThrows(NullPointerException.class, () -> normalize(null));
}
- @DataProvider
public static Object[][] illegalKeys() {
var illegalChars = List.of('\r', '\n');
var illegalStrings = Stream
@@ -478,12 +478,12 @@ public class HeadersTest {
.toArray(Object[][]::new);
}
- @Test(dataProvider = "illegalKeys")
- public static void testNormalizeOnIllegalKeys(String illegalKey) {
+ @ParameterizedTest
+ @MethodSource("illegalKeys")
+ public void testNormalizeOnIllegalKeys(String illegalKey) {
assertThrows(IllegalArgumentException.class, () -> normalize(illegalKey));
}
- @DataProvider
public static Object[][] normalizedKeys() {
return new Object[][]{
// Empty string
@@ -501,13 +501,13 @@ public class HeadersTest {
};
}
- @Test(dataProvider = "normalizedKeys")
- public static void testNormalizeOnNormalizedKeys(String normalizedKey) {
+ @ParameterizedTest
+ @MethodSource("normalizedKeys")
+ public void testNormalizeOnNormalizedKeys(String normalizedKey) {
// Verify that the fast-path is taken
assertSame(normalize(normalizedKey), normalizedKey);
}
- @DataProvider
public static Object[][] notNormalizedKeys() {
return new Object[][]{
{"a"},
@@ -517,14 +517,15 @@ public class HeadersTest {
};
}
- @Test(dataProvider = "notNormalizedKeys")
- public static void testNormalizeOnNotNormalizedKeys(String notNormalizedKey) {
+ @ParameterizedTest
+ @MethodSource("notNormalizedKeys")
+ public void testNormalizeOnNotNormalizedKeys(String notNormalizedKey) {
var normalizedKey = normalize(notNormalizedKey);
// Verify that the fast-path is *not* taken
assertNotSame(normalizedKey, notNormalizedKey);
// Verify the result
var expectedNormalizedKey = normalizedKey.substring(0, 1).toUpperCase() + normalizedKey.substring(1);
- assertEquals(normalizedKey, expectedNormalizedKey);
+ assertEquals(expectedNormalizedKey, normalizedKey);
}
private static String normalize(String key) {
diff --git a/test/jdk/com/sun/net/httpserver/HttpContextTest.java b/test/jdk/com/sun/net/httpserver/HttpContextTest.java
index aa50f1d9757..82098e4e993 100644
--- a/test/jdk/com/sun/net/httpserver/HttpContextTest.java
+++ b/test/jdk/com/sun/net/httpserver/HttpContextTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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,7 @@
* @bug 8269692
* @summary HttpContext::createContext should throw IllegalArgumentException
* if context already exists
- * @run testng/othervm HttpContextTest
+ * @run junit/othervm HttpContextTest
*/
import java.io.IOException;
@@ -34,22 +34,23 @@ import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
-import org.testng.annotations.Test;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertThrows;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.junit.jupiter.api.Test;
public class HttpContextTest {
static final Class IAE = IllegalArgumentException.class;
@Test
- public static void test() throws IOException {
+ public void test() throws IOException {
final var server = HttpServer.create(null, 0);
final var path = "/foo/";
assertThrows(IAE, () -> server.removeContext(path));
HttpContext context = server.createContext(path);
- assertEquals(context.getPath(), path);
+ assertEquals(path, context.getPath());
assertThrows(IAE, () -> server.createContext(path));
assertThrows(IAE, () -> server.createContext(path, new Handler()));
@@ -60,7 +61,7 @@ public class HttpContextTest {
assertThrows(IAE, () -> server.removeContext(path));
context = server.createContext(path, new Handler());
- assertEquals(context.getPath(), path);
+ assertEquals(path, context.getPath());
assertThrows(IAE, () -> server.createContext(path));
assertThrows(IAE, () -> server.createContext(path, new Handler()));
server.removeContext(path);
@@ -72,7 +73,7 @@ public class HttpContextTest {
* shares the prefix of an existing context.
*/
@Test
- public static void testSubcontext() throws IOException {
+ public void testSubcontext() throws IOException {
final var server = HttpServer.create(null, 0);
server.createContext("/foo/bar/");
server.createContext("/foo/");
diff --git a/test/jdk/com/sun/net/httpserver/HttpPrincipalTest.java b/test/jdk/com/sun/net/httpserver/HttpPrincipalTest.java
index 30cf0c4490c..513a79feb60 100644
--- a/test/jdk/com/sun/net/httpserver/HttpPrincipalTest.java
+++ b/test/jdk/com/sun/net/httpserver/HttpPrincipalTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2025, 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,13 +25,13 @@
* @test
* @bug 8251496
* @summary Tests for methods in HttpPrincipal
- * @run testng/othervm HttpPrincipalTest
+ * @run junit/othervm HttpPrincipalTest
*/
import com.sun.net.httpserver.HttpPrincipal;
-import org.testng.annotations.Test;
-import static org.testng.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.Test;
public class HttpPrincipalTest {
@@ -39,10 +39,10 @@ public class HttpPrincipalTest {
public void testGetters() {
var principal = new HttpPrincipal("test", "123");
- assertEquals(principal.getUsername(), "test");
- assertEquals(principal.getRealm(), "123");
- assertEquals(principal.getName(), "123:test");
- assertEquals(principal.toString(), principal.getName());
- assertEquals(("test"+"123").hashCode(), principal.hashCode());
+ assertEquals("test", principal.getUsername());
+ assertEquals("123", principal.getRealm());
+ assertEquals("123:test", principal.getName());
+ assertEquals(principal.getName(), principal.toString());
+ assertEquals(principal.hashCode(), ("test"+"123").hashCode());
}
}
diff --git a/test/jdk/com/sun/net/httpserver/HttpServerProviderTest.java b/test/jdk/com/sun/net/httpserver/HttpServerProviderTest.java
index 2912cdd40e1..db528c19488 100644
--- a/test/jdk/com/sun/net/httpserver/HttpServerProviderTest.java
+++ b/test/jdk/com/sun/net/httpserver/HttpServerProviderTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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,19 +25,19 @@
* @test
* @bug 8270286
* @summary Test for HttpServerProvider::loadProviderFromProperty
- * @run testng/othervm
+ * @run junit/othervm
* -Dcom.sun.net.httpserver.HttpServerProvider=HttpServerProviderTest$ProviderP
* HttpServerProviderTest
- * @run testng/othervm
+ * @run junit/othervm
* -Dcom.sun.net.httpserver.HttpServerProvider=HttpServerProviderTest$ProviderPNPC
* HttpServerProviderTest
- * @run testng/othervm
+ * @run junit/othervm
* -Dcom.sun.net.httpserver.HttpServerProvider=HttpServerProviderTest$ProviderNP
* HttpServerProviderTest
- * @run testng/othervm
+ * @run junit/othervm
* -Dcom.sun.net.httpserver.HttpServerProvider=HttpServerProviderTest$ProviderT
* HttpServerProviderTest
- * @run testng/othervm
+ * @run junit/othervm
* -Dcom.sun.net.httpserver.HttpServerProvider=DoesNotExist
* HttpServerProviderTest
*/
@@ -48,10 +48,11 @@ import java.util.ServiceConfigurationError;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsServer;
import com.sun.net.httpserver.spi.HttpServerProvider;
-import org.testng.annotations.Test;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.expectThrows;
+
+import org.junit.jupiter.api.Assertions;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import org.junit.jupiter.api.Test;
public class HttpServerProviderTest {
public final static String PROPERTY_KEY = "com.sun.net.httpserver.HttpServerProvider";
@@ -70,7 +71,7 @@ public class HttpServerProviderTest {
private void testPublic() throws Exception {
var n = ProviderP.class.getName();
- assertEquals(System.getProperty(PROPERTY_KEY), n);
+ assertEquals(n, System.getProperty(PROPERTY_KEY));
var p = HttpServerProvider.provider();
assertNull(p.createHttpServer(null, 0));
@@ -79,39 +80,39 @@ public class HttpServerProviderTest {
private void testPublicNonPublicConstructor() {
var n = ProviderPNPC.class.getName();
- assertEquals(System.getProperty(PROPERTY_KEY), n);
+ assertEquals(n, System.getProperty(PROPERTY_KEY));
- var e = expectThrows(ServiceConfigurationError.class, HttpServerProvider::provider);
- assertEquals(e.getClass(), ServiceConfigurationError.class);
- assertEquals(e.getCause().getClass(), IllegalAccessException.class);
+ var e = Assertions.assertThrows(ServiceConfigurationError.class, HttpServerProvider::provider);
+ assertEquals(ServiceConfigurationError.class, e.getClass());
+ assertEquals(IllegalAccessException.class, e.getCause().getClass());
}
private void testNonPublic() {
var n = ProviderNP.class.getName();
- assertEquals(System.getProperty(PROPERTY_KEY), n);
+ assertEquals(n, System.getProperty(PROPERTY_KEY));
- var e = expectThrows(ServiceConfigurationError.class, HttpServerProvider::provider);
- assertEquals(e.getClass(), ServiceConfigurationError.class);
- assertEquals(e.getCause().getClass(), IllegalAccessException.class);
+ var e = Assertions.assertThrows(ServiceConfigurationError.class, HttpServerProvider::provider);
+ assertEquals(ServiceConfigurationError.class, e.getClass());
+ assertEquals(IllegalAccessException.class, e.getCause().getClass());
}
private void testThrowingConstructor() {
var cn = ProviderT.class.getName();
- assertEquals(System.getProperty(PROPERTY_KEY), cn);
+ assertEquals(cn, System.getProperty(PROPERTY_KEY));
- var e = expectThrows(ServiceConfigurationError.class, HttpServerProvider::provider);
- assertEquals(e.getClass(), ServiceConfigurationError.class);
- assertEquals(e.getCause().getClass(), InvocationTargetException.class);
- assertEquals(e.getCause().getCause().getMessage(), "throwing constructor");
+ var e = Assertions.assertThrows(ServiceConfigurationError.class, HttpServerProvider::provider);
+ assertEquals(ServiceConfigurationError.class, e.getClass());
+ assertEquals(InvocationTargetException.class, e.getCause().getClass());
+ assertEquals("throwing constructor", e.getCause().getCause().getMessage());
}
private void testBadData() {
var cn = "DoesNotExist";
- assertEquals(System.getProperty(PROPERTY_KEY), cn);
+ assertEquals(cn, System.getProperty(PROPERTY_KEY));
- var e = expectThrows(ServiceConfigurationError.class, HttpServerProvider::provider);
- assertEquals(e.getClass(), ServiceConfigurationError.class);
- assertEquals(e.getCause().getClass(), ClassNotFoundException.class);
+ var e = Assertions.assertThrows(ServiceConfigurationError.class, HttpServerProvider::provider);
+ assertEquals(ServiceConfigurationError.class, e.getClass());
+ assertEquals(ClassNotFoundException.class, e.getCause().getClass());
}
/**
diff --git a/test/jdk/com/sun/net/httpserver/HttpsParametersClientAuthTest.java b/test/jdk/com/sun/net/httpserver/HttpsParametersClientAuthTest.java
index 37ec2701e07..5514b5da689 100644
--- a/test/jdk/com/sun/net/httpserver/HttpsParametersClientAuthTest.java
+++ b/test/jdk/com/sun/net/httpserver/HttpsParametersClientAuthTest.java
@@ -84,6 +84,7 @@ public class HttpsParametersClientAuthTest {
return t;
};
+ private static final SSLContext serverSSLCtx = SimpleSSLContext.findSSLContext();
/**
* verifies default values of {@link HttpsParameters#setNeedClientAuth(boolean)}
* and {@link HttpsParameters#setWantClientAuth(boolean)} methods
@@ -168,8 +169,6 @@ public class HttpsParametersClientAuthTest {
public void testServerNeedClientAuth(final boolean presentClientCerts) throws Exception {
// SSLContext which contains both the key and the trust material and will be used
// by the server
- final SSLContext serverSSLCtx = new SimpleSSLContext().get();
- assertNotNull(serverSSLCtx, "could not create SSLContext");
final HttpsConfigurator configurator = new HttpsConfigurator(serverSSLCtx) {
@Override
public void configure(final HttpsParameters params) {
@@ -276,8 +275,6 @@ public class HttpsParametersClientAuthTest {
public void testServerWantClientAuth(final boolean presentClientCerts) throws Exception {
// SSLContext which contains both the key and the trust material and will be used
// by the server
- final SSLContext serverSSLCtx = new SimpleSSLContext().get();
- assertNotNull(serverSSLCtx, "could not create SSLContext");
final HttpsConfigurator configurator = new HttpsConfigurator(serverSSLCtx) {
@Override
public void configure(final HttpsParameters params) {
diff --git a/test/jdk/com/sun/net/httpserver/InputNotRead.java b/test/jdk/com/sun/net/httpserver/InputNotRead.java
index 3d5bfad83c3..ff877dcaa7a 100644
--- a/test/jdk/com/sun/net/httpserver/InputNotRead.java
+++ b/test/jdk/com/sun/net/httpserver/InputNotRead.java
@@ -28,8 +28,8 @@
* read the request body and sends back a reply with no content, or when
* the client closes its outputstream while the server tries to drains
* its content.
- * @run testng/othervm InputNotRead
- * @run testng/othervm -Djava.net.preferIPv6Addresses=true InputNotRead
+ * @run junit/othervm InputNotRead
+ * @run junit/othervm -Djava.net.preferIPv6Addresses=true InputNotRead
*/
import java.io.BufferedReader;
@@ -51,11 +51,12 @@ import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
-import org.testng.annotations.Test;
import static java.nio.charset.StandardCharsets.*;
import static com.sun.net.httpserver.HttpExchange.RSPBODY_EMPTY;
+import org.junit.jupiter.api.Test;
+
public class InputNotRead {
private static final int msgCode = 200;
diff --git a/test/jdk/com/sun/net/httpserver/SANTest.java b/test/jdk/com/sun/net/httpserver/SANTest.java
index d35a590931d..99612376589 100644
--- a/test/jdk/com/sun/net/httpserver/SANTest.java
+++ b/test/jdk/com/sun/net/httpserver/SANTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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
@@ -73,7 +73,7 @@ import jdk.httpclient.test.lib.http2.Http2TestServer;
*/
public class SANTest implements HttpServerAdapters {
- static SSLContext ctx;
+ private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
static HttpServer getHttpsServer(InetSocketAddress addr, Executor exec, SSLContext ctx) throws Exception {
HttpsServer server = HttpsServer.create(addr, 0);
@@ -122,7 +122,6 @@ public class SANTest implements HttpServerAdapters {
ExecutorService executor=null;
try {
System.out.print ("SANTest: ");
- ctx = new SimpleSSLContext().get();
executor = Executors.newCachedThreadPool();
InetAddress l1 = InetAddress.getByName("::1");
diff --git a/test/jdk/com/sun/net/httpserver/SelCacheTest.java b/test/jdk/com/sun/net/httpserver/SelCacheTest.java
index 1399b65532b..8410aa0578a 100644
--- a/test/jdk/com/sun/net/httpserver/SelCacheTest.java
+++ b/test/jdk/com/sun/net/httpserver/SelCacheTest.java
@@ -59,7 +59,7 @@ public class SelCacheTest extends Test {
private static final String TEMP_FILE_PREFIX =
HttpServer.class.getPackageName() + '-' + SelCacheTest.class.getSimpleName() + '-';
- static SSLContext ctx;
+ private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
public static void main(String[] args) throws Exception {
HttpServer s1 = null;
@@ -84,7 +84,6 @@ public class SelCacheTest extends Test {
executor = Executors.newCachedThreadPool();
s1.setExecutor(executor);
s2.setExecutor(executor);
- ctx = new SimpleSSLContext().get();
s2.setHttpsConfigurator(new HttpsConfigurator(ctx));
s1.start();
s2.start();
diff --git a/test/jdk/com/sun/net/httpserver/Test1.java b/test/jdk/com/sun/net/httpserver/Test1.java
index 32bab4d9178..858c0a20f55 100644
--- a/test/jdk/com/sun/net/httpserver/Test1.java
+++ b/test/jdk/com/sun/net/httpserver/Test1.java
@@ -69,7 +69,7 @@ public class Test1 extends Test {
private static final String TEMP_FILE_PREFIX =
HttpServer.class.getPackageName() + '-' + Test1.class.getSimpleName() + '-';
- static SSLContext ctx;
+ private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
public static void main (String[] args) throws Exception {
HttpServer s1 = null;
@@ -94,7 +94,6 @@ public class Test1 extends Test {
executor = Executors.newCachedThreadPool();
s1.setExecutor (executor);
s2.setExecutor (executor);
- ctx = new SimpleSSLContext().get();
s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
s1.start();
s2.start();
diff --git a/test/jdk/com/sun/net/httpserver/Test12.java b/test/jdk/com/sun/net/httpserver/Test12.java
index 2a0ee1fc0a4..ac11e92d44e 100644
--- a/test/jdk/com/sun/net/httpserver/Test12.java
+++ b/test/jdk/com/sun/net/httpserver/Test12.java
@@ -56,7 +56,7 @@ public class Test12 extends Test {
private static final String TEMP_FILE_PREFIX =
HttpServer.class.getPackageName() + '-' + Test12.class.getSimpleName() + '-';
- static SSLContext ctx;
+ private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
public static void main (String[] args) throws Exception {
HttpServer s1 = null;
@@ -77,7 +77,6 @@ public class Test12 extends Test {
HttpContext c2 = s2.createContext ("/", h);
s1.setExecutor (executor);
s2.setExecutor (executor);
- ctx = new SimpleSSLContext().get();
s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
s1.start();
s2.start();
diff --git a/test/jdk/com/sun/net/httpserver/Test13.java b/test/jdk/com/sun/net/httpserver/Test13.java
index ead3ff95acd..0401dbce5a8 100644
--- a/test/jdk/com/sun/net/httpserver/Test13.java
+++ b/test/jdk/com/sun/net/httpserver/Test13.java
@@ -59,7 +59,7 @@ public class Test13 extends Test {
private static final String TEMP_FILE_PREFIX =
HttpServer.class.getPackageName() + '-' + Test13.class.getSimpleName() + '-';
- static SSLContext ctx;
+ private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
final static int NUM = 32; // was 32
@@ -87,7 +87,6 @@ public class Test13 extends Test {
executor = Executors.newCachedThreadPool();
s1.setExecutor (executor);
s2.setExecutor (executor);
- ctx = new SimpleSSLContext().get();
s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
s1.start();
s2.start();
diff --git a/test/jdk/com/sun/net/httpserver/Test6a.java b/test/jdk/com/sun/net/httpserver/Test6a.java
index 676edeb7b60..56614078cfe 100644
--- a/test/jdk/com/sun/net/httpserver/Test6a.java
+++ b/test/jdk/com/sun/net/httpserver/Test6a.java
@@ -21,7 +21,7 @@
* questions.
*/
-/**
+/*
* @test
* @bug 6270015
* @library /test/lib
@@ -55,7 +55,7 @@ public class Test6a extends Test {
HttpsServer server = HttpsServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
ExecutorService executor = Executors.newCachedThreadPool();
- SSLContext ssl = new SimpleSSLContext().get();
+ SSLContext ssl = SimpleSSLContext.findSSLContext();
server.setExecutor (executor);
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
server.start ();
diff --git a/test/jdk/com/sun/net/httpserver/Test7a.java b/test/jdk/com/sun/net/httpserver/Test7a.java
index 90c0615972e..8bda4ae8348 100644
--- a/test/jdk/com/sun/net/httpserver/Test7a.java
+++ b/test/jdk/com/sun/net/httpserver/Test7a.java
@@ -59,7 +59,7 @@ public class Test7a extends Test {
HttpsServer server = HttpsServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
ExecutorService executor = Executors.newCachedThreadPool();
- SSLContext ssl = new SimpleSSLContext().get();
+ SSLContext ssl = SimpleSSLContext.findSSLContext();
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
server.setExecutor (executor);
server.start ();
diff --git a/test/jdk/com/sun/net/httpserver/Test8a.java b/test/jdk/com/sun/net/httpserver/Test8a.java
index 6c642f7c22a..67f9c93172a 100644
--- a/test/jdk/com/sun/net/httpserver/Test8a.java
+++ b/test/jdk/com/sun/net/httpserver/Test8a.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2025, 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
@@ -61,7 +61,7 @@ public class Test8a extends Test {
server = HttpsServer.create (addr, 0);
HttpContext ctx = server.createContext ("/test", handler);
executor = Executors.newCachedThreadPool();
- SSLContext ssl = new SimpleSSLContext().get();
+ SSLContext ssl = SimpleSSLContext.findSSLContext();
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
server.setExecutor (executor);
server.start ();
diff --git a/test/jdk/com/sun/net/httpserver/Test9.java b/test/jdk/com/sun/net/httpserver/Test9.java
index 6051de96596..8281089c232 100644
--- a/test/jdk/com/sun/net/httpserver/Test9.java
+++ b/test/jdk/com/sun/net/httpserver/Test9.java
@@ -58,7 +58,7 @@ public class Test9 extends Test {
private static final String TEMP_FILE_PREFIX =
HttpServer.class.getPackageName() + '-' + Test9.class.getSimpleName() + '-';
- static SSLContext ctx;
+ private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
static volatile boolean error = false;
public static void main (String[] args) throws Exception {
@@ -83,7 +83,6 @@ public class Test9 extends Test {
executor = Executors.newCachedThreadPool();
s1.setExecutor (executor);
s2.setExecutor (executor);
- ctx = new SimpleSSLContext().get();
s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
s1.start();
s2.start();
diff --git a/test/jdk/com/sun/net/httpserver/Test9a.java b/test/jdk/com/sun/net/httpserver/Test9a.java
index 85acfd26518..56fbf9953a3 100644
--- a/test/jdk/com/sun/net/httpserver/Test9a.java
+++ b/test/jdk/com/sun/net/httpserver/Test9a.java
@@ -56,8 +56,8 @@ public class Test9a extends Test {
private static final String TEMP_FILE_PREFIX =
HttpServer.class.getPackageName() + '-' + Test9a.class.getSimpleName() + '-';
- static SSLContext serverCtx;
- static volatile SSLContext clientCtx = null;
+ private static final SSLContext serverCtx = SimpleSSLContext.findSSLContext();
+ private static final SSLContext clientCtx = SimpleSSLContext.findSSLContext();
static volatile boolean error = false;
public static void main (String[] args) throws Exception {
@@ -76,8 +76,6 @@ public class Test9a extends Test {
HttpContext c1 = server.createContext ("/", h);
executor = Executors.newCachedThreadPool();
server.setExecutor (executor);
- serverCtx = new SimpleSSLContext().get();
- clientCtx = new SimpleSSLContext().get();
server.setHttpsConfigurator(new HttpsConfigurator (serverCtx));
server.start();
diff --git a/test/jdk/com/sun/net/httpserver/UnmodifiableHeadersTest.java b/test/jdk/com/sun/net/httpserver/UnmodifiableHeadersTest.java
index 84fd5aceaa7..196cf36f010 100644
--- a/test/jdk/com/sun/net/httpserver/UnmodifiableHeadersTest.java
+++ b/test/jdk/com/sun/net/httpserver/UnmodifiableHeadersTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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,7 @@
* @bug 8251496 8333590
* @summary Test that UnmodifiableHeaders is in fact immutable
* @modules jdk.httpserver/sun.net.httpserver:+open
- * @run testng/othervm UnmodifiableHeadersTest
+ * @run junit/othervm UnmodifiableHeadersTest
*/
import java.io.InputStream;
@@ -36,73 +36,75 @@ import java.net.URI;
import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Stream;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpPrincipal;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
import sun.net.httpserver.UnmodifiableHeaders;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertThrows;
-import static org.testng.Assert.assertTrue;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
public class UnmodifiableHeadersTest {
@Test
- public static void testEquality() {
+ public void testEquality() {
var headers = new Headers();
var unmodifiableHeaders1 = new UnmodifiableHeaders(headers);
- assertEquals(unmodifiableHeaders1, headers);
- assertEquals(unmodifiableHeaders1.hashCode(), headers.hashCode());
- assertEquals(unmodifiableHeaders1.get("Foo"), headers.get("Foo"));
+ assertEquals(headers, unmodifiableHeaders1);
+ assertEquals(headers.hashCode(), unmodifiableHeaders1.hashCode());
+ assertEquals(headers.get("Foo"), unmodifiableHeaders1.get("Foo"));
headers.add("Foo", "Bar");
var unmodifiableHeaders2 = new UnmodifiableHeaders(headers);
- assertEquals(unmodifiableHeaders2, headers);
- assertEquals(unmodifiableHeaders2.hashCode(), headers.hashCode());
- assertEquals(unmodifiableHeaders2.get("Foo"), headers.get("Foo"));
+ assertEquals(headers, unmodifiableHeaders2);
+ assertEquals(headers.hashCode(), unmodifiableHeaders2.hashCode());
+ assertEquals(headers.get("Foo"), unmodifiableHeaders2.get("Foo"));
}
- @DataProvider
- public Object[][] headers() {
+ public static Stream headers() {
var headers = new Headers();
headers.add("Foo", "Bar");
var exchange = new TestHttpExchange(headers);
- return new Object[][] {
- { exchange.getRequestHeaders() },
- { Headers.of("Foo", "Bar") },
- { Headers.of(Map.of("Foo", List.of("Bar"))) },
- };
+ return Stream.of(exchange.getRequestHeaders(),
+ Headers.of("Foo", "Bar"),
+ Headers.of(Map.of("Foo", List.of("Bar"))));
}
- @Test(dataProvider = "headers")
- public static void testUnmodifiableHeaders(Headers headers) {
+ @ParameterizedTest
+ @MethodSource("headers")
+ public void testUnmodifiableHeaders(Headers headers) {
assertUnsupportedOperation(headers);
assertUnmodifiableCollection(headers);
assertUnmodifiableList(headers);
}
- @DataProvider
- public Object[][] toStringHeaders() {
+ public static Stream toStringHeaders() {
final Headers headers = new Headers();
headers.add("hello", "World");
- return new Object[][] {
- { headers },
- { Headers.of("abc", "XYZ") },
- { Headers.of(Map.of("foo", List.of("Bar"))) },
- { Headers.of(Map.of("Hello", List.of())) },
- { Headers.of(Map.of("one", List.of("two", "THREE"))) },
- };
+ return Stream.of(
+ headers,
+ Headers.of("abc", "XYZ"),
+ Headers.of(Map.of("foo", List.of("Bar"))),
+ Headers.of(Map.of("Hello", List.of())),
+ Headers.of(Map.of("one", List.of("two", "THREE")))
+ );
}
/*
* Verify that the String returned by Headers.toString() contains the expected
* key/value(s)
*/
- @Test(dataProvider = "toStringHeaders")
+ @ParameterizedTest
+ @MethodSource("toStringHeaders")
public void testToString(final Headers headers) {
final Headers copy = Headers.of(headers);
assertNotNull(copy, "Headers.of() returned null");
diff --git a/test/jdk/com/sun/net/httpserver/bugs/BasicAuthenticatorExceptionCheck.java b/test/jdk/com/sun/net/httpserver/bugs/BasicAuthenticatorExceptionCheck.java
index a07386be746..b4a4dfda041 100644
--- a/test/jdk/com/sun/net/httpserver/bugs/BasicAuthenticatorExceptionCheck.java
+++ b/test/jdk/com/sun/net/httpserver/bugs/BasicAuthenticatorExceptionCheck.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, 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,18 +27,20 @@
* @library /test/lib
* @summary Ensure that correct exceptions are being thrown in
* BasicAuthenticator constructor
- * @run testng BasicAuthenticatorExceptionCheck
+ * @run junit BasicAuthenticatorExceptionCheck
*/
import java.nio.charset.Charset;
import com.sun.net.httpserver.BasicAuthenticator;
-import org.testng.annotations.Test;
-import static org.testng.Assert.expectThrows;
-import static org.testng.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import static java.nio.charset.StandardCharsets.UTF_8;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
public class BasicAuthenticatorExceptionCheck {
static final Class NPE = NullPointerException.class;
@@ -62,42 +64,42 @@ public class BasicAuthenticatorExceptionCheck {
@Test
public void testAuthenticationException() {
- Throwable ex = expectThrows(NPE, () ->
+ Throwable ex = Assertions.assertThrows(NPE, () ->
createBasicAuthenticator("/test", null));
System.out.println("Valid realm and Null charset provided - " +
"NullPointerException thrown as expected: " + ex);
- ex = expectThrows(NPE, () ->
+ ex = Assertions.assertThrows(NPE, () ->
createBasicAuthenticator(null, UTF_8));
System.out.println("Null realm and valid charset provided - " +
"NullPointerException thrown as expected: " + ex);
- ex = expectThrows(IAE, () ->
+ ex = Assertions.assertThrows(IAE, () ->
createBasicAuthenticator("", UTF_8));
- assertEquals(ex.getMessage(), "realm must not be empty");
+ assertEquals("realm must not be empty", ex.getMessage());
System.out.println("Empty string for realm and valid charset provided - " +
"IllegalArgumentException thrown as expected: " + ex);
- ex = expectThrows(NPE, () ->
+ ex = Assertions.assertThrows(NPE, () ->
createBasicAuthenticator(null));
System.out.println("Null realm provided - " +
"NullPointerException thrown as expected: " + ex);
- ex = expectThrows(IAE, () ->
+ ex = Assertions.assertThrows(IAE, () ->
createBasicAuthenticator(""));
- assertEquals(ex.getMessage(), "realm must not be empty");
+ assertEquals("realm must not be empty", ex.getMessage());
System.out.println("Empty string for realm provided - " +
"IllegalArgumentException thrown as expected: " + ex);
- ex = expectThrows(IAE, () ->
+ ex = Assertions.assertThrows(IAE, () ->
createBasicAuthenticator("\"/test\""));
- assertEquals(ex.getMessage(), "realm invalid: \"/test\"");
+ assertEquals("realm invalid: \"/test\"", ex.getMessage());
System.out.println("Invalid string for realm provided - " +
"IllegalArgumentException thrown as expected: " + ex);
- ex = expectThrows(IAE, () ->
+ ex = Assertions.assertThrows(IAE, () ->
createBasicAuthenticator("\""));
- assertEquals(ex.getMessage(), "realm invalid: \"");
+ assertEquals("realm invalid: \"", ex.getMessage());
System.out.println("Invalid string for realm provided - " +
"IllegalArgumentException thrown as expected: " + ex);
diff --git a/test/jdk/com/sun/net/httpserver/bugs/HandlerConnectionClose.java b/test/jdk/com/sun/net/httpserver/bugs/HandlerConnectionClose.java
index 89839e462c5..372e941904e 100644
--- a/test/jdk/com/sun/net/httpserver/bugs/HandlerConnectionClose.java
+++ b/test/jdk/com/sun/net/httpserver/bugs/HandlerConnectionClose.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2025, 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
@@ -63,7 +63,7 @@ public class HandlerConnectionClose
{
static final int ONEK = 1024;
static final long POST_SIZE = ONEK * 1L;
- SSLContext sslContext;
+ private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
Logger logger;
void test(String[] args) throws Exception {
@@ -77,7 +77,6 @@ public class HandlerConnectionClose
} finally {
httpServer.stop(0);
}
- sslContext = new SimpleSSLContext().get();
HttpServer httpsServer = startHttpServer("https");
try {
testHttpURLConnection(httpsServer, "https","/close/legacy/https/chunked");
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/CommandLineNegativeTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/CommandLineNegativeTest.java
index a82b0bf5a6f..818469d00fc 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/CommandLineNegativeTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/CommandLineNegativeTest.java
@@ -26,7 +26,7 @@
* @summary Negative tests for java -m jdk.httpserver command
* @library /test/lib
* @modules jdk.httpserver
- * @run testng/othervm CommandLineNegativeTest
+ * @run junit/othervm CommandLineNegativeTest
*/
import java.io.IOException;
@@ -37,13 +37,14 @@ import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.util.FileUtils;
-import org.testng.SkipException;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
import static java.lang.System.out;
-import static org.testng.Assert.assertFalse;
+
+import org.junit.jupiter.api.AfterAll;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
public class CommandLineNegativeTest {
@@ -55,8 +56,8 @@ public class CommandLineNegativeTest {
static final Path TEST_FILE = TEST_DIR.resolve("file.txt");
static final String LOOPBACK_ADDR = InetAddress.getLoopbackAddress().getHostAddress();
- @BeforeTest
- public void setup() throws IOException {
+ @BeforeAll
+ public static void setup() throws IOException {
if (Files.exists(TEST_DIR)) {
FileUtils.deleteFileTreeWithRetry(TEST_DIR);
}
@@ -64,15 +65,15 @@ public class CommandLineNegativeTest {
Files.createFile(TEST_FILE);
}
- @DataProvider
- public Object[][] unknownOption() {
+ public static Object[][] unknownOption() {
return new Object[][] {
{"--unknownOption"},
{"null"}
};
}
- @Test(dataProvider = "unknownOption")
+ @ParameterizedTest
+ @MethodSource("unknownOption")
public void testBadOption(String opt) throws Throwable {
out.println("\n--- testUnknownOption, opt=\"%s\" ".formatted(opt));
simpleserver(JAVA, LOCALE_OPT, "-m", "jdk.httpserver", opt)
@@ -80,8 +81,7 @@ public class CommandLineNegativeTest {
.shouldContain("Error: unknown option: " + opt);
}
- @DataProvider
- public Object[][] tooManyOptionArgs() {
+ public static Object[][] tooManyOptionArgs() {
return new Object[][] {
{"-b", "localhost"},
{"-d", "/some/path"},
@@ -95,7 +95,8 @@ public class CommandLineNegativeTest {
};
}
- @Test(dataProvider = "tooManyOptionArgs")
+ @ParameterizedTest
+ @MethodSource("tooManyOptionArgs")
public void testTooManyOptionArgs(String opt, String arg) throws Throwable {
out.println("\n--- testTooManyOptionArgs, opt=\"%s\" ".formatted(opt));
simpleserver(JAVA, LOCALE_OPT, "-m", "jdk.httpserver", opt, arg, arg)
@@ -103,8 +104,7 @@ public class CommandLineNegativeTest {
.shouldContain("Error: unknown option: " + arg);
}
- @DataProvider
- public Object[][] noArg() {
+ public static Object[][] noArg() {
return new Object[][] {
{"-b", """
-b, --bind-address - Address to bind to. Default: %s (loopback).
@@ -122,7 +122,8 @@ public class CommandLineNegativeTest {
};
}
- @Test(dataProvider = "noArg")
+ @ParameterizedTest
+ @MethodSource("noArg")
public void testNoArg(String opt, String msg) throws Throwable {
out.println("\n--- testNoArg, opt=\"%s\" ".formatted(opt));
simpleserver(JAVA, LOCALE_OPT, "-m", "jdk.httpserver", opt)
@@ -131,8 +132,7 @@ public class CommandLineNegativeTest {
.shouldContain(msg);
}
- @DataProvider
- public Object[][] invalidValue() {
+ public static Object[][] invalidValue() {
return new Object[][] {
{"-b", "[127.0.0.1]"},
{"-b", "badhost"},
@@ -146,7 +146,8 @@ public class CommandLineNegativeTest {
};
}
- @Test(dataProvider = "invalidValue")
+ @ParameterizedTest
+ @MethodSource("invalidValue")
public void testInvalidValue(String opt, String val) throws Throwable {
out.println("\n--- testInvalidValue, opt=\"%s\" ".formatted(opt));
simpleserver(JAVA, LOCALE_OPT, "-m", "jdk.httpserver", opt, val)
@@ -154,10 +155,10 @@ public class CommandLineNegativeTest {
.shouldContain("Error: invalid value given for " + opt + ": " + val);
}
- @DataProvider
- public Object[][] portOptions() { return new Object[][] {{"-p"}, {"--port"}}; }
+ public static Object[][] portOptions() { return new Object[][] {{"-p"}, {"--port"}}; }
- @Test(dataProvider = "portOptions")
+ @ParameterizedTest
+ @MethodSource("portOptions")
public void testPortOutOfRange(String opt) throws Throwable {
out.println("\n--- testPortOutOfRange, opt=\"%s\" ".formatted(opt));
simpleserver(JAVA, LOCALE_OPT, "-m", "jdk.httpserver", opt, "65536") // range 0 to 65535
@@ -165,10 +166,10 @@ public class CommandLineNegativeTest {
.shouldContain("Error: server config failed: " + "port out of range:65536");
}
- @DataProvider
- public Object[][] directoryOptions() { return new Object[][] {{"-d"}, {"--directory"}}; }
+ public static Object[][] directoryOptions() { return new Object[][] {{"-d"}, {"--directory"}}; }
- @Test(dataProvider = "directoryOptions")
+ @ParameterizedTest
+ @MethodSource("directoryOptions")
public void testRootNotADirectory(String opt) throws Throwable {
out.println("\n--- testRootNotADirectory, opt=\"%s\" ".formatted(opt));
var file = TEST_FILE.toString();
@@ -178,7 +179,8 @@ public class CommandLineNegativeTest {
.shouldContain("Error: server config failed: " + "Path is not a directory: " + file);
}
- @Test(dataProvider = "directoryOptions")
+ @ParameterizedTest
+ @MethodSource("directoryOptions")
public void testRootDoesNotExist(String opt) throws Throwable {
out.println("\n--- testRootDoesNotExist, opt=\"%s\" ".formatted(opt));
Path root = TEST_DIR.resolve("not/existent/dir");
@@ -188,14 +190,12 @@ public class CommandLineNegativeTest {
.shouldContain("Error: server config failed: " + "Path does not exist: " + root.toString());
}
- @Test(dataProvider = "directoryOptions")
+ @ParameterizedTest
+ @MethodSource("directoryOptions")
public void testRootNotReadable(String opt) throws Throwable {
out.println("\n--- testRootNotReadable, opt=\"%s\" ".formatted(opt));
- if (Platform.isWindows()) {
- // Not applicable to Windows. Reason: cannot revoke an owner's read
- // access to a directory that was created by that owner
- throw new SkipException("cannot run on Windows");
- }
+ Assumptions.assumeFalse(Platform.isWindows(), "cannot run on Windows"); // Not applicable to Windows. Reason: cannot revoke an owner's read
+ // access to a directory that was created by that owner
Path root = Files.createDirectories(TEST_DIR.resolve("not/readable/dir"));
try {
root.toFile().setReadable(false, false);
@@ -208,8 +208,8 @@ public class CommandLineNegativeTest {
}
}
- @AfterTest
- public void teardown() throws IOException {
+ @AfterAll
+ public static void teardown() throws IOException {
if (Files.exists(TEST_DIR)) {
FileUtils.deleteFileTreeWithRetry(TEST_DIR);
}
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/CommandLinePortNotSpecifiedTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/CommandLinePortNotSpecifiedTest.java
index 61a872a8655..c665f37abe7 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/CommandLinePortNotSpecifiedTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/CommandLinePortNotSpecifiedTest.java
@@ -27,7 +27,7 @@
* @summary Tests the java -m jdk.httpserver command with port not specified
* @modules jdk.httpserver
* @library /test/lib
- * @run testng/othervm/manual CommandLinePortNotSpecifiedTest
+ * @run junit/othervm/manual CommandLinePortNotSpecifiedTest
*/
import java.io.IOException;
@@ -39,11 +39,12 @@ import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.util.FileUtils;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
import static java.lang.System.out;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
public class CommandLinePortNotSpecifiedTest {
static final Path JAVA_HOME = Path.of(System.getProperty("java.home"));
@@ -55,8 +56,8 @@ public class CommandLinePortNotSpecifiedTest {
static final String TEST_DIR_STR = TEST_DIR.toString();
static final String LOOPBACK_ADDR = InetAddress.getLoopbackAddress().getHostAddress();
- @BeforeTest
- public void setup() throws IOException {
+ @BeforeAll
+ public static void setup() throws IOException {
if (Files.exists(TEST_DIR)) {
FileUtils.deleteFileTreeWithRetry(TEST_DIR);
}
@@ -92,8 +93,8 @@ public class CommandLinePortNotSpecifiedTest {
.shouldContain("URL http://" + LOOPBACK_ADDR);
}
- @AfterTest
- public void teardown() throws IOException {
+ @AfterAll
+ public static void teardown() throws IOException {
if (Files.exists(TEST_DIR)) {
FileUtils.deleteFileTreeWithRetry(TEST_DIR);
}
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/CommandLinePositiveTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/CommandLinePositiveTest.java
index 16d0ff67ee9..3c3ac0c215d 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/CommandLinePositiveTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/CommandLinePositiveTest.java
@@ -27,7 +27,7 @@
* @library /test/lib
* @build jdk.test.lib.net.IPSupport
* @modules jdk.httpserver
- * @run testng/othervm CommandLinePositiveTest
+ * @run junit/othervm CommandLinePositiveTest
*/
import java.io.IOException;
@@ -41,12 +41,13 @@ import jdk.test.lib.net.IPSupport;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.util.FileUtils;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
import static java.lang.System.out;
+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;
+
public class CommandLinePositiveTest {
static final String JAVA_VERSION = System.getProperty("java.version");
@@ -84,8 +85,8 @@ public class CommandLinePositiveTest {
static final String LOOPBACK_ADDR = InetAddress.getLoopbackAddress().getHostAddress();
- @BeforeTest
- public void setup() throws IOException {
+ @BeforeAll
+ public static void setup() throws IOException {
if (Files.exists(ROOT_DIR)) {
FileUtils.deleteFileTreeWithRetry(ROOT_DIR);
}
@@ -105,16 +106,17 @@ public class CommandLinePositiveTest {
}
}
- @DataProvider
- public Object[][] directoryOptions() { return new Object[][] {{"-d"}, {"--directory"}}; }
+ public static Object[][] directoryOptions() { return new Object[][] {{"-d"}, {"--directory"}}; }
- @Test(dataProvider = "directoryOptions")
+ @ParameterizedTest
+ @MethodSource("directoryOptions")
public void testAbsDirectory(String opt) throws Throwable {
out.printf("\n--- testAbsDirectory, opt=\"%s\"%n", opt);
testDirectory(opt, ROOT_DIR_STR);
}
- @Test(dataProvider = "directoryOptions")
+ @ParameterizedTest
+ @MethodSource("directoryOptions")
public void testRelDirectory(String opt) throws Throwable {
out.printf("\n--- testRelDirectory, opt=\"%s\"%n", opt);
Path rootRelDir = CWD.relativize(ROOT_DIR);
@@ -129,10 +131,10 @@ public class CommandLinePositiveTest {
.shouldContain("URL http://" + LOOPBACK_ADDR);
}
- @DataProvider
- public Object[][] portOptions() { return new Object[][] {{"-p"}, {"--port"}}; }
+ public static Object[][] portOptions() { return new Object[][] {{"-p"}, {"--port"}}; }
- @Test(dataProvider = "portOptions")
+ @ParameterizedTest
+ @MethodSource("portOptions")
public void testPort(String opt) throws Throwable {
out.println("\n--- testPort, opt=\"%s\" ".formatted(opt));
simpleserver(JAVA, LOCALE_OPT, "-m", "jdk.httpserver", opt, "0")
@@ -142,8 +144,7 @@ public class CommandLinePositiveTest {
.shouldContain("URL http://" + LOOPBACK_ADDR);
}
- @DataProvider
- public Object[][] helpOptions() { return new Object[][] {{"-h"}, {"-?"}, {"--help"}}; }
+ public static Object[][] helpOptions() { return new Object[][] {{"-h"}, {"-?"}, {"--help"}}; }
static final String USAGE_TEXT = """
Usage: java -m jdk.httpserver [-b bind address] [-p port] [-d directory]
@@ -161,7 +162,8 @@ public class CommandLinePositiveTest {
-version, --version - Prints version information and exits.
To stop the server, press Ctrl + C.""".formatted(LOOPBACK_ADDR);
- @Test(dataProvider = "helpOptions")
+ @ParameterizedTest
+ @MethodSource("helpOptions")
public void testHelp(String opt) throws Throwable {
out.println("\n--- testHelp, opt=\"%s\" ".formatted(opt));
simpleserver(WaitForLine.HELP_STARTUP_LINE,
@@ -172,10 +174,10 @@ public class CommandLinePositiveTest {
.shouldContain(OPTIONS_TEXT);
}
- @DataProvider
- public Object[][] versionOptions() { return new Object[][] {{"-version"}, {"--version"}}; }
+ public static Object[][] versionOptions() { return new Object[][] {{"-version"}, {"--version"}}; }
- @Test(dataProvider = "versionOptions")
+ @ParameterizedTest
+ @MethodSource("versionOptions")
public void testVersion(String opt) throws Throwable {
out.println("\n--- testVersion, opt=\"%s\" ".formatted(opt));
simpleserver(WaitForLine.VERSION_STARTUP_LINE,
@@ -184,10 +186,10 @@ public class CommandLinePositiveTest {
.shouldHaveExitValue(0);
}
- @DataProvider
- public Object[][] bindOptions() { return new Object[][] {{"-b"}, {"--bind-address"}}; }
+ public static Object[][] bindOptions() { return new Object[][] {{"-b"}, {"--bind-address"}}; }
- @Test(dataProvider = "bindOptions")
+ @ParameterizedTest
+ @MethodSource("bindOptions")
public void testBindAllInterfaces(String opt) throws Throwable {
out.println("\n--- testBindAllInterfaces, opt=\"%s\" ".formatted(opt));
simpleserver(JAVA, LOCALE_OPT, "-m", "jdk.httpserver", "-p", "0", opt, "0.0.0.0")
@@ -202,7 +204,8 @@ public class CommandLinePositiveTest {
}
}
- @Test(dataProvider = "bindOptions")
+ @ParameterizedTest
+ @MethodSource("bindOptions")
public void testLastOneWinsBindAddress(String opt) throws Throwable {
out.println("\n--- testLastOneWinsBindAddress, opt=\"%s\" ".formatted(opt));
simpleserver(JAVA, LOCALE_OPT, "-m", "jdk.httpserver", "-p", "0", opt, "123.4.5.6", opt, LOOPBACK_ADDR)
@@ -212,7 +215,8 @@ public class CommandLinePositiveTest {
}
- @Test(dataProvider = "directoryOptions")
+ @ParameterizedTest
+ @MethodSource("directoryOptions")
public void testLastOneWinsDirectory(String opt) throws Throwable {
out.println("\n--- testLastOneWinsDirectory, opt=\"%s\" ".formatted(opt));
simpleserver(JAVA, LOCALE_OPT, "-m", "jdk.httpserver", "-p", "0", opt, ROOT_DIR_STR, opt, ROOT_DIR_STR)
@@ -222,10 +226,10 @@ public class CommandLinePositiveTest {
.shouldContain("URL http://" + LOOPBACK_ADDR);
}
- @DataProvider
- public Object[][] outputOptions() { return new Object[][] {{"-o"}, {"--output"}}; }
+ public static Object[][] outputOptions() { return new Object[][] {{"-o"}, {"--output"}}; }
- @Test(dataProvider = "outputOptions")
+ @ParameterizedTest
+ @MethodSource("outputOptions")
public void testLastOneWinsOutput(String opt) throws Throwable {
out.println("\n--- testLastOneWinsOutput, opt=\"%s\" ".formatted(opt));
simpleserver(JAVA, LOCALE_OPT, "-m", "jdk.httpserver", "-p", "0", opt, "none", opt, "verbose")
@@ -235,7 +239,8 @@ public class CommandLinePositiveTest {
.shouldContain("URL http://" + LOOPBACK_ADDR);
}
- @Test(dataProvider = "portOptions")
+ @ParameterizedTest
+ @MethodSource("portOptions")
public void testLastOneWinsPort(String opt) throws Throwable {
out.println("\n--- testLastOneWinsPort, opt=\"%s\" ".formatted(opt));
simpleserver(JAVA, LOCALE_OPT, "-m", "jdk.httpserver", opt, "-999", opt, "0")
@@ -245,8 +250,8 @@ public class CommandLinePositiveTest {
.shouldContain("URL http://" + LOOPBACK_ADDR);
}
- @AfterTest
- public void teardown() throws IOException {
+ @AfterAll
+ public static void teardown() throws IOException {
if (Files.exists(ROOT_DIR)) {
FileUtils.deleteFileTreeWithRetry(ROOT_DIR);
}
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/CustomFileSystemTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/CustomFileSystemTest.java
index 0a46ac1ea8a..c0858475ea4 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/CustomFileSystemTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/CustomFileSystemTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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 @@
* file system
* @library /test/lib
* @build jdk.test.lib.Platform jdk.test.lib.net.URIBuilder
- * @run testng/othervm CustomFileSystemTest
+ * @run junit/othervm CustomFileSystemTest
*/
import java.io.IOException;
@@ -71,16 +71,18 @@ import com.sun.net.httpserver.SimpleFileServer;
import com.sun.net.httpserver.SimpleFileServer.OutputLevel;
import jdk.test.lib.Platform;
import jdk.test.lib.net.URIBuilder;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-import org.testng.SkipException;
import static java.net.http.HttpClient.Builder.NO_PROXY;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.StandardOpenOption.CREATE;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
public class CustomFileSystemTest {
static final InetSocketAddress LOOPBACK_ADDR = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
@@ -88,8 +90,8 @@ public class CustomFileSystemTest {
static final boolean ENABLE_LOGGING = true;
static final Logger LOGGER = Logger.getLogger("com.sun.net.httpserver");
- @BeforeTest
- public void setup() throws Exception {
+ @BeforeAll
+ public static void setup() throws Exception {
if (ENABLE_LOGGING) {
ConsoleHandler ch = new ConsoleHandler();
LOGGER.setLevel(Level.ALL);
@@ -111,11 +113,11 @@ public class CustomFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "aFile.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.body(), "some text");
- assertEquals(response.headers().firstValue("content-type").get(), "text/plain");
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.headers().firstValue("last-modified").get(), lastModified);
+ assertEquals(200, response.statusCode());
+ assertEquals("some text", response.body());
+ assertEquals("text/plain", response.headers().firstValue("content-type").get());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(lastModified, response.headers().firstValue("last-modified").get());
} finally {
server.stop(0);
}
@@ -140,11 +142,11 @@ public class CustomFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().firstValue("content-type").get(), "text/html; charset=UTF-8");
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.headers().firstValue("last-modified").get(), lastModified);
- assertEquals(response.body(), expectedBody);
+ assertEquals(200, response.statusCode());
+ assertEquals("text/html; charset=UTF-8", response.headers().firstValue("content-type").get());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(lastModified, response.headers().firstValue("last-modified").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
}
@@ -164,11 +166,11 @@ public class CustomFileSystemTest {
var request = HttpRequest.newBuilder(uri(server, "aFile.txt"))
.method("HEAD", HttpRequest.BodyPublishers.noBody()).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().firstValue("content-type").get(), "text/plain");
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.headers().firstValue("last-modified").get(), lastModified);
- assertEquals(response.body(), "");
+ assertEquals(200, response.statusCode());
+ assertEquals("text/plain", response.headers().firstValue("content-type").get());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(lastModified, response.headers().firstValue("last-modified").get());
+ assertEquals("", response.body());
} finally {
server.stop(0);
}
@@ -194,18 +196,17 @@ public class CustomFileSystemTest {
var request = HttpRequest.newBuilder(uri(server, ""))
.method("HEAD", HttpRequest.BodyPublishers.noBody()).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().firstValue("content-type").get(), "text/html; charset=UTF-8");
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.headers().firstValue("last-modified").get(), lastModified);
- assertEquals(response.body(), "");
+ assertEquals(200, response.statusCode());
+ assertEquals("text/html; charset=UTF-8", response.headers().firstValue("content-type").get());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(lastModified, response.headers().firstValue("last-modified").get());
+ assertEquals("", response.body());
} finally {
server.stop(0);
}
}
- @DataProvider
- public Object[][] indexFiles() {
+ public static Object[][] indexFiles() {
var fileContent = openHTML + """
This is an index file
""" + closeHTML;
@@ -221,7 +222,8 @@ public class CustomFileSystemTest {
};
}
- @Test(dataProvider = "indexFiles")
+ @ParameterizedTest
+ @MethodSource("indexFiles")
public void testDirectoryWithIndexGET(String id,
String filename,
String contentType,
@@ -241,11 +243,11 @@ public class CustomFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().firstValue("content-type").get(), contentType);
- assertEquals(response.headers().firstValue("content-length").get(), contentLength);
- assertEquals(response.headers().firstValue("last-modified").get(), lastModified);
- assertEquals(response.body(), expectedBody);
+ assertEquals(200, response.statusCode());
+ assertEquals(contentType, response.headers().firstValue("content-type").get());
+ assertEquals(contentLength, response.headers().firstValue("content-length").get());
+ assertEquals(lastModified, response.headers().firstValue("last-modified").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
if (serveIndexFile) {
@@ -256,9 +258,7 @@ public class CustomFileSystemTest {
@Test
public void testNotReadableFileGET() throws Exception {
- if (Platform.isWindows()) {
- throw new SkipException("Not applicable on Windows");
- }
+ Assumptions.assumeFalse(Platform.isWindows(), "Not applicable on Windows");
var expectedBody = openHTML + """
File not found
/aFile.txt
@@ -276,9 +276,9 @@ public class CustomFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "aFile.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
file.toFile().setReadable(true, false);
@@ -287,9 +287,7 @@ public class CustomFileSystemTest {
@Test
public void testNotReadableSegmentGET() throws Exception {
- if (Platform.isWindows()) {
- throw new SkipException("Not applicable on Windows");
- }
+ Assumptions.assumeFalse(Platform.isWindows(), "Not applicable on Windows");
var expectedBody = openHTML + """
File not found
/dir/aFile.txt
@@ -309,9 +307,9 @@ public class CustomFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "dir/aFile.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
dir.toFile().setReadable(true, false);
@@ -333,9 +331,9 @@ public class CustomFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "aFile?#.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
}
@@ -356,9 +354,9 @@ public class CustomFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "doesNotExist.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
}
@@ -380,9 +378,9 @@ public class CustomFileSystemTest {
var request = HttpRequest.newBuilder(uri(server, "doesNotExist.txt"))
.method("HEAD", HttpRequest.BodyPublishers.noBody()).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), "");
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals("", response.body());
} finally {
server.stop(0);
}
@@ -406,9 +404,9 @@ public class CustomFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "symlink")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
}
@@ -433,21 +431,21 @@ public class CustomFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "symlink/aFile.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
}
}
- private void createSymLink(Path symlink, Path target) {
+ private static void createSymLink(Path symlink, Path target) {
try {
Files.createSymbolicLink(symlink, target);
} catch (UnsupportedOperationException uoe) {
- throw new SkipException("sym link creation not supported", uoe);
+ Assumptions.abort("sym link creation not supported");
} catch (IOException ioe) {
- throw new SkipException("probably insufficient privileges to create sym links (Windows)", ioe);
+ Assumptions.abort("probably insufficient privileges to create sym links (Windows)");
}
}
@@ -470,9 +468,9 @@ public class CustomFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, fileName)).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
}
@@ -494,15 +492,15 @@ public class CustomFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, ".hiddenDirectory/aFile.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
}
}
- private Path createHiddenFile(Path root) throws IOException {
+ private static Path createHiddenFile(Path root) throws IOException {
Path file;
if (Platform.isWindows()) {
file = Files.createFile(root.resolve("aFile.txt"));
@@ -514,7 +512,7 @@ public class CustomFileSystemTest {
return file;
}
- private Path createFileInHiddenDirectory(Path root) throws IOException {
+ private static Path createFileInHiddenDirectory(Path root) throws IOException {
Path dir;
Path file;
if (Platform.isWindows()) {
@@ -549,17 +547,17 @@ public class CustomFileSystemTest {
var uri = uri(server, "aDirectory");
var request = HttpRequest.newBuilder(uri).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 301);
- assertEquals(response.headers().firstValue("content-length").get(), "0");
- assertEquals(response.headers().firstValue("location").get(), "/aDirectory/");
+ assertEquals(301, response.statusCode());
+ assertEquals("0", response.headers().firstValue("content-length").get());
+ assertEquals("/aDirectory/", response.headers().firstValue("location").get());
// tests that query component is preserved during redirect
var uri2 = uri(server, "aDirectory", "query");
var req2 = HttpRequest.newBuilder(uri2).build();
var res2 = client.send(req2, BodyHandlers.ofString());
- assertEquals(res2.statusCode(), 301);
- assertEquals(res2.headers().firstValue("content-length").get(), "0");
- assertEquals(res2.headers().firstValue("location").get(), "/aDirectory/?query");
+ assertEquals(301, res2.statusCode());
+ assertEquals("0", res2.headers().firstValue("content-length").get());
+ assertEquals("/aDirectory/?query", res2.headers().firstValue("location").get());
}
{ // tests that redirect to returned relative URI works
@@ -568,10 +566,10 @@ public class CustomFileSystemTest {
var uri = uri(server, "aDirectory");
var request = HttpRequest.newBuilder(uri).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.body(), expectedBody);
- assertEquals(response.headers().firstValue("content-type").get(), "text/html; charset=UTF-8");
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
+ assertEquals(200, response.statusCode());
+ assertEquals(expectedBody, response.body());
+ assertEquals("text/html; charset=UTF-8", response.headers().firstValue("content-type").get());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
}
} finally {
server.stop(0);
@@ -588,7 +586,7 @@ public class CustomFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "beginDelim%3C%3EEndDelim")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
+ assertEquals(404, response.statusCode());
assertTrue(response.body().contains("beginDelim%3C%3EEndDelim"));
assertTrue(response.body().contains("File not found"));
} finally {
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/FileServerHandlerTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/FileServerHandlerTest.java
index a5179b03f16..85bad215375 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/FileServerHandlerTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/FileServerHandlerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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,7 +24,7 @@
/*
* @test
* @summary Tests for FileServerHandler
- * @run testng FileServerHandlerTest
+ * @run junit FileServerHandlerTest
*/
import java.io.ByteArrayInputStream;
@@ -44,42 +44,44 @@ import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpPrincipal;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.SimpleFileServer;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-import static org.testng.Assert.*;
+
+import static org.junit.jupiter.api.Assertions.*;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
public class FileServerHandlerTest {
static final Path CWD = Path.of(".").toAbsolutePath();
static final Class RE = RuntimeException.class;
- @DataProvider
- public Object[][] notAllowedMethods() {
+ public static Object[][] notAllowedMethods() {
var l = List.of("POST", "PUT", "DELETE", "TRACE", "OPTIONS");
return l.stream().map(s -> new Object[] { s }).toArray(Object[][]::new);
}
- @Test(dataProvider = "notAllowedMethods")
+ @ParameterizedTest
+ @MethodSource("notAllowedMethods")
public void testNotAllowedRequestMethod(String requestMethod) throws Exception {
var handler = SimpleFileServer.createFileHandler(CWD);
var exchange = new MethodHttpExchange(requestMethod);
handler.handle(exchange);
- assertEquals(exchange.rCode, 405);
- assertEquals(exchange.getResponseHeaders().getFirst("allow"), "HEAD, GET");
+ assertEquals(405, exchange.rCode);
+ assertEquals("HEAD, GET", exchange.getResponseHeaders().getFirst("allow"));
}
- @DataProvider
- public Object[][] notImplementedMethods() {
+ public static Object[][] notImplementedMethods() {
var l = List.of("GARBAGE", "RUBBISH", "TRASH", "FOO", "BAR");
return l.stream().map(s -> new Object[] { s }).toArray(Object[][]::new);
}
- @Test(dataProvider = "notImplementedMethods")
+ @ParameterizedTest
+ @MethodSource("notImplementedMethods")
public void testNotImplementedRequestMethod(String requestMethod) throws Exception {
var handler = SimpleFileServer.createFileHandler(CWD);
var exchange = new MethodHttpExchange(requestMethod);
handler.handle(exchange);
- assertEquals(exchange.rCode, 501);
+ assertEquals(501, exchange.rCode);
}
// 301 and 404 response codes tested in SimpleFileServerTest
@@ -93,8 +95,8 @@ public class FileServerHandlerTest {
throw new RuntimeException("getRequestBody");
}
};
- var t = expectThrows(RE, () -> h.handle(exchange));
- assertEquals(t.getMessage(), "getRequestBody");
+ var t = assertThrows(RE, () -> h.handle(exchange));
+ assertEquals("getRequestBody", t.getMessage());
}
{
var exchange = new ThrowingHttpExchange("GET") {
@@ -102,8 +104,8 @@ public class FileServerHandlerTest {
throw new RuntimeException("getResponseHeaders");
}
};
- var t = expectThrows(RE, () -> h.handle(exchange));
- assertEquals(t.getMessage(), "getResponseHeaders");
+ var t = assertThrows(RE, () -> h.handle(exchange));
+ assertEquals("getResponseHeaders", t.getMessage());
}
{
var exchange = new ThrowingHttpExchange("GET") {
@@ -111,8 +113,8 @@ public class FileServerHandlerTest {
throw new RuntimeException("sendResponseHeaders");
}
};
- var t = expectThrows(RE, () -> h.handle(exchange));
- assertEquals(t.getMessage(), "sendResponseHeaders");
+ var t = assertThrows(RE, () -> h.handle(exchange));
+ assertEquals("sendResponseHeaders", t.getMessage());
}
{
var exchange = new ThrowingHttpExchange("GET") {
@@ -120,8 +122,8 @@ public class FileServerHandlerTest {
throw new RuntimeException("getResponseBody");
}
};
- var t = expectThrows(RE, () -> h.handle(exchange));
- assertEquals(t.getMessage(), "getResponseBody");
+ var t = assertThrows(RE, () -> h.handle(exchange));
+ assertEquals("getResponseBody", t.getMessage());
}
{
var exchange = new ThrowingHttpExchange("GET") {
@@ -129,8 +131,8 @@ public class FileServerHandlerTest {
throw new RuntimeException("close");
}
};
- var t = expectThrows(RE, () -> h.handle(exchange));
- assertEquals(t.getMessage(), "close");
+ var t = assertThrows(RE, () -> h.handle(exchange));
+ assertEquals("close", t.getMessage());
}
}
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/HttpHandlersTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/HttpHandlersTest.java
index 85d271e44fa..46c7085ae14 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/HttpHandlersTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/HttpHandlersTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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,7 @@
* @summary Tests for HttpHandlers
* @library /test/lib
* @build jdk.test.lib.net.URIBuilder
- * @run testng/othervm HttpHandlersTest
+ * @run junit/othervm HttpHandlersTest
*/
import java.io.IOException;
@@ -44,12 +44,14 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import jdk.test.lib.net.URIBuilder;
import com.sun.net.httpserver.*;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
import static java.net.http.HttpClient.Builder.NO_PROXY;
import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.testng.Assert.*;
+
+import static org.junit.jupiter.api.Assertions.*;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
public class HttpHandlersTest {
@@ -61,8 +63,8 @@ public class HttpHandlersTest {
static final boolean ENABLE_LOGGING = true;
static final Logger LOGGER = Logger.getLogger("com.sun.net.httpserver");
- @BeforeTest
- public void setup() {
+ @BeforeAll
+ public static void setup() {
if (ENABLE_LOGGING) {
ConsoleHandler ch = new ConsoleHandler();
LOGGER.setLevel(Level.ALL);
@@ -103,11 +105,11 @@ public class HttpHandlersTest {
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, BodyHandlers.ofString());
assertTrue(response.headers().map().containsKey("date"));
- assertEquals(response.headers().firstValue("foo").get(), "bar");
- assertEquals(response.headers().firstValue("content-length").get(), "0");
- assertEquals(response.headers().map().size(), 3);
- assertEquals(response.statusCode(), 200);
- assertEquals(response.body(), "");
+ assertEquals("bar", response.headers().firstValue("foo").get());
+ assertEquals("0", response.headers().firstValue("content-length").get());
+ assertEquals(3, response.headers().map().size());
+ assertEquals(200, response.statusCode());
+ assertEquals("", response.body());
} finally {
server.stop(0);
}
@@ -125,11 +127,11 @@ public class HttpHandlersTest {
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, BodyHandlers.ofString());
assertTrue(response.headers().map().containsKey("date"));
- assertEquals(response.headers().firstValue("foo").get(), "bar");
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.headers().map().size(), 3);
- assertEquals(response.statusCode(), 200);
- assertEquals(response.body(), "hello world");
+ assertEquals("bar", response.headers().firstValue("foo").get());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(3, response.headers().map().size());
+ assertEquals(200, response.statusCode());
+ assertEquals("hello world", response.body());
} finally {
server.stop(0);
}
@@ -148,9 +150,9 @@ public class HttpHandlersTest {
.method("HEAD", BodyPublishers.noBody()).build();
var response = client.send(request, BodyHandlers.ofString());
assertTrue(response.headers().map().containsKey("date"));
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.headers().map().size(), 2);
- assertEquals(response.statusCode(), 200);
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(2, response.headers().map().size());
+ assertEquals(200, response.statusCode());
} finally {
server.stop(0);
}
@@ -168,22 +170,22 @@ public class HttpHandlersTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertNotEquals(response.headers().firstValue("date").get(), "12345");
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.headers().map().size(), 2);
- assertEquals(response.statusCode(), 200);
- assertEquals(response.body(), "hello world");
+ assertNotEquals("12345", response.headers().firstValue("date").get());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(2, response.headers().map().size());
+ assertEquals(200, response.statusCode());
+ assertEquals("hello world", response.body());
} finally {
server.stop(0);
}
}
- @DataProvider
- public Object[][] responseBodies() {
+ public static Object[][] responseBodies() {
return new Object[][] { {"hello world"}, {""} };
}
- @Test(dataProvider = "responseBodies")
+ @ParameterizedTest
+ @MethodSource("responseBodies")
public void testOfThrowingExchange(String body) {
var h = HttpHandlers.of(200, Headers.of(), body);
{
@@ -192,8 +194,8 @@ public class HttpHandlersTest {
throw new RuntimeException("getRequestBody");
}
};
- var t = expectThrows(RE, () -> h.handle(exchange));
- assertEquals(t.getMessage(), "getRequestBody");
+ var t = assertThrows(RE, () -> h.handle(exchange));
+ assertEquals("getRequestBody", t.getMessage());
}
{
var exchange = new ThrowingHttpExchange() {
@@ -201,8 +203,8 @@ public class HttpHandlersTest {
throw new RuntimeException("getResponseHeaders");
}
};
- var t = expectThrows(RE, () -> h.handle(exchange));
- assertEquals(t.getMessage(), "getResponseHeaders");
+ var t = assertThrows(RE, () -> h.handle(exchange));
+ assertEquals("getResponseHeaders", t.getMessage());
}
{
var exchange = new ThrowingHttpExchange() {
@@ -210,8 +212,8 @@ public class HttpHandlersTest {
throw new RuntimeException("sendResponseHeaders");
}
};
- var t = expectThrows(RE, () -> h.handle(exchange));
- assertEquals(t.getMessage(), "sendResponseHeaders");
+ var t = assertThrows(RE, () -> h.handle(exchange));
+ assertEquals("sendResponseHeaders", t.getMessage());
}
{
var exchange = new ThrowingHttpExchange() {
@@ -220,8 +222,8 @@ public class HttpHandlersTest {
}
};
if (!body.isEmpty()) { // getResponseBody not called if no responseBody
- var t = expectThrows(RE, () -> h.handle(exchange));
- assertEquals(t.getMessage(), "getResponseBody");
+ var t = assertThrows(RE, () -> h.handle(exchange));
+ assertEquals("getResponseBody", t.getMessage());
}
}
{
@@ -230,8 +232,8 @@ public class HttpHandlersTest {
throw new RuntimeException("close");
}
};
- var t = expectThrows(RE, () -> h.handle(exchange));
- assertEquals(t.getMessage(), "close");
+ var t = assertThrows(RE, () -> h.handle(exchange));
+ assertEquals("close", t.getMessage());
}
}
@@ -247,8 +249,8 @@ public class HttpHandlersTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.body(), "TestHandler-1");
+ assertEquals(200, response.statusCode());
+ assertEquals("TestHandler-1", response.body());
} finally {
server.stop(0);
}
@@ -266,8 +268,8 @@ public class HttpHandlersTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.body(), "TestHandler-2");
+ assertEquals(200, response.statusCode());
+ assertEquals("TestHandler-2", response.body());
} finally {
server.stop(0);
}
@@ -287,8 +289,8 @@ public class HttpHandlersTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.body(), "TestHandler-2");
+ assertEquals(200, response.statusCode());
+ assertEquals("TestHandler-2", response.body());
} finally {
server.stop(0);
}
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerAlertTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerAlertTest.java
index 2ba54d61ada..ba6812ffaa5 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerAlertTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerAlertTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2023, 2025, 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,13 @@
* @summary Test if HttpsServer sends the TLS alerts produced
* @library /test/lib
* @build jdk.test.lib.net.SimpleSSLContext
- * @run testng/othervm HttpsServerAlertTest
+ * @run junit/othervm HttpsServerAlertTest
*/
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsParameters;
import com.sun.net.httpserver.HttpsServer;
import jdk.test.lib.net.SimpleSSLContext;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException;
@@ -50,7 +48,9 @@ import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
-import static org.testng.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
public class HttpsServerAlertTest {
@@ -59,18 +59,20 @@ public class HttpsServerAlertTest {
static final boolean ENABLE_LOGGING = true;
static final Logger LOGGER = Logger.getLogger("com.sun.net.httpserver");
- SSLContext sslContext;
+ private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
- @BeforeTest
- public void setup() throws IOException {
+ static {
+ SSLContext.setDefault(sslContext);
+ }
+
+ @BeforeAll
+ public static void setup() throws IOException {
if (ENABLE_LOGGING) {
ConsoleHandler ch = new ConsoleHandler();
LOGGER.setLevel(Level.ALL);
ch.setLevel(Level.ALL);
LOGGER.addHandler(ch);
}
- sslContext = new SimpleSSLContext().get();
- SSLContext.setDefault(sslContext);
}
@Test
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerTest.java
index 2227c4cd437..794067592df 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/HttpsServerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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,7 @@
* @summary Test for HttpsServer::create
* @library /test/lib
* @build jdk.test.lib.Platform jdk.test.lib.net.URIBuilder
- * @run testng/othervm HttpsServerTest
+ * @run junit/othervm HttpsServerTest
*/
import java.io.IOException;
@@ -40,7 +40,6 @@ import java.net.http.HttpRequest;
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -52,12 +51,13 @@ import com.sun.net.httpserver.HttpsServer;
import javax.net.ssl.SSLContext;
import jdk.test.lib.net.SimpleSSLContext;
import jdk.test.lib.net.URIBuilder;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
import static java.net.http.HttpClient.Builder.NO_PROXY;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertThrows;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
public class HttpsServerTest {
@@ -67,18 +67,20 @@ public class HttpsServerTest {
static final boolean ENABLE_LOGGING = true;
static final Logger LOGGER = Logger.getLogger("com.sun.net.httpserver");
- SSLContext sslContext;
+ private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
- @BeforeTest
- public void setup() throws IOException {
+ static {
+ SSLContext.setDefault(sslContext);
+ }
+
+ @BeforeAll
+ public static void setup() throws IOException {
if (ENABLE_LOGGING) {
ConsoleHandler ch = new ConsoleHandler();
LOGGER.setLevel(Level.ALL);
ch.setLevel(Level.ALL);
LOGGER.addHandler(ch);
}
- sslContext = new SimpleSSLContext().get();
- SSLContext.setDefault(sslContext);
}
@Test
@@ -96,12 +98,12 @@ public class HttpsServerTest {
final var s1 = HttpsServer.create(null, 0);
assertNull(s1.getAddress());
s1.bind((LOOPBACK_ADDR), 0);
- assertEquals(s1.getAddress().getAddress(), LOOPBACK_ADDR.getAddress());
+ assertEquals(LOOPBACK_ADDR.getAddress(), s1.getAddress().getAddress());
final var s2 = HttpsServer.create(null, 0, "/foo/", new Handler());
assertNull(s2.getAddress());
s2.bind(LOOPBACK_ADDR, 0);
- assertEquals(s2.getAddress().getAddress(), LOOPBACK_ADDR.getAddress());
+ assertEquals(LOOPBACK_ADDR.getAddress(), s2.getAddress().getAddress());
s2.removeContext("/foo/"); // throws if context doesn't exist
}
@@ -118,11 +120,10 @@ public class HttpsServerTest {
.build();
var request = HttpRequest.newBuilder(uri(server, "/test")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.body(), "hello world");
- assertEquals(response.headers().firstValue("content-length").get(),
- Integer.toString("hello world".length()));
- assertEquals(response.statusCode(), filter.responseCode.get().intValue());
+ assertEquals(200, response.statusCode());
+ assertEquals("hello world", response.body());
+ assertEquals( Integer.toString("hello world".length()), response.headers().firstValue("content-length").get());
+ assertEquals(filter.responseCode.get().intValue(), response.statusCode());
} finally {
server.stop(0);
}
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/IdempotencyAndCommutativityTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/IdempotencyAndCommutativityTest.java
index d98944077dc..2fde02efe70 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/IdempotencyAndCommutativityTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/IdempotencyAndCommutativityTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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
@@ -37,14 +37,15 @@ import java.util.logging.Logger;
import jdk.test.lib.net.URIBuilder;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.SimpleFileServer;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
import static java.net.http.HttpClient.Builder.NO_PROXY;
import static java.nio.file.StandardOpenOption.CREATE;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
+
+import org.junit.jupiter.api.AfterAll;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
/*
* @test
@@ -52,7 +53,7 @@ import static org.testng.Assert.assertTrue;
* set of binary request sequences
* @library /test/lib
* @build jdk.test.lib.net.URIBuilder
- * @run testng/othervm IdempotencyAndCommutativityTest
+ * @run junit/othervm IdempotencyAndCommutativityTest
*/
public class IdempotencyAndCommutativityTest {
@@ -69,8 +70,8 @@ public class IdempotencyAndCommutativityTest {
static final boolean ENABLE_LOGGING = true;
static final Logger LOGGER = Logger.getLogger("com.sun.net.httpserver");
- @BeforeTest
- public void setup() throws IOException {
+ @BeforeAll
+ public static void setup() throws IOException {
if (ENABLE_LOGGING) {
ConsoleHandler ch = new ConsoleHandler();
LOGGER.setLevel(Level.ALL);
@@ -89,8 +90,7 @@ public class IdempotencyAndCommutativityTest {
record ExchangeValues(String method, String resource, int respCode, String contentType) {}
// Creates an exhaustive set of binary exchange sequences
- @DataProvider
- public Object[][] allBinarySequences() {
+ public static Object[][] allBinarySequences() {
final List sequences = List.of(
new ExchangeValues("GET", FILE_NAME, 200, "text/plain"),
new ExchangeValues("GET", DIR_NAME, 200, "text/html; charset=UTF-8"),
@@ -108,7 +108,8 @@ public class IdempotencyAndCommutativityTest {
.toArray(Object[][]::new);
}
- @Test(dataProvider = "allBinarySequences")
+ @ParameterizedTest
+ @MethodSource("allBinarySequences")
public void testBinarySequences(ExchangeValues e1, ExchangeValues e2) throws Exception {
System.out.println("---");
System.out.println(e1);
@@ -122,15 +123,15 @@ public class IdempotencyAndCommutativityTest {
.method(e.method(), HttpRequest.BodyPublishers.noBody())
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), e.respCode());
+ assertEquals(e.respCode(), response.statusCode());
if (e.contentType != null) {
- assertEquals(response.headers().firstValue("content-type").get(), e.contentType());
+ assertEquals(e.contentType(), response.headers().firstValue("content-type").get());
} else {
assertTrue(response.headers().firstValue("content-type").isEmpty());
}
}
- @AfterTest
+ @AfterAll
public static void teardown() {
server.stop(0);
}
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/MapToPathTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/MapToPathTest.java
index aa8f37acc1b..38f0b610741 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/MapToPathTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/MapToPathTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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 @@
* system path
* @library /test/lib
* @build jdk.test.lib.Platform jdk.test.lib.net.URIBuilder
- * @run testng/othervm MapToPathTest
+ * @run junit/othervm MapToPathTest
*/
import java.io.IOException;
@@ -55,13 +55,14 @@ import com.sun.net.httpserver.SimpleFileServer;
import com.sun.net.httpserver.SimpleFileServer.OutputLevel;
import jdk.test.lib.net.URIBuilder;
import jdk.test.lib.util.FileUtils;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
import static java.lang.System.out;
import static java.net.http.HttpClient.Builder.NO_PROXY;
import static java.nio.file.StandardOpenOption.CREATE;
-import static org.testng.Assert.assertEquals;
+
+import org.junit.jupiter.api.AfterAll;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
public class MapToPathTest {
@@ -74,8 +75,8 @@ public class MapToPathTest {
static final boolean ENABLE_LOGGING = true;
static final Logger LOGGER = Logger.getLogger("com.sun.net.httpserver");
- @BeforeTest
- public void setup() throws IOException {
+ @BeforeAll
+ public static void setup() throws IOException {
if (ENABLE_LOGGING) {
ConsoleHandler ch = new ConsoleHandler();
LOGGER.setLevel(Level.ALL);
@@ -88,7 +89,7 @@ public class MapToPathTest {
createDirectories(TEST_DIR);
}
- private void createDirectories(Path testDir) throws IOException {
+ private static void createDirectories(Path testDir) throws IOException {
// Create directory tree:
//
// |-- TEST_DIR
@@ -124,40 +125,40 @@ public class MapToPathTest {
try {
var req1 = HttpRequest.newBuilder(uri(server, "/")).build();
var res1 = client.send(req1, BodyHandlers.ofString());
- assertEquals(res1.statusCode(), 200);
- assertEquals(res1.headers().firstValue("content-type").get(), "text/html; charset=UTF-8");
- assertEquals(res1.headers().firstValue("content-length").get(), Long.toString(257L));
- assertEquals(res1.headers().firstValue("last-modified").get(), getLastModified(TEST_DIR));
+ assertEquals(200, res1.statusCode());
+ assertEquals("text/html; charset=UTF-8", res1.headers().firstValue("content-type").get());
+ assertEquals(Long.toString(257L), res1.headers().firstValue("content-length").get());
+ assertEquals(getLastModified(TEST_DIR), res1.headers().firstValue("last-modified").get());
var req2 = HttpRequest.newBuilder(uri(server, "/../")).build();
var res2 = client.send(req2, BodyHandlers.ofString());
- assertEquals(res2.statusCode(), 404); // cannot escape root
+ assertEquals(404, res2.statusCode()); // cannot escape root
var req3 = HttpRequest.newBuilder(uri(server, "/foo/bar/baz/c://")).build();
var res3 = client.send(req3, BodyHandlers.ofString());
- assertEquals(res3.statusCode(), 404); // not found
+ assertEquals(404, res3.statusCode()); // not found
var req4 = HttpRequest.newBuilder(uri(server, "/foo/bar/baz/c:.//")).build();
var res4 = client.send(req4, BodyHandlers.ofString());
- assertEquals(res4.statusCode(), 404); // not found
+ assertEquals(404, res4.statusCode()); // not found
var req5 = HttpRequest.newBuilder(uri(server, "/foo/bar/baz/c:..//")).build();
var res5 = client.send(req5, BodyHandlers.ofString());
- assertEquals(res5.statusCode(), 404); // not found
+ assertEquals(404, res5.statusCode()); // not found
var req6 = HttpRequest.newBuilder(uri(server, "/foo/file:" + TEST_DIR.getParent())).build();
var res6 = client.send(req6, BodyHandlers.ofString());
- assertEquals(res6.statusCode(), 404); // not found
+ assertEquals(404, res6.statusCode()); // not found
var req7 = HttpRequest.newBuilder(uri(server, "/foo/bar/\\..\\../")).build();
var res7 = client.send(req7, BodyHandlers.ofString());
- assertEquals(res7.statusCode(), 404); // not found
+ assertEquals(404, res7.statusCode()); // not found
var req8 = HttpRequest.newBuilder(uri(server, "/foo")).build();
var res8 = client.send(req8, BodyHandlers.ofString());
- assertEquals(res8.statusCode(), 301); // redirect
- assertEquals(res8.headers().firstValue("content-length").get(), "0");
- assertEquals(res8.headers().firstValue("location").get(), "/foo/");
+ assertEquals(301, res8.statusCode()); // redirect
+ assertEquals("0", res8.headers().firstValue("content-length").get());
+ assertEquals("/foo/", res8.headers().firstValue("location").get());
} finally {
server.stop(0);
}
@@ -169,15 +170,15 @@ public class MapToPathTest {
try {
var req1 = HttpRequest.newBuilder(uri(server, "/browse/file.txt")).build();
var res1 = client.send(req1, BodyHandlers.ofString());
- assertEquals(res1.statusCode(), 200);
- assertEquals(res1.body(), "testdir");
- assertEquals(res1.headers().firstValue("content-type").get(), "text/plain");
- assertEquals(res1.headers().firstValue("content-length").get(), Long.toString(7L));
- assertEquals(res1.headers().firstValue("last-modified").get(), getLastModified(TEST_DIR.resolve("file.txt")));
+ assertEquals(200, res1.statusCode());
+ assertEquals("testdir", res1.body());
+ assertEquals("text/plain", res1.headers().firstValue("content-type").get());
+ assertEquals(Long.toString(7L), res1.headers().firstValue("content-length").get());
+ assertEquals(getLastModified(TEST_DIR.resolve("file.txt")), res1.headers().firstValue("last-modified").get());
var req2 = HttpRequest.newBuilder(uri(server, "/store/file.txt")).build();
var res2 = client.send(req2, BodyHandlers.ofString());
- assertEquals(res2.statusCode(), 404); // no context found
+ assertEquals(404, res2.statusCode()); // no context found
} finally {
server.stop(0);
}
@@ -190,29 +191,29 @@ public class MapToPathTest {
try {
var req1 = HttpRequest.newBuilder(uri(server, "/foo/file.txt")).build();
var res1 = client.send(req1, BodyHandlers.ofString());
- assertEquals(res1.statusCode(), 200);
- assertEquals(res1.body(), "foo");
- assertEquals(res1.headers().firstValue("content-type").get(), "text/plain");
- assertEquals(res1.headers().firstValue("content-length").get(), Long.toString(3L));
- assertEquals(res1.headers().firstValue("last-modified").get(), getLastModified(TEST_DIR.resolve("foo").resolve("file.txt")));
+ assertEquals(200, res1.statusCode());
+ assertEquals("foo", res1.body());
+ assertEquals("text/plain", res1.headers().firstValue("content-type").get());
+ assertEquals(Long.toString(3L), res1.headers().firstValue("content-length").get());
+ assertEquals(getLastModified(TEST_DIR.resolve("foo").resolve("file.txt")), res1.headers().firstValue("last-modified").get());
var req2 = HttpRequest.newBuilder(uri(server, "/foobar/file.txt")).build();
var res2 = client.send(req2, BodyHandlers.ofString());
- assertEquals(res2.statusCode(), 404); // no context found
+ assertEquals(404, res2.statusCode()); // no context found
var req3 = HttpRequest.newBuilder(uri(server, "/foo/../foobar/file.txt")).build();
var res3 = client.send(req3, BodyHandlers.ofString());
- assertEquals(res3.statusCode(), 404); // cannot escape context
+ assertEquals(404, res3.statusCode()); // cannot escape context
var req4 = HttpRequest.newBuilder(uri(server, "/foo/../..")).build();
var res4 = client.send(req4, BodyHandlers.ofString());
- assertEquals(res4.statusCode(), 404); // cannot escape root
+ assertEquals(404, res4.statusCode()); // cannot escape root
var req5 = HttpRequest.newBuilder(uri(server, "/foo/bar")).build();
var res5 = client.send(req5, BodyHandlers.ofString());
- assertEquals(res5.statusCode(), 301); // redirect
- assertEquals(res5.headers().firstValue("content-length").get(), "0");
- assertEquals(res5.headers().firstValue("location").get(), "/foo/bar/");
+ assertEquals(301, res5.statusCode()); // redirect
+ assertEquals("0", res5.headers().firstValue("content-length").get());
+ assertEquals("/foo/bar/", res5.headers().firstValue("location").get());
} finally {
server.stop(0);
}
@@ -225,35 +226,35 @@ public class MapToPathTest {
try {
var req1 = HttpRequest.newBuilder(uri(server, "/foo/file.txt")).build();
var res1 = client.send(req1, BodyHandlers.ofString());
- assertEquals(res1.statusCode(), 200);
- assertEquals(res1.body(), "foo");
- assertEquals(res1.headers().firstValue("content-type").get(), "text/plain");
- assertEquals(res1.headers().firstValue("content-length").get(), Long.toString(3L));
- assertEquals(res1.headers().firstValue("last-modified").get(), getLastModified(TEST_DIR.resolve("foo").resolve("file.txt")));
+ assertEquals(200, res1.statusCode());
+ assertEquals("foo", res1.body());
+ assertEquals("text/plain", res1.headers().firstValue("content-type").get());
+ assertEquals(Long.toString(3L), res1.headers().firstValue("content-length").get());
+ assertEquals(getLastModified(TEST_DIR.resolve("foo").resolve("file.txt")), res1.headers().firstValue("last-modified").get());
var req2 = HttpRequest.newBuilder(uri(server, "/foobar/")).build();
var res2 = client.send(req2, BodyHandlers.ofString());
- assertEquals(res2.statusCode(), 404); // handler prevents mapping to /foo/bar
+ assertEquals(404, res2.statusCode()); // handler prevents mapping to /foo/bar
var req3 = HttpRequest.newBuilder(uri(server, "/foobar/file.txt")).build();
var res3 = client.send(req3, BodyHandlers.ofString());
- assertEquals(res3.statusCode(), 404); // handler prevents mapping to /foo/bar/file.txt
+ assertEquals(404, res3.statusCode()); // handler prevents mapping to /foo/bar/file.txt
var req4 = HttpRequest.newBuilder(uri(server, "/file.txt")).build();
var res4 = client.send(req4, BodyHandlers.ofString());
- assertEquals(res4.statusCode(), 404);
+ assertEquals(404, res4.statusCode());
var req5 = HttpRequest.newBuilder(uri(server, "/foo/bar")).build();
var res5 = client.send(req5, BodyHandlers.ofString());
- assertEquals(res5.statusCode(), 301); // redirect
- assertEquals(res5.headers().firstValue("content-length").get(), "0");
- assertEquals(res5.headers().firstValue("location").get(), "/foo/bar/");
+ assertEquals(301, res5.statusCode()); // redirect
+ assertEquals("0", res5.headers().firstValue("content-length").get());
+ assertEquals("/foo/bar/", res5.headers().firstValue("location").get());
var req6 = HttpRequest.newBuilder(uri(server, "/foo")).build();
var res6 = client.send(req6, BodyHandlers.ofString());
- assertEquals(res6.statusCode(), 301); // redirect
- assertEquals(res6.headers().firstValue("content-length").get(), "0");
- assertEquals(res6.headers().firstValue("location").get(), "/foo/");
+ assertEquals(301, res6.statusCode()); // redirect
+ assertEquals("0", res6.headers().firstValue("content-length").get());
+ assertEquals("/foo/", res6.headers().firstValue("location").get());
} finally {
server.stop(0);
}
@@ -276,7 +277,7 @@ public class MapToPathTest {
try {
var req1 = HttpRequest.newBuilder(uri(server, "/foo/bar/c:/baz/")).build();
var res1 = client.send(req1, BodyHandlers.ofString());
- assertEquals(res1.statusCode(), 404); // not found
+ assertEquals(404, res1.statusCode()); // not found
} finally {
server.stop(0);
}
@@ -303,32 +304,32 @@ public class MapToPathTest {
out.println("uri.Path=" + uriPath);
var req1 = HttpRequest.newBuilder(uri(server, uriPath)).build();
var res1 = client.send(req1, BodyHandlers.ofString());
- assertEquals(res1.statusCode(), 200);
- assertEquals(res1.body(), "root response body");
+ assertEquals(200, res1.statusCode());
+ assertEquals("root response body", res1.body());
}
{
var req1 = HttpRequest.newBuilder(uri(server, "/foo/file.txt")).build();
var res1 = client.send(req1, BodyHandlers.ofString());
- assertEquals(res1.statusCode(), 200);
- assertEquals(res1.body(), "foo");
+ assertEquals(200, res1.statusCode());
+ assertEquals("foo", res1.body());
var req2 = HttpRequest.newBuilder(uri(server, "/foo/bar/baz/file.txt")).build();
var res2 = client.send(req2, BodyHandlers.ofString());
- assertEquals(res2.statusCode(), 200);
- assertEquals(res2.body(), "foo/bar/baz");
+ assertEquals(200, res2.statusCode());
+ assertEquals("foo/bar/baz", res2.body());
}
{
var req1 = HttpRequest.newBuilder(uri(server, "/foobar/file.txt")).build();
var res1 = client.send(req1, BodyHandlers.ofString());
- assertEquals(res1.statusCode(), 200);
- assertEquals(res1.body(), "foobar");
+ assertEquals(200, res1.statusCode());
+ assertEquals("foobar", res1.body());
}
for (String uriPath : List.of("/bar/", "/bar/t", "/bar/t/z", "/bar/index.html") ) {
out.println("uri.Path=" + uriPath);
var req1 = HttpRequest.newBuilder(uri(server, uriPath)).build();
var res1 = client.send(req1, BodyHandlers.ofString());
- assertEquals(res1.statusCode(), 200);
- assertEquals(res1.body(), "bar response body");
+ assertEquals(200, res1.statusCode());
+ assertEquals("bar response body", res1.body());
}
} finally {
server.stop(0);
@@ -347,18 +348,18 @@ public class MapToPathTest {
out.println("uri.Query=" + query);
var req = HttpRequest.newBuilder(uri(server, "", query)).build();
var res = client.send(req, BodyHandlers.ofString());
- assertEquals(res.statusCode(), 200);
- assertEquals(res.headers().firstValue("content-type").get(), "text/html; charset=UTF-8");
- assertEquals(res.headers().firstValue("content-length").get(), Long.toString(257L));
- assertEquals(res.headers().firstValue("last-modified").get(), getLastModified(TEST_DIR));
+ assertEquals(200, res.statusCode());
+ assertEquals("text/html; charset=UTF-8", res.headers().firstValue("content-type").get());
+ assertEquals(Long.toString(257L), res.headers().firstValue("content-length").get());
+ assertEquals(getLastModified(TEST_DIR), res.headers().firstValue("last-modified").get());
}
} finally {
server.stop(0);
}
}
- @AfterTest
- public void teardown() throws IOException {
+ @AfterAll
+ public static void teardown() throws IOException {
if (Files.exists(TEST_DIR)) {
FileUtils.deleteFileTreeWithRetry(TEST_DIR);
}
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/OutputFilterTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/OutputFilterTest.java
index b7583ea901b..bed4b8e2f3d 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/OutputFilterTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/OutputFilterTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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 @@
* @modules java.base/sun.net.www:+open
* @library /test/lib
* @build jdk.test.lib.net.URIBuilder
- * @run testng/othervm -Djdk.httpclient.redirects.retrylimit=1 OutputFilterTest
+ * @run junit/othervm -Djdk.httpclient.redirects.retrylimit=1 OutputFilterTest
*/
import java.io.ByteArrayOutputStream;
@@ -53,15 +53,17 @@ import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.SimpleFileServer;
import com.sun.net.httpserver.SimpleFileServer.OutputLevel;
import jdk.test.lib.net.URIBuilder;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
import static java.net.http.HttpClient.Builder.NO_PROXY;
import static java.nio.charset.StandardCharsets.*;
import static com.sun.net.httpserver.SimpleFileServer.OutputLevel.*;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertThrows;
-import static org.testng.Assert.assertTrue;
+
+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 org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
public class OutputFilterTest {
static final Class NPE = NullPointerException.class;
@@ -74,8 +76,8 @@ public class OutputFilterTest {
static final boolean ENABLE_LOGGING = true;
static final Logger logger = Logger.getLogger("com.sun.net.httpserver");
- @BeforeTest
- public void setup() {
+ @BeforeAll
+ public static void setup() {
if (ENABLE_LOGGING) {
ConsoleHandler ch = new ConsoleHandler();
logger.setLevel(Level.ALL);
@@ -94,10 +96,10 @@ public class OutputFilterTest {
@Test
public void testDescription() {
var filter = SimpleFileServer.createOutputFilter(OUT, VERBOSE);
- assertEquals(filter.description(), "HttpExchange OutputFilter (outputLevel: VERBOSE)");
+ assertEquals("HttpExchange OutputFilter (outputLevel: VERBOSE)", filter.description());
filter = SimpleFileServer.createOutputFilter(OUT, INFO);
- assertEquals(filter.description(), "HttpExchange OutputFilter (outputLevel: INFO)");
+ assertEquals("HttpExchange OutputFilter (outputLevel: INFO)", filter.description());
}
@Test
@@ -120,9 +122,9 @@ public class OutputFilterTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().map().size(), 3);
- assertEquals(response.body(), "hello world");
+ assertEquals(200, response.statusCode());
+ assertEquals(3, response.headers().map().size());
+ assertEquals("hello world", response.body());
} finally {
server.stop(0);
baos.flush();
@@ -172,9 +174,9 @@ public class OutputFilterTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().map().size(), 2);
- assertEquals(response.body(), "hello world");
+ assertEquals(200, response.statusCode());
+ assertEquals(2, response.headers().map().size());
+ assertEquals("hello world", response.body());
} finally {
server.stop(0);
baos.flush();
@@ -207,8 +209,7 @@ public class OutputFilterTest {
}
}
- @DataProvider
- public Object[][] throwingHandler() {
+ public static Object[][] throwingHandler() {
return new Object[][] {
{VERBOSE, "Error: server exchange handling failed: IOE ThrowingHandler" + System.lineSeparator()},
{INFO, "Error: server exchange handling failed: IOE ThrowingHandler" + System.lineSeparator()},
@@ -223,7 +224,8 @@ public class OutputFilterTest {
* prevent retries on the client side, which would result in more than one
* error message.
*/
- @Test(dataProvider = "throwingHandler")
+ @ParameterizedTest
+ @MethodSource("throwingHandler")
public void testExchangeThrowingHandler(OutputLevel level,
String expectedOutput) throws Exception {
var baos = new ByteArrayOutputStream();
@@ -243,7 +245,7 @@ public class OutputFilterTest {
} finally {
server.stop(0);
baos.flush();
- assertEquals(baos.toString(UTF_8), expectedOutput);
+ assertEquals(expectedOutput, baos.toString(UTF_8));
}
}
@@ -264,8 +266,8 @@ public class OutputFilterTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "aFile\u0000.txt")).build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().map().size(), 3);
+ assertEquals(404, response.statusCode());
+ assertEquals(3, response.headers().map().size());
} finally {
server.stop(0);
baos.flush();
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/RequestTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/RequestTest.java
index cb740f4dd2a..5e29d7a3ddf 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/RequestTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/RequestTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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,7 +24,7 @@
/*
* @test
* @summary Tests for Request
- * @run testng RequestTest
+ * @run junit RequestTest
*/
import java.io.InputStream;
@@ -35,9 +35,10 @@ import java.util.AbstractMap;
import java.util.List;
import java.util.Map;
import com.sun.net.httpserver.*;
-import org.testng.annotations.Test;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertThrows;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.junit.jupiter.api.Test;
public class RequestTest {
@@ -46,8 +47,8 @@ public class RequestTest {
var headers = new Headers();
Request request = new TestHttpExchange(headers);
request = request.with("Foo", List.of("Bar"));
- assertEquals(request.getRequestHeaders().size(), 1);
- assertEquals(request.getRequestHeaders().get("Foo"), List.of("Bar"));
+ assertEquals(1, request.getRequestHeaders().size());
+ assertEquals(List.of("Bar"), request.getRequestHeaders().get("Foo"));
assertReadOnly(request.getRequestHeaders());
}
@@ -57,9 +58,9 @@ public class RequestTest {
headers.add("Foo", "Bar");
Request request = new TestHttpExchange(headers);
request = request.with("X-Foo", List.of("Bar"));
- assertEquals(request.getRequestHeaders().size(), 2);
- assertEquals(request.getRequestHeaders().get("Foo"), List.of("Bar"));
- assertEquals(request.getRequestHeaders().get("X-Foo"), List.of("Bar"));
+ assertEquals(2, request.getRequestHeaders().size());
+ assertEquals(List.of("Bar"), request.getRequestHeaders().get("Foo"));
+ assertEquals(List.of("Bar"), request.getRequestHeaders().get("X-Foo"));
assertReadOnly(request.getRequestHeaders());
}
@@ -70,8 +71,8 @@ public class RequestTest {
headers.add(headerName, "Bar");
Request request = new TestHttpExchange(headers);
request = request.with(headerName, List.of("blahblahblah"));
- assertEquals(request.getRequestHeaders().size(), 1);
- assertEquals(request.getRequestHeaders().get(headerName), List.of("Bar"));
+ assertEquals(1, request.getRequestHeaders().size());
+ assertEquals(List.of("Bar"), request.getRequestHeaders().get(headerName));
assertReadOnly(request.getRequestHeaders());
}
@@ -83,11 +84,11 @@ public class RequestTest {
request = request.with("Larry", List.of("a"))
.with("Curly", List.of("b"))
.with("Moe", List.of("c"));
- assertEquals(request.getRequestHeaders().size(), 4);
- assertEquals(request.getRequestHeaders().getFirst("Foo"), "Bar");
- assertEquals(request.getRequestHeaders().getFirst("Larry"), "a");
- assertEquals(request.getRequestHeaders().getFirst("Curly"), "b");
- assertEquals(request.getRequestHeaders().getFirst("Moe" ), "c");
+ assertEquals(4, request.getRequestHeaders().size());
+ assertEquals("Bar", request.getRequestHeaders().getFirst("Foo"));
+ assertEquals("a", request.getRequestHeaders().getFirst("Larry"));
+ assertEquals("b", request.getRequestHeaders().getFirst("Curly"));
+ assertEquals("c", request.getRequestHeaders().getFirst("Moe" ));
assertReadOnly(request.getRequestHeaders());
}
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/ServerMimeTypesResolutionTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/ServerMimeTypesResolutionTest.java
index baa7d17b505..dff0eb8c1d1 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/ServerMimeTypesResolutionTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/ServerMimeTypesResolutionTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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
@@ -39,14 +39,14 @@ import java.util.stream.Collectors;
import jdk.test.lib.net.URIBuilder;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.SimpleFileServer;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
import sun.net.www.MimeTable;
import static java.net.http.HttpClient.Builder.NO_PROXY;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
/*
* @test
@@ -54,7 +54,7 @@ import static org.testng.Assert.assertTrue;
* @modules java.base/sun.net.www:+open
* @library /test/lib
* @build jdk.test.lib.net.URIBuilder
- * @run testng/othervm ServerMimeTypesResolutionTest
+ * @run junit/othervm ServerMimeTypesResolutionTest
*/
public class ServerMimeTypesResolutionTest {
@@ -70,8 +70,8 @@ public class ServerMimeTypesResolutionTest {
static final boolean ENABLE_LOGGING = true;
static final Logger LOGGER = Logger.getLogger("com.sun.net.httpserver");
- @BeforeTest
- public void setup() throws Exception {
+ @BeforeAll
+ public static void setup() throws Exception {
if (ENABLE_LOGGING) {
ConsoleHandler ch = new ConsoleHandler();
LOGGER.setLevel(Level.ALL);
@@ -139,7 +139,7 @@ public class ServerMimeTypesResolutionTest {
}
@Test
- public static void testMimeTypeHeaders() throws Exception {
+ public void testMimeTypeHeaders() throws Exception {
final var server = SimpleFileServer.createFileServer(LOOPBACK_ADDR, root, SimpleFileServer.OutputLevel.VERBOSE);
server.start();
try {
@@ -163,8 +163,8 @@ public class ServerMimeTypesResolutionTest {
final var uri = uri(server, toFileName(extension));
final var request = HttpRequest.newBuilder(uri).build();
final var response = client.send(request, HttpResponse.BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().firstValue("content-type").get(),expectedMimeType);
+ assertEquals(200, response.statusCode());
+ assertEquals(expectedMimeType, response.headers().firstValue("content-type").get());
}
static URI uri(HttpServer server, String path) {
@@ -176,7 +176,6 @@ public class ServerMimeTypesResolutionTest {
.buildUnchecked();
}
- @DataProvider
public static Object[][] commonExtensions() {
Set extensions = Set.of(".aac", ".abw", ".arc", ".avi", ".azw", ".bin", ".bmp", ".bz",
".bz2", ".csh", ".css", ".csv", ".doc", ".docx",".eot", ".epub", ".gz", ".gif", ".htm", ".html", ".ico",
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/SimpleFileServerTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/SimpleFileServerTest.java
index 167fcd3b5d3..104b4ea0cbe 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/SimpleFileServerTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/SimpleFileServerTest.java
@@ -26,7 +26,7 @@
* @summary Tests for SimpleFileServer
* @library /test/lib
* @build jdk.test.lib.Platform jdk.test.lib.net.URIBuilder
- * @run testng/othervm SimpleFileServerTest
+ * @run junit/othervm SimpleFileServerTest
*/
import java.io.IOException;
@@ -52,15 +52,17 @@ import com.sun.net.httpserver.SimpleFileServer.OutputLevel;
import jdk.test.lib.Platform;
import jdk.test.lib.net.URIBuilder;
import jdk.test.lib.util.FileUtils;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-import org.testng.SkipException;
import static java.net.http.HttpClient.Builder.NO_PROXY;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.StandardOpenOption.CREATE;
-import static org.testng.Assert.*;
+
+import org.junit.jupiter.api.AfterAll;
+import static org.junit.jupiter.api.Assertions.*;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
public class SimpleFileServerTest {
@@ -78,8 +80,8 @@ public class SimpleFileServerTest {
static final String EXPECTED_LAST_MODIFIED_OF_FAVICON = "Mon, 23 May 1995 11:11:11 GMT";
- @BeforeTest
- public void setup() throws IOException {
+ @BeforeAll
+ public static void setup() throws IOException {
if (ENABLE_LOGGING) {
ConsoleHandler ch = new ConsoleHandler();
LOGGER.setLevel(Level.ALL);
@@ -105,11 +107,11 @@ public class SimpleFileServerTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "aFile.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.body(), "some text");
- assertEquals(response.headers().firstValue("content-type").get(), "text/plain");
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.headers().firstValue("last-modified").get(), lastModified);
+ assertEquals(200, response.statusCode());
+ assertEquals("some text", response.body());
+ assertEquals("text/plain", response.headers().firstValue("content-type").get());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(lastModified, response.headers().firstValue("last-modified").get());
} finally {
server.stop(0);
}
@@ -134,11 +136,11 @@ public class SimpleFileServerTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().firstValue("content-type").get(), "text/html; charset=UTF-8");
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.headers().firstValue("last-modified").get(), lastModified);
- assertEquals(response.body(), expectedBody);
+ assertEquals(200, response.statusCode());
+ assertEquals("text/html; charset=UTF-8", response.headers().firstValue("content-type").get());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(lastModified, response.headers().firstValue("last-modified").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
}
@@ -155,9 +157,9 @@ public class SimpleFileServerTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "favicon.ico")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().firstValue("content-type").get(), "image/x-icon");
- assertEquals(response.headers().firstValue("last-modified").get(), EXPECTED_LAST_MODIFIED_OF_FAVICON);
+ assertEquals(200, response.statusCode());
+ assertEquals("image/x-icon", response.headers().firstValue("content-type").get());
+ assertEquals(EXPECTED_LAST_MODIFIED_OF_FAVICON, response.headers().firstValue("last-modified").get());
// expect custom (and broken) icon
var file = Files.writeString(root.resolve("favicon.ico"), "broken icon", CREATE);
@@ -165,19 +167,19 @@ public class SimpleFileServerTest {
var lastModified = getLastModified(file);
var expectedLength = Long.toString(Files.size(file));
response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().firstValue("content-type").get(), "application/octet-stream");
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.headers().firstValue("last-modified").get(), lastModified);
+ assertEquals(200, response.statusCode());
+ assertEquals("application/octet-stream", response.headers().firstValue("content-type").get());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(lastModified, response.headers().firstValue("last-modified").get());
} finally {
Files.delete(file);
}
// expect built-in icon
response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().firstValue("content-type").get(), "image/x-icon");
- assertEquals(response.headers().firstValue("last-modified").get(), EXPECTED_LAST_MODIFIED_OF_FAVICON);
+ assertEquals(200, response.statusCode());
+ assertEquals("image/x-icon", response.headers().firstValue("content-type").get());
+ assertEquals(EXPECTED_LAST_MODIFIED_OF_FAVICON, response.headers().firstValue("last-modified").get());
} finally {
server.stop(0);
}
@@ -194,10 +196,10 @@ public class SimpleFileServerTest {
var request = HttpRequest.newBuilder(uri(server, "favicon.ico"))
.method("HEAD", BodyPublishers.noBody()).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().firstValue("content-type").get(), "image/x-icon");
- assertEquals(response.headers().firstValue("last-modified").get(), EXPECTED_LAST_MODIFIED_OF_FAVICON);
- assertEquals(response.body(), "");
+ assertEquals(200, response.statusCode());
+ assertEquals("image/x-icon", response.headers().firstValue("content-type").get());
+ assertEquals(EXPECTED_LAST_MODIFIED_OF_FAVICON, response.headers().firstValue("last-modified").get());
+ assertEquals("", response.body());
} finally {
server.stop(0);
}
@@ -217,11 +219,11 @@ public class SimpleFileServerTest {
var request = HttpRequest.newBuilder(uri(server, "aFile.txt"))
.method("HEAD", BodyPublishers.noBody()).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().firstValue("content-type").get(), "text/plain");
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.headers().firstValue("last-modified").get(), lastModified);
- assertEquals(response.body(), "");
+ assertEquals(200, response.statusCode());
+ assertEquals("text/plain", response.headers().firstValue("content-type").get());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(lastModified, response.headers().firstValue("last-modified").get());
+ assertEquals("", response.body());
} finally {
server.stop(0);
}
@@ -247,18 +249,17 @@ public class SimpleFileServerTest {
var request = HttpRequest.newBuilder(uri(server, ""))
.method("HEAD", BodyPublishers.noBody()).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().firstValue("content-type").get(), "text/html; charset=UTF-8");
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.headers().firstValue("last-modified").get(), lastModified);
- assertEquals(response.body(), "");
+ assertEquals(200, response.statusCode());
+ assertEquals("text/html; charset=UTF-8", response.headers().firstValue("content-type").get());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(lastModified, response.headers().firstValue("last-modified").get());
+ assertEquals("", response.body());
} finally {
server.stop(0);
}
}
- @DataProvider
- public Object[][] indexFiles() {
+ public static Object[][] indexFiles() {
var fileContent = openHTML + """
This is an index file
""" + closeHTML;
@@ -274,7 +275,8 @@ public class SimpleFileServerTest {
};
}
- @Test(dataProvider = "indexFiles")
+ @ParameterizedTest
+ @MethodSource("indexFiles")
public void testDirectoryWithIndexGET(String id,
String filename,
String contentType,
@@ -294,11 +296,11 @@ public class SimpleFileServerTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().firstValue("content-type").get(), contentType);
- assertEquals(response.headers().firstValue("content-length").get(), contentLength);
- assertEquals(response.headers().firstValue("last-modified").get(), lastModified);
- assertEquals(response.body(), expectedBody);
+ assertEquals(200, response.statusCode());
+ assertEquals(contentType, response.headers().firstValue("content-type").get());
+ assertEquals(contentLength, response.headers().firstValue("content-length").get());
+ assertEquals(lastModified, response.headers().firstValue("last-modified").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
if (serveIndexFile) {
@@ -309,9 +311,7 @@ public class SimpleFileServerTest {
@Test
public void testNotReadableFileGET() throws Exception {
- if (Platform.isWindows()) {
- throw new SkipException("Not applicable on Windows");
- }
+ Assumptions.assumeFalse(Platform.isWindows(), "Not applicable on Windows");
var expectedBody = openHTML + """
File not found
/aFile.txt
@@ -329,9 +329,9 @@ public class SimpleFileServerTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "aFile.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
file.toFile().setReadable(true, false);
@@ -340,9 +340,7 @@ public class SimpleFileServerTest {
@Test
public void testNotReadableSegmentGET() throws Exception {
- if (Platform.isWindows()) {
- throw new SkipException("Not applicable on Windows");
- }
+ Assumptions.assumeFalse(Platform.isWindows(), "Not applicable on Windows");
var expectedBody = openHTML + """
File not found
/dir/aFile.txt
@@ -362,9 +360,9 @@ public class SimpleFileServerTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "dir/aFile.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
dir.toFile().setReadable(true, false);
@@ -386,9 +384,9 @@ public class SimpleFileServerTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "aFile?#.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
}
@@ -409,9 +407,9 @@ public class SimpleFileServerTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "doesNotExist.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
}
@@ -433,9 +431,9 @@ public class SimpleFileServerTest {
var request = HttpRequest.newBuilder(uri(server, "doesNotExist.txt"))
.method("HEAD", BodyPublishers.noBody()).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), "");
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals("", response.body());
} finally {
server.stop(0);
}
@@ -459,9 +457,9 @@ public class SimpleFileServerTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "symlink")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
}
@@ -486,21 +484,21 @@ public class SimpleFileServerTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "symlink/aFile.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
}
}
- private void createSymLink(Path symlink, Path target) {
+ private static void createSymLink(Path symlink, Path target) {
try {
Files.createSymbolicLink(symlink, target);
} catch (UnsupportedOperationException uoe) {
- throw new SkipException("sym link creation not supported", uoe);
+ Assumptions.abort("sym link creation not supported");
} catch (IOException ioe) {
- throw new SkipException("probably insufficient privileges to create sym links (Windows)", ioe);
+ Assumptions.abort("probably insufficient privileges to create sym links (Windows)");
}
}
@@ -523,9 +521,9 @@ public class SimpleFileServerTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, fileName)).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
}
@@ -547,15 +545,15 @@ public class SimpleFileServerTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, ".hiddenDirectory/aFile.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
}
}
- private Path createHiddenFile(Path root) throws IOException {
+ private static Path createHiddenFile(Path root) throws IOException {
Path file;
if (Platform.isWindows()) {
file = Files.createFile(root.resolve("aFile.txt"));
@@ -567,7 +565,7 @@ public class SimpleFileServerTest {
return file;
}
- private Path createFileInHiddenDirectory(Path root) throws IOException {
+ private static Path createFileInHiddenDirectory(Path root) throws IOException {
Path dir;
Path file;
if (Platform.isWindows()) {
@@ -602,17 +600,17 @@ public class SimpleFileServerTest {
var uri = uri(server, "aDirectory");
var request = HttpRequest.newBuilder(uri).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 301);
- assertEquals(response.headers().firstValue("content-length").get(), "0");
- assertEquals(response.headers().firstValue("location").get(), "/aDirectory/");
+ assertEquals(301, response.statusCode());
+ assertEquals("0", response.headers().firstValue("content-length").get());
+ assertEquals("/aDirectory/", response.headers().firstValue("location").get());
// tests that query component is preserved during redirect
var uri2 = uri(server, "aDirectory", "query");
var req2 = HttpRequest.newBuilder(uri2).build();
var res2 = client.send(req2, BodyHandlers.ofString());
- assertEquals(res2.statusCode(), 301);
- assertEquals(res2.headers().firstValue("content-length").get(), "0");
- assertEquals(res2.headers().firstValue("location").get(), "/aDirectory/?query");
+ assertEquals(301, res2.statusCode());
+ assertEquals("0", res2.headers().firstValue("content-length").get());
+ assertEquals("/aDirectory/?query", res2.headers().firstValue("location").get());
}
{ // tests that redirect to returned relative URI works
@@ -621,10 +619,10 @@ public class SimpleFileServerTest {
var uri = uri(server, "aDirectory");
var request = HttpRequest.newBuilder(uri).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.body(), expectedBody);
- assertEquals(response.headers().firstValue("content-type").get(), "text/html; charset=UTF-8");
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
+ assertEquals(200, response.statusCode());
+ assertEquals(expectedBody, response.body());
+ assertEquals("text/html; charset=UTF-8", response.headers().firstValue("content-type").get());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
}
} finally {
server.stop(0);
@@ -673,28 +671,26 @@ public class SimpleFileServerTest {
{ // not a directory
Path p = Files.createFile(TEST_DIR.resolve("aFile"));
assert !Files.isDirectory(p);
- var iae = expectThrows(IAE, () -> SimpleFileServer.createFileServer(addr, p, OutputLevel.INFO));
+ var iae = assertThrows(IAE, () -> SimpleFileServer.createFileServer(addr, p, OutputLevel.INFO));
assertTrue(iae.getMessage().contains("not a directory"));
}
{ // does not exist
Path p = TEST_DIR.resolve("doesNotExist");
assert !Files.exists(p);
- var iae = expectThrows(IAE, () -> SimpleFileServer.createFileServer(addr, p, OutputLevel.INFO));
+ var iae = assertThrows(IAE, () -> SimpleFileServer.createFileServer(addr, p, OutputLevel.INFO));
assertTrue(iae.getMessage().contains("does not exist"));
}
}
@Test
public void testNonReadablePath() throws Exception {
- if (Platform.isWindows()) {
- throw new SkipException("Not applicable on Windows");
- }
+ Assumptions.assumeFalse(Platform.isWindows(), "Not applicable on Windows");
var addr = LOOPBACK_ADDR;
Path p = Files.createDirectory(TEST_DIR.resolve("aDir"));
p.toFile().setReadable(false, false);
assert !Files.isReadable(p);
try {
- var iae = expectThrows(IAE, () -> SimpleFileServer.createFileServer(addr, p, OutputLevel.INFO));
+ var iae = assertThrows(IAE, () -> SimpleFileServer.createFileServer(addr, p, OutputLevel.INFO));
assertTrue(iae.getMessage().contains("not readable"));
} finally {
p.toFile().setReadable(true, false);
@@ -718,7 +714,7 @@ public class SimpleFileServerTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "beginDelim%3C%3EEndDelim")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
+ assertEquals(404, response.statusCode());
assertTrue(response.body().contains("beginDelim%3C%3EEndDelim"));
assertTrue(response.body().contains("File not found"));
} finally {
@@ -726,8 +722,8 @@ public class SimpleFileServerTest {
}
}
- @AfterTest
- public void teardown() throws IOException {
+ @AfterAll
+ public static void teardown() throws IOException {
if (Files.exists(TEST_DIR)) {
FileUtils.deleteFileTreeWithRetry(TEST_DIR);
}
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/StressDirListings.java b/test/jdk/com/sun/net/httpserver/simpleserver/StressDirListings.java
index 18a1f060c48..23442ab6b20 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/StressDirListings.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/StressDirListings.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2025, 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
* @summary Test to stress directory listings
* @library /test/lib
- * @run testng/othervm/timeout=180 StressDirListings
+ * @run junit/othervm/timeout=180 StressDirListings
*/
import java.io.IOException;
@@ -43,12 +43,13 @@ import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.SimpleFileServer;
import com.sun.net.httpserver.SimpleFileServer.OutputLevel;
import jdk.test.lib.net.URIBuilder;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
import static java.lang.System.out;
import static java.net.http.HttpClient.Builder.NO_PROXY;
-import static org.testng.Assert.assertEquals;
+
+import org.junit.jupiter.api.AfterAll;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
public class StressDirListings {
@@ -66,10 +67,10 @@ public class StressDirListings {
return String.format("[%d s, %d ms, %d ns] ", secs, mill, nan);
}
- HttpServer simpleFileServer;
+ static HttpServer simpleFileServer;
- @BeforeTest
- public void setup() throws IOException {
+ @BeforeAll
+ public static void setup() throws IOException {
out.println(now() + " creating server");
if (ENABLE_LOGGING) {
ConsoleHandler ch = new ConsoleHandler();
@@ -82,8 +83,8 @@ public class StressDirListings {
out.println(now() + " server started");
}
- @AfterTest
- public void teardown() {
+ @AfterAll
+ public static void teardown() {
out.println(now() + " stopping server");
simpleFileServer.stop(0);
out.println(now() + " server stopped");
@@ -105,7 +106,7 @@ public class StressDirListings {
var request = HttpRequest.newBuilder(uri(simpleFileServer)).build();
for (int i=0; iThis is an index file
""" + closeHTML;
@@ -212,7 +213,8 @@ public class ZipFileSystemTest {
};
}
- @Test(dataProvider = "indexFiles")
+ @ParameterizedTest
+ @MethodSource("indexFiles")
public void testDirectoryWithIndexGET(String id,
String filename,
String contentType,
@@ -232,11 +234,11 @@ public class ZipFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 200);
- assertEquals(response.headers().firstValue("content-type").get(), contentType);
- assertEquals(response.headers().firstValue("content-length").get(), contentLength);
- assertEquals(response.headers().firstValue("last-modified").get(), lastModified);
- assertEquals(response.body(), expectedBody);
+ assertEquals(200, response.statusCode());
+ assertEquals(contentType, response.headers().firstValue("content-type").get());
+ assertEquals(contentLength, response.headers().firstValue("content-length").get());
+ assertEquals(lastModified, response.headers().firstValue("last-modified").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
if (serveIndexFile) {
@@ -265,9 +267,9 @@ public class ZipFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "aFile?#.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
root.getFileSystem().close();
@@ -290,9 +292,9 @@ public class ZipFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "doesNotExist.txt")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), expectedBody);
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals(expectedBody, response.body());
} finally {
server.stop(0);
root.getFileSystem().close();
@@ -317,9 +319,9 @@ public class ZipFileSystemTest {
var request = HttpRequest.newBuilder(uri(server, "doesNotExist.txt"))
.method("HEAD", BodyPublishers.noBody()).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
- assertEquals(response.headers().firstValue("content-length").get(), expectedLength);
- assertEquals(response.body(), "");
+ assertEquals(404, response.statusCode());
+ assertEquals(expectedLength, response.headers().firstValue("content-length").get());
+ assertEquals("", response.body());
} finally {
server.stop(0);
root.getFileSystem().close();
@@ -339,9 +341,9 @@ public class ZipFileSystemTest {
var uri = uri(server, "aDirectory");
var request = HttpRequest.newBuilder(uri).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 301);
- assertEquals(response.headers().firstValue("content-length").get(), "0");
- assertEquals(response.headers().firstValue("location").get(), "/aDirectory/");
+ assertEquals(301, response.statusCode());
+ assertEquals("0", response.headers().firstValue("content-length").get());
+ assertEquals("/aDirectory/", response.headers().firstValue("location").get());
} finally {
server.stop(0);
root.getFileSystem().close();
@@ -366,7 +368,7 @@ public class ZipFileSystemTest {
var client = HttpClient.newBuilder().proxy(NO_PROXY).build();
var request = HttpRequest.newBuilder(uri(server, "beginDelim%3C%3EEndDelim")).build();
var response = client.send(request, BodyHandlers.ofString());
- assertEquals(response.statusCode(), 404);
+ assertEquals(404, response.statusCode());
assertTrue(response.body().contains("beginDelim%3C%3EEndDelim"));
assertTrue(response.body().contains("File not found"));
} finally {
@@ -376,8 +378,8 @@ public class ZipFileSystemTest {
}
}
- @AfterTest
- public void teardown() throws IOException {
+ @AfterAll
+ public static void teardown() throws IOException {
if (Files.exists(TEST_DIR)) {
FileUtils.deleteFileTreeWithRetry(TEST_DIR);
}
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/CommandLineNegativeTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/CommandLineNegativeTest.java
index da01b1542d8..22812ae0117 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/CommandLineNegativeTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/CommandLineNegativeTest.java
@@ -26,7 +26,7 @@
* @summary Negative tests for the jwebserver command-line tool
* @library /test/lib
* @modules jdk.httpserver
- * @run testng/othervm CommandLineNegativeTest
+ * @run junit/othervm CommandLineNegativeTest
*/
import java.io.IOException;
@@ -37,13 +37,14 @@ import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.util.FileUtils;
-import org.testng.SkipException;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
import static java.lang.System.out;
-import static org.testng.Assert.assertFalse;
+
+import org.junit.jupiter.api.AfterAll;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
public class CommandLineNegativeTest {
@@ -55,8 +56,8 @@ public class CommandLineNegativeTest {
static final Path TEST_FILE = TEST_DIR.resolve("file.txt");
static final String LOOPBACK_ADDR = InetAddress.getLoopbackAddress().getHostAddress();
- @BeforeTest
- public void setup() throws IOException {
+ @BeforeAll
+ public static void setup() throws IOException {
if (Files.exists(TEST_DIR)) {
FileUtils.deleteFileTreeWithRetry(TEST_DIR);
}
@@ -64,15 +65,15 @@ public class CommandLineNegativeTest {
Files.createFile(TEST_FILE);
}
- @DataProvider
- public Object[][] unknownOption() {
+ public static Object[][] unknownOption() {
return new Object[][] {
{"--unknownOption"},
{"null"}
};
}
- @Test(dataProvider = "unknownOption")
+ @ParameterizedTest
+ @MethodSource("unknownOption")
public void testBadOption(String opt) throws Throwable {
out.println("\n--- testUnknownOption, opt=\"%s\" ".formatted(opt));
simpleserver(JWEBSERVER, LOCALE_OPT, opt)
@@ -80,8 +81,7 @@ public class CommandLineNegativeTest {
.shouldContain("Error: unknown option: " + opt);
}
- @DataProvider
- public Object[][] tooManyOptionArgs() {
+ public static Object[][] tooManyOptionArgs() {
return new Object[][] {
{"-b", "localhost"},
{"-d", "/some/path"},
@@ -95,7 +95,8 @@ public class CommandLineNegativeTest {
};
}
- @Test(dataProvider = "tooManyOptionArgs")
+ @ParameterizedTest
+ @MethodSource("tooManyOptionArgs")
public void testTooManyOptionArgs(String opt, String arg) throws Throwable {
out.println("\n--- testTooManyOptionArgs, opt=\"%s\" ".formatted(opt));
simpleserver(JWEBSERVER, LOCALE_OPT, opt, arg, arg)
@@ -103,8 +104,7 @@ public class CommandLineNegativeTest {
.shouldContain("Error: unknown option: " + arg);
}
- @DataProvider
- public Object[][] noArg() {
+ public static Object[][] noArg() {
return new Object[][] {
{"-b", """
-b, --bind-address - Address to bind to. Default: %s (loopback).
@@ -122,7 +122,8 @@ public class CommandLineNegativeTest {
};
}
- @Test(dataProvider = "noArg")
+ @ParameterizedTest
+ @MethodSource("noArg")
public void testNoArg(String opt, String msg) throws Throwable {
out.println("\n--- testNoArg, opt=\"%s\" ".formatted(opt));
simpleserver(JWEBSERVER, LOCALE_OPT, opt)
@@ -131,8 +132,7 @@ public class CommandLineNegativeTest {
.shouldContain(msg);
}
- @DataProvider
- public Object[][] invalidValue() {
+ public static Object[][] invalidValue() {
return new Object[][] {
{"-b", "[127.0.0.1]"},
{"-b", "badhost"},
@@ -146,7 +146,8 @@ public class CommandLineNegativeTest {
};
}
- @Test(dataProvider = "invalidValue")
+ @ParameterizedTest
+ @MethodSource("invalidValue")
public void testInvalidValue(String opt, String val) throws Throwable {
out.println("\n--- testInvalidValue, opt=\"%s\" ".formatted(opt));
simpleserver(JWEBSERVER, LOCALE_OPT, opt, val)
@@ -154,10 +155,10 @@ public class CommandLineNegativeTest {
.shouldContain("Error: invalid value given for " + opt + ": " + val);
}
- @DataProvider
- public Object[][] portOptions() { return new Object[][] {{"-p"}, {"--port"}}; }
+ public static Object[][] portOptions() { return new Object[][] {{"-p"}, {"--port"}}; }
- @Test(dataProvider = "portOptions")
+ @ParameterizedTest
+ @MethodSource("portOptions")
public void testPortOutOfRange(String opt) throws Throwable {
out.println("\n--- testPortOutOfRange, opt=\"%s\" ".formatted(opt));
simpleserver(JWEBSERVER, LOCALE_OPT, opt, "65536") // range 0 to 65535
@@ -165,10 +166,10 @@ public class CommandLineNegativeTest {
.shouldContain("Error: server config failed: " + "port out of range:65536");
}
- @DataProvider
- public Object[][] directoryOptions() { return new Object[][] {{"-d"}, {"--directory"}}; }
+ public static Object[][] directoryOptions() { return new Object[][] {{"-d"}, {"--directory"}}; }
- @Test(dataProvider = "directoryOptions")
+ @ParameterizedTest
+ @MethodSource("directoryOptions")
public void testRootNotADirectory(String opt) throws Throwable {
out.println("\n--- testRootNotADirectory, opt=\"%s\" ".formatted(opt));
var file = TEST_FILE.toString();
@@ -178,7 +179,8 @@ public class CommandLineNegativeTest {
.shouldContain("Error: server config failed: " + "Path is not a directory: " + file);
}
- @Test(dataProvider = "directoryOptions")
+ @ParameterizedTest
+ @MethodSource("directoryOptions")
public void testRootDoesNotExist(String opt) throws Throwable {
out.println("\n--- testRootDoesNotExist, opt=\"%s\" ".formatted(opt));
Path root = TEST_DIR.resolve("not/existent/dir");
@@ -188,14 +190,12 @@ public class CommandLineNegativeTest {
.shouldContain("Error: server config failed: " + "Path does not exist: " + root.toString());
}
- @Test(dataProvider = "directoryOptions")
+ @ParameterizedTest
+ @MethodSource("directoryOptions")
public void testRootNotReadable(String opt) throws Throwable {
out.println("\n--- testRootNotReadable, opt=\"%s\" ".formatted(opt));
- if (Platform.isWindows()) {
- // Not applicable to Windows. Reason: cannot revoke an owner's read
- // access to a directory that was created by that owner
- throw new SkipException("cannot run on Windows");
- }
+ Assumptions.assumeFalse(Platform.isWindows(), "cannot run on Windows"); // Not applicable to Windows. Reason: cannot revoke an owner's read
+ // access to a directory that was created by that owner
Path root = Files.createDirectories(TEST_DIR.resolve("not/readable/dir"));
try {
root.toFile().setReadable(false, false);
@@ -208,8 +208,8 @@ public class CommandLineNegativeTest {
}
}
- @AfterTest
- public void teardown() throws IOException {
+ @AfterAll
+ public static void teardown() throws IOException {
if (Files.exists(TEST_DIR)) {
FileUtils.deleteFileTreeWithRetry(TEST_DIR);
}
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/CommandLinePortNotSpecifiedTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/CommandLinePortNotSpecifiedTest.java
index cd2ccbeded4..f6250d63908 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/CommandLinePortNotSpecifiedTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/CommandLinePortNotSpecifiedTest.java
@@ -27,7 +27,7 @@
* @summary Tests the jwebserver tool with port not specified
* @modules jdk.httpserver
* @library /test/lib
- * @run testng/othervm/manual CommandLinePortNotSpecifiedTest
+ * @run junit/othervm/manual CommandLinePortNotSpecifiedTest
*/
import java.io.IOException;
@@ -39,11 +39,12 @@ import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.util.FileUtils;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
import static java.lang.System.out;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
public class CommandLinePortNotSpecifiedTest {
static final Path JAVA_HOME = Path.of(System.getProperty("java.home"));
@@ -55,8 +56,8 @@ public class CommandLinePortNotSpecifiedTest {
static final String TEST_DIR_STR = TEST_DIR.toString();
static final String LOOPBACK_ADDR = InetAddress.getLoopbackAddress().getHostAddress();
- @BeforeTest
- public void setup() throws IOException {
+ @BeforeAll
+ public static void setup() throws IOException {
if (Files.exists(TEST_DIR)) {
FileUtils.deleteFileTreeWithRetry(TEST_DIR);
}
@@ -92,8 +93,8 @@ public class CommandLinePortNotSpecifiedTest {
.shouldContain("URL http://" + LOOPBACK_ADDR);
}
- @AfterTest
- public void teardown() throws IOException {
+ @AfterAll
+ public static void teardown() throws IOException {
if (Files.exists(TEST_DIR)) {
FileUtils.deleteFileTreeWithRetry(TEST_DIR);
}
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/CommandLinePositiveTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/CommandLinePositiveTest.java
index c0b0b4bc768..8110f5d9b10 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/CommandLinePositiveTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/CommandLinePositiveTest.java
@@ -27,7 +27,7 @@
* @library /test/lib
* @build jdk.test.lib.net.IPSupport
* @modules jdk.httpserver
- * @run testng/othervm CommandLinePositiveTest
+ * @run junit/othervm CommandLinePositiveTest
*/
import java.io.IOException;
@@ -41,12 +41,13 @@ import jdk.test.lib.net.IPSupport;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.util.FileUtils;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
import static java.lang.System.out;
+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;
+
public class CommandLinePositiveTest {
static final String JAVA_VERSION = System.getProperty("java.version");
@@ -84,8 +85,8 @@ public class CommandLinePositiveTest {
static final String LOOPBACK_ADDR = InetAddress.getLoopbackAddress().getHostAddress();
- @BeforeTest
- public void setup() throws IOException {
+ @BeforeAll
+ public static void setup() throws IOException {
if (Files.exists(ROOT_DIR)) {
FileUtils.deleteFileTreeWithRetry(ROOT_DIR);
}
@@ -105,16 +106,17 @@ public class CommandLinePositiveTest {
}
}
- @DataProvider
- public Object[][] directoryOptions() { return new Object[][] {{"-d"}, {"--directory"}}; }
+ public static Object[][] directoryOptions() { return new Object[][] {{"-d"}, {"--directory"}}; }
- @Test(dataProvider = "directoryOptions")
+ @ParameterizedTest
+ @MethodSource("directoryOptions")
public void testAbsDirectory(String opt) throws Throwable {
out.printf("\n--- testAbsDirectory, opt=\"%s\"%n", opt);
testDirectory(opt, ROOT_DIR_STR);
}
- @Test(dataProvider = "directoryOptions")
+ @ParameterizedTest
+ @MethodSource("directoryOptions")
public void testRelDirectory(String opt) throws Throwable {
out.printf("\n--- testRelDirectory, opt=\"%s\"%n", opt);
Path rootRelDir = CWD.relativize(ROOT_DIR);
@@ -129,10 +131,10 @@ public class CommandLinePositiveTest {
.shouldContain("URL http://" + LOOPBACK_ADDR);
}
- @DataProvider
- public Object[][] portOptions() { return new Object[][] {{"-p"}, {"--port"}}; }
+ public static Object[][] portOptions() { return new Object[][] {{"-p"}, {"--port"}}; }
- @Test(dataProvider = "portOptions")
+ @ParameterizedTest
+ @MethodSource("portOptions")
public void testPort(String opt) throws Throwable {
out.println("\n--- testPort, opt=\"%s\" ".formatted(opt));
simpleserver(JWEBSERVER, LOCALE_OPT, opt, "0")
@@ -142,8 +144,7 @@ public class CommandLinePositiveTest {
.shouldContain("URL http://" + LOOPBACK_ADDR);
}
- @DataProvider
- public Object[][] helpOptions() { return new Object[][] {{"-h"}, {"-?"}, {"--help"}}; }
+ public static Object[][] helpOptions() { return new Object[][] {{"-h"}, {"-?"}, {"--help"}}; }
static final String USAGE_TEXT = """
Usage: jwebserver [-b bind address] [-p port] [-d directory]
@@ -161,7 +162,8 @@ public class CommandLinePositiveTest {
-version, --version - Prints version information and exits.
To stop the server, press Ctrl + C.""".formatted(LOOPBACK_ADDR);
- @Test(dataProvider = "helpOptions")
+ @ParameterizedTest
+ @MethodSource("helpOptions")
public void testHelp(String opt) throws Throwable {
out.println("\n--- testHelp, opt=\"%s\" ".formatted(opt));
simpleserver(WaitForLine.HELP_STARTUP_LINE,
@@ -172,10 +174,10 @@ public class CommandLinePositiveTest {
.shouldContain(OPTIONS_TEXT);
}
- @DataProvider
- public Object[][] versionOptions() { return new Object[][] {{"-version"}, {"--version"}}; }
+ public static Object[][] versionOptions() { return new Object[][] {{"-version"}, {"--version"}}; }
- @Test(dataProvider = "versionOptions")
+ @ParameterizedTest
+ @MethodSource("versionOptions")
public void testVersion(String opt) throws Throwable {
out.println("\n--- testVersion, opt=\"%s\" ".formatted(opt));
simpleserver(WaitForLine.VERSION_STARTUP_LINE,
@@ -184,10 +186,10 @@ public class CommandLinePositiveTest {
.shouldHaveExitValue(0);
}
- @DataProvider
- public Object[][] bindOptions() { return new Object[][] {{"-b"}, {"--bind-address"}}; }
+ public static Object[][] bindOptions() { return new Object[][] {{"-b"}, {"--bind-address"}}; }
- @Test(dataProvider = "bindOptions")
+ @ParameterizedTest
+ @MethodSource("bindOptions")
public void testBindAllInterfaces(String opt) throws Throwable {
out.println("\n--- testBindAllInterfaces, opt=\"%s\" ".formatted(opt));
simpleserver(JWEBSERVER, LOCALE_OPT, "-p", "0", opt, "0.0.0.0")
@@ -202,7 +204,8 @@ public class CommandLinePositiveTest {
}
}
- @Test(dataProvider = "bindOptions")
+ @ParameterizedTest
+ @MethodSource("bindOptions")
public void testLastOneWinsBindAddress(String opt) throws Throwable {
out.println("\n--- testLastOneWinsBindAddress, opt=\"%s\" ".formatted(opt));
simpleserver(JWEBSERVER, LOCALE_OPT, "-p", "0", opt, "123.4.5.6", opt, LOOPBACK_ADDR)
@@ -212,7 +215,8 @@ public class CommandLinePositiveTest {
}
- @Test(dataProvider = "directoryOptions")
+ @ParameterizedTest
+ @MethodSource("directoryOptions")
public void testLastOneWinsDirectory(String opt) throws Throwable {
out.println("\n--- testLastOneWinsDirectory, opt=\"%s\" ".formatted(opt));
simpleserver(JWEBSERVER, LOCALE_OPT, "-p", "0", opt, CWD_STR, opt, CWD_STR)
@@ -222,10 +226,10 @@ public class CommandLinePositiveTest {
.shouldContain("URL http://" + LOOPBACK_ADDR);
}
- @DataProvider
- public Object[][] outputOptions() { return new Object[][] {{"-o"}, {"--output"}}; }
+ public static Object[][] outputOptions() { return new Object[][] {{"-o"}, {"--output"}}; }
- @Test(dataProvider = "outputOptions")
+ @ParameterizedTest
+ @MethodSource("outputOptions")
public void testLastOneWinsOutput(String opt) throws Throwable {
out.println("\n--- testLastOneWinsOutput, opt=\"%s\" ".formatted(opt));
simpleserver(JWEBSERVER, LOCALE_OPT, "-p", "0", opt, "none", opt, "verbose")
@@ -235,7 +239,8 @@ public class CommandLinePositiveTest {
.shouldContain("URL http://" + LOOPBACK_ADDR);
}
- @Test(dataProvider = "portOptions")
+ @ParameterizedTest
+ @MethodSource("portOptions")
public void testLastOneWinsPort(String opt) throws Throwable {
out.println("\n--- testLastOneWinsPort, opt=\"%s\" ".formatted(opt));
simpleserver(JWEBSERVER, LOCALE_OPT, opt, "-999", opt, "0")
@@ -245,8 +250,8 @@ public class CommandLinePositiveTest {
.shouldContain("URL http://" + LOOPBACK_ADDR);
}
- @AfterTest
- public void teardown() throws IOException {
+ @AfterAll
+ public static void teardown() throws IOException {
if (Files.exists(ROOT_DIR)) {
FileUtils.deleteFileTreeWithRetry(ROOT_DIR);
}
diff --git a/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/MaxRequestTimeTest.java b/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/MaxRequestTimeTest.java
index c972f87dc18..c19ca632bf3 100644
--- a/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/MaxRequestTimeTest.java
+++ b/test/jdk/com/sun/net/httpserver/simpleserver/jwebserver/MaxRequestTimeTest.java
@@ -27,7 +27,7 @@
* @summary Tests the jwebserver's maximum request time
* @modules jdk.httpserver
* @library /test/lib
- * @run testng/othervm MaxRequestTimeTest
+ * @run junit/othervm MaxRequestTimeTest
*/
import java.io.IOException;
@@ -47,12 +47,13 @@ import jdk.test.lib.net.SimpleSSLContext;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.util.FileUtils;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
import static java.lang.System.out;
import static java.net.http.HttpClient.Builder.NO_PROXY;
-import static org.testng.Assert.*;
+
+import org.junit.jupiter.api.AfterAll;
+import static org.junit.jupiter.api.Assertions.*;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
/**
* This test confirms that the jwebserver does not wait indefinitely for
@@ -78,18 +79,14 @@ public class MaxRequestTimeTest {
static final String LOOPBACK_ADDR = InetAddress.getLoopbackAddress().getHostAddress();
static final AtomicInteger PORT = new AtomicInteger();
- static SSLContext sslContext;
+ private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
- @BeforeTest
- public void setup() throws IOException {
+ @BeforeAll
+ public static void setup() throws IOException {
if (Files.exists(TEST_DIR)) {
FileUtils.deleteFileTreeWithRetry(TEST_DIR);
}
Files.createDirectories(TEST_DIR);
-
- sslContext = new SimpleSSLContext().get();
- if (sslContext == null)
- throw new AssertionError("Unexpected null sslContext");
}
@Test
@@ -122,17 +119,17 @@ public class MaxRequestTimeTest {