From 44c234332e01c90d9538a8fd1eee568217a2f054 Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Fri, 13 Oct 2006 13:02:54 +0000 Subject: Added Sun FSContext to client-test lib Updated referenceabletest files to use the temporary directory reported by the System.properties. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@463671 13f79535-47bb-0310-9956-ffa450edef68 --- .../test/lib/fscontext-1_2-beta3/fscontext.jar | Bin 0 -> 22769 bytes .../test/lib/fscontext-1_2-beta3/providerutil.jar | Bin 0 -> 77116 bytes .../org/apache/qpid/jndi/referenceable/Bind.java | 2 +- .../org/apache/qpid/jndi/referenceable/Unbind.java | 6 +-- .../apache/qpid/jndi/referenceabletest/Bind.java | 52 ++++++++++++++++----- .../referenceabletest/JNDIReferenceableTest.java | 8 +--- .../apache/qpid/jndi/referenceabletest/Lookup.java | 35 +++++++++++--- .../apache/qpid/jndi/referenceabletest/Unbind.java | 29 ++++++++++-- 8 files changed, 100 insertions(+), 32 deletions(-) create mode 100644 java/client/test/lib/fscontext-1_2-beta3/fscontext.jar create mode 100644 java/client/test/lib/fscontext-1_2-beta3/providerutil.jar (limited to 'java') diff --git a/java/client/test/lib/fscontext-1_2-beta3/fscontext.jar b/java/client/test/lib/fscontext-1_2-beta3/fscontext.jar new file mode 100644 index 0000000000..0efc25071a Binary files /dev/null and b/java/client/test/lib/fscontext-1_2-beta3/fscontext.jar differ diff --git a/java/client/test/lib/fscontext-1_2-beta3/providerutil.jar b/java/client/test/lib/fscontext-1_2-beta3/providerutil.jar new file mode 100644 index 0000000000..0d6e48f388 Binary files /dev/null and b/java/client/test/lib/fscontext-1_2-beta3/providerutil.jar differ diff --git a/java/client/test/src/org/apache/qpid/jndi/referenceable/Bind.java b/java/client/test/src/org/apache/qpid/jndi/referenceable/Bind.java index 0829de0e82..3715ef7cc4 100644 --- a/java/client/test/src/org/apache/qpid/jndi/referenceable/Bind.java +++ b/java/client/test/src/org/apache/qpid/jndi/referenceable/Bind.java @@ -33,7 +33,7 @@ import java.io.IOException; * Binds a reference from a JNDI source. * Given a properties file with the JNDI information and a binding string. */ -class Bind +public class Bind { private static final String USAGE="USAGE: java bind -cf | -c [-t ] [-q ]"; public Bind(String propertiesFile, String bindingURL, Referenceable reference) throws NameAlreadyBoundException, NoInitialContextException diff --git a/java/client/test/src/org/apache/qpid/jndi/referenceable/Unbind.java b/java/client/test/src/org/apache/qpid/jndi/referenceable/Unbind.java index 90e5918e5c..1e9f57c07f 100644 --- a/java/client/test/src/org/apache/qpid/jndi/referenceable/Unbind.java +++ b/java/client/test/src/org/apache/qpid/jndi/referenceable/Unbind.java @@ -28,11 +28,11 @@ import java.io.IOException; * Unbinds a reference from a JNDI source. * Given a properties file with the JNDI information and a binding string. */ -class UnBind +public class Unbind { private static final String USAGE = "USAGE: java unbind -b "; - public UnBind(String propertiesFile, String bindingValue) throws NamingException + public Unbind(String propertiesFile, String bindingValue) throws NamingException { // Set up the environment for creating the initial context String qpid_home = System.getProperty("QPID_HOME"); @@ -143,7 +143,7 @@ class UnBind System.out.print("UnBinding:" + binding); try { - new UnBind(args[0], binding); + new Unbind(args[0], binding); System.out.println(" ..Successful"); } catch (NamingException nabe) diff --git a/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Bind.java b/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Bind.java index d5840d9600..221237a37c 100644 --- a/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Bind.java +++ b/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Bind.java @@ -18,15 +18,22 @@ package org.apache.qpid.jndi.referenceabletest; import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQTopic; import org.apache.qpid.client.AMQConnectionFactory; -import org.apache.qpid.AMQException; +import org.apache.qpid.client.AMQTopic; import org.apache.qpid.url.URLSyntaxException; import org.junit.Assert; -import javax.jms.*; -import javax.naming.*; - +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.JMSException; +import javax.jms.Session; +import javax.jms.Topic; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NameAlreadyBoundException; +import javax.naming.NamingException; +import javax.naming.NoInitialContextException; +import java.io.File; import java.util.Hashtable; /** @@ -41,11 +48,12 @@ import java.util.Hashtable; */ class Bind { + public static final String DEFAULT_PROVIDER_FILE_PATH = System.getProperty("java.io.tmpdir") + "/JNDITest"; + public static final String PROVIDER_URL = "file://" + DEFAULT_PROVIDER_FILE_PATH; String _connectionFactoryString = ""; - String _connectionString = "amqp://guest:guest@clientid/testpath?brokerlist='tcp://localhost:5672'"; - + String _connectionString = "amqp://guest:guest@clientid/testpath?brokerlist='vm://:1'"; Topic _topic = null; boolean _bound = false; @@ -54,13 +62,35 @@ class Bind { this(false); } + public Bind(boolean output) throws NameAlreadyBoundException, NoInitialContextException { // Set up the environment for creating the initial context Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); - env.put(Context.PROVIDER_URL, "file:/temp/qpid-jndi-test"); + env.put(Context.PROVIDER_URL, PROVIDER_URL); + + + File file = new File(PROVIDER_URL.substring(PROVIDER_URL.indexOf("://") + 3)); + + if (file.exists() && !file.isDirectory()) + { + System.out.println("Couldn't make directory file already exists"); + return; + } + else + { + if (!file.exists()) + { + if (!file.mkdirs()) + { + System.out.println("Couldn't make directory"); + return; + } + } + } + try { @@ -93,7 +123,6 @@ class Bind Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); _topic = session.createTopic("Fruity"); - } catch (JMSException jmse) { @@ -129,15 +158,14 @@ class Bind System.out.println("Operation failed: " + e); if (e instanceof NameAlreadyBoundException) { - throw (NameAlreadyBoundException) e; + throw(NameAlreadyBoundException) e; } if (e instanceof NoInitialContextException) { - throw (NoInitialContextException) e; + throw(NoInitialContextException) e; } } - } public String connectionFactoryValue() diff --git a/java/client/test/src/org/apache/qpid/jndi/referenceabletest/JNDIReferenceableTest.java b/java/client/test/src/org/apache/qpid/jndi/referenceabletest/JNDIReferenceableTest.java index c167442783..7c7d32991f 100644 --- a/java/client/test/src/org/apache/qpid/jndi/referenceabletest/JNDIReferenceableTest.java +++ b/java/client/test/src/org/apache/qpid/jndi/referenceabletest/JNDIReferenceableTest.java @@ -45,12 +45,9 @@ public class JNDIReferenceableTest Bind b = null; try { - - try { b = new Bind(); - } catch (NameAlreadyBoundException e) { @@ -69,7 +66,6 @@ public class JNDIReferenceableTest { Assert.fail("Unable to clear bound objects for test."); } - } } catch (NoInitialContextException e) @@ -99,10 +95,8 @@ public class JNDIReferenceableTest } - public static junit.framework.Test suite - () + public static junit.framework.Test suite() { return new JUnit4TestAdapter(JNDIReferenceableTest.class); } - } diff --git a/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Lookup.java b/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Lookup.java index f5bebeec6b..481500b8f0 100644 --- a/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Lookup.java +++ b/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Lookup.java @@ -17,11 +17,14 @@ */ package org.apache.qpid.jndi.referenceabletest; -import org.apache.qpid.client.AMQTopic; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQConnectionFactory; +import org.apache.qpid.client.AMQTopic; -import javax.naming.*; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import java.io.File; import java.util.Hashtable; @@ -37,6 +40,9 @@ import java.util.Hashtable; */ class Lookup { + public static final String DEFAULT_PROVIDER_FILE_PATH = System.getProperty("java.io.tmpdir") + "/JNDITest"; + public static final String PROVIDER_URL = "file://" + DEFAULT_PROVIDER_FILE_PATH; + AMQTopic _topic = null; AMQConnection _connection = null; AMQConnectionFactory _connectionFactory = null; @@ -47,7 +53,26 @@ class Lookup Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); - env.put(Context.PROVIDER_URL, "file:/temp/qpid-jndi-test"); + env.put(Context.PROVIDER_URL, PROVIDER_URL); + + File file = new File(PROVIDER_URL.substring(PROVIDER_URL.indexOf("://") + 3)); + + if (file.exists() && !file.isDirectory()) + { + System.out.println("Couldn't make directory file already exists"); + return; + } + else + { + if (!file.exists()) + { + if (!file.mkdirs()) + { + System.out.println("Couldn't make directory"); + return; + } + } + } try { @@ -70,10 +95,9 @@ class Lookup } } - public String connectionFactoryValue() { - return ((AMQConnection) _connectionFactory.getConnectionURL()).toURL(); + return _connectionFactory.getConnectionURL().toString(); } public String connectionValue() @@ -86,7 +110,6 @@ class Lookup return _topic.toURL(); } - public static void main(String[] args) { new Lookup(); diff --git a/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Unbind.java b/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Unbind.java index d2787f6dd0..767f7c5737 100644 --- a/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Unbind.java +++ b/java/client/test/src/org/apache/qpid/jndi/referenceabletest/Unbind.java @@ -17,7 +17,10 @@ */ package org.apache.qpid.jndi.referenceabletest; -import javax.naming.*; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NameNotFoundException; +import javax.naming.NamingException; import java.io.File; import java.util.Hashtable; @@ -33,7 +36,8 @@ import java.util.Hashtable; */ class Unbind { - + public static final String DEFAULT_PROVIDER_FILE_PATH = System.getProperty("java.io.tmpdir") + "/JNDITest"; + public static final String PROVIDER_URL = "file://" + DEFAULT_PROVIDER_FILE_PATH; boolean _unbound = false; @@ -49,7 +53,26 @@ class Unbind Hashtable env = new Hashtable(11); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); - env.put(Context.PROVIDER_URL, "file:/temp/qpid-jndi-test"); + env.put(Context.PROVIDER_URL, PROVIDER_URL); + + File file = new File(PROVIDER_URL.substring(PROVIDER_URL.indexOf("://") + 3)); + + if (file.exists() && !file.isDirectory()) + { + System.out.println("Couldn't make directory file already exists"); + return; + } + else + { + if (!file.exists()) + { + if (!file.mkdirs()) + { + System.out.println("Couldn't make directory"); + return; + } + } + } try { -- cgit v1.2.1