qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject svn commit: r1337871 - in /qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/jndi: PropertiesFileInitialContextFactoryTest.java hello.properties
Date Sun, 13 May 2012 13:16:03 GMT
Author: robbie
Date: Sun May 13 13:16:03 2012
New Revision: 1337871

URL: http://svn.apache.org/viewvc?rev=1337871&view=rev
Log:
QPID-3971: resolve CI failure (hopefully), make misc test improvements

- Use File.createTempFile to target the tmp dir, hopefully resolving the CI failure, ensure
it is deleted even if the test subsequently fails.
- Use QpidTestCase system property handling, ensuring modified properties are unset/restored
to prior values following the test.
- Move the properties used in the test internally as opposed to loading from another file.
- Verify the values returned from the loaded Context are as expected an not only non-null.
- Remove unused imports, fields.

Removed:
    qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/jndi/hello.properties
Modified:
    qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java

Modified: qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java?rev=1337871&r1=1337870&r2=1337871&view=diff
==============================================================================
--- qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java
(original)
+++ qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/jndi/PropertiesFileInitialContextFactoryTest.java
Sun May 13 13:16:03 2012
@@ -22,76 +22,46 @@ package org.apache.qpid.jndi;
 
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
-import java.io.FileWriter;
+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"));
-
-        ctx = new InitialContext(properties);
-    }
-
-    public void testContextFromProviderURL() throws Exception
-    {
-        Properties properties = new Properties();
-        properties.load(this.getClass().getResourceAsStream("hello.properties"));
-        File f = new File(System.getProperty("java.io.tmpdir") + FILE_NAME);
-        FileOutputStream fos = new FileOutputStream(f);
-        properties.store(fos, null);
-
-        System.setProperty("java.naming.factory.initial", "org.apache.qpid.jndi.PropertiesFileInitialContextFactory");
-        System.setProperty("java.naming.provider.url", "file://" + f.getCanonicalPath());
-
-        InitialContext context = new InitialContext();
-        assertNotNull("Lookup from URI based context should not be null", context.lookup("topicExchange"));
+    private static final String CONNECTION_URL = "amqp://username:password@clientid/test?brokerlist='tcp://testContextFromProviderURL:5672'";
 
-        context.close();
-
-        System.setProperty("java.naming.provider.url", f.getCanonicalPath());
-        context = new InitialContext();
-        assertNotNull("Lookup from fileName should not be null", context.lookup("qpidConnectionfactory"));
-
-        context.close();
-        f.delete();
-
-    }
     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())
@@ -109,13 +79,59 @@ public class PropertiesFileInitialContex
 
         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();
+        }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message