1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact tma@netspace.net.au.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2001-2004 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: SendReceiveStopTest.java,v 1.4 2004/02/03 07:32:07 tanderson Exp $
44 */
45 package org.exolab.jmscts.test.connection;
46
47 import javax.jms.Connection;
48
49 import org.apache.log4j.Category;
50
51 import junit.framework.Test;
52
53 import org.exolab.jmscts.core.AbstractSendReceiveTestCase;
54 import org.exolab.jmscts.core.MessageReceiver;
55 import org.exolab.jmscts.core.TestContext;
56 import org.exolab.jmscts.core.TestCreator;
57
58
59 /***
60 * This class tests the behaviour of <code>Connection.stop</code> and
61 * <code>Connection.start</code>
62 *
63 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
64 * @version $Revision: 1.4 $
65 * @see AbstractSendReceiveTestCase
66 * @jmscts.message TextMessage
67 * @jmscts.delivery consumer
68 */
69 public class SendReceiveStopTest extends AbstractSendReceiveTestCase {
70
71 /***
72 * The destination to create prior to running the test
73 */
74 private static final String DESTINATION = "SendReceiveStopTest";
75
76 /***
77 * The logger
78 */
79 private static final Category log =
80 Category.getInstance(SendReceiveStopTest.class);
81
82
83 /***
84 * Construct a new <code>SendReceiveStopTest</code>
85 *
86 * @param name the name of test case
87 */
88 public SendReceiveStopTest(String name) {
89 super(name);
90 }
91
92 /***
93 * Sets up the test suite
94 *
95 * @return an instance of this class that may be run by
96 * {@link org.exolab.jmscts.core.JMSTestRunner}
97 */
98 public static Test suite() {
99 return TestCreator.createSendReceiveTest(SendReceiveStopTest.class);
100 }
101
102 /***
103 * Returns if this test can share resources with other test cases.
104 * This implementation always returns <code>false</code>, to
105 * ensure that a new connection is created for each test.
106 *
107 * @return <code>false</code>
108 */
109 public boolean share() {
110 return false;
111 }
112
113 /***
114 * Returns if the connection should be started prior to running the test.
115 * This implementation always returns <code>false</code> to avoid
116 * conflicts with test cases
117 *
118 * @return <code>false</code>
119 */
120 public boolean startConnection() {
121 return false;
122 }
123
124 /***
125 * Returns the list of destination names used by this test case. These
126 * are used to pre-create destinations prior to running the test case.
127 *
128 * @return the list of destinations used by this test case
129 */
130 public String[] getDestinations() {
131 return new String[]{DESTINATION};
132 }
133
134 /***
135 * Verifies that a connection does not receive any messages on creation.
136 *
137 * @jmscts.requirement connection.creation
138 * @jmscts.requirement connection.stopped
139 * @jmscts.requirement connection.stopped.send
140 * @throws Exception for any error
141 */
142 public void testStoppedOnCreation() throws Exception {
143 final int count = 10; // the number of messages to send
144
145 MessageReceiver receiver = createReceiver(DESTINATION);
146
147 send(DESTINATION, count);
148
149 try {
150 // verify that the receiver doesn't receive any messages
151 receive(receiver, 0);
152 } finally {
153 receiver.remove();
154 }
155 }
156
157 /***
158 * Verifies that a connection doesn't receive any messages after starting a
159 * connection, sending messages, and then stopping it.
160 *
161 * @jmscts.requirement connection.stopped
162 * @throws Exception for any error
163 */
164 public void testStop() throws Exception {
165 final int count = 10; // the number of messages to send
166 TestContext context = getContext();
167 Connection connection = context.getConnection();
168 connection.start();
169
170 MessageReceiver receiver = createReceiver(DESTINATION);
171
172 try {
173 // send count messages and stop the connection.
174 send(DESTINATION, count);
175 connection.stop();
176
177 // verify that the receiver doesn't receive any messages
178 receive(receiver, 0);
179
180 // restart the connection and verify that the receiver
181 // receives messages
182 connection.start();
183 receive(receiver, count);
184 } finally {
185 receiver.remove();
186 }
187 }
188
189 }
This page was automatically generated by Maven