add some tests using only the Context environment [system] properties rather than direct instantiation
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/4a6c1b22 Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/4a6c1b22 Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/4a6c1b22 Branch: refs/heads/master Commit: 4a6c1b221267df7c7bd5f960727b9c1f18aaebaa Parents: 9b18728 Author: Robert Gemmell <[email protected]> Authored: Mon Feb 2 16:49:08 2015 +0000 Committer: Robert Gemmell <[email protected]> Committed: Mon Feb 2 16:50:47 2015 +0000 ---------------------------------------------------------------------- .../jms/jndi/JmsInitialContextFactoryTest.java | 86 ++++++++++++++++++++ 1 file changed, 86 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/4a6c1b22/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java ---------------------------------------------------------------------- diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java index c2b9b4b..488bc4e 100644 --- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java +++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/jndi/JmsInitialContextFactoryTest.java @@ -18,9 +18,16 @@ package org.apache.qpid.jms.jndi; import static org.junit.Assert.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.Hashtable; +import java.util.Properties; +import javax.jms.ConnectionFactory; import javax.naming.Context; +import javax.naming.InitialContext; import javax.naming.NameNotFoundException; import javax.naming.NamingException; import javax.naming.OperationNotSupportedException; @@ -302,4 +309,83 @@ public class JmsInitialContextFactoryTest extends QpidJmsTestCase { ctx.rename("lookupName", ""); } + + @Test + public void testContextFromProviderUrlInEnvironmentMap() throws Exception { + doContextFromProviderUrlInEnvironmentMapTestImpl(false); + } + + @Test + public void testContextFromProviderUrlInEnvironmentMapWithBareFilePath() throws Exception { + doContextFromProviderUrlInEnvironmentMapTestImpl(true); + } + + private void doContextFromProviderUrlInEnvironmentMapTestImpl(boolean useBareFilePath) throws IOException, FileNotFoundException, NamingException { + String myFactory = "myFactory"; + String myURI = "amqp://example.com:2765"; + + Properties properties = new Properties(); + properties.put("connectionfactory." + myFactory, myURI); + + File f = File.createTempFile(getTestName(), ".properties"); + try { + FileOutputStream fos = new FileOutputStream(f); + try { + properties.store(fos, null); + } finally { + fos.close(); + } + + Hashtable<Object, Object> env = new Hashtable<Object, Object>(); + env.put(Context.INITIAL_CONTEXT_FACTORY, JmsInitialContextFactory.class.getName()); + if (useBareFilePath) { + env.put(Context.PROVIDER_URL, f.getAbsolutePath()); + } else { + env.put(Context.PROVIDER_URL, "file://" + f.getAbsolutePath()); + } + + InitialContext context = new InitialContext(env); + + ConnectionFactory factory = (ConnectionFactory) context.lookup(myFactory); + assertEquals("Unexpected type of object", JmsConnectionFactory.class, factory.getClass()); + assertEquals("Unexpected URI value", myURI, ((JmsConnectionFactory) factory).getRemoteURI()); + + context.close(); + } finally { + f.delete(); + } + } + + @Test + public void testContextFromProviderUrlInSystemProperty() throws Exception + { + String myFactory = "myFactory"; + String myURI = "amqp://example.com:2765"; + + Properties properties = new Properties(); + properties.put("connectionfactory." + myFactory, myURI); + + File f = File.createTempFile(getTestName(), ".properties"); + try { + FileOutputStream fos = new FileOutputStream(f); + try { + properties.store(fos, null); + } finally { + fos.close(); + } + + setTestSystemProperty(Context.INITIAL_CONTEXT_FACTORY, JmsInitialContextFactory.class.getName()); + setTestSystemProperty(Context.PROVIDER_URL, "file://" + f.getAbsolutePath()); + + InitialContext context = new InitialContext(); + + ConnectionFactory factory = (ConnectionFactory) context.lookup(myFactory); + assertEquals("Unexpected type of object", JmsConnectionFactory.class, factory.getClass()); + assertEquals("Unexpected URI value", myURI, ((JmsConnectionFactory) factory).getRemoteURI()); + + context.close(); + } finally { + f.delete(); + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
