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: RollbackClearTest.java,v 1.9 2004/02/03 21:52:09 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.test.message.clear; 46 47 import java.util.Iterator; 48 import java.util.List; 49 50 import javax.jms.Message; 51 import javax.jms.Session; 52 53 import junit.framework.Test; 54 55 import org.exolab.jmscts.core.AbstractSendReceiveTestCase; 56 import org.exolab.jmscts.core.MessageReceiver; 57 import org.exolab.jmscts.core.MessageSender; 58 import org.exolab.jmscts.core.MessageVerifier; 59 import org.exolab.jmscts.core.TestContext; 60 import org.exolab.jmscts.core.TestCreator; 61 62 import org.exolab.jmscts.test.message.util.MessagePopulatorVerifier; 63 import org.exolab.jmscts.test.message.util.MessagePropertyVerifier; 64 import org.exolab.jmscts.test.message.util.PopulatorVerifierFactory; 65 66 67 /*** 68 * This class tests the behaviour of <code>Message.clearBody()</code> and 69 * <code>Message.clearProperties()</code> for transacted sessions where the 70 * session is rolled back. 71 * 72 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 73 * @version $Revision: 1.9 $ 74 * @jmscts.session TRANSACTED 75 * @jmscts.delivery all 76 */ 77 public class RollbackClearTest extends AbstractSendReceiveTestCase { 78 79 /*** 80 * The destination used by this test case 81 */ 82 private static final String DESTINATION = "RollbackClearTest"; 83 84 85 /*** 86 * Construct a new <code>RollbackClearTest</code> 87 * 88 * @param name the name of test case 89 */ 90 public RollbackClearTest(String name) { 91 super(name); 92 } 93 94 /*** 95 * Sets up the test suite 96 * 97 * @return an instance of this class that may be run by 98 * {@link org.exolab.jmscts.core.JMSTestRunner} 99 */ 100 public static Test suite() { 101 return TestCreator.createSendReceiveTest(RollbackClearTest.class); 102 } 103 104 /*** 105 * Returns the list of destination names used by this test case. These 106 * are used to pre-create destinations prior to running the test case. 107 * 108 * @return the list of destinations used by this test case 109 */ 110 public String[] getDestinations() { 111 return new String[] {DESTINATION}; 112 } 113 114 /*** 115 * Verifies that clearing the properties and bodies of received messages 116 * doesn't affect the messages received after rolling back the session 117 * 118 * @jmscts.requirement message.method.clearProperties 119 * @jmscts.requirement message.method.clearBody 120 * @throws Exception for any error 121 */ 122 public void testRollback() throws Exception { 123 final int count = 2; 124 TestContext context = getContext(); 125 Message message = context.getMessage(); 126 MessagePopulatorVerifier properties = new MessagePropertyVerifier(); 127 MessagePopulatorVerifier body = PopulatorVerifierFactory.create( 128 message); 129 130 MessageReceiver receiver = createReceiver(DESTINATION); 131 132 try { 133 MessageSender sender = createSender(DESTINATION); 134 for (int i = 0; i < count; ++i) { 135 message.clearProperties(); 136 properties.populate(message); 137 message.clearBody(); 138 body.populate(message); 139 sender.send(message, 1); 140 } 141 142 // send the messages 143 Session session = context.getSession(); 144 session.commit(); 145 146 // now receive and verify them 147 List messages = verify(receiver, properties, body, count); 148 149 // clear the received messages 150 Iterator iter = messages.iterator(); 151 while (iter.hasNext()) { 152 Message received = (Message) iter.next(); 153 message.clearProperties(); 154 message.clearBody(); 155 } 156 157 // roll back the session, and re-receive and verify the messages 158 // haven't changed 159 session.rollback(); 160 verify(receiver, properties, body, count); 161 session.commit(); 162 } finally { 163 receiver.remove(); 164 } 165 } 166 167 /*** 168 * Receive messages, and verify them 169 * 170 * @param receiver the receiver 171 * @param properties the message property verifier 172 * @param body the message body verifier 173 * @param count the no. of mesages to receive 174 * @return the received messages 175 * @throws Exception for any error 176 */ 177 private List verify(MessageReceiver receiver, MessageVerifier properties, 178 MessageVerifier body, int count) throws Exception { 179 180 // receive the messages, and verify them 181 List messages = receive(receiver, count); 182 Iterator iter = messages.iterator(); 183 while (iter.hasNext()) { 184 Message received = (Message) iter.next(); 185 properties.verify(received); 186 body.verify(received); 187 } 188 return messages; 189 } 190 191 }

This page was automatically generated by Maven