summaryrefslogtreecommitdiff
path: root/java/client/src/test/java/org/apache/qpid/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'java/client/src/test/java/org/apache/qpid/test/unit')
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java42
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java128
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java120
-rw-r--r--java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java14
4 files changed, 252 insertions, 52 deletions
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java
index 412c458247..1e9e5b00a5 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/BrokerDetails/BrokerDetailsTest.java
@@ -120,6 +120,48 @@ public class BrokerDetailsTest extends TestCase
{
assertTrue(urise.getReason().equals("Illegal character in port number"));
}
+ }
+
+ public void testToStringMasksKeyStorePassword() throws Exception
+ {
+ String url = "tcp://localhost:5672?key_store_password='password'";
+ BrokerDetails details = new AMQBrokerDetails(url);
+
+ String expectedToString = "tcp://localhost:5672?key_store_password='********'";
+ String actualToString = details.toString();
+
+ assertEquals("Unexpected toString", expectedToString, actualToString);
+ }
+
+ public void testToStringMasksTrustStorePassword() throws Exception
+ {
+ String url = "tcp://localhost:5672?trust_store_password='password'";
+ BrokerDetails details = new AMQBrokerDetails(url);
+
+ String expectedToString = "tcp://localhost:5672?trust_store_password='********'";
+ String actualToString = details.toString();
+
+ assertEquals("Unexpected toString", expectedToString, actualToString);
+ }
+
+ public void testDefaultSsl() throws URLSyntaxException
+ {
+ String brokerURL = "tcp://localhost:5672";
+ AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL);
+
+ assertNull("default value should be null", broker.getProperty(BrokerDetails.OPTIONS_SSL));
+ }
+
+ public void testOverridingSsl() throws URLSyntaxException
+ {
+ String brokerURL = "tcp://localhost:5672?ssl='true'";
+ AMQBrokerDetails broker = new AMQBrokerDetails(brokerURL);
+
+ assertTrue("value should be true", Boolean.valueOf(broker.getProperty(BrokerDetails.OPTIONS_SSL)));
+
+ brokerURL = "tcp://localhost:5672?ssl='false''&maxprefetch='1'";
+ broker = new AMQBrokerDetails(brokerURL);
+ assertFalse("value should be false", Boolean.valueOf(broker.getProperty(BrokerDetails.OPTIONS_SSL)));
}
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
index 392ef1f29b..8c193622e3 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
@@ -30,7 +30,6 @@ import org.apache.qpid.url.URLSyntaxException;
public class ConnectionURLTest extends TestCase
{
-
public void testFailoverURL() throws URLSyntaxException
{
String url = "amqp://ritchiem:bob@/test?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin?cyclecount='100''";
@@ -252,55 +251,47 @@ public class ConnectionURLTest extends TestCase
assertTrue(service.getPort() == 5672);
}
- public void testSingleTransportDefaultedBrokerWithIPandPort() throws URLSyntaxException
+ public void testConnectionURLOptionToStringMasksPassword() throws URLSyntaxException
{
- String url = "amqp://guest:guest@/test?brokerlist='127.0.0.1:1234'";
+ String url = "amqp://guest:guest@client/localhost?brokerlist='tcp://localhost:1234'";
+ ConnectionURL connectionurl = new AMQConnectionURL(url);
+
+ String expectedToString = "amqp://guest:********@client/localhost?brokerlist='tcp://localhost:1234'";
+ String actualToString = connectionurl.toString();
+ assertEquals("Unexpected toString form", expectedToString, actualToString);
+ }
+
+ public void testConnectionURLOptionToStringMasksSslTrustStorePassword() throws URLSyntaxException
+ {
+ String url = "amqp://guest:guest@client/vhost?brokerlist='tcp://host:1234?trust_store_password='truststorepassword''";
+ ConnectionURL connectionurl = new AMQConnectionURL(url);
-// ConnectionURL connectionurl = new AMQConnectionURL(url);
-//
-// assertTrue(connectionurl.getFailoverMethod() == null);
-// assertTrue(connectionurl.getUsername().equals("guest"));
-// assertTrue(connectionurl.getPassword().equals("guest"));
-// assertTrue(connectionurl.getVirtualHost().equals("/temp"));
-//
-//
-// assertTrue(connectionurl.getBrokerCount() == 1);
-//
-// BrokerDetails service = connectionurl.getBrokerDetails(0);
-//
-// assertTrue(service.getTransport().equals("tcp"));
-//
-// assertTrue(service.getHost().equals("127.0.0.1"));
-// assertTrue(service.getPort() == 1234);
+ String expectedToString = "amqp://guest:********@client/vhost?brokerlist='tcp://host:1234?trust_store_password='********''";
+ String actualToString = connectionurl.toString();
+ assertEquals("Unexpected toString form", expectedToString, actualToString);
+ }
+
+ public void testConnectionURLOptionToStringMasksSslKeyStorePassword() throws URLSyntaxException
+ {
+ String url = "amqp://guest:guest@client/vhost?brokerlist='tcp://host:1234?key_store_password='keystorepassword1';tcp://host:1235?key_store_password='keystorepassword2''";
+ ConnectionURL connectionurl = new AMQConnectionURL(url);
+
+ String expectedToString = "amqp://guest:********@client/vhost?brokerlist='tcp://host:1234?key_store_password='********';tcp://host:1235?key_store_password='********''";
+ String actualToString = connectionurl.toString();
+ assertEquals("Unexpected toString form", expectedToString, actualToString);
}
/**
* Test for QPID-3662 to ensure the {@code toString()} representation is correct.
*/
- public void testConnectionURLOptionToString() throws URLSyntaxException
+ public void testConnectionURLOptionToStringWithMaxPreftech() throws URLSyntaxException
{
String url = "amqp://guest:guest@client/localhost?maxprefetch='1'&brokerlist='tcp://localhost:1234?tcp_nodelay='true''";
ConnectionURL connectionurl = new AMQConnectionURL(url);
- assertNull(connectionurl.getFailoverMethod());
- assertEquals("guest", connectionurl.getUsername());
- assertEquals("guest", connectionurl.getPassword());
- assertEquals("client", connectionurl.getClientName());
- assertEquals("/localhost", connectionurl.getVirtualHost());
- assertEquals("1", connectionurl.getOption("maxprefetch"));
- assertTrue(connectionurl.getBrokerCount() == 1);
-
- BrokerDetails service = connectionurl.getBrokerDetails(0);
- assertTrue(service.getTransport().equals("tcp"));
- assertTrue(service.getHost().equals("localhost"));
- assertTrue(service.getPort() == 1234);
- assertTrue(service.getProperties().containsKey("tcp_nodelay"));
- assertEquals("true", service.getProperties().get("tcp_nodelay"));
-
- String nopasswd = "amqp://guest:********@client/localhost?maxprefetch='1'&brokerlist='tcp://localhost:1234?tcp_nodelay='true''";
- String tostring = connectionurl.toString();
- assertEquals(tostring.indexOf("maxprefetch"), tostring.lastIndexOf("maxprefetch"));
- assertEquals(nopasswd, tostring);
+ String expectedToString = "amqp://guest:********@client/localhost?maxprefetch='1'&brokerlist='tcp://localhost:1234?tcp_nodelay='true''";
+ String actualToString = connectionurl.toString();
+ assertEquals("Unexpected toString form", expectedToString, actualToString);
}
public void testSingleTransportMultiOptionURL() throws URLSyntaxException
@@ -572,9 +563,64 @@ public class ConnectionURLTest extends TestCase
connectionurl.getOption(ConnectionURL.OPTIONS_REJECT_BEHAVIOUR));
}
- public static junit.framework.Test suite()
+ /**
+ * Verify that when the ssl option is not specified, asking for the option returns null,
+ * such that this can later be used to verify it wasnt specified.
+ */
+ public void testDefaultSsl() throws URLSyntaxException
{
- return new junit.framework.TestSuite(ConnectionURLTest.class);
+ String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&foo='bar'";
+ ConnectionURL connectionURL = new AMQConnectionURL(url);
+
+ assertNull("default ssl value should be null", connectionURL.getOption(ConnectionURL.OPTIONS_SSL));
+ }
+
+ /**
+ * Verify that when the ssl option is specified, asking for the option returns the value,
+ * such that this can later be used to verify what value it was specified as.
+ */
+ public void testOverridingSsl() throws URLSyntaxException
+ {
+ String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&ssl='true'";
+ ConnectionURL connectionURL = new AMQConnectionURL(url);
+
+ assertTrue("value should be true", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_SSL)));
+
+ url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&ssl='false'";
+ connectionURL = new AMQConnectionURL(url);
+
+ assertFalse("value should be false", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_SSL)));
+ }
+
+ /**
+ * Verify that when the {@value ConnectionURL#OPTIONS_VERIFY_QUEUE_ON_SEND} option is not
+ * specified, asking for the option returns null, such that this can later be used to
+ * verify it wasn't specified.
+ */
+ public void testDefaultVerifyQueueOnSend() throws URLSyntaxException
+ {
+ String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&foo='bar'";
+ ConnectionURL connectionURL = new AMQConnectionURL(url);
+
+ assertNull("default ssl value should be null", connectionURL.getOption(ConnectionURL.OPTIONS_SSL));
+ }
+
+ /**
+ * Verify that when the {@value ConnectionURL#OPTIONS_VERIFY_QUEUE_ON_SEND} option is
+ * specified, asking for the option returns the value, such that this can later be used
+ * to verify what value it was specified as.
+ */
+ public void testOverridingVerifyQueueOnSend() throws URLSyntaxException
+ {
+ String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&verifyQueueOnSend='true'";
+ ConnectionURL connectionURL = new AMQConnectionURL(url);
+
+ assertTrue("value should be true", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND)));
+
+ url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'&verifyQueueOnSend='false'";
+ connectionURL = new AMQConnectionURL(url);
+
+ assertFalse("value should be false", Boolean.valueOf(connectionURL.getOption(ConnectionURL.OPTIONS_VERIFY_QUEUE_ON_SEND)));
}
}
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java
index 9addb0ee71..8f578e6a2f 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java
@@ -193,6 +193,126 @@ public class DestinationURLTest extends TestCase
assertTrue(dest.getQueueName().equals("test:testQueueD"));
}
+ public void testExchangeOptionsNotPresent() throws URISyntaxException
+ {
+ String url = "exchangeClass://exchangeName/Destination/Queue";
+
+ AMQBindingURL burl = new AMQBindingURL(url);
+
+ assertTrue(url.equals(burl.toString()));
+
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_DURABLE));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_AUTODELETE));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_INTERNAL));
+
+ class MyTestAMQDestination extends AMQDestination
+ {
+ public MyTestAMQDestination(BindingURL url)
+ {
+ super(url);
+ }
+ public boolean isNameRequired()
+ {
+ return false;
+ }
+ };
+
+ AMQDestination dest = new MyTestAMQDestination(burl);
+ assertFalse(dest.isExchangeAutoDelete());
+ assertFalse(dest.isExchangeDurable());
+ assertFalse(dest.isExchangeInternal());
+ }
+
+ public void testExchangeAutoDeleteOptionPresent() throws URISyntaxException
+ {
+ String url = "exchangeClass://exchangeName/Destination/Queue?" + BindingURL.OPTION_EXCHANGE_AUTODELETE + "='true'";
+
+ AMQBindingURL burl = new AMQBindingURL(url);
+
+ assertTrue(url.equals(burl.toString()));
+
+ assertEquals("true", burl.getOption(BindingURL.OPTION_EXCHANGE_AUTODELETE));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_DURABLE));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_INTERNAL));
+
+ class MyTestAMQDestination extends AMQDestination
+ {
+ public MyTestAMQDestination(BindingURL url)
+ {
+ super(url);
+ }
+ public boolean isNameRequired()
+ {
+ return false;
+ }
+ };
+
+ AMQDestination dest = new MyTestAMQDestination(burl);
+ assertTrue(dest.isExchangeAutoDelete());
+ assertFalse(dest.isExchangeDurable());
+ assertFalse(dest.isExchangeInternal());
+ }
+
+ public void testExchangeDurableOptionPresent() throws URISyntaxException
+ {
+ String url = "exchangeClass://exchangeName/Destination/Queue?" + BindingURL.OPTION_EXCHANGE_DURABLE + "='true'";
+
+ AMQBindingURL burl = new AMQBindingURL(url);
+
+ assertTrue(url.equals(burl.toString()));
+
+ assertEquals("true", burl.getOption(BindingURL.OPTION_EXCHANGE_DURABLE));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_AUTODELETE));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_INTERNAL));
+
+ class MyTestAMQDestination extends AMQDestination
+ {
+ public MyTestAMQDestination(BindingURL url)
+ {
+ super(url);
+ }
+ public boolean isNameRequired()
+ {
+ return false;
+ }
+ };
+
+ AMQDestination dest = new MyTestAMQDestination(burl);
+ assertTrue(dest.isExchangeDurable());
+ assertFalse(dest.isExchangeAutoDelete());
+ assertFalse(dest.isExchangeInternal());
+ }
+
+ public void testExchangeInternalOptionPresent() throws URISyntaxException
+ {
+ String url = "exchangeClass://exchangeName/Destination/Queue?" + BindingURL.OPTION_EXCHANGE_INTERNAL + "='true'";
+
+ AMQBindingURL burl = new AMQBindingURL(url);
+
+ assertTrue(url.equals(burl.toString()));
+
+ assertEquals("true", burl.getOption(BindingURL.OPTION_EXCHANGE_INTERNAL));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_AUTODELETE));
+ assertNull(burl.getOption(BindingURL.OPTION_EXCHANGE_DURABLE));
+
+ class MyTestAMQDestination extends AMQDestination
+ {
+ public MyTestAMQDestination(BindingURL url)
+ {
+ super(url);
+ }
+ public boolean isNameRequired()
+ {
+ return false;
+ }
+ };
+
+ AMQDestination dest = new MyTestAMQDestination(burl);
+ assertTrue(dest.isExchangeInternal());
+ assertFalse(dest.isExchangeDurable());
+ assertFalse(dest.isExchangeAutoDelete());
+ }
+
public void testRejectBehaviourPresent() throws URISyntaxException
{
String url = "exchangeClass://exchangeName/Destination/Queue?rejectbehaviour='server'";
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java b/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java
index f199961b6f..4ad9069ba0 100644
--- a/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java
+++ b/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java
@@ -124,7 +124,7 @@ public class TestAMQSession extends AMQSession_0_8
return false;
}
- public void sendConsume(BasicMessageConsumer_0_8 consumer, AMQShortString queueName, AMQProtocolHandler protocolHandler, boolean nowait, int tag) throws AMQException, FailoverException
+ public void sendConsume(BasicMessageConsumer_0_8 consumer, AMQShortString queueName, boolean nowait, int tag) throws AMQException, FailoverException
{
}
@@ -139,13 +139,13 @@ public class TestAMQSession extends AMQSession_0_8
return null;
}
- public void sendExchangeDeclare(AMQShortString name, AMQShortString type, AMQProtocolHandler protocolHandler, boolean nowait) throws AMQException, FailoverException
+ public void sendExchangeDeclare(AMQShortString name, AMQShortString type, boolean nowait, boolean durable, boolean autoDelete, boolean internal) throws AMQException, FailoverException
{
}
public void sendQueueDeclare(AMQDestination amqd, AMQProtocolHandler protocolHandler,
- boolean nowait, boolean passive) throws AMQException, FailoverException
+ boolean passive) throws AMQException, FailoverException
{
}
@@ -189,14 +189,6 @@ public class TestAMQSession extends AMQSession_0_8
{
}
- public void handleAddressBasedDestination(AMQDestination dest,
- boolean isConsumer,
- boolean noWait) throws AMQException
- {
- throw new UnsupportedOperationException("The new addressing based sytanx is "
- + "not supported for AMQP 0-8/0-9 versions");
- }
-
@Override
protected void flushAcknowledgments()
{