NIFI-8741 Changed JettyServerGroovyTest to use NetworkUtils.getAvailableTcpPort()

Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com>

This closes #5200.
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/test/groovy/org/apache/nifi/web/server/JettyServerGroovyTest.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/test/groovy/org/apache/nifi/web/server/JettyServerGroovyTest.groovy
index d00ed76..dc296a7 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/test/groovy/org/apache/nifi/web/server/JettyServerGroovyTest.groovy
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/test/groovy/org/apache/nifi/web/server/JettyServerGroovyTest.groovy
@@ -23,6 +23,7 @@
 import org.apache.nifi.nar.ExtensionMapping
 import org.apache.nifi.nar.SystemBundle
 import org.apache.nifi.processor.DataUnit
+import org.apache.nifi.remote.io.socket.NetworkUtils
 import org.apache.nifi.security.util.StandardTlsConfiguration
 import org.apache.nifi.security.util.TlsConfiguration
 import org.apache.nifi.security.util.TlsPlatform
@@ -49,7 +50,6 @@
 import org.junit.contrib.java.lang.system.SystemOutRule
 import org.junit.runner.RunWith
 import org.junit.runners.JUnit4
-import org.mockito.ArgumentCaptor
 import org.mockito.ArgumentMatchers
 import org.mockito.Mockito
 import org.mockito.invocation.InvocationOnMock
@@ -77,7 +77,10 @@
     @Rule
     public final SystemErrRule systemErrRule = new SystemErrRule().enableLog()
 
-    private static final int HTTPS_PORT = 8443
+    private static final int DEFAULT_HTTP_PORT = 8080
+    private static final int DEFAULT_HTTPS_PORT = 8443
+
+    private static final int HTTPS_PORT = NetworkUtils.getAvailableTcpPort()
     private static final String HTTPS_HOSTNAME = "localhost"
 
     private static final String KEYSTORE_PATH = "src/test/resources/keystore.jks"
@@ -139,8 +142,8 @@
                 (NiFiProperties.WEB_THREADS)   : NiFiProperties.DEFAULT_WEB_THREADS
         ]
         NiFiProperties mockProps = Mockito.mock(NiFiProperties.class)
-        Mockito.when(mockProps.getPort()).thenReturn(8080)
-        Mockito.when(mockProps.getSslPort()).thenReturn(8443)
+        Mockito.when(mockProps.getPort()).thenReturn(DEFAULT_HTTP_PORT)
+        Mockito.when(mockProps.getSslPort()).thenReturn(DEFAULT_HTTPS_PORT)
 
         Mockito.when(mockProps.getProperty(ArgumentMatchers.anyString())).thenAnswer(new Answer<Object>() {
             @Override
@@ -168,7 +171,7 @@
                 (NiFiProperties.WEB_HTTPS_HOST): null,
         ]
         NiFiProperties httpProps = [
-                getPort    : { -> 8080 },
+                getPort    : { -> DEFAULT_HTTP_PORT },
                 getSslPort : { -> null },
                 getProperty: { String prop ->
                     String value = httpMap[prop] ?: "no_value"
@@ -183,7 +186,7 @@
         ]
         NiFiProperties httpsProps = [
                 getPort    : { -> null },
-                getSslPort : { -> 8443 },
+                getSslPort : { -> DEFAULT_HTTPS_PORT },
                 getProperty: { String prop ->
                     String value = httpsMap[prop] ?: "no_value"
                     logger.mock("getProperty(${prop}) -> ${value}")
@@ -216,8 +219,8 @@
                 (NiFiProperties.WEB_HTTPS_HOST): "secure.host.com",
         ]
         NiFiProperties mockProps = [
-                getPort            : { -> 8080 },
-                getSslPort         : { -> 8443 },
+                getPort            : { -> DEFAULT_HTTP_PORT },
+                getSslPort         : { -> DEFAULT_HTTPS_PORT },
                 getProperty        : { String prop ->
                     String value = badProps[prop] ?: "no_value"
                     logger.mock("getProperty(${prop}) -> ${value}")
@@ -463,7 +466,7 @@
     void testShouldEnableContentLengthFilterIfWebMaxContentSizeSet() {
         // Arrange
         Map defaultProps = [
-                (NiFiProperties.WEB_HTTP_PORT)       : "8080",
+                (NiFiProperties.WEB_HTTP_PORT)       : DEFAULT_HTTP_PORT as String,
                 (NiFiProperties.WEB_HTTP_HOST)       : "localhost",
                 (NiFiProperties.WEB_MAX_CONTENT_SIZE): "1 MB",
         ]
@@ -507,7 +510,7 @@
     void testShouldNotEnableContentLengthFilterIfWebMaxContentSizeEmpty() {
         // Arrange
         Map defaultProps = [
-                (NiFiProperties.WEB_HTTP_PORT): "8080",
+                (NiFiProperties.WEB_HTTP_PORT): DEFAULT_HTTP_PORT as String,
                 (NiFiProperties.WEB_HTTP_HOST): "localhost",
         ]
         NiFiProperties mockProps = new NiFiProperties(new Properties(defaultProps))