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: SendReceiveTestRunner.java,v 1.6 2004/01/31 13:44:24 tanderson Exp $
44 */
45 package org.exolab.jmscts.core;
46
47 import junit.framework.Test;
48 import junit.framework.TestResult;
49
50
51 /***
52 * This class enables generic message test cases to be run for each JMS
53 * message type using different delivery modes, synchronous/asynchronous
54 * messaging, and administered and non-administered destinations.
55 * <p>
56 * Test cases must implement the {@link SendReceiveTestCase} interface.
57 *
58 * @version $Revision: 1.6 $ $Date: 2004/01/31 13:44:24 $
59 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
60 * @see SendReceiveTestCase
61 */
62 public class SendReceiveTestRunner extends AbstractMessageTestRunner {
63
64 /***
65 * Construct an instance with the test case to run.
66 *
67 * @param test the test case to run.
68 */
69 public SendReceiveTestRunner(SendReceiveTestCase test) {
70 super(test);
71 }
72
73 /***
74 * Counts the number of test cases that will be run by this test
75 *
76 * @return the number of test cases that will be run
77 */
78 public int countTestCases() {
79 int count = super.countTestCases();
80 SendReceiveTestCase test = (SendReceiveTestCase) getTest();
81
82 DeliveryType[] types = test.getDeliveryTypes().getTypes();
83 int deliveryTypes = 0; // the number of applicable delivery types
84 int durable = 0;
85
86 if (getContext().isQueueConnectionFactory()) {
87 deliveryTypes = types.length;
88 } else {
89 for (int i = 0; i < types.length; ++i) {
90 DeliveryType type = types[i];
91 ReceiptType receipt = type.getReceiptType();
92 if (!ReceiptType.BROWSER.equals(receipt)) {
93 // BROWSER receipt is not applicable for topic connections
94 if (types[i].getAdministered() && !test.getDurableOnly()) {
95 ++deliveryTypes;
96 }
97 if (types[i].getAdministered()) {
98 ++durable;
99 }
100 }
101 }
102 }
103 return (deliveryTypes + durable) * count;
104 }
105
106 /***
107 * Runs a test case for a particular message type, against each of the
108 * supported delivery types.
109 *
110 * @param test the test case
111 * @param result the instance to collect test results in
112 * @param messageType the message type
113 */
114 protected void runTest(Test test, TestResult result, Class messageType) {
115 TestContext context = getContext();
116 SendReceiveTestCase sendReceive = (SendReceiveTestCase) test;
117 DeliveryType[] types = sendReceive.getDeliveryTypes().getTypes();
118 boolean isTopic = context.isTopic();
119 TestFilter filter = getFilter();
120
121 for (int i = 0; i < types.length && !result.shouldStop(); ++i) {
122 DeliveryType type = types[i];
123 ReceiptType receipt = type.getReceiptType();
124
125 if (isTopic && ReceiptType.BROWSER.equals(receipt)) {
126 // BROWSER receipt is not applicable for topics, so skip it
127 } else {
128 MessagingBehaviour behaviour = new MessagingBehaviour(type);
129
130 if (!filtered(behaviour, messageType, test)) {
131 runTest(test, result, messageType, behaviour);
132 }
133
134 if (receipt != null && isTopic && type.getAdministered()) {
135 // run the test using a durable topic subscriber
136 behaviour.setDurable(true);
137 if (!filtered(behaviour, messageType, test)) {
138 runTest(test, result, messageType, behaviour);
139 }
140 }
141 }
142 }
143 }
144
145 /***
146 * Runs a test case for a particular message type, against a particular
147 * messaging behaviour
148 *
149 * @param test the test case
150 * @param result the instance to collect test results in
151 * @param messageType the message type
152 * @param behaviour the messaging behaviour
153 */
154 protected void runTest(Test test, TestResult result, Class messageType,
155 MessagingBehaviour behaviour) {
156 SendReceiveTestInvoker tester = new SendReceiveTestInvoker(
157 test, result, getContext(), getFilter(), messageType, behaviour);
158 result.runProtected(test, tester);
159 }
160
161 /***
162 * Determines if a test case is excluded from being run
163 *
164 * @param behaviour the message behaviour
165 * @param messageType the message type
166 * @param test the test case
167 * @return <code>true</code> if the test case is excluded
168 */
169 private boolean filtered(MessagingBehaviour behaviour, Class messageType,
170 Test test) {
171 boolean result = false;
172 SendReceiveTestCase sendReceive = (SendReceiveTestCase) test;
173 TestContext context = getContext();
174
175 if (context.isTopic() && behaviour.getAdministered()
176 && sendReceive.getDurableOnly() && !behaviour.getDurable()) {
177 // if the test doesn't support non-durable topic subscribers, then
178 // skip this test
179 result = true;
180 } else {
181 TestFilter filter = getFilter();
182 result = (filter != null && !filter.includes(context, behaviour,
183 messageType, test));
184 }
185 return result;
186 }
187
188 }
This page was automatically generated by Maven