diff options
| author | Kim van der Riet <kpvdr@apache.org> | 2012-08-03 12:13:32 +0000 |
|---|---|---|
| committer | Kim van der Riet <kpvdr@apache.org> | 2012-08-03 12:13:32 +0000 |
| commit | d43d1912b376322e27fdcda551a73f9ff5487972 (patch) | |
| tree | ce493e10baa95f44be8beb5778ce51783463196d /java/client/src/test | |
| parent | 04877fec0c6346edec67072d7f2d247740cf2af5 (diff) | |
| download | qpid-python-d43d1912b376322e27fdcda551a73f9ff5487972.tar.gz | |
QPID-3858: Updated branch - merged from trunk r.1368650
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/asyncstore@1368910 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/client/src/test')
| -rw-r--r-- | java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java (renamed from java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java) | 20 | ||||
| -rw-r--r-- | java/client/src/test/java/org/apache/qpid/client/message/AbstractJMSMessageTest.java | 2 | ||||
| -rw-r--r-- | java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java | 78 | ||||
| -rw-r--r-- | java/client/src/test/java/org/apache/qpid/jndi/hello.properties | 27 |
4 files changed, 79 insertions, 48 deletions
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java b/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java index 20496026ce..bb92fa4ecd 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/ConnectionFactoryTest.java +++ b/java/client/src/test/java/org/apache/qpid/client/AMQConnectionFactoryTest.java @@ -18,7 +18,9 @@ * under the License. * */ -package org.apache.qpid.test.unit.jndi; +package org.apache.qpid.client; + +import javax.jms.JMSException; import junit.framework.TestCase; @@ -26,7 +28,7 @@ import org.apache.qpid.client.AMQConnectionFactory; import org.apache.qpid.jms.BrokerDetails; import org.apache.qpid.jms.ConnectionURL; -public class ConnectionFactoryTest extends TestCase +public class AMQConnectionFactoryTest extends TestCase { //URL will be returned with the password field swapped for '********' @@ -58,6 +60,20 @@ public class ConnectionFactoryTest extends TestCase assertEquals("tcp", service.getTransport()); assertEquals("localhost", service.getHost()); assertEquals(5672, service.getPort()); + } + + public void testInstanceCreatedWithDefaultConstructorThrowsExceptionOnCallingConnectWithoutSettingURL() throws Exception + { + AMQConnectionFactory factory = new AMQConnectionFactory(); + try + { + factory.createConnection(); + fail("Expected exception not thrown"); + } + catch(JMSException e) + { + assertEquals("Unexpected exception", AMQConnectionFactory.NO_URL_CONFIGURED, e.getMessage()); + } } } diff --git a/java/client/src/test/java/org/apache/qpid/client/message/AbstractJMSMessageTest.java b/java/client/src/test/java/org/apache/qpid/client/message/AbstractJMSMessageTest.java index 1fbd7cf212..c535fdd705 100644 --- a/java/client/src/test/java/org/apache/qpid/client/message/AbstractJMSMessageTest.java +++ b/java/client/src/test/java/org/apache/qpid/client/message/AbstractJMSMessageTest.java @@ -1,4 +1,3 @@ -package org.apache.qpid.client.message; /* * * Licensed to the Apache Software Foundation (ASF) under one @@ -19,6 +18,7 @@ package org.apache.qpid.client.message; * under the License. * */ +package org.apache.qpid.client.message; import junit.framework.TestCase; diff --git a/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java b/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java index 2989970dcd..ce9e681eaf 100644 --- a/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java +++ b/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java @@ -21,51 +21,47 @@ package org.apache.qpid.jndi; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.Properties; +import javax.jms.ConnectionFactory; import javax.jms.Destination; import javax.jms.Queue; import javax.jms.Topic; import javax.naming.ConfigurationException; import javax.naming.Context; import javax.naming.InitialContext; +import javax.naming.NamingException; -import junit.framework.TestCase; - +import org.apache.qpid.client.AMQConnectionFactory; import org.apache.qpid.client.AMQDestination; +import org.apache.qpid.configuration.ClientProperties; import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.test.utils.QpidTestCase; -public class PropertiesFileInitialContextFactoryTest extends TestCase +public class PropertiesFileInitialContextFactoryTest extends QpidTestCase { - private static final String FILE_URL_PATH = System.getProperty("user.dir") + "/client/src/test/java/org/apache/qpid/jndi/"; - private static final String FILE_NAME = "hello.properties"; - - private Context ctx; - - protected void setUp() throws Exception - { - Properties properties = new Properties(); - properties.load(this.getClass().getResourceAsStream("JNDITest.properties")); - - //Create the initial context - ctx = new InitialContext(properties); - } - + private static final String CONNECTION_URL = "amqp://username:password@clientid/test?brokerlist='tcp://testContextFromProviderURL:5672'"; public void testQueueNamesWithTrailingSpaces() throws Exception { + Context ctx = prepareContext(); Queue queue = (Queue)ctx.lookup("QueueNameWithSpace"); assertEquals("QueueNameWithSpace",queue.getQueueName()); } public void testTopicNamesWithTrailingSpaces() throws Exception { + Context ctx = prepareContext(); Topic topic = (Topic)ctx.lookup("TopicNameWithSpace"); assertEquals("TopicNameWithSpace",topic.getTopicName()); } public void testMultipleTopicNamesWithTrailingSpaces() throws Exception { + Context ctx = prepareContext(); Topic topic = (Topic)ctx.lookup("MultipleTopicNamesWithSpace"); int i = 0; for (AMQShortString bindingKey: ((AMQDestination)topic).getBindingKeys()) @@ -83,13 +79,59 @@ public class PropertiesFileInitialContextFactoryTest extends TestCase try { - ctx = new InitialContext(properties); + new InitialContext(properties); fail("A configuration exception should be thrown with details about the address syntax error"); } catch(ConfigurationException e) { assertTrue("Incorrect exception", e.getMessage().contains("Failed to parse entry: amq.topic/test;create:always}")); } + } + + private InitialContext prepareContext() throws IOException, NamingException + { + Properties properties = new Properties(); + properties.load(this.getClass().getResourceAsStream("JNDITest.properties")); + return new InitialContext(properties); + } + + /** + * Test loading of a JNDI properties file through use of a file:// URL + * supplied via the InitialContext.PROVIDER_URL system property. + */ + public void testContextFromProviderURL() throws Exception + { + Properties properties = new Properties(); + properties.put("connectionfactory.qpidConnectionfactory", CONNECTION_URL); + properties.put("destination.topicExchange", "destName"); + + File f = File.createTempFile(getTestName(), ".properties"); + try + { + FileOutputStream fos = new FileOutputStream(f); + properties.store(fos, null); + fos.close(); + + setTestSystemProperty(ClientProperties.DEST_SYNTAX, "ADDR"); + setTestSystemProperty(InitialContext.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jndi.PropertiesFileInitialContextFactory"); + setTestSystemProperty(InitialContext.PROVIDER_URL, "file://" + f.getCanonicalPath()); + + InitialContext context = new InitialContext(); + Destination dest = (Destination) context.lookup("topicExchange"); + assertNotNull("Lookup from URI based context should not be null", dest); + assertTrue("Unexpected value from lookup", dest.toString().contains("destName")); + + ConnectionFactory factory = (ConnectionFactory) context.lookup("qpidConnectionfactory"); + assertTrue("ConnectionFactory was not an instance of AMQConnectionFactory", factory instanceof AMQConnectionFactory); + assertEquals("Unexpected ConnectionURL value", CONNECTION_URL.replaceAll("password", "********"), + ((AMQConnectionFactory)factory).getConnectionURLString()); + + context.close(); + } + finally + { + f.delete(); + } } } diff --git a/java/client/src/test/java/org/apache/qpid/jndi/hello.properties b/java/client/src/test/java/org/apache/qpid/jndi/hello.properties deleted file mode 100644 index d017d137fe..0000000000 --- a/java/client/src/test/java/org/apache/qpid/jndi/hello.properties +++ /dev/null @@ -1,27 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialContextFactory - -# register some connection factories -# connectionfactory.[jndiname] = [ConnectionURL] -connectionfactory.qpidConnectionfactory = amqp://guest:guest@clientid/test?brokerlist='tcp://10.0.1.46:5672' - -# Register an AMQP destination in JNDI -# destination.[jniName] = [Address Format] -destination.topicExchange = amq.topic |
