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 2003-2004 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * $Id: RepublishTest.java,v 1.3 2004/02/03 21:52:12 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.test.session.clientack; 46 47 import java.util.List; 48 49 import javax.jms.Message; 50 51 import org.apache.log4j.Category; 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.TestCreator; 59 import org.exolab.jmscts.core.TestContext; 60 61 62 /*** 63 * This class tests the behaviour of republishing a received message, and then 64 * acknowledging it. 65 * 66 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 67 * @version $Revision: 1.3 $ 68 * @see AbstractSendReceiveTestCase 69 * @see org.exolab.jmscts.core.SendReceiveTestRunner 70 * @jmscts.session CLIENT_ACKNOWLEDGE 71 * @jmscts.message StreamMessage 72 * @jmscts.delivery PERSISTENT, administered, synchronous 73 * @jmscts.delivery PERSISTENT, administered, asynchronous 74 * @jmscts.durableonly true 75 */ 76 public class RepublishTest extends AbstractSendReceiveTestCase { 77 78 /*** 79 * The destination that the message listener receives messages on 80 */ 81 private static final String DEST1 = "Republish1"; 82 83 /*** 84 * The destination that the message listeners send messages to 85 */ 86 private static final String DEST2 = "Republish2"; 87 88 /*** 89 * The destinations to create prior to running the test 90 */ 91 private static final String[] DESTINATIONS = {DEST1, DEST2}; 92 93 /*** 94 * The logger 95 */ 96 private static final Category log = 97 Category.getInstance(RepublishTest.class); 98 99 100 /*** 101 * Construct a new <code>RepublishTest</code> 102 * 103 * @param name the name of test case 104 */ 105 public RepublishTest(String name) { 106 super(name); 107 } 108 109 /*** 110 * Sets up the test suite 111 * 112 * @return an instance of this class that may be run by 113 * {@link org.exolab.jmscts.core.JMSTestRunner} 114 */ 115 public static Test suite() { 116 return TestCreator.createSendReceiveTest(RepublishTest.class); 117 } 118 119 /*** 120 * Returns the list of destination names used by this test case. These 121 * are used to pre-create destinations prior to running the test case. 122 * 123 * @return the list of destinations used by this test case 124 */ 125 public String[] getDestinations() { 126 return DESTINATIONS; 127 } 128 129 /*** 130 * Verify the behaviour of republishing a received message, and then 131 * acknowledging it. 132 * 133 * @throws Exception for any error 134 * @jmscts.requirement session.CLIENT_ACKNOWLEDGE 135 */ 136 public void testRepublish() throws Exception { 137 MessageReceiver receiver = null; 138 MessageSender sender1 = null; 139 MessageSender sender2 = null; 140 TestContext context = getContext(); 141 Message message = context.getMessage(); 142 143 try { 144 receiver = createReceiver(DEST1); 145 sender1 = createSender(DEST1); 146 sender2 = createSender(DEST2); 147 148 // send the message to DEST1 149 sender1.send(message, 1); 150 151 // ... and receive it 152 List messages = receive(receiver, 1); 153 Message received = (Message) messages.get(0); 154 155 // republish the message to DEST2 156 sender2.send(received, 1); 157 158 // now acknowledge the received message, and verify it has been 159 // acknowledged by ensuring that it cannot be re-received 160 received.acknowledge(); 161 receiver = recreate(receiver); 162 receive(receiver, 0); 163 } finally { 164 close(receiver); 165 close(sender1); 166 close(sender2); 167 } 168 } 169 170 } 171

This page was automatically generated by Maven