1   /*
2    * $Id: Jms11SupportTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.providers.jms;
12  
13  import org.mule.tck.AbstractMuleTestCase;
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  public class Jms11SupportTestCase extends AbstractMuleTestCase
26  {
27  
28      public void testNoLocalCalledForDurableTopic() throws Exception
29      {
30          Jms11Support jmsSupport = new Jms11Support(new JmsConnector(), null, false, false);
31  
32          Mock mockTopic = new Mock(Topic.class);
33          Topic topic = (Topic)mockTopic.proxy();
34  
35          String durableName = "durableName";
36          boolean noLocal = true;
37  
38          FullConstraintMatcher matcher = new FullConstraintMatcher(new Constraint[]{C.eq(topic),
39              C.eq(durableName), C.IS_NULL, C.IS_TRUE});
40  
41          Mock mockSession = new Mock(Session.class);
42          mockSession.expect("createDurableSubscriber", matcher);
43  
44          jmsSupport.createConsumer((Session)mockSession.proxy(), topic, null, noLocal, durableName, true);
45  
46          mockTopic.verify();
47          mockSession.verify();
48      }
49  
50      public void testNoLocalCalledForNonDurableTopic() throws Exception
51      {
52          Jms11Support jmsSupport = new Jms11Support(new JmsConnector(), null, false, false);
53  
54          Mock mockTopic = new Mock(Topic.class);
55          Topic topic = (Topic)mockTopic.proxy();
56  
57          boolean noLocal = true;
58  
59          FullConstraintMatcher matcher = new FullConstraintMatcher(new Constraint[]{C.eq(topic), C.IS_NULL,
60              C.IS_TRUE});
61  
62          Mock mockSession = new Mock(Session.class);
63          mockSession.expect("createConsumer", matcher);
64  
65          jmsSupport.createConsumer((Session)mockSession.proxy(), topic, null, noLocal, null, true);
66  
67          mockTopic.verify();
68          mockSession.verify();
69      }
70  
71      public void testNoLocalNotCalledForQueue() throws Exception
72      {
73          Jms11Support jmsSupport = new Jms11Support(new JmsConnector(), null, false, false);
74  
75          Mock mockQueue = new Mock(Queue.class);
76          Queue queue = (Queue)mockQueue.proxy();
77  
78          boolean noLocal = true;
79  
80          FullConstraintMatcher matcher = new FullConstraintMatcher(new Constraint[]{C.eq(queue), C.IS_NULL});
81  
82          Mock mockSession = new Mock(Session.class);
83          mockSession.expect("createConsumer", matcher);
84  
85          jmsSupport.createConsumer((Session)mockSession.proxy(), queue, null, noLocal, null, false);
86  
87          mockQueue.verify();
88          mockSession.verify();
89      }
90  
91      public void testDurableWithQueueThrowsException() throws Exception
92      {
93          Jms11Support jmsSupport = new Jms11Support(new JmsConnector(), null, false, false);
94  
95          Mock mockQueue = new Mock(Queue.class);
96          Queue queue = (Queue)mockQueue.proxy();
97  
98          String durableName = "durableName";
99          boolean noLocal = true;
100 
101         Mock mockSession = new Mock(Session.class);
102 
103         try
104         {
105             jmsSupport.createConsumer((Session)mockSession.proxy(), queue, null, noLocal, durableName, false);
106         }
107         catch (JMSException jmsex)
108         {
109             // expected
110             assertEquals("Wrong exception text.",
111                 "A durable subscriber name was set but the destination was not a Topic", jmsex.getMessage());
112         }
113 
114         mockQueue.verify();
115         mockSession.verify();
116     }
117 
118 }