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