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 2004 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * $Id: ConnectionConsumerTest.java,v 1.2 2004/02/03 21:52:09 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.test.asf; 46 47 import javax.jms.ConnectionConsumer; 48 import javax.jms.Destination; 49 50 import org.apache.log4j.Category; 51 52 import junit.framework.Test; 53 54 import org.exolab.jmscts.core.AbstractSendReceiveTestCase; 55 import org.exolab.jmscts.core.AckType; 56 import org.exolab.jmscts.core.ConnectionHelper; 57 import org.exolab.jmscts.core.CountingListener; 58 import org.exolab.jmscts.core.DestinationHelper; 59 import org.exolab.jmscts.core.MessagingBehaviour; 60 import org.exolab.jmscts.core.TestContext; 61 import org.exolab.jmscts.core.TestCreator; 62 import org.exolab.jmscts.jms.asf.BasicServerSessionPool; 63 64 65 /*** 66 * This class tests the behaviour of <code>ConnectionConsumer</code>s 67 * 68 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 69 * @version $Revision: 1.2 $ 70 * @jmscts.message TextMessage 71 */ 72 public class ConnectionConsumerTest extends AbstractSendReceiveTestCase { 73 74 /*** 75 * The destination to create prior to running the test 76 */ 77 private static final String DESTINATION = "ConnectionConsumerTest"; 78 79 /*** 80 * The logger 81 */ 82 private static final Category log = 83 Category.getInstance(ConnectionConsumerTest.class.getName()); 84 85 /*** 86 * Create a new <code>ConnectionConsumerTest</code>. 87 * 88 * @param name the name of test case 89 */ 90 public ConnectionConsumerTest(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(ConnectionConsumerTest.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 a <code>ConnectionConsumer</code> can be created 116 * 117 * @jmscts.requirement asf.connectionconsumer 118 * @throws Exception for any error 119 */ 120 public void test() throws Exception { 121 final int maxMessages = 1; 122 final int threads = 1; 123 final int count = 10; 124 125 TestContext context = getContext(); 126 AckType type = context.getAckType(); 127 MessagingBehaviour behaviour = context.getMessagingBehaviour(); 128 Destination destination = getDestination(DESTINATION); 129 130 CountingListener listener = new CountingListener(count); 131 BasicServerSessionPool pool = new BasicServerSessionPool( 132 threads, context.getConnection(), type.getTransacted(), 133 type.getAcknowledgeMode(), listener); 134 ConnectionConsumer consumer = null; 135 136 try { 137 consumer = ConnectionHelper.createConnectionConsumer( 138 context, destination, null, null, pool, maxMessages); 139 140 // send messages, and wait for the consumer to receive them 141 send(destination, count); 142 143 listener.waitForCompletion(count * behaviour.getTimeout()); 144 145 if (listener.getReceived() != count) { 146 fail("Expected " + count + " messages from destination=" 147 + DestinationHelper.getName(destination) + " but got " 148 + listener.getReceived()); 149 } 150 151 } finally { 152 if (consumer != null) { 153 consumer.close(); 154 } 155 pool.close(); 156 } 157 158 } 159 160 }

This page was automatically generated by Maven