QPIDJMS-207 Add tests to validate Exception handling paths

Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/6eac5922
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/6eac5922
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/6eac5922

Branch: refs/heads/master
Commit: 6eac592221d514a7db53713fcfb6cafdb26f79cd
Parents: fcc6710
Author: Timothy Bish <tabish...@gmail.com>
Authored: Mon Sep 19 16:02:47 2016 -0400
Committer: Timothy Bish <tabish...@gmail.com>
Committed: Mon Sep 19 16:02:47 2016 -0400

----------------------------------------------------------------------
 .../qpid/jms/producer/JmsProducerTest.java      | 116 +++++++++++++++++++
 1 file changed, 116 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6eac5922/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java
----------------------------------------------------------------------
diff --git 
a/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java
 
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java
index 1bf4a08..457b51e 100644
--- 
a/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java
+++ 
b/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsProducerTest.java
@@ -34,22 +34,27 @@ import java.util.UUID;
 import javax.jms.CompletionListener;
 import javax.jms.DeliveryMode;
 import javax.jms.Destination;
+import javax.jms.IllegalStateException;
+import javax.jms.IllegalStateRuntimeException;
 import javax.jms.JMSException;
 import javax.jms.JMSProducer;
 import javax.jms.Message;
 import javax.jms.MessageFormatRuntimeException;
+import javax.jms.Queue;
 
 import org.apache.qpid.jms.JmsConnectionTestSupport;
 import org.apache.qpid.jms.JmsContext;
 import org.apache.qpid.jms.JmsMessageProducer;
 import org.apache.qpid.jms.JmsProducer;
 import org.apache.qpid.jms.JmsSession;
+import org.apache.qpid.jms.JmsTemporaryQueue;
 import org.apache.qpid.jms.JmsTopic;
 import org.apache.qpid.jms.message.JmsMessage;
 import org.apache.qpid.jms.message.JmsOutboundMessageDispatch;
 import org.apache.qpid.jms.provider.mock.MockRemotePeer;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.Matchers;
 import org.mockito.Mockito;
 
 /**
@@ -1148,6 +1153,117 @@ public class JmsProducerTest extends 
JmsConnectionTestSupport {
         assertEquals(bodyValue, message.getBody(UUID.class));
     }
 
+    //----- Test for conversions to JMSRuntimeException 
----------------------//
+
+    @Test
+    public void testRuntimeExceptionFromSendMessage() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageProducer messageProducer = 
Mockito.mock(JmsMessageProducer.class);
+        Message message = Mockito.mock(Message.class);
+
+        Mockito.when(session.createTemporaryQueue()).thenReturn(new 
JmsTemporaryQueue());
+        Mockito.when(session.createMessage()).thenReturn(message);
+
+        
Mockito.doThrow(IllegalStateException.class).when(message).setJMSCorrelationID(Matchers.anyString());
+
+        JmsProducer producer = new JmsProducer(session, messageProducer);
+
+        producer.setJMSCorrelationID("id");
+
+        try {
+            producer.send(session.createTemporaryQueue(), 
session.createMessage());
+            fail("Should have thrown an exception");
+        } catch (IllegalStateRuntimeException isre) {}
+    }
+
+    @Test
+    public void testRuntimeExceptionFromSendByteBody() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageProducer messageProducer = 
Mockito.mock(JmsMessageProducer.class);
+
+        Mockito.when(session.createTemporaryQueue()).thenReturn(new 
JmsTemporaryQueue());
+        
Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));
+
+        
Mockito.doThrow(IllegalStateException.class).when(session).createBytesMessage();
+
+        JmsProducer producer = new JmsProducer(session, messageProducer);
+
+        try {
+            producer.send(session.createTemporaryQueue(), new byte[0]);
+            fail("Should have thrown an exception");
+        } catch (IllegalStateRuntimeException isre) {}
+    }
+
+    @Test
+    public void testRuntimeExceptionFromSendMapBody() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageProducer messageProducer = 
Mockito.mock(JmsMessageProducer.class);
+
+        Mockito.when(session.createTemporaryQueue()).thenReturn(new 
JmsTemporaryQueue());
+        
Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));
+
+        
Mockito.doThrow(IllegalStateException.class).when(session).createMapMessage();
+
+        JmsProducer producer = new JmsProducer(session, messageProducer);
+
+        try {
+            producer.send(session.createTemporaryQueue(), Collections.<String, 
Object>emptyMap());
+            fail("Should have thrown an exception");
+        } catch (IllegalStateRuntimeException isre) {}
+    }
+
+    @Test
+    public void testRuntimeExceptionFromSendSerializableBody() throws 
JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageProducer messageProducer = 
Mockito.mock(JmsMessageProducer.class);
+
+        Mockito.when(session.createTemporaryQueue()).thenReturn(new 
JmsTemporaryQueue());
+        
Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));
+
+        
Mockito.doThrow(IllegalStateException.class).when(session).createObjectMessage();
+
+        JmsProducer producer = new JmsProducer(session, messageProducer);
+
+        try {
+            producer.send(session.createTemporaryQueue(), UUID.randomUUID());
+            fail("Should have thrown an exception");
+        } catch (IllegalStateRuntimeException isre) {}
+    }
+
+    @Test
+    public void testRuntimeExceptionFromSendStringBody() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageProducer messageProducer = 
Mockito.mock(JmsMessageProducer.class);
+
+        Mockito.when(session.createTemporaryQueue()).thenReturn(new 
JmsTemporaryQueue());
+        
Mockito.when(session.createMessage()).thenReturn(Mockito.mock(Message.class));
+
+        
Mockito.doThrow(IllegalStateException.class).when(session).createTextMessage(Matchers.anyString());
+
+        JmsProducer producer = new JmsProducer(session, messageProducer);
+
+        try {
+            producer.send(session.createTemporaryQueue(), "test");
+            fail("Should have thrown an exception");
+        } catch (IllegalStateRuntimeException isre) {}
+    }
+
+    @Test
+    public void testRuntimeExceptionFromSetJMSReplyTo() throws JMSException {
+        JmsSession session = Mockito.mock(JmsSession.class);
+        JmsMessageProducer messageProducer = 
Mockito.mock(JmsMessageProducer.class);
+        Queue queue = Mockito.mock(Queue.class);
+
+        
Mockito.doThrow(IllegalStateException.class).when(queue).getQueueName();
+
+        JmsProducer producer = new JmsProducer(session, messageProducer);
+
+        try {
+            producer.setJMSReplyTo(queue);
+            fail("Should have thrown an exception");
+        } catch (IllegalStateRuntimeException isre) {}
+    }
+
     //----- Internal Support 
-------------------------------------------------//
 
     private void sendWithBodyOfType(JMSProducer producer, Class<?> asType) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to