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 2017/01/06 20:02:52 UTC

qpid-jms git commit: QPIDJMS-245 Add additional testing of the URI handling code

Repository: qpid-jms
Updated Branches:
  refs/heads/master 8485ada97 -> b2f137b09


QPIDJMS-245 Add additional testing of the URI handling code

Adds some additional tests and refines some others for better coverage.

Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/b2f137b0
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/b2f137b0
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/b2f137b0

Branch: refs/heads/master
Commit: b2f137b094b5709ccabc4e95018d287fecc773d0
Parents: 8485ada
Author: Timothy Bish <ta...@gmail.com>
Authored: Fri Jan 6 15:02:42 2017 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Fri Jan 6 15:02:42 2017 -0500

----------------------------------------------------------------------
 .../jms/integration/SaslIntegrationTest.java    |  21 +-
 .../apache/qpid/jms/util/PropertyUtilTest.java  | 258 ++++++++++++++-----
 .../apache/qpid/jms/util/URISupportTest.java    | 149 +++++++----
 3 files changed, 307 insertions(+), 121 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/b2f137b0/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SaslIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SaslIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SaslIntegrationTest.java
index c790457..8279316 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SaslIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SaslIntegrationTest.java
@@ -20,9 +20,14 @@
  */
 package org.apache.qpid.jms.integration;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
 import javax.jms.JMSException;
@@ -122,8 +127,20 @@ public class SaslIntegrationTest extends QpidJmsTestCase {
 
             // Expect a PLAIN connection with decoded password from URL encoded value.
             String user = "user";
-            String pass = "CN24tCa+Hn/av";
-            String encodedPass = "CN24tCa%2BHn%2Fav";
+            String pass = " CN24tCa+Hn/av";
+
+            // If double decoded this value results in " CN24tCa Hn/av" as the decoded plus
+            // becomes a valid encoding for a space character and would be removed.
+            String encodedPass = "+CN24tCa%2BHn%2Fav";
+
+            String urlEncodedPassword = URLEncoder.encode(pass, "UTF-8");
+            String urlDecodedPassword = URLDecoder.decode(pass, "UTF-8");
+
+            // Inadvertent double decoding of the password should result in a different value
+            // which would fail this test.
+            assertEquals(encodedPass, urlEncodedPassword);
+            assertFalse(urlEncodedPassword.equals(urlDecodedPassword));
+            assertFalse(pass.equals(urlDecodedPassword));
 
             testPeer.expectSaslPlain(user, pass);
             testPeer.expectOpen();

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/b2f137b0/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java
index 46ee509..7177ed9 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/PropertyUtilTest.java
@@ -167,6 +167,8 @@ public class PropertyUtilTest {
         new PropertyUtil();
     }
 
+    //----- replaceQuery -----------------------------------------------------//
+
     @Test
     public void testReplaceQueryUsingMap() throws URISyntaxException {
         URI original = new URI("http://www.example.com?option=true");
@@ -188,6 +190,108 @@ public class PropertyUtilTest {
     }
 
     @Test
+    public void testReplaceQueryPreservesFragment() throws URISyntaxException {
+        URI original = new URI("http://www.example.com?option=true#fragment");
+        URI updated = PropertyUtil.replaceQuery(original, "param=replaced");
+
+        assertEquals("param=replaced", updated.getQuery());
+        assertEquals("fragment", updated.getFragment());
+    }
+
+    @Test
+    public void testReplaceQueryPreservesFragmentWhenNoQueryPresent() throws URISyntaxException {
+        URI original = new URI("http://www.example.com#fragment");
+        URI updated = PropertyUtil.replaceQuery(original, "param=replaced");
+
+        assertEquals("param=replaced", updated.getQuery());
+        assertEquals("fragment", updated.getFragment());
+    }
+
+    @Test
+    public void testReplaceQueryWithStringDoesNotReencode() throws URISyntaxException {
+        URI original = new URI("http://www.example.com?option=X");
+
+        final String encodedValue = "%25Ca%2BHn%2Fav";
+        final String decodedValue = "%Ca+Hn/av";
+
+        final String encodedKey = "user%2Bname";
+        final String decodedKey = "user+name";
+
+        String newQuery = encodedKey + "=" + encodedValue;
+
+        URI updated = PropertyUtil.replaceQuery(original, newQuery);
+
+        assertEquals(encodedKey + "=" + encodedValue, updated.getRawQuery());
+        assertEquals(decodedKey + "=" + decodedValue, updated.getQuery());
+    }
+
+    @Test
+    public void testReplaceQueryUsingMapEncodesParameters() throws URISyntaxException {
+        URI original = new URI("http://www.example.com?option=X");
+
+        final String encodedValue = "%25Ca%2BHn%2Fav";
+        final String decodedValue = "%Ca+Hn/av";
+
+        final String encodedKey = "user%2Bname";
+        final String decodedKey = "user+name";
+
+        Map<String, String> newQuery = new HashMap<String, String>();
+        newQuery.put(decodedKey, decodedValue);
+
+        URI updated = PropertyUtil.replaceQuery(original, newQuery);
+
+        assertEquals(encodedKey + "=" + encodedValue, updated.getRawQuery());
+        assertEquals(decodedKey + "=" + decodedValue, updated.getQuery());
+    }
+
+    @Test
+    public void testReplaceQueryIgnoresQueryInCompositeURI() throws URISyntaxException {
+        URI original = new URI("failover:(amqp://example.com:5672?amqp.traceFrames=true)");
+        URI expected = new URI("failover:(amqp://example.com:5672?amqp.traceFrames=true)?failover.maxReconnectAttempts=1");
+        URI updated = PropertyUtil.replaceQuery(original, "failover.maxReconnectAttempts=1");
+
+        assertEquals(expected, updated);
+    }
+
+    @Test
+    public void testReplaceQueryIgnoresQueryAndFragmentInCompositeURI() throws URISyntaxException {
+        URI original = new URI("failover:(amqp://example.com:5672?amqp.traceFrames=true#ignored)");
+        URI expected = new URI("failover:(amqp://example.com:5672?amqp.traceFrames=true#ignored)?failover.maxReconnectAttempts=1");
+        URI updated = PropertyUtil.replaceQuery(original, "failover.maxReconnectAttempts=1");
+
+        assertEquals(expected, updated);
+    }
+
+    @Test
+    public void testReplaceQueryIgnoresQueryInCompositeURIPreservesFragment() throws URISyntaxException {
+        URI original = new URI("failover:(amqp://example.com:5672?amqp.traceFrames=true)#fragment");
+        URI expected = new URI("failover:(amqp://example.com:5672?amqp.traceFrames=true)?failover.maxReconnectAttempts=1#fragment");
+        URI updated = PropertyUtil.replaceQuery(original, "failover.maxReconnectAttempts=1");
+
+        assertEquals(expected, updated);
+    }
+
+    @Test
+    public void testReplaceQueryIgnoresQueryInCompositeURIReplaceExisting() throws URISyntaxException {
+        URI original = new URI("failover:(amqp://example.com:5672?amqp.traceFrames=true)?failover.maxReconnectAttempts=2");
+        URI expected = new URI("failover:(amqp://example.com:5672?amqp.traceFrames=true)?failover.maxReconnectAttempts=1");
+        URI updated = PropertyUtil.replaceQuery(original, "failover.maxReconnectAttempts=1");
+
+        assertEquals(expected, updated);
+    }
+
+    @Test
+    public void testReplaceQueryIgnoresQueryInCompositeURIReplaceExistingPreservesFragment() throws URISyntaxException {
+        URI original = new URI("failover:(amqp://example.com:5672?amqp.traceFrames=true)?failover.maxReconnectAttempts=2#fragment");
+        URI expected = new URI("failover:(amqp://example.com:5672?amqp.traceFrames=true)?failover.maxReconnectAttempts=1#fragment");
+        URI updated = PropertyUtil.replaceQuery(original, "failover.maxReconnectAttempts=1");
+
+        assertEquals(expected, updated);
+    }
+
+    //----- eraseQuery -------------------------------------------------------//
+
+    @Test
     public void testEraseQuery() throws URISyntaxException {
         URI original = new URI("http://www.example.com?option=true");
         URI updated = PropertyUtil.eraseQuery(original);
@@ -196,6 +300,44 @@ public class PropertyUtilTest {
     }
 
     @Test
+    public void testEraseQueryPreservesFragment() throws URISyntaxException {
+        URI original = new URI("http://www.example.com?option=true#fragment");
+        URI updated = PropertyUtil.eraseQuery(original);
+
+        assertNull(updated.getQuery());
+        assertEquals("fragment", updated.getFragment());
+    }
+
+    @Test
+    public void testEraseQueryPreservesFragmentWhenNoQueryPresent() throws URISyntaxException {
+        URI original = new URI("http://www.example.com#fragment");
+        URI updated = PropertyUtil.eraseQuery(original);
+
+        assertNull(updated.getQuery());
+        assertEquals("fragment", updated.getFragment());
+    }
+
+    @Test
+    public void testEraseQueryIgnoresQueryInCompositeURI() throws URISyntaxException {
+        URI original = new URI("failover:(amqp://example.com:5672?amqp.traceFrames=true)");
+        URI expected = new URI("failover:(amqp://example.com:5672?amqp.traceFrames=true)");
+        URI updated = PropertyUtil.eraseQuery(original);
+
+        assertEquals(expected, updated);
+    }
+
+    @Test
+    public void testEraseQueryIgnoresQueryAndFragmentInCompositeURI() throws URISyntaxException {
+        URI original = new URI("failover:(amqp://example.com:5672?amqp.traceFrames=true#ignored)?failover.maxReconnectAttempts=1");
+        URI expected = new URI("failover:(amqp://example.com:5672?amqp.traceFrames=true#ignored)");
+        URI updated = PropertyUtil.eraseQuery(original);
+
+        assertEquals(expected, updated);
+    }
+
+    //----- createQuery ------------------------------------------------------//
+
+    @Test
     public void testCreateQuery() throws URISyntaxException {
         Map<String, String> newQuery = new HashMap<String, String>();
         newQuery.put("param1", "value");
@@ -208,6 +350,25 @@ public class PropertyUtilTest {
     }
 
     @Test
+    public void testCreateQueryEncodesParameters() throws URISyntaxException {
+
+        final String encodedValue = "%25Ca%2BHn%2Fav";
+        final String decodedValue = "%Ca+Hn/av";
+
+        final String encodedKey = "user%2Bname";
+        final String decodedKey = "user+name";
+
+        Map<String, String> source = new HashMap<String, String>();
+        source.put(decodedKey, decodedValue);
+
+        String result = PropertyUtil.createQueryString(source);
+
+        assertEquals(encodedKey + "=" + encodedValue, result);
+    }
+
+    //----- parseQuery -------------------------------------------------------//
+
+    @Test
     public void testParseQueryFromURI() throws Exception {
         URI original = new URI("http://www.example.com?option=true&another=false");
         Map<String, String> result = PropertyUtil.parseQuery(original);
@@ -290,6 +451,22 @@ public class PropertyUtilTest {
         assertTrue(result.isEmpty());
     }
 
+    @Test
+    public void testParseQueryDecodesParameters() throws Exception {
+        URI original = new URI("http://www.example.com?user%2Bname=%25Ca%2BHn%2Fav");
+
+        final String decodedKey = "user+name";
+        final String decodedValue = "%Ca+Hn/av";
+
+        Map<String, String> result = PropertyUtil.parseQuery(original);
+
+        assertEquals(1, result.size());
+        assertTrue(result.containsKey(decodedKey));
+        assertEquals(decodedValue, result.get(decodedKey));
+    }
+
+    //----- filterProperties -------------------------------------------------//
+
     @Test(expected=IllegalArgumentException.class)
     public void testFilterPropertiesNullProperties() throws Exception {
         PropertyUtil.filterProperties(null, "option.");
@@ -313,6 +490,8 @@ public class PropertyUtilTest {
         assertEquals("false", result.get("filtered2"));
     }
 
+    //----- setProperties ----------------------------------------------------//
+
     @Test
     public void testSetProperties() throws Exception {
         Options configObject = new Options();
@@ -386,6 +565,8 @@ public class PropertyUtilTest {
         assertEquals("bar", configObject.getLastName());
     }
 
+    //----- getProperties ----------------------------------------------------//
+
     @Test
     public void testGetProperties() throws Exception {
         Options configObject = new Options("foo", "bar");
@@ -462,6 +643,8 @@ public class PropertyUtilTest {
         assertNull(result);
     }
 
+    //----- setProperty ------------------------------------------------------//
+
     @Test
     public void testSetProperty() throws Exception {
         Options configObject = new Options();
@@ -546,6 +729,8 @@ public class PropertyUtilTest {
         PropertyUtil.setProperties(new Options(), (Properties) null);
     }
 
+    //----- stripPrefix ------------------------------------------------------//
+
     @Test
     public void testStripPrefix() {
         String value = "prefixed.option";
@@ -565,6 +750,8 @@ public class PropertyUtilTest {
         assertNull(PropertyUtil.stripPrefix((String) null, "prefixed."));
     }
 
+    //----- stripBefore ------------------------------------------------------//
+
     @Test
     public void testStripBefore() {
         String value = "prefixed.option";
@@ -577,6 +764,8 @@ public class PropertyUtilTest {
         assertNull(PropertyUtil.stripBefore((String) null, '.'));
     }
 
+    //----- stripUpto ------------------------------------------------------//
+
     @Test
     public void testStripUpTo() {
         String value = "prefixed.option";
@@ -589,73 +778,4 @@ public class PropertyUtilTest {
         assertNull(PropertyUtil.stripUpto((String) null, '.'));
     }
 
-    //----- Tests for URI options that are URL Encoded -----------------------//
-
-    @Test
-    public void testReplaceQueryWithStringDoesNotReencode() throws URISyntaxException {
-        URI original = new URI("http://www.example.com?option=X");
-
-        final String encodedValue = "%25Ca%2BHn%2Fav";
-        final String decodedValue = "%Ca+Hn/av";
-
-        final String encodedKey = "user%2Bname";
-        final String decodedKey = "user+name";
-
-        String newQuery = encodedKey + "=" + encodedValue;
-
-        URI updated = PropertyUtil.replaceQuery(original, newQuery);
-
-        assertEquals(encodedKey + "=" + encodedValue, updated.getRawQuery());
-        assertEquals(decodedKey + "=" + decodedValue, updated.getQuery());
-    }
-
-    @Test
-    public void testReplaceQueryUsingMapEncodesParameters() throws URISyntaxException {
-        URI original = new URI("http://www.example.com?option=X");
-
-        final String encodedValue = "%25Ca%2BHn%2Fav";
-        final String decodedValue = "%Ca+Hn/av";
-
-        final String encodedKey = "user%2Bname";
-        final String decodedKey = "user+name";
-
-        Map<String, String> newQuery = new HashMap<String, String>();
-        newQuery.put(decodedKey, decodedValue);
-
-        URI updated = PropertyUtil.replaceQuery(original, newQuery);
-
-        assertEquals(encodedKey + "=" + encodedValue, updated.getRawQuery());
-        assertEquals(decodedKey + "=" + decodedValue, updated.getQuery());
-    }
-
-    @Test
-    public void testParseQueryDecodesParameters() throws Exception {
-        URI original = new URI("http://www.example.com?user%2Bname=%25Ca%2BHn%2Fav");
-
-        final String decodedKey = "user+name";
-        final String decodedValue = "%Ca+Hn/av";
-
-        Map<String, String> result = PropertyUtil.parseQuery(original);
-
-        assertEquals(1, result.size());
-        assertTrue(result.containsKey(decodedKey));
-        assertEquals(decodedValue, result.get(decodedKey));
-    }
-
-    @Test
-    public void testCreateQueryEncodesParameters() throws URISyntaxException {
-
-        final String encodedValue = "%25Ca%2BHn%2Fav";
-        final String decodedValue = "%Ca+Hn/av";
-
-        final String encodedKey = "user%2Bname";
-        final String decodedKey = "user+name";
-
-        Map<String, String> source = new HashMap<String, String>();
-        source.put(decodedKey, decodedValue);
-
-        String result = PropertyUtil.createQueryString(source);
-
-        assertEquals(encodedKey + "=" + encodedValue, result);
-    }
 }

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/b2f137b0/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java
index b9b556a..ba2674e 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/util/URISupportTest.java
@@ -35,6 +35,8 @@ import org.junit.Test;
 
 public class URISupportTest {
 
+    //---- parseComposite ----------------------------------------------------//
+
     @Test
     public void testEmptyCompositePath() throws Exception {
         CompositeData data = URISupport.parseComposite(new URI("broker:()/localhost?persistent=false"));
@@ -127,6 +129,15 @@ public class URISupportTest {
     }
 
     @Test
+    public void testParsingCompositeURI() throws URISyntaxException {
+        CompositeData data = URISupport.parseComposite(new URI("broker://(tcp://localhost:61616)?name=foo"));
+        assertEquals("one component", 1, data.getComponents().size());
+        assertEquals("Size: " + data.getParameters(), 1, data.getParameters().size());
+    }
+
+    //---- parseQuery --------------------------------------------------------//
+
+    @Test
     public void testParsingURI() throws Exception {
         URI source = new URI("tcp://localhost:61626/foo/bar?cheese=Edam&x=123");
 
@@ -160,12 +171,7 @@ public class URISupportTest {
         assertEquals("Map key: " + key, map.get(key), expected);
     }
 
-    @Test
-    public void testParsingCompositeURI() throws URISyntaxException {
-        CompositeData data = URISupport.parseComposite(new URI("broker://(tcp://localhost:61616)?name=foo"));
-        assertEquals("one component", 1, data.getComponents().size());
-        assertEquals("Size: " + data.getParameters(), 1, data.getParameters().size());
-    }
+    //---- checkParenthesis --------------------------------------------------------//
 
     @Test
     public void testCheckParenthesis() throws Exception {
@@ -181,16 +187,7 @@ public class URISupportTest {
         assertTrue(URISupport.checkParenthesis(""));
     }
 
-    @Test
-    public void testCreateWithQuery() throws Exception {
-        URI source = new URI("vm://localhost");
-        URI dest = PropertyUtil.replaceQuery(source, "network=true&one=two");
-
-        assertEquals("correct param count", 2, URISupport.parseParameters(dest).size());
-        assertEquals("same uri, host", source.getHost(), dest.getHost());
-        assertEquals("same uri, scheme", source.getScheme(), dest.getScheme());
-        assertFalse("same uri, ssp", dest.getQuery().equals(source.getQuery()));
-    }
+    //---- replaceQuery ------------------------------------------------------//
 
     @Test
     public void testParsingParams() throws Exception {
@@ -209,26 +206,14 @@ public class URISupportTest {
     }
 
     @Test
-    public void testCompositeCreateURIWithQuery() throws Exception {
-        String queryString = "query=value";
-        URI originalURI = new URI("outerscheme:(innerscheme:innerssp)");
-        URI querylessURI = originalURI;
-        assertEquals(querylessURI, PropertyUtil.eraseQuery(originalURI));
-        assertEquals(querylessURI, PropertyUtil.replaceQuery(originalURI, ""));
-        assertEquals(new URI(querylessURI + "?" + queryString), PropertyUtil.replaceQuery(originalURI, queryString));
-        originalURI = new URI("outerscheme:(innerscheme:innerssp)?outerquery=0");
-        assertEquals(querylessURI, PropertyUtil.eraseQuery(originalURI));
-        assertEquals(querylessURI, PropertyUtil.replaceQuery(originalURI, ""));
-        assertEquals(new URI(querylessURI + "?" + queryString), PropertyUtil.replaceQuery(originalURI, queryString));
-        originalURI = new URI("outerscheme:(innerscheme:innerssp?innerquery=0)");
-        querylessURI = originalURI;
-        assertEquals(querylessURI, PropertyUtil.eraseQuery(originalURI));
-        assertEquals(querylessURI, PropertyUtil.replaceQuery(originalURI, ""));
-        assertEquals(new URI(querylessURI + "?" + queryString), PropertyUtil.replaceQuery(originalURI, queryString));
-        originalURI = new URI("outerscheme:(innerscheme:innerssp?innerquery=0)?outerquery=0");
-        assertEquals(querylessURI, PropertyUtil.eraseQuery(originalURI));
-        assertEquals(querylessURI, PropertyUtil.replaceQuery(originalURI, ""));
-        assertEquals(new URI(querylessURI + "?" + queryString), PropertyUtil.replaceQuery(originalURI, queryString));
+    public void testCreateWithQuery() throws Exception {
+        URI source = new URI("vm://localhost");
+        URI dest = PropertyUtil.replaceQuery(source, "network=true&one=two");
+
+        assertEquals("correct param count", 2, URISupport.parseParameters(dest).size());
+        assertEquals("same uri, host", source.getHost(), dest.getHost());
+        assertEquals("same uri, scheme", source.getScheme(), dest.getScheme());
+        assertFalse("same uri, ssp", dest.getQuery().equals(source.getQuery()));
     }
 
     @Test
@@ -254,6 +239,31 @@ public class URISupportTest {
         verifyParams(URISupport.parseParameters(uri));
     }
 
+    //---- parseParameters ---------------------------------------------------//
+
+    @Test
+    public void testCompositeCreateURIWithQuery() throws Exception {
+        String queryString = "query=value";
+        URI originalURI = new URI("outerscheme:(innerscheme:innerssp)");
+        URI querylessURI = originalURI;
+        assertEquals(querylessURI, PropertyUtil.eraseQuery(originalURI));
+        assertEquals(querylessURI, PropertyUtil.replaceQuery(originalURI, ""));
+        assertEquals(new URI(querylessURI + "?" + queryString), PropertyUtil.replaceQuery(originalURI, queryString));
+        originalURI = new URI("outerscheme:(innerscheme:innerssp)?outerquery=0");
+        assertEquals(querylessURI, PropertyUtil.eraseQuery(originalURI));
+        assertEquals(querylessURI, PropertyUtil.replaceQuery(originalURI, ""));
+        assertEquals(new URI(querylessURI + "?" + queryString), PropertyUtil.replaceQuery(originalURI, queryString));
+        originalURI = new URI("outerscheme:(innerscheme:innerssp?innerquery=0)");
+        querylessURI = originalURI;
+        assertEquals(querylessURI, PropertyUtil.eraseQuery(originalURI));
+        assertEquals(querylessURI, PropertyUtil.replaceQuery(originalURI, ""));
+        assertEquals(new URI(querylessURI + "?" + queryString), PropertyUtil.replaceQuery(originalURI, queryString));
+        originalURI = new URI("outerscheme:(innerscheme:innerssp?innerquery=0)?outerquery=0");
+        assertEquals(querylessURI, PropertyUtil.eraseQuery(originalURI));
+        assertEquals(querylessURI, PropertyUtil.replaceQuery(originalURI, ""));
+        assertEquals(new URI(querylessURI + "?" + queryString), PropertyUtil.replaceQuery(originalURI, queryString));
+    }
+
     @Test
     public void testApplyParametersPreservesOriginalParameters() throws Exception {
         URI uri = new URI("http://0.0.0.0:61616?timeout=1000");
@@ -272,6 +282,8 @@ public class URISupportTest {
         assertEquals(parameters.get("proxyPort"), "80");
     }
 
+    //---- isCompositeURI ----------------------------------------------------//
+
     @Test
     public void testIsCompositeURIWithQueryNoSlashes() throws URISyntaxException {
         URI[] compositeURIs = new URI[] { new URI("test:(part1://host?part1=true)?outside=true"), new URI("broker:(tcp://localhost:61616)?name=foo") };
@@ -303,6 +315,55 @@ public class URISupportTest {
     }
 
     @Test
+    public void testIsCompositeURINoQueryNoSlashesNoParentheses() throws URISyntaxException {
+        assertFalse("test:part1" + " must be detected as non-composite URI", URISupport.isCompositeURI(new URI("test:part1")));
+    }
+
+    @Test
+    public void testIsCompositeURINoQueryWithSlashes() throws URISyntaxException {
+        URI[] compositeURIs = new URI[] { new URI("failover://(tcp://bla:61616,tcp://bla:61617)"),
+                new URI("failover://(tcp://localhost:61616,ssl://anotherhost:61617)") };
+        for (URI uri : compositeURIs) {
+            assertTrue(uri + " must be detected as composite URI", URISupport.isCompositeURI(uri));
+        }
+    }
+
+    //---- indexOfParenthesisMatch -------------------------------------------//
+
+    @Test
+    public void testIndexOfParenthesisMatch() throws URISyntaxException {
+        String source1 = "a(b)c";
+        assertEquals(3, URISupport.indexOfParenthesisMatch(source1, 1));
+
+        String source2 = "(b)";
+        assertEquals(2, URISupport.indexOfParenthesisMatch(source2, 0));
+
+        String source3 = "()";
+        assertEquals(1, URISupport.indexOfParenthesisMatch(source3, 0));
+    }
+
+    @Test
+    public void testIndexOfParenthesisMatchWhenNoMatchPresent() throws URISyntaxException {
+        try {
+            String source = "a(bc";
+            URISupport.indexOfParenthesisMatch(source, 1);
+            fail("Should have thrown URISyntaxException");
+        } catch (URISyntaxException use) {}
+
+        try {
+            String source = "(";
+            URISupport.indexOfParenthesisMatch(source, 0);
+            fail("Should have thrown URISyntaxException");
+        } catch (URISyntaxException use) {}
+
+        try {
+            String source = "a(";
+            URISupport.indexOfParenthesisMatch(source, 1);
+            fail("Should have thrown URISyntaxException");
+        } catch (URISyntaxException use) {}
+    }
+
+    @Test
     public void testIndexOfParenthesisMatchExceptions() throws URISyntaxException {
         try {
             URISupport.indexOfParenthesisMatch(null, -1);
@@ -325,6 +386,8 @@ public class URISupportTest {
         } catch (URISyntaxException iobe) {}
     }
 
+    //---- applyParameters ---------------------------------------------------//
+
     @Test
     public void testApplyParametersWithNullOrEmptyParameters() throws URISyntaxException {
         URI uri = new URI("tcp://localhost");
@@ -335,18 +398,4 @@ public class URISupportTest {
         result = URISupport.applyParameters(uri, Collections.<String, String>emptyMap(), "value.");
         assertSame(uri, result);
     }
-
-    @Test
-    public void testIsCompositeURINoQueryNoSlashesNoParentheses() throws URISyntaxException {
-        assertFalse("test:part1" + " must be detected as non-composite URI", URISupport.isCompositeURI(new URI("test:part1")));
-    }
-
-    @Test
-    public void testIsCompositeURINoQueryWithSlashes() throws URISyntaxException {
-        URI[] compositeURIs = new URI[] { new URI("failover://(tcp://bla:61616,tcp://bla:61617)"),
-                new URI("failover://(tcp://localhost:61616,ssl://anotherhost:61617)") };
-        for (URI uri : compositeURIs) {
-            assertTrue(uri + " must be detected as composite URI", URISupport.isCompositeURI(uri));
-        }
-    }
 }


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