User: d_jencks Date: 01/09/11 21:55:40 Added: src/main/org/jboss/test/mdb/test MDBUnitTestCase.java Removed: src/main/org/jboss/test/mdb/test Main.java Log: Changed naming scheme of tests to *UnitTestCase.java for short running tests and *StressTestCase.java for lengthy tests. Made tests-unit and tests-stress targets in build.xml Revision Changes Path 1.1 jbosstest/src/main/org/jboss/test/mdb/test/MDBUnitTestCase.java Index: MDBUnitTestCase.java =================================================================== /* * Copyright (c) 2000 Peter Antman Tim <[EMAIL PROTECTED]> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.jboss.test.mdb.test; import javax.naming.*; import javax.jms.*; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.jboss.test.mdb.bean.CustomMessage; import org.jboss.test.util.Deploy; //import org.jboss.jms.jndi.*; /** * Some simple tests of MDB. These could be much more aloborated. * * In the future at least the following tests should be done some how: * <ol> * <li>Queue * <li>Topic * <li>Durable topic * <li>Bean TX - with AUTO_ACK and DUPS_OK * <li>CMT Required * <li>CMT NotSupported * <li>Selector * <li>User and password login * <li>Al the stuff with the context * </ol> * * <p>Created: Fri Dec 29 16:53:26 2000 * * @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a> * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a> * @version <pre>$Revision: 1.1 $</pre> */ public class MDBUnitTestCase extends TestCase { // Static -------------------------------------------------------- static boolean deployed = false; // Provider specific static String TOPIC_FACTORY = "ConnectionFactory"; static String QUEUE_FACTORY = "ConnectionFactory"; QueueConnection queueConnection; TopicConnection topicConnection; // JMSProviderAdapter providerAdapter; Context context; String dest; public MDBUnitTestCase(String name, String dest) { super(name); this.dest = dest; // Get JMS JNDI Adapter // Class cls = Class.forName(providerAdapterClass); // providerAdapter = (JMSProviderAdapter)cls.newInstance(); // This is not completly clean since it still have to use // provider specific queue and topic names!! } protected void setUp() throws Exception { // test methods call getXXXSession() to create session & connection context = new InitialContext(); } protected void tearDown() throws Exception { if (topicConnection != null) { topicConnection.close(); } if (queueConnection != null) { queueConnection.close(); } } protected void printHeader() { System.out.println("\n---- Testing method " + getName() + " for destination " +dest); } private QueueSession getQueueSession() throws Exception { if (queueConnection == null) { QueueConnectionFactory queueFactory = (QueueConnectionFactory)context.lookup(QUEUE_FACTORY); queueConnection = queueFactory.createQueueConnection(); } return queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); } private TopicSession getTopicSession() throws Exception { if (topicConnection == null) { TopicConnectionFactory topicFactory = (TopicConnectionFactory)context.lookup(TOPIC_FACTORY); topicConnection = topicFactory.createTopicConnection(); } // No transaction & auto ack return topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); } /** * Test sending messages to Topic testTopic */ public void testQueue() throws Exception { printHeader(); QueueSession session = getQueueSession(); Queue queue = (Queue)context.lookup(dest); QueueSender sender = session.createSender(queue); System.out.println("TestQueue: " + dest + " Sending 10 messages 1-10"); for (int i = 1; i < 11; i++) { TextMessage message = session.createTextMessage(); message.setText("Queue Message " + dest + " nr " + i); sender.send(queue, message); } sender.close(); } /** * Test sending messages to Queue testQueue */ public void testTopic() throws Exception { printHeader(); TopicSession session = getTopicSession(); Topic topic = (Topic)context.lookup(dest); TopicPublisher pub = session.createPublisher(topic); System.out.println("TestTopic: " + dest + ": Sending 10st messages 1-10"); for (int i = 1; i < 11; i++) { TextMessage message = session.createTextMessage(); message.setText("Topic Message " + dest + " nr " + i); pub.publish(topic, message); } pub.close(); } /** * Test sending messages to queue testObjectMessage */ public void testObjectMessage() throws Exception { printHeader(); QueueSession session = getQueueSession(); // Non portable!! Queue queue = (Queue)context.lookup("queue/testObjectMessage"); QueueSender sender = session.createSender(queue); System.out.println("TestQueue: Sending 10 messages 1-10"); for (int i = 1; i < 11; i++) { ObjectMessage message = session.createObjectMessage(); message.setObject(new CustomMessage(i)); sender.send(queue, message); } sender.close(); session.close(); } /** * Setup the test suite. */ public static Test suite() { TestSuite suite = new TestSuite(); // add a test case to deploy our support applications String filename = "mdb.jar"; suite.addTest(new Deploy.Deployer(filename)); suite.addTest(new MDBUnitTestCase("testObjectMessage","")); suite.addTest(new MDBUnitTestCase("testQueue","queue/testQueue")); suite.addTest(new MDBUnitTestCase("testTopic","topic/testTopic")); suite.addTest(new MDBUnitTestCase("testTopic","topic/testDurableTopic")); suite.addTest(new MDBUnitTestCase("testQueue","queue/ex")); // add a test case to undeploy our support applications suite.addTest(new Deploy.Undeployer(filename)); return suite; } } _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
