diff options
author | Marnie McCormack <marnie@apache.org> | 2006-11-24 10:02:38 +0000 |
---|---|---|
committer | Marnie McCormack <marnie@apache.org> | 2006-11-24 10:02:38 +0000 |
commit | 80b543c3ae202e53236bf6132bd4b0ff3330b7d2 (patch) | |
tree | f16be00d88a1cbf47994b5840de80f0c5abc02ec /java | |
parent | 5c5b418c4db21949d1a526fde57e619195039e54 (diff) | |
download | qpid-python-80b543c3ae202e53236bf6132bd4b0ff3330b7d2.tar.gz |
Added example.properties file and amended tests to use for PropertiesFileInitialContextFactoryTest. Good example (I hope) for users.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@478822 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
2 files changed, 76 insertions, 10 deletions
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java index c8d54cdcc5..cdb00240b6 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java @@ -29,6 +29,8 @@ import javax.naming.InitialContext; import javax.naming.NamingException; import javax.naming.spi.InitialContextFactory; import java.util.Properties; +import java.io.InputStream; + import junit.framework.TestCase; @@ -36,21 +38,34 @@ public class PropertiesFileInitialContextFactoryTest extends TestCase { InitialContextFactory contextFactory; Properties _properties; + Properties _fileProperties; protected void setUp() throws Exception { super.setUp(); + + //create simple set of hardcoded props _properties = new Properties(); _properties.put("java.naming.factory.initial", "org.apache.qpid.jndi.PropertiesFileInitialContextFactory"); _properties.put("connectionfactory.local", "amqp://guest:guest@clientid/testpath?brokerlist='vm://:1'"); _properties.put("queue.MyQueue", "example.MyQueue"); _properties.put("topic.ibmStocks", "stocks.nyse.ibm"); _properties.put("destination.direct", "direct://amq.direct//directQueue"); + + //create properties from file as a more realistic test + _fileProperties = new Properties(); + ClassLoader cl = this.getClass().getClassLoader(); + InputStream is = cl.getResourceAsStream("org/apache/qpid/test/unit/jndi/example.properties"); + _fileProperties.load(is); } - public void test() + /** + * Test using hardcoded properties + */ + public void testWithoutFile() { Context ctx = null; + try { ctx = new InitialContext(_properties); @@ -60,6 +75,41 @@ public class PropertiesFileInitialContextFactoryTest extends TestCase fail("Error loading context:" + ne); } + checkPropertiesMatch(ctx, "Using hardcoded properties: "); + } + + /** + * Test using properties from example file + */ + public void testWithFile() + { + Context ctx = null; + + try + { + ctx = new InitialContext(_fileProperties); + } + catch (Exception e) + { + fail("Error loading context:" + e); + } + + checkPropertiesMatch(ctx, "Using properties from file: "); + } + + public void tearDown() + { + _properties = null; + _fileProperties = null; + } + + public static junit.framework.Test suite() + { + return new junit.framework.TestSuite(PropertiesFileInitialContextFactoryTest.class); + } + + private void checkPropertiesMatch(Context ctx, String errorInfo) + { try { AMQConnectionFactory cf = (AMQConnectionFactory) ctx.lookup("local"); @@ -67,7 +117,7 @@ public class PropertiesFileInitialContextFactoryTest extends TestCase } catch (NamingException ne) { - fail("Unable to create Connection Factory:" + ne); + fail(errorInfo + "Unable to create Connection Factory:" + ne); } try @@ -77,7 +127,7 @@ public class PropertiesFileInitialContextFactoryTest extends TestCase } catch (NamingException ne) { - fail("Unable to create queue:" + ne); + fail(errorInfo + "Unable to create queue:" + ne); } try @@ -87,7 +137,7 @@ public class PropertiesFileInitialContextFactoryTest extends TestCase } catch (Exception ne) { - fail("Unable to create topic:" + ne); + fail(errorInfo + "Unable to create topic:" + ne); } try @@ -97,12 +147,7 @@ public class PropertiesFileInitialContextFactoryTest extends TestCase } catch (NamingException ne) { - fail("Unable to create direct destination:" + ne); + fail(errorInfo + "Unable to create direct destination:" + ne); } } - - public static junit.framework.Test suite() - { - return new junit.framework.TestSuite(PropertiesFileInitialContextFactoryTest.class); - } } diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/jndi/example.properties b/java/client/src/test/java/org/apache/qpid/test/unit/jndi/example.properties new file mode 100644 index 0000000000..82de41908f --- /dev/null +++ b/java/client/src/test/java/org/apache/qpid/test/unit/jndi/example.properties @@ -0,0 +1,21 @@ +java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialContextFactory + +# use the following property to configure the default connector +#java.naming.provider.url - ignored. + +# register some connection factories +# connectionfactory.[jndiname] = [ConnectionURL] +connectionfactory.local = amqp://guest:guest@clientid/testpath?brokerlist='vm://:1' + +# register some queues in JNDI using the form +# queue.[jndiName] = [physicalName] +queue.MyQueue = example.MyQueue + +# register some topics in JNDI using the form +# topic.[jndiName] = [physicalName] +topic.ibmStocks = stocks.nyse.ibm + +# Register an AMQP destination in JNDI +# NOTE: Qpid currently only supports direct,topics and headers +# destination.[jniName] = [BindingURL] +destination.direct = direct://amq.direct//directQueue |