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 07:31:02 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.test.message.close; 46 47 import javax.jms.Connection; 48 import javax.jms.IllegalStateException; 49 import javax.jms.Message; 50 import javax.jms.Session; 51 52 import junit.framework.Test; 53 54 import org.exolab.jmscts.core.AbstractSendReceiveTestCase; 55 import org.exolab.jmscts.core.MessagePopulator; 56 import org.exolab.jmscts.core.TestContext; 57 import org.exolab.jmscts.core.TestCreator; 58 import org.exolab.jmscts.test.message.util.MessagePopulatorVerifier; 59 import org.exolab.jmscts.test.message.util.PopulatorVerifierFactory; 60 61 62 /*** 63 * This class tests the behaviour of messages when the associated 64 * connection or session is closed. 65 * 66 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 67 * @version $Revision: 1.6 $ 68 * @see AbstractSendReceiveTestCase 69 * @see org.exolab.jmscts.core.SendReceiveTestRunner 70 * @jmscts.session all 71 * @jmscts.delivery consumer 72 */ 73 public class CloseTest extends AbstractSendReceiveTestCase { 74 75 /*** 76 * The destination used by this test case 77 */ 78 private static final String DESTINATION = "CloseTest"; 79 80 /*** 81 * Construct an instance of this class for a specific test case. 82 * The test will be run against all message, consumer and session types. 83 * 84 * @param name the name of test case 85 */ 86 public CloseTest(String name) { 87 super(name); 88 } 89 90 /*** 91 * Sets up the test suite 92 * 93 * @return an instance of this class that may be run by 94 * {@link org.exolab.jmscts.core.JMSTestRunner} 95 */ 96 public static Test suite() { 97 return TestCreator.createSendReceiveTest(CloseTest.class); 98 } 99 100 /*** 101 * Returns if this test can share resources with other test cases. 102 * This implementation always returns <code>false</code>, to 103 * ensure that a new session is created for each test. 104 * 105 * @return <code>false</code> 106 */ 107 public boolean share() { 108 return false; 109 } 110 111 /*** 112 * Get the message populator. This implementation always returns null 113 * 114 * @return null 115 */ 116 public MessagePopulator getMessagePopulator() { 117 return null; 118 } 119 120 /*** 121 * Returns the list of destination names used by this test case. These 122 * are used to pre-create destinations prior to running the test case. 123 * 124 * @return this implementation returns <code>null</code>. 125 */ 126 public String[] getDestinations() { 127 return new String[]{DESTINATION}; 128 } 129 130 /*** 131 * Verifies that all the methods for a message may be invoked for a closed 132 * session, with the exception of <code>Message.acknowledge()</code>, which 133 * should throw <code>IllegalStateException</code>. 134 * 135 * @jmscts.requirement session.close.message 136 * @throws Exception for any error 137 */ 138 public void testCloseSession() throws Exception { 139 TestContext context = getContext(); 140 Session session = context.getSession(); 141 Message message = context.getMessage(); 142 143 MessagePopulatorVerifier verifier = PopulatorVerifierFactory.create( 144 message); 145 146 verifier.populate(message); 147 Message received = sendReceive(message, DESTINATION); 148 149 // close the session, and verify that methods may be invoked on the 150 // sent and received messages 151 session.close(); 152 153 // verify that the sent message can be cleared and populated 154 message.clearBody(); 155 verifier.populate(message); 156 157 // verify that the received message can be read 158 verifier.verify(received); 159 160 // now verify that invoking acknowledge throws IllegalStateException 161 try { 162 received.acknowledge(); 163 fail("Expected IllegalStateException to be thrown when invoking " 164 + "ackwnowledge for a closed session"); 165 } catch (IllegalStateException expected) { 166 // the expected behaviour 167 } catch (Exception exception) { 168 fail("Expected IllegalStateException to be thrown when invoking " 169 + "ackwnowledge for a closed session, but got: " + exception); 170 } 171 } 172 173 /*** 174 * Verifies that all the methods for a message may be invoked for a closed 175 * connection, with the exception of <code>Message.acknowledge()</code>, 176 * which should throw <code>IllegalStateException</code>. 177 * 178 * @jmscts.requirement connection.close.message 179 * @throws Exception for any error 180 */ 181 public void testCloseConnection() throws Exception { 182 TestContext context = getContext(); 183 Connection connection = context.getConnection(); 184 Message message = context.getMessage(); 185 186 MessagePopulatorVerifier verifier = PopulatorVerifierFactory.create( 187 message); 188 189 verifier.populate(message); 190 Message received = sendReceive(message, DESTINATION); 191 192 // close the connection, and verify that methods may be invoked on the 193 // sent and received messages 194 connection.close(); 195 196 // verify that the sent message can be cleared and populated 197 message.clearBody(); 198 verifier.populate(message); 199 200 // verify that the received message can be read 201 verifier.verify(received); 202 203 // now verify that invoking acknowledge throws IllegalStateException 204 try { 205 received.acknowledge(); 206 fail("Expected IllegalStateException to be thrown when invoking " 207 + "ackwnowledge for a closed connection"); 208 } catch (IllegalStateException expected) { 209 // the expected behaviour 210 } catch (Exception exception) { 211 fail("Expected IllegalStateException to be thrown when invoking " 212 + "ackwnowledge for a closed connection, but got: " 213 + exception); 214 } 215 } 216 217 }

This page was automatically generated by Maven