You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2021/06/03 16:20:03 UTC

[qpid-protonj2] branch main updated: PROTON-2393 Add support for providing a query string for the server URI

This is an automated email from the ASF dual-hosted git repository.

tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git


The following commit(s) were added to refs/heads/main by this push:
     new 3f5986c  PROTON-2393 Add support for providing a query string for the server URI
3f5986c is described below

commit 3f5986c0be6c13325e0c068170aa166be51206db
Author: Timothy Bish <ta...@gmail.com>
AuthorDate: Thu Jun 3 12:19:45 2021 -0400

    PROTON-2393 Add support for providing a query string for the server URI
    
    Allows a client to supply the query string that should be supplied when
    requesting a connection URI for the running test server.
---
 .../protonj2/test/driver/ProtonTestServer.java     | 36 +++++++++++++++++++++-
 .../protonj2/test/driver/netty/NettyServer.java    |  8 +++--
 .../protonj2/test/driver/ProtonTestServerTest.java | 32 +++++++++++++++++++
 3 files changed, 73 insertions(+), 3 deletions(-)

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 61e42cc..4f9e7aa 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
@@ -71,6 +71,9 @@ public class ProtonTestServer extends ProtonTestPeer {
         this.server = new NettyTestDriverServer(options);
     }
 
+    /**
+     * Starts the test server and allows acceptance of a new connection.
+     */
     public void start() {
         checkClosed();
         try {
@@ -80,10 +83,41 @@ public class ProtonTestServer extends ProtonTestPeer {
         }
     }
 
+    /**
+     * Returns a connection string that a client can use to connect to this AMQP test server with
+     * typical AMQP scheme values based on server configuration.  The values for the scheme follow the
+     * standard practice of 'amqp', 'amqps', 'amqpws' and 'amqpwss' for connection that use SSL or that
+     * provide WebSocket and secure WebSocket connections.
+     *
+     * The server nust be started prior to a call to this method.
+     *
+     * @return a URI that a client can use to connect to this remote test server.
+     *
+     * @throws IllegalStateException if the server is not started or has been shutdown.
+     */
     public URI getServerURI() {
+        return getServerURI(null);
+    }
+
+    /**
+     * Returns a connection string that a client can use to connect to this AMQP test server with
+     * typical AMQP scheme values based on server configuration.  The values for the scheme follow the
+     * standard practice of 'amqp', 'amqps', 'amqpws' and 'amqpwss' for connection that use SSL or that
+     * provide WebSocket and secure WebSocket connections.
+     *
+     * The server nust be started prior to a call to this method.
+     *
+     * @param query
+     * 		The value that should be populated in the URI query string segment.
+     *
+     * @return a URI that a client can use to connect to this remote test server.
+     *
+     * @throws IllegalStateException if the server is not started or has been shutdown.
+     */
+    public URI getServerURI(String query) {
         checkClosed();
         try {
-            return server.getConnectionURI();
+            return server.getConnectionURI(query);
         } catch (Exception e) {
             throw new RuntimeException("Failed to get connection URI: ", e);
         }
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 7ef2105..7525da7 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
@@ -167,7 +167,7 @@ public abstract class NettyServer implements AutoCloseable {
         return handshakeComplete;
     }
 
-    public URI getConnectionURI() throws Exception {
+    public URI getConnectionURI(String queryString) throws Exception {
         if (!started.get()) {
             throw new IllegalStateException("Cannot get URI of non-started server");
         }
@@ -197,7 +197,11 @@ public abstract class NettyServer implements AutoCloseable {
             path = null;
         }
 
-        return new URI(scheme, null, "localhost", port, path, null, null);
+        if (queryString != null && queryString.startsWith("?")) {
+            queryString = queryString.substring(1);
+        }
+
+        return new URI(scheme, null, "localhost", port, path, queryString, null);
     }
 
     public void start() throws Exception {
diff --git a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ProtonTestServerTest.java b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ProtonTestServerTest.java
index be46b38..13e9071 100644
--- a/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ProtonTestServerTest.java
+++ b/protonj2-test-driver/src/test/java/org/apache/qpid/protonj2/test/driver/ProtonTestServerTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.qpid.protonj2.test.driver;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -42,6 +43,37 @@ public class ProtonTestServerTest extends TestPeerTestsBase {
     }
 
     @Test
+    public void testSupplyQueryStringToServerGetURI() throws Exception {
+        doTestSupplyQueryStringToServerGetURI("param=value");
+    }
+
+    @Test
+    public void testSupplyQueryStringToServerGetURIWithLeadingQuestionMark() throws Exception {
+        doTestSupplyQueryStringToServerGetURI("?param=value");
+    }
+
+    @Test
+    public void testSupplyNullQueryStringToServerGetURI() throws Exception {
+        doTestSupplyQueryStringToServerGetURI(null);
+    }
+
+    private void doTestSupplyQueryStringToServerGetURI(String queryString) throws Exception {
+        try (ProtonTestServer peer = new ProtonTestServer()) {
+            peer.expectAMQPHeader().respondWithAMQPHeader();
+            peer.expectOpen().withFrameSize(4096);
+            peer.start();
+
+            final URI remoteURI = peer.getServerURI(queryString);
+
+            if (queryString != null && queryString.startsWith("?")) {
+                queryString = queryString.substring(1);
+            }
+
+            assertEquals(queryString, remoteURI.getQuery());
+        }
+    }
+
+    @Test
     public void testServerFailsTestIfFrameSizeExpectationNotMet() throws Exception {
         try (ProtonTestServer peer = new ProtonTestServer()) {
             peer.expectAMQPHeader().respondWithAMQPHeader();

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org