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: MessageTestRunner.java,v 1.5 2004/01/31 13:44:24 tanderson Exp $
44 */
45 package org.exolab.jmscts.core;
46
47 import javax.jms.Message;
48
49 import org.apache.log4j.Category;
50
51 import junit.framework.Test;
52 import junit.framework.TestResult;
53
54
55 /***
56 * This class enables generic message test cases to be run for each JMS
57 * message type.
58 * <p>
59 * Test cases must implement the {@link MessageTestCase} interface.
60 *
61 * @version $Revision: 1.5 $ $Date: 2004/01/31 13:44:24 $
62 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
63 * @see MessageTestCase
64 */
65 public class MessageTestRunner extends AbstractMessageTestRunner {
66
67 /***
68 * The logger
69 */
70 private static final Category log =
71 Category.getInstance(MessageTestRunner.class.getName());
72
73
74 /***
75 * Construct an instance with the test case to run.
76 *
77 * @param test the test case to run.
78 */
79 public MessageTestRunner(MessageTestCase test) {
80 super(test);
81 }
82
83 /***
84 * Runs a test case for the given message type.
85 *
86 * @param test the test case
87 * @param result the instance to collect test results in
88 * @param messageType the message type
89 */
90 protected void runTest(Test test, TestResult result, Class messageType) {
91 Tester tester = new Tester(test, result, getContext(), getFilter(),
92 messageType);
93 result.runProtected(test, tester);
94 }
95
96 /***
97 * Helper class to run a test case, for the given message type
98 */
99 private class Tester extends MessageTestInvoker {
100
101 /***
102 * Construct a new <code>Tester</code>
103 *
104 * @param test the test to run. Must be an instance of
105 * <code>MessageTestCase</code>
106 * @param result the result of the test
107 * @param context the test context
108 * @param filter the test filter. May be <code>null</code>
109 * @param type the message type to run the test against
110 */
111 public Tester(Test test, TestResult result, TestContext context,
112 TestFilter filter, Class type) {
113 super(test, result, context, filter, type);
114 }
115
116 /***
117 * Setup the test
118 *
119 * @param test the test
120 * @param context the test context
121 * @throws Exception for any error
122 */
123 protected void setUp(JMSTest test, TestContext context)
124 throws Exception {
125 super.setUp(test, context);
126
127 if (log.isDebugEnabled()) {
128 String sessionType = context.getSessionType().getName();
129 String messageType =
130 getChildContext().getMessageType().getName();
131 String msg = "test=" + test + " using session type="
132 + sessionType + ", message type=" + messageType;
133
134 log.debug("running " + msg);
135 }
136
137 MessageTestCase messageTest = (MessageTestCase) test;
138 TestContext child;
139 if (messageTest.shouldCreateMessage()) {
140 // set up the message for the test
141 Message message = create();
142 child = new TestContext(context, message);
143 } else {
144 child = new TestContext(context, getMessageType());
145 }
146
147 setChildContext(child);
148 test.setContext(child);
149 }
150
151 /***
152 * Tear down the test
153 *
154 * @param test the test
155 * @param context the test context
156 * @throws Exception for any error
157 */
158 protected void tearDown(JMSTest test, TestContext context)
159 throws Exception {
160 if (log.isDebugEnabled()) {
161 String sessionType = context.getSessionType().getName();
162 String messageType =
163 getChildContext().getMessageType().getName();
164 String msg = "test=" + test + " using session type="
165 + sessionType + ", message type=" + messageType;
166
167 log.debug("completed " + msg);
168 }
169 }
170
171 }
172
173 }
This page was automatically generated by Maven