Add a test that can be used to validate local port bindings work
This test is disabled by default as it requires the use of a fixed local
port which cannot be relied upon in CI or other test environments.
diff --git a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ConnectionTest.java b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ConnectionTest.java
index 2fea4fc..44ff4e2 100644
--- a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ConnectionTest.java
+++ b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ConnectionTest.java
@@ -55,6 +55,7 @@
 import org.apache.qpid.protonj2.types.transport.ConnectionError;
 import org.apache.qpid.protonj2.types.transport.Role;
 import org.hamcrest.Matchers;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.Timeout;
 import org.slf4j.Logger;
@@ -1461,6 +1462,36 @@
         }
     }
 
+    @Disabled("Disabled due to requirement of hard coded port")
+    @Test
+    public void testLocalPortOption() throws Exception {
+        try (ProtonTestServer peer = new ProtonTestServer()) {
+            peer.expectSASLAnonymousConnect();
+            peer.expectOpen().respond();
+            peer.expectClose().respond();
+            peer.start();
+
+            URI remoteURI = peer.getServerURI();
+
+            LOG.info("Test started, peer listening on: {}", remoteURI);
+
+            final int localPort = 5671;
+
+            Client container = Client.create();
+            ConnectionOptions options = new ConnectionOptions();
+            options.transportOptions().localPort(localPort);
+            Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), options);
+
+            connection.openFuture().get();
+
+            assertEquals(localPort, peer.getConnectionRemotePort());
+
+            connection.close();
+
+            peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
+        }
+    }
+
     protected ProtonTestServerOptions testServerOptions() {
         return new ProtonTestServerOptions();
     }
diff --git a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/ProtonTestServer.java b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/ProtonTestServer.java
index fab6ad7..dfdfff0 100644
--- a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/ProtonTestServer.java
+++ b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/ProtonTestServer.java
@@ -109,6 +109,10 @@
         return server.getConnectionSSLEngine();
     }
 
+    public int getConnectionRemotePort() {
+        return server.getClientPort();
+    }
+
     @Override
     public AMQPTestDriver getDriver() {
         return driver;
diff --git a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/netty/NettyServer.java b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/netty/NettyServer.java
index 9004b9d..7ef2105 100644
--- a/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/netty/NettyServer.java
+++ b/protonj2-test-driver/src/main/java/org/apache/qpid/protonj2/test/driver/netty/NettyServer.java
@@ -23,6 +23,7 @@
 import java.net.URI;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
+import java.util.Objects;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -109,6 +110,15 @@
         return sslHandler != null;
     }
 
+    public boolean hasClientConnection() {
+        return clientChannel != null && clientChannel.isOpen();
+    }
+
+    public int getClientPort() {
+        Objects.requireNonNull(clientChannel);
+        return (((InetSocketAddress) clientChannel.remoteAddress()).getPort());
+    }
+
     public boolean isPeerVerified() {
         try {
             if (hasSecureConnection()) {