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: SendReceiveClearTest.java,v 1.9 2004/02/03 07:31:02 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.MessagePopulator; 57 import org.exolab.jmscts.core.MessageReceiver; 58 import org.exolab.jmscts.core.MessageSender; 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> on send and receipt, against all 70 * message, delivery, and transaction types 71 * 72 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 73 * @version $Revision: 1.9 $ 74 * @jmscts.delivery all 75 */ 76 public class SendReceiveClearTest extends AbstractSendReceiveTestCase { 77 78 /*** 79 * The destination used by this test case 80 */ 81 private static final String DESTINATION = "SendReceiveClearTest"; 82 83 84 /*** 85 * Construct a new <code>SendReceiveClearTest</code> 86 * 87 * @param name the name of test case 88 */ 89 public SendReceiveClearTest(String name) { 90 super(name); 91 } 92 93 /*** 94 * Sets up the test suite 95 * 96 * @return an instance of this class that may be run by 97 * {@link org.exolab.jmscts.core.JMSTestRunner} 98 */ 99 public static Test suite() { 100 return TestCreator.createSendReceiveTest(SendReceiveClearTest.class); 101 } 102 103 /*** 104 * Get the message populator. This implementation returns null, as 105 * population is handled by the test cases. 106 * 107 * @return <code>null</code> 108 */ 109 public MessagePopulator getMessagePopulator() { 110 return null; 111 } 112 113 /*** 114 * Returns the list of destination names used by this test case. These 115 * are used to pre-create destinations prior to running the test case. 116 * 117 * @return the list of destinations used by this test case 118 */ 119 public String[] getDestinations() { 120 return new String[] {DESTINATION}; 121 } 122 123 /*** 124 * Verifies that <code>Message.clearProperties()</code> leaves the message 125 * properties empty, and doesn't clear the message body, on receipt of 126 * a message. 127 * 128 * @jmscts.requirement message.method.clearProperties 129 * @throws Exception for any error 130 */ 131 public void testClearPropertiesOnReceipt() throws Exception { 132 TestContext context = getContext(); 133 Message message = context.getMessage(); 134 135 MessagePopulatorVerifier properties = new MessagePropertyVerifier(); 136 properties.populate(message); 137 138 MessagePopulatorVerifier body = PopulatorVerifierFactory.create( 139 message); 140 body.populate(message); 141 142 Message received = sendReceive(message, DESTINATION); 143 ClearHelper.checkClearProperties(received, body, true); 144 } 145 146 /*** 147 * Verifies that <code>Message.clearBody()</code> leaves the message 148 * body empty, and doesn't clear the message properties, on receipt of 149 * a message. 150 * 151 * @jmscts.message Message 152 * @jmscts.message MapMessage 153 * @jmscts.message ObjectMessage 154 * @jmscts.message TextMessage 155 * @jmscts.requirement message.method.clearBody 156 * @throws Exception for any error 157 */ 158 public void testClearBodyOnReceipt() throws Exception { 159 checkClearBodyOnReceipt(); 160 } 161 162 /*** 163 * Verifies that <code>BytesMessage.clearBody()</code> leaves the message 164 * body empty, and doesn't clear the message properties, on receipt of 165 * a message. 166 * 167 * @jmscts.message BytesMessage 168 * @jmscts.requirement message.method.clearBody 169 * @jmscts.requirement message.bytes.method.clearBody 170 * @throws Exception for any error 171 */ 172 public void testBytesClearBodyOnReceipt() throws Exception { 173 checkClearBodyOnReceipt(); 174 } 175 176 /*** 177 * Verifies that <code>StreamMessage.clearBody()</code> leaves the message 178 * body empty, and doesn't clear the message properties, on receipt of 179 * a message. 180 * 181 * @jmscts.message StreamMessage 182 * @jmscts.requirement message.method.clearBody 183 * @jmscts.requirement message.stream.method.clearBody 184 * @throws Exception for any error 185 */ 186 public void testStreamClearBodyOnReceipt() throws Exception { 187 checkClearBodyOnReceipt(); 188 } 189 190 /*** 191 * Verifies that <code>Message.clearProperties()</code> and 192 * <code>Message.clearBody()</code> on send doesn't affect the sent message 193 * 194 * @jmscts.requirement message.method.clearProperties 195 * @jmscts.requirement message.method.clearBody 196 * @throws Exception for any error 197 */ 198 public void testClearOnSend() throws Exception { 199 final int count = 10; 200 TestContext context = getContext(); 201 Message message = context.getMessage(); 202 203 MessagePopulatorVerifier properties = new MessagePropertyVerifier(); 204 MessagePopulatorVerifier body = PopulatorVerifierFactory.create( 205 message); 206 207 MessageReceiver receiver = createReceiver(DESTINATION); 208 try { 209 MessageSender sender = createSender(DESTINATION); 210 for (int i = 0; i < count; ++i) { 211 message.clearProperties(); 212 properties.populate(message); 213 message.clearBody(); 214 body.populate(message); 215 sender.send(message, 1); 216 } 217 218 Session session = context.getSession(); 219 if (session.getTransacted()) { 220 session.commit(); 221 } 222 223 List messages = receive(receiver, count); 224 Iterator iter = messages.iterator(); 225 while (iter.hasNext()) { 226 Message received = (Message) iter.next(); 227 properties.verify(received); 228 body.verify(received); 229 } 230 } finally { 231 receiver.remove(); 232 } 233 } 234 235 /*** 236 * Verifies that <code>Message.clearProperties()</code> leaves the message 237 * properties empty, and doesn't clear the message body, on receipt of 238 * a message. 239 * 240 * @throws Exception for any error 241 */ 242 private void checkClearBodyOnReceipt() throws Exception { 243 TestContext context = getContext(); 244 Message message = context.getMessage(); 245 246 MessagePopulatorVerifier properties = new MessagePropertyVerifier(); 247 MessagePopulatorVerifier body = PopulatorVerifierFactory.create( 248 message); 249 250 properties.populate(message); 251 body.populate(message); 252 253 Message received = sendReceive(message, DESTINATION); 254 ClearHelper.checkClearBody(received, properties); 255 } 256 257 }

This page was automatically generated by Maven