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: ProviderTestRunner.java,v 1.6 2004/01/31 13:44:24 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.core; 46 47 import javax.jms.ConnectionFactory; 48 import javax.jms.QueueConnectionFactory; 49 import javax.jms.TopicConnectionFactory; 50 import javax.jms.XAQueueConnectionFactory; 51 import javax.jms.XATopicConnectionFactory; 52 53 import junit.framework.Test; 54 import junit.framework.TestResult; 55 56 import org.apache.log4j.Category; 57 58 import org.exolab.jmscts.provider.Administrator; 59 import org.exolab.jmscts.provider.Provider; 60 import org.exolab.jmscts.provider.ProviderLoader; 61 62 63 /*** 64 * This class enables generic connection factory test cases to be run for 65 * each JMS provider. 66 * <p> 67 * Test cases must implement the {@link ConnectionFactoryTestCase} interface. 68 * 69 * @version $Revision: 1.6 $ $Date: 2004/01/31 13:44:24 $ 70 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 71 * @see ConnectionTestCase 72 * @see JMSTestRunner 73 * @see Provider 74 */ 75 public class ProviderTestRunner extends TestRunner { 76 77 /*** 78 * The provider 79 */ 80 private ProviderLoader _provider = null; 81 82 /*** 83 * The logger 84 */ 85 private static final Category log = 86 Category.getInstance(ProviderTestRunner.class); 87 88 89 /*** 90 * Construct an instance with the test case to run. 91 * 92 * @param test the test case to run. The test must implement the 93 * {@link ConnectionFactoryTestCase} interface, unless it is a TestSuite, 94 * where each contained test must implement the 95 * {@link ConnectionFactoryTestCase} interface. 96 */ 97 public ProviderTestRunner(Test test) { 98 super(test); 99 } 100 101 /*** 102 * Set the provider loader 103 * This must be invoked prior to running the test case. 104 * 105 * @param provider the provider loader 106 */ 107 public void setProvider(ProviderLoader provider) { 108 _provider = provider; 109 } 110 111 /*** 112 * Initialises the provider 113 * 114 * @throws Exception if the provider proxy cannot be initialised. 115 */ 116 protected void setUp() throws Exception { 117 Provider provider = _provider.getProvider(); 118 provider.initialise(_provider.getStart()); 119 120 TestContext context = new TestContext(getContext(), 121 provider.getAdministrator()); 122 setContext(context); 123 } 124 125 /*** 126 * Cleans up after the test case has been run 127 * 128 * @throws Exception if the provider can't be cleaned up 129 */ 130 protected void tearDown() throws Exception { 131 super.tearDown(); 132 Provider provider = _provider.getProvider(); 133 provider.cleanup(_provider.getStop()); 134 _provider = null; 135 } 136 137 /*** 138 * Runs a test case against each supported connection type 139 * 140 * @param test the test case 141 * @param result the instance to collect test results in 142 */ 143 protected void runTest(Test test, TestResult result) { 144 ConnectionFactoryTestCase factoryTest = 145 (ConnectionFactoryTestCase) test; 146 Class[] types = factoryTest.getConnectionFactoryTypes().getTypes(); 147 TestContext context = getContext(); 148 TestFilter filter = getFilter(); 149 for (int i = 0; i < types.length; ++i) { 150 if (filter == null || filter.includes(types[i], test)) { 151 Tester tester = new Tester(test, result, context, filter, 152 types[i]); 153 result.runProtected(test, tester); 154 } 155 } 156 } 157 158 /*** 159 * Helper class to run a test case against a connection factory 160 */ 161 private class Tester extends TestInvoker { 162 163 /*** 164 * The connection factory type 165 */ 166 private final Class _type; 167 168 /*** 169 * Construct an instance to run a test case against a connection 170 * factory. 171 * 172 * @param test the test case 173 * @param result the instance to collect test results in 174 * @param context the test context 175 * @param filter the test filter 176 * @param type the type of the connection factory 177 */ 178 public Tester(Test test, TestResult result, TestContext context, 179 TestFilter filter, Class type) { 180 super(test, result, context, filter); 181 _type = type; 182 } 183 184 /*** 185 * Setup the test 186 * 187 * @param test the test 188 * @param context the test context 189 * @throws Exception for any error 190 */ 191 protected void setUp(JMSTest test, TestContext context) 192 throws Exception { 193 194 final ConnectionFactoryTestCase factoryTest = 195 (ConnectionFactoryTestCase) test; 196 197 Provider provider = _provider.getProvider(); 198 Administrator admin = provider.getAdministrator(); 199 boolean queue = true; 200 String factoryName = null; 201 ConnectionFactory factory = null; 202 203 try { 204 if (_type.equals(QueueConnectionFactory.class)) { 205 factoryName = admin.getQueueConnectionFactory(); 206 } else if (_type.equals(TopicConnectionFactory.class)) { 207 queue = false; 208 factoryName = admin.getTopicConnectionFactory(); 209 } else if (_type.equals(XAQueueConnectionFactory.class)) { 210 factoryName = admin.getXAQueueConnectionFactory(); 211 } else if (_type.equals(XATopicConnectionFactory.class)) { 212 queue = false; 213 factoryName = admin.getXATopicConnectionFactory(); 214 } else { 215 throw new Exception("Unsupported connection factory type=" 216 + _type.getName()); 217 } 218 219 if (factoryName == null) { 220 throw new Exception( 221 "Provider returned null for factory of type=" 222 + _type.getName()); 223 } 224 225 factory = (ConnectionFactory) admin.lookup(factoryName); 226 227 } catch (Exception exception) { 228 log.debug(exception, exception); 229 throw exception; 230 } 231 232 233 if (log.isDebugEnabled()) { 234 log.debug("running test=" + test 235 + " using connection factory type=" 236 + _type.getName()); 237 } 238 TestContext child = new TestContext(getContext(), factory, _type); 239 factoryTest.setContext(child); 240 } 241 242 /*** 243 * Tear down the test 244 * 245 * @param test the test 246 * @param context the test context 247 * @throws Exception for any error 248 */ 249 protected void tearDown(JMSTest test, TestContext context) 250 throws Exception { 251 252 if (log.isDebugEnabled()) { 253 log.debug("completed running test=" 254 + test + " using connection factory type=" 255 + _type.getName()); 256 } 257 } 258 259 } 260 261 } 262

This page was automatically generated by Maven