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: ConnectionCloseTest.java,v 1.5 2004/02/03 07:32:07 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.test.connection; 46 47 import javax.jms.Connection; 48 import javax.jms.ExceptionListener; 49 import javax.jms.IllegalStateException; 50 import javax.jms.JMSException; 51 52 import org.apache.log4j.Category; 53 54 import junit.framework.Test; 55 56 import org.exolab.jmscts.core.AbstractConnectionTestCase; 57 import org.exolab.jmscts.core.MethodInvoker; 58 import org.exolab.jmscts.core.TestContext; 59 import org.exolab.jmscts.core.TestCreator; 60 61 62 /*** 63 * This class tests the behaviour of <code>Connection.close</code> 64 * 65 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 66 * @version $Revision: 1.5 $ 67 * @see AbstractConnectionTestCase 68 */ 69 public class ConnectionCloseTest extends AbstractConnectionTestCase { 70 71 /*** 72 * The logger 73 */ 74 private static final Category log = 75 Category.getInstance(ConnectionCloseTest.class); 76 77 78 /*** 79 * Create a new <code>ConnectionCloseTest</code>. 80 * The test will be run against all connection types. 81 * 82 * @param name the name of test case 83 */ 84 public ConnectionCloseTest(String name) { 85 super(name); 86 } 87 88 /*** 89 * Sets up the test suite 90 * 91 * @return an instance of this class that may be run by 92 * {@link org.exolab.jmscts.core.JMSTestRunner} 93 */ 94 public static Test suite() { 95 return TestCreator.createConnectionTest(ConnectionCloseTest.class); 96 } 97 98 /*** 99 * Returns if this test can share resources with other test cases. 100 * This implementation always returns <code>false</code>, to 101 * ensure that a new connection is created for each test. 102 * 103 * @return <code>false</code> 104 */ 105 public boolean share() { 106 return false; 107 } 108 109 /*** 110 * Verifies that a IllegalStateException is thrown for any Connection 111 * method (except Connection.close()), if the connection has been closed 112 * 113 * @jmscts.requirement connection.close 114 * @throws Exception for any error 115 */ 116 public void testExceptionOnClose() throws Exception { 117 TestContext context = getContext(); 118 Connection connection = context.getConnection(); 119 MethodInvoker invoker = new MethodInvoker( 120 context.getConnectionType(), IllegalStateException.class); 121 122 ExceptionListener dummyListener = new ExceptionListener() { 123 public void onException(JMSException exception) { 124 } 125 }; 126 127 connection.close(); 128 129 invoker.invoke(connection, "getClientID"); 130 invoker.invoke(connection, "getExceptionListener"); 131 invoker.invoke(connection, "getMetaData"); 132 invoker.invoke(connection, "setClientID", "dummyID"); 133 invoker.invoke(connection, "setExceptionListener", dummyListener); 134 invoker.invoke(connection, "start"); 135 invoker.invoke(connection, "stop"); 136 137 Object[] args = new Object[]{Boolean.TRUE, new Integer(0)}; 138 if (context.isQueueConnectionFactory()) { 139 invoker.invoke(connection, "createQueueSession", args); 140 } else if (context.isTopicConnectionFactory()) { 141 invoker.invoke(connection, "createTopicSession", args); 142 } else if (context.isXAQueueConnectionFactory()) { 143 invoker.invoke(connection, "createQueueSession", args); 144 invoker.invoke(connection, "createXAQueueSession"); 145 } else { 146 invoker.invoke(connection, "createTopicSession", args); 147 invoker.invoke(connection, "createXATopicSession"); 148 } 149 } 150 151 /*** 152 * Verifies that closing a closed connection does not produce an 153 * exception. 154 * 155 * @jmscts.requirement connection.close.closed 156 * @throws Exception for any error 157 */ 158 public void testCloseForClosedConnection() throws Exception { 159 TestContext context = getContext(); 160 Connection connection = context.getConnection(); 161 connection.close(); 162 163 try { 164 connection.close(); 165 } catch (Exception exception) { 166 String msg = "Closing a closed connection shouldn't generate an " 167 + "exception"; 168 log.debug(msg, exception); 169 fail(msg); 170 } 171 } 172 173 }

This page was automatically generated by Maven