[jboss-cvs] JBoss Messaging SVN: r4447 - trunk/tests/src/org/jboss/messaging/tests/unit/jms/client.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jun 12 11:16:28 EDT 2008
Author: jmesnil
Date: 2008-06-12 11:16:27 -0400 (Thu, 12 Jun 2008)
New Revision: 4447
Modified:
trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossConnectionTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossSessionTest.java
Log:
added unit tests for exception cases
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossConnectionTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossConnectionTest.java 2008-06-12 14:45:06 UTC (rev 4446)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossConnectionTest.java 2008-06-12 15:16:27 UTC (rev 4447)
@@ -34,6 +34,7 @@
import org.jboss.messaging.core.client.ClientConnection;
import org.jboss.messaging.core.client.ClientSession;
import org.jboss.messaging.core.client.RemotingSessionListener;
+import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.version.Version;
import org.jboss.messaging.jms.client.JBossConnection;
import org.jboss.messaging.tests.util.RandomUtil;
@@ -86,6 +87,28 @@
verify(clientConn);
}
+ public void testStartThrowsException() throws Exception
+ {
+ ClientConnection clientConn = createStrictMock(ClientConnection.class);
+ clientConn.start();
+ expectLastCall().andThrow(new MessagingException());
+
+ replay(clientConn);
+
+ JBossConnection connection = new JBossConnection(clientConn,
+ JBossConnection.TYPE_QUEUE_CONNECTION, null, -1);
+
+ try
+ {
+ connection.start();
+ fail("should throw a JMSException");
+ } catch(JMSException e)
+ {
+ }
+
+ verify(clientConn);
+ }
+
public void testStop() throws Exception
{
ClientConnection clientConn = createStrictMock(ClientConnection.class);
@@ -102,6 +125,50 @@
verify(clientConn);
}
+ public void testStopThrowsException() throws Exception
+ {
+ ClientConnection clientConn = createStrictMock(ClientConnection.class);
+ clientConn.stop();
+ expectLastCall().andThrow(new MessagingException());
+
+ replay(clientConn);
+
+ JBossConnection connection = new JBossConnection(clientConn,
+ JBossConnection.TYPE_QUEUE_CONNECTION, null, -1);
+
+ try
+ {
+ connection.stop();
+ fail("should throw a JMSException");
+ } catch(JMSException e)
+ {
+ }
+
+ verify(clientConn);
+ }
+
+ public void testCloseThrowsException() throws Exception
+ {
+ ClientConnection clientConn = createStrictMock(ClientConnection.class);
+ clientConn.close();
+ expectLastCall().andThrow(new MessagingException());
+
+ replay(clientConn);
+
+ JBossConnection connection = new JBossConnection(clientConn,
+ JBossConnection.TYPE_QUEUE_CONNECTION, null, -1);
+
+ try
+ {
+ connection.close();
+ fail("should throw a JMSException");
+ } catch(JMSException e)
+ {
+ }
+
+ verify(clientConn);
+ }
+
public void testUsingClosedConnection() throws Exception
{
ClientConnection clientConn = createStrictMock(ClientConnection.class);
@@ -334,6 +401,27 @@
verify(clientConn, topic, sessionPool);
}
+ public void testCreateSessionThrowsException() throws Exception
+ {
+ ClientConnection clientConn = createStrictMock(ClientConnection.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ expect(clientConn.createClientSession(false, false, false, -1, false, false)).andThrow(new MessagingException());
+ replay(clientConn, clientSession);
+
+ JBossConnection connection = new JBossConnection(clientConn,
+ JBossConnection.TYPE_QUEUE_CONNECTION, null, -1);
+
+ try
+ {
+ connection.createQueueSession(true, 0);
+ fail("should throw a JMSException");
+ } catch(JMSException e)
+ {
+ }
+
+ verify(clientConn, clientSession);
+ }
+
public void testCreateTransactedQueueSession() throws Exception
{
ClientConnection clientConn = createStrictMock(ClientConnection.class);
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossSessionTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossSessionTest.java 2008-06-12 14:45:06 UTC (rev 4446)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/jms/client/JBossSessionTest.java 2008-06-12 15:16:27 UTC (rev 4447)
@@ -8,6 +8,7 @@
import static org.easymock.EasyMock.createStrictMock;
import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.jboss.messaging.tests.util.RandomUtil.randomString;
@@ -43,6 +44,7 @@
import org.jboss.messaging.core.client.ClientConnection;
import org.jboss.messaging.core.client.ClientProducer;
import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionBindingQueryResponseMessage;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionQueueQueryResponseMessage;
import org.jboss.messaging.jms.JBossDestination;
@@ -89,6 +91,31 @@
verify(clientConn, clientSession);
}
+ public void testCloseThrowsException() throws Exception
+ {
+ ClientConnection clientConn = createStrictMock(ClientConnection.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ clientSession.close();
+ expectLastCall().andThrow(new MessagingException());
+ replay(clientConn, clientSession);
+
+ JBossConnection connection = new JBossConnection(clientConn,
+ JBossConnection.TYPE_QUEUE_CONNECTION, null, -1);
+ Session session = new JBossSession(connection, true, false,
+ Session.DUPS_OK_ACKNOWLEDGE, clientSession,
+ JBossSession.TYPE_GENERIC_SESSION);
+
+ try
+ {
+ session.close();
+ fail("should throw a JMSException");
+ } catch (JMSException e)
+ {
+ }
+
+ verify(clientConn, clientSession);
+ }
+
public void testClosedSession() throws Exception
{
ClientConnection clientConn = createStrictMock(ClientConnection.class);
@@ -173,6 +200,31 @@
verify(clientConn, clientSession);
}
+ public void testCommitThrowsException() throws Exception
+ {
+ ClientConnection clientConn = createStrictMock(ClientConnection.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ clientSession.commit();
+ expectLastCall().andThrow(new MessagingException());
+ replay(clientConn, clientSession);
+
+ JBossConnection connection = new JBossConnection(clientConn,
+ JBossConnection.TYPE_QUEUE_CONNECTION, null, -1);
+ Session session = new JBossSession(connection, true, false,
+ Session.DUPS_OK_ACKNOWLEDGE, clientSession,
+ JBossSession.TYPE_GENERIC_SESSION);
+
+ try
+ {
+ session.commit();
+ fail("should throw a JMSException");
+ } catch (JMSException e)
+ {
+ }
+
+ verify(clientConn, clientSession);
+ }
+
public void testCommitOnNonTransactedSession() throws Exception
{
ClientConnection clientConn = createStrictMock(ClientConnection.class);
@@ -239,6 +291,31 @@
verify(clientConn, clientSession);
}
+ public void testRollbackThrowsException() throws Exception
+ {
+ ClientConnection clientConn = createStrictMock(ClientConnection.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ clientSession.rollback();
+ expectLastCall().andThrow(new MessagingException());
+ replay(clientConn, clientSession);
+
+ JBossConnection connection = new JBossConnection(clientConn,
+ JBossConnection.TYPE_QUEUE_CONNECTION, null, -1);
+ Session session = new JBossSession(connection, true, false,
+ Session.DUPS_OK_ACKNOWLEDGE, clientSession,
+ JBossSession.TYPE_GENERIC_SESSION);
+
+ try
+ {
+ session.rollback();
+ fail("should throw a JMSException");
+ } catch (JMSException e)
+ {
+ }
+
+ verify(clientConn, clientSession);
+ }
+
public void testRollbackOnNonTransactedSession() throws Exception
{
ClientConnection clientConn = createStrictMock(ClientConnection.class);
@@ -327,6 +404,31 @@
verify(clientConn, clientSession);
}
+ public void testRecoverThrowsException() throws Exception
+ {
+ ClientConnection clientConn = createStrictMock(ClientConnection.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ clientSession.rollback();
+ expectLastCall().andThrow(new MessagingException());
+ replay(clientConn, clientSession);
+
+ JBossConnection connection = new JBossConnection(clientConn,
+ JBossConnection.TYPE_QUEUE_CONNECTION, null, -1);
+ Session session = new JBossSession(connection, false, false,
+ Session.DUPS_OK_ACKNOWLEDGE, clientSession,
+ JBossSession.TYPE_GENERIC_SESSION);
+
+ try
+ {
+ session.recover();
+ fail("should throw a JMSException");
+ } catch (JMSException e)
+ {
+ }
+
+ verify(clientConn, clientSession);
+ }
+
public void testMessageListener() throws Exception
{
ClientConnection clientConn = createStrictMock(ClientConnection.class);
@@ -343,7 +445,7 @@
assertNull(session.getMessageListener());
session.setMessageListener(listener);
assertSame(listener, session.getMessageListener());
-
+
verify(clientConn, clientSession, listener);
}
@@ -473,6 +575,34 @@
EasyMock.verify(clientConn, clientSession, clientProducer);
}
+ public void testCreateProducerThrowsException() throws Exception
+ {
+ JBossDestination destination = new JBossQueue(randomString());
+ ClientConnection clientConn = createStrictMock(ClientConnection.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ ClientProducer clientProducer = createStrictMock(ClientProducer.class);
+ expect(clientSession.createProducer(destination.getSimpleAddress()))
+ .andThrow(new MessagingException());
+
+ replay(clientConn, clientSession, clientProducer);
+
+ JBossConnection connection = new JBossConnection(clientConn,
+ JBossConnection.TYPE_QUEUE_CONNECTION, null, -1);
+ Session session = new JBossSession(connection, false, false,
+ Session.AUTO_ACKNOWLEDGE, clientSession,
+ JBossSession.TYPE_GENERIC_SESSION);
+
+ try
+ {
+ session.createProducer(destination);
+ fail("should throw a JMSException");
+ } catch (JMSException e)
+ {
+ }
+
+ EasyMock.verify(clientConn, clientSession, clientProducer);
+ }
+
public void testCreateProducerWithInvalidDestination() throws Exception
{
ClientConnection clientConn = createStrictMock(ClientConnection.class);
@@ -517,15 +647,15 @@
EasyMock.verify(clientConn, clientSession, clientProducer);
}
-
+
public void testCreatePublisher() throws Exception
{
JBossTopic topic = new JBossTopic(randomString());
ClientConnection clientConn = createStrictMock(ClientConnection.class);
ClientSession clientSession = createStrictMock(ClientSession.class);
ClientProducer clientProducer = createStrictMock(ClientProducer.class);
- expect(clientSession.createProducer(topic.getSimpleAddress()))
- .andReturn(clientProducer);
+ expect(clientSession.createProducer(topic.getSimpleAddress())).andReturn(
+ clientProducer);
replay(clientConn, clientSession, clientProducer);
@@ -547,8 +677,8 @@
ClientConnection clientConn = createStrictMock(ClientConnection.class);
ClientSession clientSession = createStrictMock(ClientSession.class);
ClientProducer clientProducer = createStrictMock(ClientProducer.class);
- expect(clientSession.createProducer(queue.getSimpleAddress()))
- .andReturn(clientProducer);
+ expect(clientSession.createProducer(queue.getSimpleAddress())).andReturn(
+ clientProducer);
replay(clientConn, clientSession, clientProducer);
@@ -563,7 +693,7 @@
EasyMock.verify(clientConn, clientSession, clientProducer);
}
-
+
public void testCreateBrowser() throws Exception
{
JBossQueue queue = new JBossQueue(randomString());
@@ -587,6 +717,34 @@
EasyMock.verify(clientConn, clientSession, clientBrowser);
}
+ public void testCreateBrowserThrowsException() throws Exception
+ {
+ JBossQueue queue = new JBossQueue(randomString());
+ ClientConnection clientConn = createStrictMock(ClientConnection.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ ClientBrowser clientBrowser = createStrictMock(ClientBrowser.class);
+ expect(clientSession.createBrowser(queue.getSimpleAddress(), null))
+ .andThrow(new MessagingException());
+
+ replay(clientConn, clientSession, clientBrowser);
+
+ JBossConnection connection = new JBossConnection(clientConn,
+ JBossConnection.TYPE_QUEUE_CONNECTION, null, -1);
+ QueueSession session = new JBossSession(connection, false, false,
+ Session.AUTO_ACKNOWLEDGE, clientSession,
+ JBossSession.TYPE_QUEUE_SESSION);
+
+ try
+ {
+ session.createBrowser(queue);
+ fail("should throw a JMSException");
+ } catch (JMSException e)
+ {
+ }
+
+ EasyMock.verify(clientConn, clientSession, clientBrowser);
+ }
+
public void testCreateBrowserWithEmptyFilter() throws Exception
{
JBossQueue queue = new JBossQueue(randomString());
@@ -606,10 +764,10 @@
QueueBrowser browser = session.createBrowser(queue, "");
assertNotNull(browser);
-
+
EasyMock.verify(clientConn, clientSession, clientBrowser);
}
-
+
public void testCreateBrowserWithFilter() throws Exception
{
String filter = "color = 'red'";
@@ -617,8 +775,9 @@
ClientConnection clientConn = createStrictMock(ClientConnection.class);
ClientSession clientSession = createStrictMock(ClientSession.class);
ClientBrowser clientBrowser = createStrictMock(ClientBrowser.class);
- expect(clientSession.createBrowser(queue.getSimpleAddress(), new SimpleString(filter)))
- .andReturn(clientBrowser);
+ expect(
+ clientSession.createBrowser(queue.getSimpleAddress(),
+ new SimpleString(filter))).andReturn(clientBrowser);
replay(clientConn, clientSession, clientBrowser);
@@ -633,7 +792,7 @@
EasyMock.verify(clientConn, clientSession, clientBrowser);
}
-
+
public void testCreateBrowserFromTopicSession() throws Exception
{
Queue queue = new JBossQueue(randomString());
@@ -655,10 +814,10 @@
} catch (IllegalStateException e)
{
}
-
+
EasyMock.verify(clientConn, clientSession);
}
-
+
public void testCreateBrowserForNullQueue() throws Exception
{
ClientConnection clientConn = createStrictMock(ClientConnection.class);
@@ -679,10 +838,10 @@
} catch (InvalidDestinationException e)
{
}
-
+
EasyMock.verify(clientConn, clientSession);
}
-
+
public void testCreateBrowserForInvalidQueue() throws Exception
{
Queue queue = createStrictMock(Queue.class);
@@ -704,10 +863,10 @@
} catch (InvalidDestinationException e)
{
}
-
+
EasyMock.verify(clientConn, clientSession, queue);
}
-
+
public void testCreateQueue() throws Exception
{
// FIXME need to clean up use of queue address/simple address/name
@@ -715,9 +874,11 @@
ClientConnection clientConn = createStrictMock(ClientConnection.class);
ClientSession clientSession = createStrictMock(ClientSession.class);
// isExists() will return true
- SessionQueueQueryResponseMessage resp = new SessionQueueQueryResponseMessage(false, false, -1, -1, 1, null, tempQueue.getSimpleAddress());
- expect(clientSession.queueQuery(tempQueue.getSimpleAddress())).andReturn(resp);
-
+ SessionQueueQueryResponseMessage resp = new SessionQueueQueryResponseMessage(
+ false, false, -1, -1, 1, null, tempQueue.getSimpleAddress());
+ expect(clientSession.queueQuery(tempQueue.getSimpleAddress())).andReturn(
+ resp);
+
replay(clientConn, clientSession);
JBossConnection connection = new JBossConnection(clientConn,
@@ -731,7 +892,33 @@
EasyMock.verify(clientConn, clientSession);
}
-
+
+ public void testCreateQueueThrowsException() throws Exception
+ {
+ // FIXME need to clean up use of queue address/simple address/name
+ JBossQueue tempQueue = new JBossQueue(randomString());
+ ClientConnection clientConn = createStrictMock(ClientConnection.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ expect(clientSession.queueQuery(tempQueue.getSimpleAddress())).andThrow(new MessagingException());
+
+ replay(clientConn, clientSession);
+
+ JBossConnection connection = new JBossConnection(clientConn,
+ JBossConnection.TYPE_QUEUE_CONNECTION, null, -1);
+ QueueSession session = new JBossSession(connection, false, false,
+ Session.AUTO_ACKNOWLEDGE, clientSession,
+ JBossSession.TYPE_QUEUE_SESSION);
+
+ try
+ {
+ session.createQueue(tempQueue.getName());
+ fail("should throw a JMSException");
+ } catch (JMSException e)
+ {
+ }
+
+ EasyMock.verify(clientConn, clientSession);
+ }
public void testCreateQueueWithUnknownName() throws Exception
{
// FIXME need to clean up use of queue address/simple address/name
@@ -740,8 +927,9 @@
ClientSession clientSession = createStrictMock(ClientSession.class);
// isExists() will return false
SessionQueueQueryResponseMessage resp = new SessionQueueQueryResponseMessage();
- expect(clientSession.queueQuery(tempQueue.getSimpleAddress())).andReturn(resp);
-
+ expect(clientSession.queueQuery(tempQueue.getSimpleAddress())).andReturn(
+ resp);
+
replay(clientConn, clientSession);
JBossConnection connection = new JBossConnection(clientConn,
@@ -750,22 +938,22 @@
Session.AUTO_ACKNOWLEDGE, clientSession,
JBossSession.TYPE_QUEUE_SESSION);
- try
+ try
{
- session.createQueue(tempQueue.getName());
+ session.createQueue(tempQueue.getName());
fail("creating a queue with an unknown name must throw a JMSException");
- } catch(JMSException e)
+ } catch (JMSException e)
{
}
EasyMock.verify(clientConn, clientSession);
}
-
+
public void testCreateQueueFromTopicSession() throws Exception
{
ClientConnection clientConn = createStrictMock(ClientConnection.class);
ClientSession clientSession = createStrictMock(ClientSession.class);
-
+
replay(clientConn, clientSession);
JBossConnection connection = new JBossConnection(clientConn,
@@ -774,26 +962,28 @@
Session.AUTO_ACKNOWLEDGE, clientSession,
JBossSession.TYPE_TOPIC_SESSION);
- try
+ try
{
- session.createQueue(randomString());
+ session.createQueue(randomString());
fail("creating a queue from a topic session must throw a IllegalStateException");
- } catch(IllegalStateException e)
+ } catch (IllegalStateException e)
{
}
EasyMock.verify(clientConn, clientSession);
}
-
+
public void testCreateTopic() throws Exception
{
// FIXME need to clean up use of topic address/simple address/name
JBossTopic tempTopic = new JBossTopic(randomString());
ClientConnection clientConn = createStrictMock(ClientConnection.class);
ClientSession clientSession = createStrictMock(ClientSession.class);
- SessionBindingQueryResponseMessage resp = new SessionBindingQueryResponseMessage(true, new ArrayList<SimpleString>());
- expect(clientSession.bindingQuery(tempTopic.getSimpleAddress())).andReturn(resp);
-
+ SessionBindingQueryResponseMessage resp = new SessionBindingQueryResponseMessage(
+ true, new ArrayList<SimpleString>());
+ expect(clientSession.bindingQuery(tempTopic.getSimpleAddress()))
+ .andReturn(resp);
+
replay(clientConn, clientSession);
JBossConnection connection = new JBossConnection(clientConn,
@@ -804,19 +994,50 @@
Topic topic = session.createTopic(tempTopic.getName());
assertNotNull(topic);
+
+ EasyMock.verify(clientConn, clientSession);
+ }
+
+ public void testCreateTopicThrowsException() throws Exception
+ {
+ // FIXME need to clean up use of topic address/simple address/name
+ JBossTopic tempTopic = new JBossTopic(randomString());
+ ClientConnection clientConn = createStrictMock(ClientConnection.class);
+ ClientSession clientSession = createStrictMock(ClientSession.class);
+ expect(clientSession.bindingQuery(tempTopic.getSimpleAddress()))
+ .andThrow(new MessagingException());
+ replay(clientConn, clientSession);
+
+ JBossConnection connection = new JBossConnection(clientConn,
+ JBossConnection.TYPE_QUEUE_CONNECTION, null, -1);
+ QueueSession session = new JBossSession(connection, false, false,
+ Session.AUTO_ACKNOWLEDGE, clientSession,
+ JBossSession.TYPE_TOPIC_SESSION);
+
+ try
+ {
+ session.createTopic(tempTopic.getName());
+ fail("should throw a JMSException");
+ } catch (JMSException e)
+ {
+ }
+
EasyMock.verify(clientConn, clientSession);
}
-
+
+
public void testCreateTopicWithUnknownName() throws Exception
{
// FIXME need to clean up use of topic address/simple address/name
JBossTopic tempTopic = new JBossTopic(randomString());
ClientConnection clientConn = createStrictMock(ClientConnection.class);
ClientSession clientSession = createStrictMock(ClientSession.class);
- SessionBindingQueryResponseMessage resp = new SessionBindingQueryResponseMessage(false, new ArrayList<SimpleString>());
- expect(clientSession.bindingQuery(tempTopic.getSimpleAddress())).andReturn(resp);
-
+ SessionBindingQueryResponseMessage resp = new SessionBindingQueryResponseMessage(
+ false, new ArrayList<SimpleString>());
+ expect(clientSession.bindingQuery(tempTopic.getSimpleAddress()))
+ .andReturn(resp);
+
replay(clientConn, clientSession);
JBossConnection connection = new JBossConnection(clientConn,
@@ -825,22 +1046,22 @@
Session.AUTO_ACKNOWLEDGE, clientSession,
JBossSession.TYPE_TOPIC_SESSION);
- try
+ try
{
- session.createTopic(tempTopic.getName());
+ session.createTopic(tempTopic.getName());
fail("creating a topic with an unknown name must throw a JMSException");
- } catch(JMSException e)
+ } catch (JMSException e)
{
}
EasyMock.verify(clientConn, clientSession);
}
-
+
public void testCreateTopicFromQueueSession() throws Exception
{
ClientConnection clientConn = createStrictMock(ClientConnection.class);
ClientSession clientSession = createStrictMock(ClientSession.class);
-
+
replay(clientConn, clientSession);
JBossConnection connection = new JBossConnection(clientConn,
@@ -849,16 +1070,17 @@
Session.AUTO_ACKNOWLEDGE, clientSession,
JBossSession.TYPE_QUEUE_SESSION);
- try
+ try
{
- session.createTopic(randomString());
+ session.createTopic(randomString());
fail("creating a topic from a queue session must throw a IllegalStateException");
- } catch(IllegalStateException e)
+ } catch (IllegalStateException e)
{
}
EasyMock.verify(clientConn, clientSession);
}
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
More information about the jboss-cvs-commits
mailing list