1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.jms;
12
13 import org.mule.tck.AbstractMuleTestCase;
14 import org.mule.transport.jms.Jms11Support;
15 import org.mule.transport.jms.JmsConnector;
16
17 import com.mockobjects.constraint.Constraint;
18 import com.mockobjects.dynamic.C;
19 import com.mockobjects.dynamic.FullConstraintMatcher;
20 import com.mockobjects.dynamic.Mock;
21
22 import javax.jms.JMSException;
23 import javax.jms.Queue;
24 import javax.jms.Session;
25 import javax.jms.Topic;
26
27 public class Jms11SupportTestCase extends AbstractMuleTestCase
28 {
29
30 public void testNoLocalCalledForDurableTopic() throws Exception
31 {
32 Jms11Support jmsSupport = new Jms11Support(new JmsConnector());
33
34 Mock mockTopic = new Mock(Topic.class);
35 Topic topic = (Topic)mockTopic.proxy();
36
37 String durableName = "durableName";
38 boolean noLocal = true;
39
40 FullConstraintMatcher matcher = new FullConstraintMatcher(new Constraint[]{C.eq(topic),
41 C.eq(durableName), C.IS_NULL, C.IS_TRUE});
42
43 Mock mockSession = new Mock(Session.class);
44 mockSession.expect("createDurableSubscriber", matcher);
45
46 jmsSupport.createConsumer((Session)mockSession.proxy(), topic, null, noLocal, durableName, true);
47
48 mockTopic.verify();
49 mockSession.verify();
50 }
51
52 public void testNoLocalCalledForNonDurableTopic() throws Exception
53 {
54 Jms11Support jmsSupport = new Jms11Support(new JmsConnector());
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);
68
69 mockTopic.verify();
70 mockSession.verify();
71 }
72
73 public void testNoLocalNotCalledForQueue() throws Exception
74 {
75 Jms11Support jmsSupport = new Jms11Support(new JmsConnector());
76
77 Mock mockQueue = new Mock(Queue.class);
78 Queue queue = (Queue)mockQueue.proxy();
79
80 boolean noLocal = true;
81
82 FullConstraintMatcher matcher = new FullConstraintMatcher(new Constraint[]{C.eq(queue), C.IS_NULL});
83
84 Mock mockSession = new Mock(Session.class);
85 mockSession.expect("createConsumer", matcher);
86
87 jmsSupport.createConsumer((Session)mockSession.proxy(), queue, null, noLocal, null, false);
88
89 mockQueue.verify();
90 mockSession.verify();
91 }
92
93 public void testDurableWithQueueThrowsException() throws Exception
94 {
95 Jms11Support jmsSupport = new Jms11Support(new JmsConnector());
96
97 Mock mockQueue = new Mock(Queue.class);
98 Queue queue = (Queue)mockQueue.proxy();
99
100 String durableName = "durableName";
101 boolean noLocal = true;
102
103 Mock mockSession = new Mock(Session.class);
104
105 try
106 {
107 jmsSupport.createConsumer((Session)mockSession.proxy(), queue, null, noLocal, durableName, false);
108 }
109 catch (JMSException jmsex)
110 {
111
112 assertEquals("Wrong exception text.",
113 "A durable subscriber name was set but the destination was not a Topic", jmsex.getMessage());
114 }
115
116 mockQueue.verify();
117 mockSession.verify();
118 }
119
120 }