[jboss-cvs] JBoss Messaging SVN: r4517 - in trunk: tests/src/org/jboss/messaging/tests/unit/jms/client and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 18 10:36:36 EDT 2008
Author: jmesnil
Date: 2008-06-18 10:36:35 -0400 (Wed, 18 Jun 2008)
New Revision: 4517
Added:
trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossConnectionFactoryTest.java
Modified:
trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionFactory.java
Log:
added unit tests for JBossConnectionFactory
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionFactory.java 2008-06-18 14:26:10 UTC (rev 4516)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossConnectionFactory.java 2008-06-18 14:36:35 UTC (rev 4517)
@@ -122,6 +122,25 @@
this.defaultSendNonPersistentMessagesBlocking = defaultSendNonPersistentMessagesBlocking;
this.defaultSendPersistentMessagesBlocking = defaultSendPersistentMessagesBlocking;
}
+
+ public JBossConnectionFactory(final ClientConnectionFactory factory,
+ final String clientID, final int dupsOKBatchSize,
+ final Location location, final ConnectionParams connectionParams,
+ final int defaultConsumerWindowSize, final int defaultConsumerMaxRate,
+ final int defaultProducerWindowSize, final int defaultProducerMaxRate,
+ final boolean defaultBlockOnAcknowledge,
+ final boolean defaultSendNonPersistentMessagesBlocking,
+ final boolean defaultSendPersistentMessagesBlocking)
+ {
+ this(clientID, dupsOKBatchSize, location, connectionParams,
+ defaultConsumerWindowSize, defaultConsumerMaxRate,
+ defaultProducerWindowSize, defaultProducerMaxRate,
+ defaultBlockOnAcknowledge,
+ defaultSendNonPersistentMessagesBlocking,
+ defaultSendPersistentMessagesBlocking);
+ this.connectionFactory = factory;
+ }
+
// ConnectionFactory implementation -------------------------------------------------------------
public Connection createConnection() throws JMSException
Added: trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossConnectionFactoryTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossConnectionFactoryTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossConnectionFactoryTest.java 2008-06-18 14:36:35 UTC (rev 4517)
@@ -0,0 +1,274 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.unit.jms.client;
+
+import static org.easymock.EasyMock.createStrictMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+
+import javax.jms.Connection;
+import javax.jms.QueueConnection;
+import javax.jms.TopicConnection;
+import javax.jms.XAConnection;
+import javax.jms.XAQueueConnection;
+import javax.jms.XATopicConnection;
+
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.client.Location;
+import org.jboss.messaging.jms.client.JBossConnectionFactory;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class JBossConnectionFactoryTest extends TestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testCreateConnection() throws Exception
+ {
+ doCreateConnection(Connection.class, new ConnectionCreation()
+ {
+ Connection createConnection(JBossConnectionFactory factory)
+ throws Exception
+ {
+ return factory.createConnection();
+ }
+ });
+ }
+
+ public void testCreateConnectionWithCredentials() throws Exception
+ {
+ doCreateConnectionWithCredentials(Connection.class, randomString(),
+ randomString(), new ConnectionCreation()
+ {
+ Connection createConnection(JBossConnectionFactory factory,
+ String user, String password) throws Exception
+ {
+ return factory.createConnection(user, password);
+ }
+ });
+ }
+
+ public void testCreateQueueConnection() throws Exception
+ {
+ doCreateConnection(QueueConnection.class, new ConnectionCreation()
+ {
+ public Connection createConnection(JBossConnectionFactory factory)
+ throws Exception
+ {
+ return factory.createQueueConnection();
+ }
+ });
+ }
+
+ public void testCreateQueueConnectionWithCredentials() throws Exception
+ {
+ doCreateConnectionWithCredentials(QueueConnection.class, randomString(),
+ randomString(), new ConnectionCreation()
+ {
+ Connection createConnection(JBossConnectionFactory factory,
+ String user, String password) throws Exception
+ {
+ return factory.createQueueConnection(user, password);
+ }
+ });
+ }
+
+ public void testCreateTopicConnection() throws Exception
+ {
+ doCreateConnection(TopicConnection.class, new ConnectionCreation()
+ {
+ public Connection createConnection(JBossConnectionFactory factory)
+ throws Exception
+ {
+ return factory.createTopicConnection();
+ }
+ });
+ }
+
+ public void testCreateTopicConnectionWithUserPassword() throws Exception
+ {
+ doCreateConnectionWithCredentials(TopicConnection.class, randomString(),
+ randomString(), new ConnectionCreation()
+ {
+ Connection createConnection(JBossConnectionFactory factory,
+ String user, String password) throws Exception
+ {
+ return factory.createTopicConnection(user, password);
+ }
+ });
+ }
+
+ public void testCreateXAConnection() throws Exception
+ {
+ doCreateConnection(XAConnection.class, new ConnectionCreation()
+ {
+ Connection createConnection(JBossConnectionFactory factory)
+ throws Exception
+ {
+ return factory.createXAConnection();
+ }
+ });
+ }
+
+ public void testCreateXAConnectionWithCredentials() throws Exception
+ {
+ doCreateConnectionWithCredentials(XAConnection.class, randomString(),
+ randomString(), new ConnectionCreation()
+ {
+ Connection createConnection(JBossConnectionFactory factory,
+ String user, String password) throws Exception
+ {
+ return factory.createXAConnection(user, password);
+ }
+ });
+ }
+
+ public void testCreateXAQueueConnection() throws Exception
+ {
+ doCreateConnection(XAQueueConnection.class, new ConnectionCreation()
+ {
+ public Connection createConnection(JBossConnectionFactory factory)
+ throws Exception
+ {
+ return factory.createXAQueueConnection();
+ }
+ });
+ }
+
+ public void testCreateXAQueueConnectionWithCredentials() throws Exception
+ {
+ doCreateConnectionWithCredentials(XAQueueConnection.class,
+ randomString(), randomString(), new ConnectionCreation()
+ {
+ Connection createConnection(JBossConnectionFactory factory,
+ String user, String password) throws Exception
+ {
+ return factory.createXAQueueConnection(user, password);
+ }
+ });
+ }
+
+ public void testCreateXATopicConnection() throws Exception
+ {
+ doCreateConnection(XATopicConnection.class, new ConnectionCreation()
+ {
+ public Connection createConnection(JBossConnectionFactory factory)
+ throws Exception
+ {
+ return factory.createXATopicConnection();
+ }
+ });
+ }
+
+ public void testCreateXATopicConnectionWithUserPassword() throws Exception
+ {
+ doCreateConnectionWithCredentials(XATopicConnection.class,
+ randomString(), randomString(), new ConnectionCreation()
+ {
+ Connection createConnection(JBossConnectionFactory factory,
+ String user, String password) throws Exception
+ {
+ return factory.createXATopicConnection(user, password);
+ }
+ });
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ private void doCreateConnection(Class expectedInterface,
+ ConnectionCreation creation) throws Exception
+ {
+ Location location = createStrictMock(Location.class);
+ ClientConnection clientConnection = createStrictMock(ClientConnection.class);
+ ClientConnectionFactory clientConnectionFactory = createStrictMock(ClientConnectionFactory.class);
+ expect(clientConnectionFactory.createConnection(null, null)).andReturn(
+ clientConnection);
+ replay(location, clientConnectionFactory);
+
+ JBossConnectionFactory factory = new JBossConnectionFactory(
+ clientConnectionFactory, null, 0, location, null, 0, 0, 0, 0,
+ false, false, false);
+ Object connection = creation.createConnection(factory);
+ assertNotNull(connection);
+ assertTrue(expectedInterface.isAssignableFrom(connection.getClass()));
+ verify(location, clientConnectionFactory);
+ }
+
+ private void doCreateConnectionWithCredentials(Class expectedInterface,
+ String user, String password, ConnectionCreation creation)
+ throws Exception
+ {
+ Location location = createStrictMock(Location.class);
+ ClientConnection clientConnection = createStrictMock(ClientConnection.class);
+ ClientConnectionFactory clientConnectionFactory = createStrictMock(ClientConnectionFactory.class);
+ expect(clientConnectionFactory.createConnection(user, password))
+ .andReturn(clientConnection);
+ replay(location, clientConnectionFactory);
+
+ JBossConnectionFactory factory = new JBossConnectionFactory(
+ clientConnectionFactory, null, 0, location, null, 0, 0, 0, 0,
+ false, false, false);
+ Object connection = creation.createConnection(factory, user, password);
+ assertNotNull(connection);
+ assertTrue(expectedInterface.isAssignableFrom(connection.getClass()));
+ verify(location, clientConnectionFactory);
+ }
+
+ // Inner classes -------------------------------------------------
+
+ private class ConnectionCreation
+ {
+ Connection createConnection(JBossConnectionFactory factory)
+ throws Exception
+ {
+ return null;
+ }
+
+ Connection createConnection(JBossConnectionFactory factory, String user,
+ String password) throws Exception
+ {
+ return null;
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list