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: MessageTestInvoker.java,v 1.2 2004/01/31 13:44:24 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.core; 46 47 import javax.jms.Connection; 48 import javax.jms.Session; 49 import javax.jms.Message; 50 51 import junit.framework.Test; 52 import junit.framework.TestResult; 53 54 55 /*** 56 * Helper class to run an {@link MessageTestCase} 57 * 58 * @version $Revision: 1.2 $ $Date: 2004/01/31 13:44:24 $ 59 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 60 * @see MessageTestCase 61 */ 62 abstract class MessageTestInvoker extends TestInvoker { 63 64 /*** 65 * The message type 66 */ 67 private final Class _type; 68 69 70 /*** 71 * Construct a new <code>MessageTestInvoker</code> 72 * 73 * @param test the test to run. Must be an instance of 74 * <code>MessageTestCase</code> 75 * @param result the result of the test 76 * @param context the test context 77 * @param filter the test filter. May be <code>null</code> 78 * @param type the message type to run the test against 79 */ 80 public MessageTestInvoker(Test test, TestResult result, 81 TestContext context, TestFilter filter, 82 Class type) { 83 super(test, result, context, filter); 84 85 if (!(test instanceof MessageTestCase)) { 86 throw new IllegalArgumentException( 87 "Argument 'test' must implement MessageTestCase"); 88 } 89 if (type == null) { 90 throw new IllegalArgumentException("Argument 'type' is null"); 91 } 92 _type = type; 93 } 94 95 /*** 96 * Setup the test 97 * 98 * @param test the test 99 * @param context the test context 100 * @throws Exception for any error 101 */ 102 protected void setUp(JMSTest test, TestContext context) throws Exception { 103 MessageTestCase messageTest = (MessageTestCase) test; 104 105 if (!messageTest.share()) { 106 // test case cannot share resources, so a new connection and 107 // session have been allocated by the parent 108 if (messageTest.startConnection()) { 109 context.getConnection().start(); 110 } 111 } else { 112 // note that the connection is only stopped for shared 113 // connections. This is to avoid conflicts with tests 114 // that test connection stop/start behaviour when the 115 // connection is created 116 Connection connection = context.getConnection(); 117 if (messageTest.startConnection()) { 118 connection.start(); 119 } else { 120 connection.stop(); 121 } 122 } 123 } 124 125 /*** 126 * Create a message to test against, corresponding to the type 127 * passed at construction. If the test has an associated 128 * <code>MessagePopulator</code>, this will be used to populate the message 129 * 130 * @return a new message 131 * @throws Exception for any error 132 */ 133 protected Message create() throws Exception { 134 MessageTestCase test = (MessageTestCase) getTest(); 135 TestContext context = getContext(); 136 Session session = context.getSession(); 137 MessageCreator creator = new MessageCreator( 138 session, test.getMessagePopulator()); 139 return creator.create(_type); 140 } 141 142 /*** 143 * Returns the type of the message to test against 144 * 145 * @return the type of the message to test against 146 */ 147 protected Class getMessageType() { 148 return _type; 149 } 150 151 }

This page was automatically generated by Maven