qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r478822 - in /incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi: PropertiesFileInitialContextFactoryTest.java example.properties
Date Fri, 24 Nov 2006 10:02:39 GMT
Author: marnie
Date: Fri Nov 24 02:02:38 2006
New Revision: 478822

URL: http://svn.apache.org/viewvc?view=rev&rev=478822
Log:
Added example.properties file and amended tests to use for PropertiesFileInitialContextFactoryTest.
Good example (I hope) for users.

Added:
    incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/example.properties
  (with props)
Modified:
    incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java

Modified: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java?view=diff&rev=478822&r1=478821&r2=478822
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java
(original)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/PropertiesFileInitialContextFactoryTest.java
Fri Nov 24 02:02:38 2006
@@ -29,6 +29,8 @@
 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 @@
 {
     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 @@
             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 @@
         }
         catch (NamingException ne)
         {
-            fail("Unable to create Connection Factory:" + ne);
+            fail(errorInfo + "Unable to create Connection Factory:" + ne);
         }
 
         try
@@ -77,7 +127,7 @@
         }
         catch (NamingException ne)
         {
-            fail("Unable to create queue:" + ne);
+            fail(errorInfo + "Unable to create queue:" + ne);
         }
 
         try
@@ -87,7 +137,7 @@
         }
         catch (Exception ne)
         {
-            fail("Unable to create topic:" + ne);
+            fail(errorInfo + "Unable to create topic:" + ne);
         }
 
         try
@@ -97,12 +147,7 @@
         }
         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);
     }
 }

Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/example.properties
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/example.properties?view=auto&rev=478822
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/example.properties
(added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/example.properties
Fri Nov 24 02:02:38 2006
@@ -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

Propchange: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/example.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/jndi/example.properties
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message