Added:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/message/TextMessageTest.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/message/TextMessageTest.java?view=auto&rev=472458
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/message/TextMessageTest.java
(added)
+++
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/message/TextMessageTest.java
Wed Nov 8 04:12:24 2006
@@ -0,0 +1,53 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.test.unit.client.message;
+
+import junit.framework.JUnit4TestAdapter;
+import org.junit.Test;
+import org.junit.Assert;
+import org.apache.qpid.client.message.TestMessageHelper;
+import org.apache.qpid.client.message.JMSTextMessage;
+
+public class TextMessageTest
+{
+ @Test
+ public void testTextOnConstruction() throws Exception
+ {
+ JMSTextMessage tm = TestMessageHelper.newJMSTextMessage();
+ tm.setText("pies");
+ String val = tm.getText();
+ Assert.assertEquals(val, "pies");
+ }
+
+ @Test
+ public void testClearBody() throws Exception
+ {
+ JMSTextMessage tm = TestMessageHelper.newJMSTextMessage();
+ tm.setText("pies");
+ tm.clearBody();
+ String val = tm.getText();
+ Assert.assertNull(val);
+ tm.setText("Banana");
+ val = tm.getText();
+ Assert.assertEquals(val, "Banana");
+ }
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(TextMessageTest.class);
+ }
+}
Propchange:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/message/TextMessageTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java?view=auto&rev=472458
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java
(added)
+++
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java
Wed Nov 8 04:12:24 2006
@@ -0,0 +1,116 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.test.unit.client.protocol;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.protocol.AMQProtocolHandler;
+import org.apache.qpid.client.protocol.AMQProtocolSession;
+import org.apache.mina.common.IoSession;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.After;
+import junit.framework.JUnit4TestAdapter;
+import junit.framework.Assert;
+
+public class AMQProtocolSessionTest extends AMQProtocolSession
+{
+ //private Strings for test values and expected results
+ private String _brokenAddress;
+ private String _generatedAddress;
+ private String _emptyAddress;
+ private String _generatedAddress_2;
+ private String _validAddress;
+ private String _generatedAddress_3;
+ private int _port;
+ private AMQProtocolSessionTest _testSession;
+
+ public AMQProtocolSessionTest()
+ {
+
+ }
+
+ public AMQProtocolSessionTest(AMQProtocolHandler protocolHandler,
IoSession protocolSession, AMQConnection connection)
+ {
+ super(protocolHandler,protocolSession,connection);
+ }
+
+ public TestIoSession getMinaProtocolSession()
+ {
+ return (TestIoSession) _minaProtocolSession;
+ }
+
+ @Before
+ public void setUp()
+ {
+ //don't care about the values set here apart from the dummy IoSession
+ _testSession = new AMQProtocolSessionTest(null,new
TestIoSession(),null);
+
+ //initialise addresses for test and expected results
+ _port = 123;
+ _brokenAddress = "tcp://myAddress;:";
+ _generatedAddress = "tmp_tcpmyAddress123_1";
+ _emptyAddress = "";
+ _generatedAddress_2 = "tmp_localhost127.0.0.1123_2";
+ _validAddress = "abc";
+ _generatedAddress_3 = "tmp_abc123_3";
+
+ }
+
+ @Test
+ public void TestGenerateQueueName()
+ {
+ String testAddress;
+
+ //test address with / and ; chars which generateQueueName should remove
+
_testSession.getMinaProtocolSession().setStringLocalAddress(_brokenAddress);
+ _testSession.getMinaProtocolSession().setLocalPort(_port);
+
+ testAddress = _testSession.generateQueueName();
+ Assert.assertEquals("Failure when generating a queue name from an
address with special chars",_generatedAddress,testAddress);
+
+ //test empty address
+
_testSession.getMinaProtocolSession().setStringLocalAddress(_emptyAddress);
+
+ testAddress = _testSession.generateQueueName();
+ Assert.assertEquals("Failure when generating a queue name from an
empty address",_generatedAddress_2,testAddress);
+
+ //test address with no special chars
+
_testSession.getMinaProtocolSession().setStringLocalAddress(_validAddress);
+
+ testAddress = _testSession.generateQueueName();
+ Assert.assertEquals("Failure when generating a queue name from an
address with no special chars",_generatedAddress_3,testAddress);
+
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(AMQProtocolSessionTest.class);
+ }
+
+ @After
+ public void tearDown()
+ {
+ _testSession = null;
+ _brokenAddress = null;
+ _generatedAddress = null;
+ _emptyAddress = null;
+ _generatedAddress_2 = null;
+ _validAddress = null;
+ _generatedAddress_3 = null;
+ }
+}
Propchange:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/protocol/TestIoSession.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/protocol/TestIoSession.java?view=auto&rev=472458
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/protocol/TestIoSession.java
(added)
+++
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/protocol/TestIoSession.java
Wed Nov 8 04:12:24 2006
@@ -0,0 +1,96 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.test.unit.client.protocol;
+
+import org.apache.mina.common.support.BaseIoSession;
+import org.apache.mina.common.*;
+
+import java.net.SocketAddress;
+import java.net.InetSocketAddress;
+
+public class TestIoSession extends BaseIoSession {
+
+ private String _stringLocalAddress;
+ private int _localPort;
+
+ public SocketAddress getLocalAddress()
+ {
+ //create a new address for testing purposes using member variables
+ return new InetSocketAddress(_stringLocalAddress,_localPort);
+ }
+
+ protected void updateTrafficMask() {
+ //dummy
+ }
+
+ public IoService getService() {
+ return null;
+ }
+
+ public IoServiceConfig getServiceConfig() {
+ return null;
+ }
+
+ public IoHandler getHandler() {
+ return null;
+ }
+
+ public IoSessionConfig getConfig() {
+ return null;
+ }
+
+ public IoFilterChain getFilterChain() {
+ return null;
+ }
+
+ public TransportType getTransportType() {
+ return null;
+ }
+
+ public SocketAddress getRemoteAddress() {
+ return null;
+ }
+
+ public SocketAddress getServiceAddress() {
+ return null;
+ }
+
+ public int getScheduledWriteRequests() {
+ return 0;
+ }
+
+ public int getScheduledWriteBytes() {
+ return 0;
+ }
+
+ public String getStringLocalAddress() {
+ return _stringLocalAddress;
+ }
+
+ public void setStringLocalAddress(String _stringLocalAddress) {
+ this._stringLocalAddress = _stringLocalAddress;
+ }
+
+ public int getLocalPort() {
+ return _localPort;
+ }
+
+ public void setLocalPort(int _localPort) {
+ this._localPort = _localPort;
+ }
+}
Propchange:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/client/protocol/TestIoSession.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java?view=auto&rev=472458
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java
(added)
+++
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java
Wed Nov 8 04:12:24 2006
@@ -0,0 +1,210 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.test.unit.jndi.referenceabletest;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQConnectionFactory;
+import org.apache.qpid.client.AMQTopic;
+import org.apache.qpid.url.URLSyntaxException;
+import org.junit.Assert;
+
+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;
+
+/**
+ * Usage: To run these you need to have the sun JNDI SPI for the FileSystem.
+ * This can be downloaded from sun here:
+ * http://java.sun.com/products/jndi/downloads/index.html
+ * Click : Download JNDI 1.2.1 & More button
+ * Download: File System Service Provider, 1.2 Beta 3
+ * and add the two jars in the lib dir to your class path.
+ * <p/>
+ * Also you need to create the directory /temp/qpid-jndi-test
+ */
+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:[EMAIL
PROTECTED]/testpath?brokerlist='vm://:1'";
+ Topic _topic = null;
+
+ boolean _bound = false;
+
+ public Bind() throws NameAlreadyBoundException, NoInitialContextException
+ {
+ 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, 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;
+ }
+ }
+ }
+
+ Connection connection = null;
+ try
+ {
+ // Create the initial context
+ Context ctx = new InitialContext(env);
+
+ // Create the connection factory to be bound
+ ConnectionFactory connectionFactory = null;
+ // Create the Connection to be bound
+
+
+ try
+ {
+ connectionFactory = new
AMQConnectionFactory(_connectionString);
+ connection = connectionFactory.createConnection();
+
+ _connectionFactoryString = ((AMQConnectionFactory)
connectionFactory).getConnectionURL().getURL();
+ }
+ catch (JMSException jmsqe)
+ {
+ Assert.fail("Unable to create Connection:" + jmsqe);
+ }
+ catch (URLSyntaxException urlse)
+ {
+ Assert.fail("Unable to create Connection:" + urlse);
+ }
+
+ try
+ {
+ Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+
+ _topic = session.createTopic("Fruity");
+ }
+ catch (JMSException jmse)
+ {
+
+ }
+ // Perform the binds
+ ctx.bind("ConnectionFactory", connectionFactory);
+ if (output)
+ {
+ System.out.println("Bound factory\n" + ((AMQConnectionFactory)
connectionFactory).getConnectionURL());
+ }
+ ctx.bind("Connection", connection);
+ if (output)
+ {
+ System.out.println("Bound Connection\n" + ((AMQConnection)
connection).toURL());
+ }
+ ctx.bind("Topic", _topic);
+ if (output)
+ {
+ System.out.println("Bound Topic:\n" + ((AMQTopic)
_topic).toURL());
+ }
+ _bound = true;
+
+ // Check that it is bound
+ //Object obj = ctx.lookup("Connection");
+ //System.out.println(((AMQConnection)obj).toURL());
+
+ // Close the context when we're done
+ ctx.close();
+ }
+ catch (NamingException e)
+ {
+ System.out.println("Operation failed: " + e);
+ if (e instanceof NameAlreadyBoundException)
+ {
+ throw(NameAlreadyBoundException) e;
+ }
+
+ if (e instanceof NoInitialContextException)
+ {
+ throw(NoInitialContextException) e;
+ }
+ }
+ finally
+ {
+ try
+ {
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }
+ catch (JMSException e)
+ {
+ //ignore just want it closed
+ }
+ }
+ }
+
+ public String connectionFactoryValue()
+ {
+ return _connectionFactoryString;
+ }
+
+ public String connectionValue()
+ {
+ return _connectionString;
+ }
+
+ public String topicValue()
+ {
+ return ((AMQTopic) _topic).toURL();
+ }
+
+ public boolean bound()
+ {
+ return _bound;
+ }
+
+ public static void main(String[] args) throws NameAlreadyBoundException,
NoInitialContextException
+ {
+ new Bind(true);
+ }
+}
+
Propchange:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java?view=auto&rev=472458
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java
(added)
+++
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java
Wed Nov 8 04:12:24 2006
@@ -0,0 +1,123 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.test.unit.jndi.referenceabletest;
+
+import org.junit.Test;
+import org.junit.Assert;
+import org.junit.After;
+import org.junit.Before;
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import junit.framework.JUnit4TestAdapter;
+
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NoInitialContextException;
+
+
+/**
+ * Usage: To run these you need to have the sun JNDI SPI for the FileSystem.
+ * This can be downloaded from sun here:
+ * http://java.sun.com/products/jndi/downloads/index.html
+ * Click : Download JNDI 1.2.1 & More button
+ * Download: File System Service Provider, 1.2 Beta 3
+ * and add the two jars in the lib dir to your class path.
+ * <p/>
+ * Also you need to create the directory /temp/qpid-jndi-test
+ */
+public class JNDIReferenceableTest
+{
+ @Before
+ public void createVMBroker()
+ {
+ try
+ {
+ TransportConnection.createVMBroker(1);
+ }
+ catch (AMQVMBrokerCreationException e)
+ {
+ Assert.fail("Unable to create broker: " + e);
+ }
+ }
+
+ @After
+ public void stopVmBroker()
+ {
+ TransportConnection.killVMBroker(1);
+ }
+
+ @Test
+ public void referenceable()
+ {
+ Bind b = null;
+ try
+ {
+ try
+ {
+ b = new Bind();
+ }
+ catch (NameAlreadyBoundException e)
+ {
+ if (new Unbind().unbound())
+ {
+ try
+ {
+ b = new Bind();
+ }
+ catch (NameAlreadyBoundException ee)
+ {
+ Assert.fail("Unable to clear bound objects for test.");
+ }
+ }
+ else
+ {
+ Assert.fail("Unable to clear bound objects for test.");
+ }
+ }
+ }
+ catch (NoInitialContextException e)
+ {
+ Assert.fail("You don't have the File System SPI on you class
path.\n" +
+ "This can be downloaded from sun here:\n" +
+
"http://java.sun.com/products/jndi/downloads/index.html\n" +
+ "Click : Download JNDI 1.2.1 & More button\n" +
+ "Download: File System Service Provider, 1.2 Beta 3\n"
+
+ "and add the two jars in the lib dir to your class
path.");
+ }
+
+ Assert.assertTrue(b.bound());
+
+ Lookup l = new Lookup();
+
+
Assert.assertTrue(l.connectionFactoryValue().equals(b.connectionFactoryValue()));
+
+ Assert.assertTrue(l.connectionValue().equals(b.connectionValue()));
+
+ Assert.assertTrue(l.topicValue().equals(b.topicValue()));
+
+
+ Unbind u = new Unbind();
+
+ Assert.assertTrue(u.unbound());
+
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(JNDIReferenceableTest.class);
+ }
+}
Propchange:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Lookup.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Lookup.java?view=auto&rev=472458
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Lookup.java
(added)
+++
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Lookup.java
Wed Nov 8 04:12:24 2006
@@ -0,0 +1,136 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.test.unit.jndi.referenceabletest;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQConnectionFactory;
+import org.apache.qpid.client.AMQTopic;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.jms.JMSException;
+import java.io.File;
+import java.util.Hashtable;
+
+
+/**
+ * Usage: To run these you need to have the sun JNDI SPI for the FileSystem.
+ * This can be downloaded from sun here:
+ * http://java.sun.com/products/jndi/downloads/index.html
+ * Click : Download JNDI 1.2.1 & More button
+ * Download: File System Service Provider, 1.2 Beta 3
+ * and add the two jars in the lib dir to your class path.
+ * <p/>
+ * Also you need to create the directory /temp/qpid-jndi-test
+ */
+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;
+ private String _connectionURL;
+
+ public Lookup()
+ {
+ // 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, 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
+ {
+ // Create the initial context
+ Context ctx = new InitialContext(env);
+
+ _topic = (AMQTopic) ctx.lookup("Topic");
+
+ _connection = (AMQConnection) ctx.lookup("Connection");
+
+ _connectionURL = _connection.toURL();
+
+ _connectionFactory = (AMQConnectionFactory)
ctx.lookup("ConnectionFactory");
+ //System.out.println(topic);
+
+ // Close the context when we're done
+ ctx.close();
+ }
+ catch (NamingException e)
+ {
+ System.out.println("Operation failed: " + e);
+ }
+ finally
+ {
+ try
+ {
+ if (_connection != null)
+ {
+ _connection.close();
+ }
+ }
+ catch (JMSException e)
+ {
+ //ignore just need to close
+ }
+ }
+ }
+
+ public String connectionFactoryValue()
+ {
+ return _connectionFactory.getConnectionURL().toString();
+ }
+
+ public String connectionValue()
+ {
+ return _connectionURL;
+ }
+
+ public String topicValue()
+ {
+ return _topic.toURL();
+ }
+
+ public static void main(String[] args)
+ {
+ new Lookup();
+ }
+}
+
Propchange:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Lookup.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Unbind.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Unbind.java?view=auto&rev=472458
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Unbind.java
(added)
+++
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Unbind.java
Wed Nov 8 04:12:24 2006
@@ -0,0 +1,158 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.test.unit.jndi.referenceabletest;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import java.io.File;
+import java.util.Hashtable;
+
+/**
+ * Usage: To run these you need to have the sun JNDI SPI for the FileSystem.
+ * This can be downloaded from sun here:
+ * http://java.sun.com/products/jndi/downloads/index.html
+ * Click : Download JNDI 1.2.1 & More button
+ * Download: File System Service Provider, 1.2 Beta 3
+ * and add the two jars in the lib dir to your class path.
+ * <p/>
+ * Also you need to create the directory /temp/qpid-jndi-test
+ */
+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;
+
+ public Unbind()
+ {
+ this(false);
+ }
+
+ public Unbind(boolean output)
+ {
+ // 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, 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
+ {
+ // Create the initial context
+ Context ctx = new InitialContext(env);
+
+ // Remove the binding
+ ctx.unbind("ConnectionFactory");
+ ctx.unbind("Connection");
+ ctx.unbind("Topic");
+
+ // Check that it is gone
+ Object obj = null;
+ try
+ {
+ obj = ctx.lookup("ConnectionFactory");
+ }
+ catch (NameNotFoundException ne)
+ {
+ if (output)
+ {
+ System.out.println("unbind ConnectionFactory successful");
+ }
+ try
+ {
+ obj = ctx.lookup("Connection");
+ try
+ {
+ ((Connection) obj).close();
+ }
+ catch (JMSException e)
+ {
+ //ignore just need to close
+ }
+ }
+ catch (NameNotFoundException ne2)
+ {
+ if (output)
+ {
+ System.out.println("unbind Connection successful");
+ }
+
+ try
+ {
+ obj = ctx.lookup("Topic");
+ }
+ catch (NameNotFoundException ne3)
+ {
+ if (output)
+ {
+ System.out.println("unbind Topic successful");
+ }
+ _unbound = true;
+ }
+ }
+ }
+
+ //System.out.println("unbind failed; object still there: " + obj);
+
+ // Close the context when we're done
+
+ ctx.close();
+
+ }
+ catch (NamingException e)
+ {
+ System.out.println("Operation failed: " + e);
+ }
+ }
+
+ public boolean unbound()
+ {
+ return _unbound;
+ }
+
+ public static void main(String[] args)
+ {
+
+ new Unbind(true);
+ }
+}
+
Propchange:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Unbind.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java?view=auto&rev=472458
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java
(added)
+++
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java
Wed Nov 8 04:12:24 2006
@@ -0,0 +1,32 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.test.unit.jndi.referenceabletest;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import junit.framework.JUnit4TestAdapter;
+
[EMAIL PROTECTED](Suite.class)
[EMAIL PROTECTED]({JNDIReferenceableTest.class})
+public class UnitTests
+{
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(UnitTests.class);
+ }
+}
Propchange:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java?view=auto&rev=472458
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
(added)
+++
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
Wed Nov 8 04:12:24 2006
@@ -0,0 +1,157 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.test.unit.topic;
+
+import junit.framework.JUnit4TestAdapter;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import org.apache.qpid.url.URLSyntaxException;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.AMQTopic;
+import org.apache.qpid.client.transport.TransportConnection;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.TopicSubscriber;
+
+public class DurableSubscriptionTest
+{
+
+ @Before
+ public void createVMBroker()
+ {
+ try
+ {
+ TransportConnection.createVMBroker(1);
+ }
+ catch (AMQVMBrokerCreationException e)
+ {
+ Assert.fail("Unable to create broker: " + e);
+ }
+ }
+
+ @After
+ public void stopVmBroker()
+ {
+ TransportConnection.killVMBroker(1);
+ }
+
+ @Test
+ public void unsubscribe() throws AMQException, JMSException,
URLSyntaxException
+ {
+ AMQTopic topic = new AMQTopic("MyTopic");
+ AMQConnection con = new AMQConnection("vm://:1", "guest", "guest",
"test", "/test");
+ Session session1 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE);
+ MessageConsumer consumer1 = session1.createConsumer(topic);
+ MessageProducer producer = session1.createProducer(topic);
+
+ Session session2 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE);
+ TopicSubscriber consumer2 = session2.createDurableSubscriber(topic,
"MySubscription");
+
+ con.start();
+
+ producer.send(session1.createTextMessage("A"));
+
+ Message msg;
+ msg = consumer1.receive();
+ Assert.assertEquals("A", ((TextMessage) msg).getText());
+ msg = consumer1.receive(1000);
+ Assert.assertEquals(null, msg);
+
+ msg = consumer2.receive();
+ Assert.assertEquals("A", ((TextMessage) msg).getText());
+ msg = consumer2.receive(1000);
+ Assert.assertEquals(null, msg);
+
+ session2.unsubscribe("MySubscription");
+
+ producer.send(session1.createTextMessage("B"));
+
+ msg = consumer1.receive();
+ Assert.assertEquals("B", ((TextMessage) msg).getText());
+ msg = consumer1.receive(1000);
+ Assert.assertEquals(null, msg);
+
+ msg = consumer2.receive(1000);
+ Assert.assertEquals(null, msg);
+
+ con.close();
+ }
+
+ @Test
+ public void durability() throws AMQException, JMSException,
URLSyntaxException
+ {
+ AMQTopic topic = new AMQTopic("MyTopic");
+ AMQConnection con = new AMQConnection("vm://:1", "guest", "guest",
"test", "/test");
+ Session session1 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE);
+ MessageConsumer consumer1 = session1.createConsumer(topic);
+ MessageProducer producer = session1.createProducer(topic);
+
+ Session session2 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE);
+ TopicSubscriber consumer2 = session2.createDurableSubscriber(topic,
"MySubscription");
+
+ con.start();
+
+ producer.send(session1.createTextMessage("A"));
+
+ Message msg;
+ msg = consumer1.receive();
+ Assert.assertEquals("A", ((TextMessage) msg).getText());
+ msg = consumer1.receive(1000);
+ Assert.assertEquals(null, msg);
+
+ msg = consumer2.receive();
+ Assert.assertEquals("A", ((TextMessage) msg).getText());
+ msg = consumer2.receive(1000);
+ Assert.assertEquals(null, msg);
+
+ consumer2.close();
+
+ Session session3 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE);
+ MessageConsumer consumer3 = session3.createDurableSubscriber(topic,
"MySubscription");
+
+ producer.send(session1.createTextMessage("B"));
+
+ msg = consumer1.receive();
+ Assert.assertEquals("B", ((TextMessage) msg).getText());
+ msg = consumer1.receive(1000);
+ Assert.assertEquals(null, msg);
+
+ msg = consumer3.receive();
+ Assert.assertEquals("B", ((TextMessage) msg).getText());
+ msg = consumer3.receive(1000);
+ Assert.assertEquals(null, msg);
+
+ con.close();
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(DurableSubscriptionTest.class);
+ }
+
+}
Propchange:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/transacted/TransactedTest.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/transacted/TransactedTest.java?view=auto&rev=472458
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/transacted/TransactedTest.java
(added)
+++
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/transacted/TransactedTest.java
Wed Nov 8 04:12:24 2006
@@ -0,0 +1,170 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.test.unit.transacted;
+
+import junit.framework.JUnit4TestAdapter;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import org.junit.After;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+
+import javax.jms.*;
+
+public class TransactedTest
+{
+ private AMQQueue queue1;
+ private AMQQueue queue2;
+
+ private AMQConnection con;
+ private Session session;
+ private MessageConsumer consumer1;
+ private MessageProducer producer2;
+
+ private AMQConnection prepCon;
+ private Session prepSession;
+ private MessageProducer prepProducer1;
+
+ private AMQConnection testCon;
+ private Session testSession;
+ private MessageConsumer testConsumer1;
+ private MessageConsumer testConsumer2;
+
+
+ public void createVMBroker()
+ {
+ try
+ {
+ TransportConnection.createVMBroker(1);
+ }
+ catch (AMQVMBrokerCreationException e)
+ {
+ Assert.fail("Unable to create broker: " + e);
+ }
+ }
+
+ @After
+ public void stopVmBroker()
+ {
+ TransportConnection.killVMBroker(1);
+ }
+
+ @Before
+ public void setup() throws Exception
+ {
+ createVMBroker();
+ queue1 = new AMQQueue("Q1", false);
+ queue2 = new AMQQueue("Q2", false);
+
+ con = new AMQConnection("vm://:1", "guest", "guest", "TransactedTest",
"/test");
+ session = con.createSession(true, 0);
+ consumer1 = session.createConsumer(queue1);
+ producer2 = session.createProducer(queue2);
+ con.start();
+
+ prepCon = new AMQConnection("vm://:1", "guest", "guest",
"PrepConnection", "/test");
+ prepSession = prepCon.createSession(false, AMQSession.NO_ACKNOWLEDGE);
+ prepProducer1 = prepSession.createProducer(queue1);
+ prepCon.start();
+
+
+ //add some messages
+ prepProducer1.send(prepSession.createTextMessage("A"));
+ prepProducer1.send(prepSession.createTextMessage("B"));
+ prepProducer1.send(prepSession.createTextMessage("C"));
+
+ testCon = new AMQConnection("vm://:1", "guest", "guest",
"TestConnection", "/test");
+ testSession = testCon.createSession(false, AMQSession.NO_ACKNOWLEDGE);
+ testConsumer1 = testSession.createConsumer(queue1);
+ testConsumer2 = testSession.createConsumer(queue2);
+ testCon.start();
+ }
+
+ @After
+ public void shutdown() throws Exception
+ {
+ con.close();
+ testCon.close();
+ prepCon.close();
+ }
+
+ @Test
+ public void commit() throws Exception
+ {
+ //send and receive some messages
+ producer2.send(session.createTextMessage("X"));
+ producer2.send(session.createTextMessage("Y"));
+ producer2.send(session.createTextMessage("Z"));
+ expect("A", consumer1.receive(1000));
+ expect("B", consumer1.receive(1000));
+ expect("C", consumer1.receive(1000));
+
+ //commit
+ session.commit();
+
+ //ensure sent messages can be received and received messages are gone
+ expect("X", testConsumer2.receive(1000));
+ expect("Y", testConsumer2.receive(1000));
+ expect("Z", testConsumer2.receive(1000));
+
+ assertTrue(null == testConsumer1.receive(1000));
+ assertTrue(null == testConsumer2.receive(1000));
+ }
+
+ @Test
+ public void rollback() throws Exception
+ {
+ producer2.send(session.createTextMessage("X"));
+ producer2.send(session.createTextMessage("Y"));
+ producer2.send(session.createTextMessage("Z"));
+ expect("A", consumer1.receive(1000));
+ expect("B", consumer1.receive(1000));
+ expect("C", consumer1.receive(1000));
+
+ //rollback
+ session.rollback();
+
+ //ensure sent messages are not visible and received messages are
requeued
+ expect("A", consumer1.receive(1000));
+ expect("B", consumer1.receive(1000));
+ expect("C", consumer1.receive(1000));
+
+ assertTrue(null == testConsumer1.receive(1000));
+ assertTrue(null == testConsumer2.receive(1000));
+ }
+
+ private void expect(String text, Message msg) throws JMSException
+ {
+ assertTrue(msg instanceof TextMessage);
+ assertEquals(text, ((TextMessage) msg).getText());
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(TransactedTest.class);
+ }
+
+}
Propchange:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/transacted/TransactedTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/transacted/UnitTests.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/transacted/UnitTests.java?view=auto&rev=472458
==============================================================================
---
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/transacted/UnitTests.java
(added)
+++
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/transacted/UnitTests.java
Wed Nov 8 04:12:24 2006
@@ -0,0 +1,32 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.qpid.test.unit.transacted;
+
+import junit.framework.JUnit4TestAdapter;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
[EMAIL PROTECTED](Suite.class)
[EMAIL PROTECTED]({TransactedTest.class})
+public class UnitTests
+{
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(UnitTests.class);
+ }
+}
Propchange:
incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/test/unit/transacted/UnitTests.java
------------------------------------------------------------------------------
svn:eol-style = native