View Javadoc
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: TestCreator.java,v 1.3 2004/01/31 13:44:24 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.core; 46 47 import java.util.Enumeration; 48 49 import junit.framework.Test; 50 import junit.framework.TestSuite; 51 52 53 /*** 54 * Helper class for creating JUnit test cases runnable by JMSTestRunner 55 * 56 * @version $Revision: 1.3 $ $Date: 2004/01/31 13:44:24 $ 57 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 58 * @see JMSTestRunner 59 * @see ProviderTestRunner 60 * @see ConnectionTestRunner 61 * @see SessionTestRunner 62 * @see MessageTestRunner 63 * @see SendReceiveTestRunner 64 */ 65 public final class TestCreator { 66 67 /*** 68 * Prevent construction of utility class 69 */ 70 private TestCreator() { 71 } 72 73 /*** 74 * Create a connection factory test using its class. The class must 75 * implement the {@link ConnectionFactoryTestCase} interface. 76 * 77 * @param test the test class 78 * @return the test 79 */ 80 public static Test createConnectionFactoryTest(Class test) { 81 return new TestSuite(test); 82 } 83 84 /*** 85 * Create a connection test. 86 * 87 * @param test the test case. 88 * @return the test 89 */ 90 public static Test createConnectionTest(Test test) { 91 Test result; 92 if (test instanceof TestSuite) { 93 TestSuite suite = new TestSuite(); 94 Enumeration tests = ((TestSuite) test).tests(); 95 while (tests.hasMoreElements()) { 96 ConnectionTestCase child = 97 (ConnectionTestCase) tests.nextElement(); 98 suite.addTest(new ConnectionTestRunner(child)); 99 } 100 result = suite; 101 } else { 102 result = new ConnectionTestRunner((ConnectionTestCase) test); 103 } 104 return result; 105 } 106 107 /*** 108 * Create a connection test using its class. The class must implement the 109 * {@link ConnectionTestCase} interface. 110 * 111 * @param test the test class 112 * @return the test 113 */ 114 public static Test createConnectionTest(Class test) { 115 return createConnectionTest(new TestSuite(test)); 116 } 117 118 /*** 119 * Create a session test. 120 * 121 * @param test the test case 122 * @return the test 123 */ 124 public static Test createSessionTest(Test test) { 125 Test result; 126 if (test instanceof TestSuite) { 127 TestSuite suite = new TestSuite(); 128 Enumeration tests = ((TestSuite) test).tests(); 129 while (tests.hasMoreElements()) { 130 SessionTestCase child = (SessionTestCase) tests.nextElement(); 131 suite.addTest(new SessionTestRunner(child)); 132 } 133 result = suite; 134 } else { 135 result = new SessionTestRunner((SessionTestCase) test); 136 } 137 return createConnectionTest(result); 138 } 139 140 /*** 141 * Create a session test using its class. The class must implement the 142 * {@link SessionTestCase} interface. 143 * 144 * @param test the test class 145 * @return the test 146 */ 147 public static Test createSessionTest(Class test) { 148 return createSessionTest(new TestSuite(test)); 149 } 150 151 /*** 152 * Create a message test. The test must implement the 153 * {@link MessageTestCase} interface. 154 * 155 * @param test the test case 156 * @return the test 157 */ 158 public static Test createMessageTest(Test test) { 159 Test result; 160 if (test instanceof TestSuite) { 161 TestSuite suite = new TestSuite(); 162 Enumeration tests = ((TestSuite) test).tests(); 163 while (tests.hasMoreElements()) { 164 MessageTestCase child = (MessageTestCase) tests.nextElement(); 165 suite.addTest(new MessageTestRunner(child)); 166 } 167 result = suite; 168 } else { 169 result = new MessageTestRunner((MessageTestCase) test); 170 } 171 return createSessionTest(result); 172 } 173 174 /*** 175 * Create a message test using its class. The class must implement the 176 * {@link MessageTestCase} interface. 177 * 178 * @param test the test class 179 * @return the test 180 */ 181 public static Test createMessageTest(Class test) { 182 return createMessageTest(new TestSuite(test)); 183 } 184 185 /*** 186 * Create a send/receive test. The test must implement 187 * the {@link SendReceiveTestCase} interface. 188 * 189 * @param test the test case 190 * @return the test 191 */ 192 public static Test createSendReceiveTest(Test test) { 193 Test result; 194 if (test instanceof TestSuite) { 195 TestSuite suite = new TestSuite(); 196 Enumeration tests = ((TestSuite) test).tests(); 197 while (tests.hasMoreElements()) { 198 SendReceiveTestCase child = 199 (SendReceiveTestCase) tests.nextElement(); 200 suite.addTest(new SendReceiveTestRunner(child)); 201 } 202 result = suite; 203 } else { 204 result = new SendReceiveTestRunner((SendReceiveTestCase) test); 205 } 206 return createSessionTest(result); 207 } 208 209 /*** 210 * Create a send/receive test using its class. The class must implement 211 * the {@link SendReceiveTestCase} interface. 212 * 213 * @param test the test class 214 * @return the test 215 */ 216 public static Test createSendReceiveTest(Class test) { 217 return createSendReceiveTest(new TestSuite(test)); 218 } 219 220 }

This page was automatically generated by Maven