summaryrefslogtreecommitdiff
path: root/qpid/java/client/src/test
diff options
context:
space:
mode:
authorWeston M. Price <wprice@apache.org>2012-05-03 19:03:57 +0000
committerWeston M. Price <wprice@apache.org>2012-05-03 19:03:57 +0000
commit7d01b7ea7529ccb52e4f965f3997d67f153a5b0e (patch)
tree7a591efe6018c346003aeaab43ca1c564a072499 /qpid/java/client/src/test
parent82695a85d7f1caa65b6ce805f2214abafd2f7f52 (diff)
downloadqpid-python-7d01b7ea7529ccb52e4f965f3997d67f153a5b0e.tar.gz
QPID-3971: PropertiesFileInitialContextFactory cannot open file URL
*Added capability to read java.naming.provider.url from file:// URI *Added PropertiesFileInitialContextFactoryTest *Moved functionaly from old JNDIPropertiesTest to new test class *Minor cleanup. Added @SuppressWarnings annotation to PropertiesFileInitialContext git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1333586 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/client/src/test')
-rw-r--r--qpid/java/client/src/test/java/org/apache/qpid/jndi/JNDITest.properties (renamed from qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/JNDITest.properties)0
-rw-r--r--qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java (renamed from qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/JNDIPropertyFileTest.java)64
-rw-r--r--qpid/java/client/src/test/java/org/apache/qpid/jndi/hello.properties27
3 files changed, 72 insertions, 19 deletions
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/JNDITest.properties b/qpid/java/client/src/test/java/org/apache/qpid/jndi/JNDITest.properties
index 07017a05a6..07017a05a6 100644
--- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/JNDITest.properties
+++ b/qpid/java/client/src/test/java/org/apache/qpid/jndi/JNDITest.properties
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/JNDIPropertyFileTest.java b/qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java
index 576ab4fa05..4371f8d753 100644
--- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/JNDIPropertyFileTest.java
+++ b/qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java
@@ -14,29 +14,35 @@
* "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.
+ * under the License.
+ *
*
- *
*/
-package org.apache.qpid.test.unit.jndi;
+package org.apache.qpid.jndi;
-import junit.framework.TestCase;
-import org.apache.qpid.client.AMQDestination;
-import org.apache.qpid.framing.AMQShortString;
+import java.util.Properties;
+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 java.util.Properties;
-public class JNDIPropertyFileTest extends TestCase
+import junit.framework.TestCase;
+
+import org.apache.qpid.client.AMQDestination;
+import org.apache.qpid.framing.AMQShortString;
+
+public class PropertiesFileInitialContextFactoryTest extends TestCase
{
+ 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;
-
- public JNDIPropertyFileTest() throws Exception
+
+ protected void setUp() throws Exception
{
Properties properties = new Properties();
properties.load(this.getClass().getResourceAsStream("JNDITest.properties"));
@@ -44,19 +50,39 @@ public class JNDIPropertyFileTest extends TestCase
//Create the initial context
ctx = new InitialContext(properties);
}
-
+
+ public void testInitialContextProviderURL() throws Exception
+ {
+ Destination d = null;
+
+ System.setProperty("java.naming.factory.initial", "org.apache.qpid.jndi.PropertiesFileInitialContextFactory");
+ System.setProperty("java.naming.provider.url", FILE_URL_PATH + FILE_NAME);
+
+ InitialContext ctx = new InitialContext();
+ d = (Destination)ctx.lookup("topicExchange");
+ assertNotNull("Lookup for Destination from file path should not be null", d);
+
+ ctx.close();
+
+ System.setProperty("java.naming.provider.url", "file:///" + FILE_URL_PATH + FILE_NAME);
+
+ ctx = new InitialContext();
+ d = (Destination)ctx.lookup("topicExchange");
+ assertNotNull("Lookup for Destination from file URI should not be null", d);
+ }
+
public void testQueueNamesWithTrailingSpaces() throws Exception
{
Queue queue = (Queue)ctx.lookup("QueueNameWithSpace");
- assertEquals("QueueNameWithSpace",queue.getQueueName());
+ assertEquals("QueueNameWithSpace",queue.getQueueName());
}
-
+
public void testTopicNamesWithTrailingSpaces() throws Exception
{
Topic topic = (Topic)ctx.lookup("TopicNameWithSpace");
- assertEquals("TopicNameWithSpace",topic.getTopicName());
+ assertEquals("TopicNameWithSpace",topic.getTopicName());
}
-
+
public void testMultipleTopicNamesWithTrailingSpaces() throws Exception
{
Topic topic = (Topic)ctx.lookup("MultipleTopicNamesWithSpace");
@@ -64,16 +90,16 @@ public class JNDIPropertyFileTest extends TestCase
for (AMQShortString bindingKey: ((AMQDestination)topic).getBindingKeys())
{
i++;
- assertEquals("Topic" + i + "WithSpace",bindingKey.asString());
+ assertEquals("Topic" + i + "WithSpace",bindingKey.asString());
}
}
-
+
public void testConfigurationErrors() throws Exception
{
Properties properties = new Properties();
properties.put("java.naming.factory.initial", "org.apache.qpid.jndi.PropertiesFileInitialContextFactory");
properties.put("destination.my-queue","amq.topic/test;create:always}");
-
+
try
{
ctx = new InitialContext(properties);
@@ -83,6 +109,6 @@ public class JNDIPropertyFileTest extends TestCase
{
assertTrue("Incorrect exception", e.getMessage().contains("Failed to parse entry: amq.topic/test;create:always}"));
}
-
+
}
}
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/jndi/hello.properties b/qpid/java/client/src/test/java/org/apache/qpid/jndi/hello.properties
new file mode 100644
index 0000000000..d017d137fe
--- /dev/null
+++ b/qpid/java/client/src/test/java/org/apache/qpid/jndi/hello.properties
@@ -0,0 +1,27 @@
+#
+# 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