changeset 17385:8a8741cfb084

8163489: Avoid using Utils.getFreePort() in TsacertOptionTest.java test Reviewed-by: chegar
author weijun
date Wed, 10 Aug 2016 11:21:01 +0800
parents a670a92950d9
children 12c7305432b7
files test/sun/security/tools/jarsigner/TsacertOptionTest.java
diffstat 1 files changed, 23 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/test/sun/security/tools/jarsigner/TsacertOptionTest.java	Fri Jul 29 09:58:28 2016 -0700
+++ b/test/sun/security/tools/jarsigner/TsacertOptionTest.java	Wed Aug 10 11:21:01 2016 +0800
@@ -77,11 +77,6 @@
         Utils.createFiles(FILENAME);
         JarUtils.createJar(UNSIGNED_JARFILE, FILENAME);
 
-        // look for free network port for TSA service
-        int port = jdk.testlibrary.Utils.getFreePort();
-        String host = "127.0.0.1";
-        String tsaUrl = "http://" + host + ":" + port;
-
         // create key pair for jar signing
         ProcessTools.executeCommand(KEYTOOL,
                 "-genkey",
@@ -126,24 +121,30 @@
                 "-keypass", PASSWORD,
                 "-file", "cert").shouldHaveExitValue(0);
 
-        // create key pair for TSA service
-        // SubjectInfoAccess extension contains URL to TSA service
-        ProcessTools.executeCommand(KEYTOOL,
-                "-genkey",
-                "-v",
-                "-alias", TSA_KEY_ALIAS,
-                "-keyalg", KEY_ALG,
-                "-keysize", Integer.toString(KEY_SIZE),
-                "-keystore", KEYSTORE,
-                "-storepass", PASSWORD,
-                "-keypass", PASSWORD,
-                "-dname", "CN=TSA",
-                "-ext", "ExtendedkeyUsage:critical=timeStamping",
-                "-ext", "SubjectInfoAccess=timeStamping:URI:" + tsaUrl,
-                "-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);
 
-        try (TimestampCheck.Handler tsa = TimestampCheck.Handler.init(port,
-                KEYSTORE);) {
+        try (TimestampCheck.Handler tsa = TimestampCheck.Handler.init(0,
+                KEYSTORE)) {
+
+            // look for free network port for TSA service
+            int port = tsa.getPort();
+            String host = "127.0.0.1";
+            String tsaUrl = "http://" + host + ":" + port;
+
+            // create key pair for TSA service
+            // SubjectInfoAccess extension contains URL to TSA service
+            ProcessTools.executeCommand(KEYTOOL,
+                    "-genkey",
+                    "-v",
+                    "-alias", TSA_KEY_ALIAS,
+                    "-keyalg", KEY_ALG,
+                    "-keysize", Integer.toString(KEY_SIZE),
+                    "-keystore", KEYSTORE,
+                    "-storepass", PASSWORD,
+                    "-keypass", PASSWORD,
+                    "-dname", "CN=TSA",
+                    "-ext", "ExtendedkeyUsage:critical=timeStamping",
+                    "-ext", "SubjectInfoAccess=timeStamping:URI:" + tsaUrl,
+                    "-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);
 
             // start TSA
             tsa.start();