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: CloseTest.java,v 1.6 2004/02/03 21:52:11 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.test.session; 46 47 import javax.jms.Destination; 48 import javax.jms.Session; 49 import javax.jms.IllegalStateException; 50 import javax.jms.QueueSession; 51 52 import org.apache.log4j.Category; 53 54 import junit.framework.Test; 55 56 import org.exolab.jmscts.core.AbstractSessionTestCase; 57 import org.exolab.jmscts.core.AckTypes; 58 import org.exolab.jmscts.core.DestinationHelper; 59 import org.exolab.jmscts.core.MethodInvoker; 60 import org.exolab.jmscts.core.TestContext; 61 import org.exolab.jmscts.core.TestCreator; 62 63 64 /*** 65 * This class tests the behaviour of <code>Session.close</code> 66 * 67 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 68 * @version $Revision: 1.6 $ 69 * @see AbstractSessionTestCase 70 */ 71 public class CloseTest extends AbstractSessionTestCase { 72 73 /*** 74 * The logger 75 */ 76 private static final Category log = Category.getInstance(CloseTest.class); 77 78 79 /*** 80 * Construct a new <code>CloseTest</code> 81 * 82 * @param name the name of test case 83 */ 84 public CloseTest(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.createSessionTest(CloseTest.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 session 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 IllegalStateException is thrown for any Session method 111 * (except Session.close()) when invoking methods on a closed session. 112 * 113 * @jmscts.requirement session.close 114 * @throws Exception for any error 115 */ 116 public void testExceptionOnClose() throws Exception { 117 final String name = "CloseTest"; 118 TestContext context = getContext(); 119 Session session = context.getSession(); 120 session.close(); 121 122 // set up the destination 123 DestinationHelper.destroy(name, context.getAdministrator()); 124 Destination destination = DestinationHelper.create( 125 name, context.isQueue(), context.getAdministrator()); 126 127 try { 128 invokeSessionMethods(destination); 129 } finally { 130 DestinationHelper.destroy(name, context.getAdministrator()); 131 } 132 } 133 134 /*** 135 * Verifies that closing a closed session has no effect. 136 * 137 * @jmscts.requirement session.close.closed 138 * @throws Exception for any error 139 */ 140 public void testCloseForClosedSession() throws Exception { 141 TestContext context = getContext(); 142 Session session = context.getSession(); 143 session.close(); 144 145 try { 146 session.close(); 147 } catch (Exception exception) { 148 String msg = "Closing a closed session shouldn't generate an " 149 + "exception"; 150 log.debug(msg, exception); 151 fail(msg); 152 } 153 } 154 155 /*** 156 * Invoke session methods 157 * 158 * @param destination the destination to use 159 * @throws Exception for any error 160 */ 161 private void invokeSessionMethods(Destination destination) 162 throws Exception { 163 TestContext context = getContext(); 164 Session session = context.getSession(); 165 MethodInvoker invoker = new MethodInvoker( 166 context.getSessionType(), IllegalStateException.class); 167 168 invoker.invoke(session, "createBytesMessage"); 169 invoker.invoke(session, "createMapMessage"); 170 invoker.invoke(session, "createObjectMessage"); 171 invoker.invoke(session, "createObjectMessage", "ABC"); 172 invoker.invoke(session, "createStreamMessage"); 173 invoker.invoke(session, "createTextMessage"); 174 invoker.invoke(session, "createTextMessage", "ABC"); 175 invoker.invoke(session, "getTransacted"); 176 177 if (context.getAckType() == AckTypes.TRANSACTED) { 178 invoker.invoke(session, "commit"); 179 invoker.invoke(session, "rollback"); 180 } else { 181 invoker.invoke(session, "recover"); 182 } 183 184 // @todo - need to add support for get/setMessageListener, run 185 // and XA 186 187 if (session instanceof QueueSession) { 188 invoker.invoke(session, "createBrowser", destination); 189 invoker.invoke(session, "createBrowser", 190 new Object[]{destination, "1=1"}); 191 invoker.invoke(session, "createQueue", "dummy"); 192 invoker.invoke(session, "createReceiver", destination); 193 invoker.invoke(session, "createReceiver", 194 new Object[]{destination, "1=1"}); 195 invoker.invoke(session, "createSender", destination); 196 invoker.invoke(session, "createTemporaryQueue"); 197 } else { 198 invoker.invoke(session, "createDurableSubscriber", 199 new Object[]{destination, "ABC"}); 200 invoker.invoke(session, "createDurableSubscriber", 201 new Object[]{destination, "CDE", "1=1", 202 Boolean.TRUE}); 203 invoker.invoke(session, "createPublisher", destination); 204 invoker.invoke(session, "createSubscriber", destination); 205 invoker.invoke(session, "createSubscriber", 206 new Object[]{destination, "1=1", Boolean.FALSE}); 207 invoker.invoke(session, "createTemporaryTopic"); 208 invoker.invoke(session, "createTopic", "dummy"); 209 invoker.invoke(session, "unsubscribe", "ABC"); 210 } 211 } 212 213 }

This page was automatically generated by Maven