KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jms > connection > SingleConnectionFactoryTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.springframework.jms.connection;
17
18 import javax.jms.Connection JavaDoc;
19 import javax.jms.ConnectionFactory JavaDoc;
20 import javax.jms.JMSException JavaDoc;
21 import javax.jms.QueueConnection JavaDoc;
22 import javax.jms.QueueConnectionFactory JavaDoc;
23 import javax.jms.TopicConnection JavaDoc;
24 import javax.jms.TopicConnectionFactory JavaDoc;
25
26 import junit.framework.TestCase;
27 import org.easymock.MockControl;
28
29 /**
30  * @author Juergen Hoeller
31  * @since 26.07.2004
32  */

33 public class SingleConnectionFactoryTests extends TestCase {
34
35     public void testWithConnection() throws JMSException JavaDoc {
36         MockControl conControl = MockControl.createControl(Connection JavaDoc.class);
37         Connection JavaDoc con = (Connection JavaDoc) conControl.getMock();
38
39         con.start();
40         conControl.setVoidCallable(2);
41         con.close();
42         conControl.setVoidCallable(1);
43
44         conControl.replay();
45
46         SingleConnectionFactory scf = new SingleConnectionFactory(con);
47         Connection JavaDoc con1 = scf.createConnection();
48         con1.start();
49         con1.close(); // should be ignored
50
Connection JavaDoc con2 = scf.createConnection();
51         con2.start();
52         con2.close(); // should be ignored
53
scf.destroy(); // should trigger actual close
54

55         conControl.verify();
56     }
57
58     public void testWithQueueConnection() throws JMSException JavaDoc {
59         MockControl conControl = MockControl.createControl(QueueConnection JavaDoc.class);
60         Connection JavaDoc con = (QueueConnection JavaDoc) conControl.getMock();
61
62         con.start();
63         conControl.setVoidCallable(2);
64         con.close();
65         conControl.setVoidCallable(1);
66
67         conControl.replay();
68
69         SingleConnectionFactory scf = new SingleConnectionFactory(con);
70         QueueConnection JavaDoc con1 = scf.createQueueConnection();
71         con1.start();
72         con1.close(); // should be ignored
73
QueueConnection JavaDoc con2 = scf.createQueueConnection();
74         con2.start();
75         con2.close(); // should be ignored
76
scf.destroy(); // should trigger actual close
77

78         conControl.verify();
79     }
80
81     public void testWithTopicConnection() throws JMSException JavaDoc {
82         MockControl conControl = MockControl.createControl(TopicConnection JavaDoc.class);
83         Connection JavaDoc con = (TopicConnection JavaDoc) conControl.getMock();
84
85         con.start();
86         conControl.setVoidCallable(2);
87         con.close();
88         conControl.setVoidCallable(1);
89
90         conControl.replay();
91
92         SingleConnectionFactory scf = new SingleConnectionFactory(con);
93         TopicConnection JavaDoc con1 = scf.createTopicConnection();
94         con1.start();
95         con1.close(); // should be ignored
96
TopicConnection JavaDoc con2 = scf.createTopicConnection();
97         con2.start();
98         con2.close(); // should be ignored
99
scf.destroy(); // should trigger actual close
100

101         conControl.verify();
102     }
103
104     public void testWithConnectionFactory() throws JMSException JavaDoc {
105         MockControl cfControl = MockControl.createControl(ConnectionFactory JavaDoc.class);
106         ConnectionFactory JavaDoc cf = (ConnectionFactory JavaDoc) cfControl.getMock();
107         MockControl conControl = MockControl.createControl(Connection JavaDoc.class);
108         Connection JavaDoc con = (Connection JavaDoc) conControl.getMock();
109
110         cf.createConnection();
111         cfControl.setReturnValue(con, 1);
112         con.start();
113         conControl.setVoidCallable(2);
114         con.close();
115         conControl.setVoidCallable(1);
116
117         cfControl.replay();
118         conControl.replay();
119
120         SingleConnectionFactory scf = new SingleConnectionFactory(cf);
121         Connection JavaDoc con1 = scf.createConnection();
122         con1.start();
123         con1.close(); // should be ignored
124
Connection JavaDoc con2 = scf.createConnection();
125         con2.start();
126         con2.close(); // should be ignored
127
scf.destroy(); // should trigger actual close
128

129         cfControl.verify();
130         conControl.verify();
131     }
132
133     public void testConnectionFactory102WithQueue() throws JMSException JavaDoc {
134         MockControl cfControl = MockControl.createControl(QueueConnectionFactory JavaDoc.class);
135         QueueConnectionFactory JavaDoc cf = (QueueConnectionFactory JavaDoc) cfControl.getMock();
136         MockControl conControl = MockControl.createControl(QueueConnection JavaDoc.class);
137         QueueConnection JavaDoc con = (QueueConnection JavaDoc) conControl.getMock();
138
139         cf.createQueueConnection();
140         cfControl.setReturnValue(con, 1);
141         con.start();
142         conControl.setVoidCallable(2);
143         con.close();
144         conControl.setVoidCallable(1);
145
146         cfControl.replay();
147         conControl.replay();
148
149         SingleConnectionFactory scf = new SingleConnectionFactory102(cf, false);
150         QueueConnection JavaDoc con1 = scf.createQueueConnection();
151         con1.start();
152         con1.close(); // should be ignored
153
QueueConnection JavaDoc con2 = scf.createQueueConnection();
154         con2.start();
155         con2.close(); // should be ignored
156
scf.destroy(); // should trigger actual close
157

158         cfControl.verify();
159         conControl.verify();
160     }
161
162     public void testConnectionFactory102WithTopic() throws JMSException JavaDoc {
163         MockControl cfControl = MockControl.createControl(TopicConnectionFactory JavaDoc.class);
164         TopicConnectionFactory JavaDoc cf = (TopicConnectionFactory JavaDoc) cfControl.getMock();
165         MockControl conControl = MockControl.createControl(TopicConnection JavaDoc.class);
166         TopicConnection JavaDoc con = (TopicConnection JavaDoc) conControl.getMock();
167
168         cf.createTopicConnection();
169         cfControl.setReturnValue(con, 1);
170         con.start();
171         conControl.setVoidCallable(2);
172         con.close();
173         conControl.setVoidCallable(1);
174
175         cfControl.replay();
176         conControl.replay();
177
178         SingleConnectionFactory scf = new SingleConnectionFactory102(cf, true);
179         TopicConnection JavaDoc con1 = scf.createTopicConnection();
180         con1.start();
181         con1.close(); // should be ignored
182
TopicConnection JavaDoc con2 = scf.createTopicConnection();
183         con2.start();
184         con2.close(); // should be ignored
185
scf.destroy(); // should trigger actual close
186

187         cfControl.verify();
188         conControl.verify();
189     }
190
191 }
192
Popular Tags