View Javadoc

1   /*
2    * $Id: Jms11SupportTestCase.java 22387 2011-07-12 03:53:36Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.jms;
12  
13  import org.mule.tck.junit4.AbstractMuleContextTestCase;
14  
15  import com.mockobjects.constraint.Constraint;
16  import com.mockobjects.dynamic.C;
17  import com.mockobjects.dynamic.FullConstraintMatcher;
18  import com.mockobjects.dynamic.Mock;
19  
20  import javax.jms.JMSException;
21  import javax.jms.Queue;
22  import javax.jms.Session;
23  import javax.jms.Topic;
24  
25  import org.junit.Test;
26  
27  import static org.junit.Assert.assertEquals;
28  
29  public class Jms11SupportTestCase extends AbstractMuleContextTestCase
30  {
31  
32      @Test
33      public void testNoLocalCalledForDurableTopic() throws Exception
34      {
35          Jms11Support jmsSupport = new Jms11Support(new JmsConnector(muleContext));
36  
37          Mock mockTopic = new Mock(Topic.class);
38          Topic topic = (Topic)mockTopic.proxy();
39  
40          String durableName = "durableName";
41          boolean noLocal = true;
42  
43          FullConstraintMatcher matcher = new FullConstraintMatcher(new Constraint[]{C.eq(topic),
44              C.eq(durableName), C.IS_NULL, C.IS_TRUE});
45  
46          Mock mockSession = new Mock(Session.class);
47          mockSession.expect("createDurableSubscriber", matcher);
48  
49          jmsSupport.createConsumer((Session)mockSession.proxy(), topic, null, noLocal, durableName, true, getTestInboundEndpoint("test"));
50  
51          mockTopic.verify();
52          mockSession.verify();
53      }
54  
55      @Test
56      public void testNoLocalCalledForNonDurableTopic() throws Exception
57      {
58          Jms11Support jmsSupport = new Jms11Support(new JmsConnector(muleContext));
59  
60          Mock mockTopic = new Mock(Topic.class);
61          Topic topic = (Topic)mockTopic.proxy();
62  
63          boolean noLocal = true;
64  
65          FullConstraintMatcher matcher = new FullConstraintMatcher(new Constraint[]{C.eq(topic), C.IS_NULL,
66              C.IS_TRUE});
67  
68          Mock mockSession = new Mock(Session.class);
69          mockSession.expect("createConsumer", matcher);
70  
71          jmsSupport.createConsumer((Session)mockSession.proxy(), topic, null, noLocal, null, true, getTestInboundEndpoint("test"));
72  
73          mockTopic.verify();
74          mockSession.verify();
75      }
76  
77      @Test
78      public void testNoLocalNotCalledForQueue() throws Exception
79      {
80          Jms11Support jmsSupport = new Jms11Support(new JmsConnector(muleContext));
81  
82          Mock mockQueue = new Mock(Queue.class);
83          Queue queue = (Queue)mockQueue.proxy();
84  
85          boolean noLocal = true;
86  
87          FullConstraintMatcher matcher = new FullConstraintMatcher(new Constraint[]{C.eq(queue), C.IS_NULL});
88  
89          Mock mockSession = new Mock(Session.class);
90          mockSession.expect("createConsumer", matcher);
91  
92          jmsSupport.createConsumer((Session)mockSession.proxy(), queue, null, noLocal, null, false, getTestInboundEndpoint("test"));
93  
94          mockQueue.verify();
95          mockSession.verify();
96      }
97  
98      @Test
99      public void testDurableWithQueueThrowsException() throws Exception
100     {
101         Jms11Support jmsSupport = new Jms11Support(new JmsConnector(muleContext));
102 
103         Mock mockQueue = new Mock(Queue.class);
104         Queue queue = (Queue)mockQueue.proxy();
105 
106         String durableName = "durableName";
107         boolean noLocal = true;
108 
109         Mock mockSession = new Mock(Session.class);
110 
111         try
112         {
113             jmsSupport.createConsumer((Session)mockSession.proxy(), queue, null, noLocal, durableName, false, getTestInboundEndpoint("test"));
114         }
115         catch (JMSException jmsex)
116         {
117             // expected
118             assertEquals("Wrong exception text.",
119                 "A durable subscriber name was set but the destination was not a Topic", jmsex.getMessage());
120         }
121 
122         mockQueue.verify();
123         mockSession.verify();
124     }
125 
126 }