User: user57
Date: 01/07/03 18:27:34
Modified: src/main/org/jboss/test/jmsra/test AllJUnitTests.java
RaTest.java
Added: src/main/org/jboss/test/jmsra/test RaQueueTest.java
RaTopicTest.java
Log:
o Beginning to fix the JMS RA test suite. This should run with-out any
errors, but there is still something odd about it, I think it has something
todo with the topic testing. Will look into that more tomorrow.
Revision Changes Path
1.2 +25 -38 jbosstest/src/main/org/jboss/test/jmsra/test/AllJUnitTests.java
Index: AllJUnitTests.java
===================================================================
RCS file:
/cvsroot/jboss/jbosstest/src/main/org/jboss/test/jmsra/test/AllJUnitTests.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AllJUnitTests.java 2001/05/06 01:13:18 1.1
+++ AllJUnitTests.java 2001/07/04 01:27:34 1.2
@@ -24,51 +24,38 @@
import org.jboss.test.util.Deploy;
/**
- * TestSuite.java
+ * TestSuite for JMS Resource Adapter.
*
+ * <p>Created: Mon Apr 23 22:08:13 2001
*
- * Created: Mon Apr 23 22:08:13 2001
- *
- * @author
- * @version
+ * @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
+ * @version $Revision: 1.2 $
*/
-
-public class AllJUnitTests extends TestCase{
-
- public AllJUnitTests(String name) {
- super(name);
+public class AllJUnitTests
+ extends TestCase
+{
+ public AllJUnitTests(final String name) {
+ super(name);
}
-
- public static Test suite ()
- {
- TestSuite suite = new TestSuite();
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
- try{
- System.out.println("Deploying");
- Deploy.deploy("../deploy/jmsra.jar");
-
- System.out.println("Testing Queue publishing");
- suite.addTest(new RaTest("testSimple", "TxPublisher"));
- suite.addTest(new RaTest("testSimpleFail", "TxPublisher"));
- suite.addTest(new RaTest("testBeanOk", "TxPublisher"));
- suite.addTest(new RaTest("testBeanError", "TxPublisher"));
+ try {
+ System.out.println("Deploying...");
+ Deploy.deploy("../deploy/jmsra.jar");
+ System.out.println("Deployed");
- System.out.println("Testing topic publishing");
- suite.addTest(new RaTest("testSimple", "TxTopicPublisher"));
- suite.addTest(new RaTest("testSimpleFail", "TxTopicPublisher"));
- suite.addTest(new RaTest("testBeanOk", "TxTopicPublisher"));
- suite.addTest(new RaTest("testBeanError", "TxTopicPublisher"));
- } catch (Exception ex) {
- ex.printStackTrace();
- System.exit(0);
-
- }
- return suite;
- }
-
- public static void main(String[] args) {
-
+ suite.addTest(new TestSuite(RaQueueTest.class));
+ suite.addTest(new TestSuite(RaTopicTest.class));
+ }
+ catch (Throwable t) {
+ t.printStackTrace(System.err);
+ System.exit(0);
+ }
+
+ return suite;
}
} // TestSuite
1.3 +104 -68 jbosstest/src/main/org/jboss/test/jmsra/test/RaTest.java
Index: RaTest.java
===================================================================
RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/jmsra/test/RaTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RaTest.java 2001/05/20 12:29:11 1.2
+++ RaTest.java 2001/07/04 01:27:34 1.3
@@ -17,88 +17,133 @@
*/
package org.jboss.test.jmsra.test;
-import org.jboss.test.jmsra.bean.*;
-
-import javax.jms.*;
-
import javax.naming.InitialContext;
import javax.naming.Context;
+import javax.jms.MessageConsumer;
+import javax.jms.Message;
+import javax.jms.Connection;
+import javax.jms.Session;
+
+import junit.framework.TestCase;
+
+import org.jboss.test.jmsra.bean.*;
+
/**
- * RaTest.java
- *
+ * Abstract test cases for JMS Resource Adapter.
*
- * Created: Mon Apr 23 21:35:25 2001
+ * <p>Created: Mon Apr 23 21:35:25 2001
*
- * @author
- * @version
+ * @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
+ * @version $Revision: 1.3 $
*/
-
-public class RaTest extends junit.framework.TestCase implements MessageListener
+public abstract class RaTest
+ extends TestCase
{
- private String QUEUE_FACTORY = "QueueConnectionFactory";
- private String QUEUE = "queue/testQueue";
-
- private String beanJNDI;
- private QueueConnection queueConnection;
- private QueueSession queueSession;
- private QueueReceiver queueReceiver;
- private Queue queue;
- private Publisher publisher;
- private String n;
-
- public RaTest(String name, String beanJNDI) throws Exception {
+ public static final long DEFAULT_TIMEOUT = 5000L;
+ public static final long FLUSH_TIMEOUT = 1500L;
+
+ protected String beanJNDI;
+ protected MessageConsumer consumer;
+ protected Publisher publisher;
+ protected Connection connection;
+ protected Session session;
+
+ protected RaTest(final String name, final String beanJNDI)
+ throws Exception
+ {
super(name);
- n = name;
this.beanJNDI = beanJNDI;
}
+ protected abstract void init(final Context context) throws Exception;
+
+ protected void setUp() throws Exception {
+ // Create a publisher
+ Context context = new InitialContext();
+ try {
+ PublisherHome home = (PublisherHome)context.lookup(beanJNDI);
+ publisher = home.create();
+
+ init(context);
+ }
+ finally {
+ context.close();
+ }
+
+ // start up the session
+ connection.start();
+
+ // flush the destination
+ flush();
+ }
+
+ protected void tearDown() throws Exception {
+ if (consumer != null) {
+ consumer.close();
+ }
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
protected void printHeader() {
- System.out.println("\n---- Testing method " + n +
+ System.out.println("\n---- Testing method " + name() +
" for bean " + beanJNDI);
}
protected void printOK() {
- System.out.println("Test OK\n----");
+ System.out.println("---- Test OK\n");
}
-
- protected void setUp() throws Exception {
- // Get publisher
- Context context = new InitialContext();
- PublisherHome publisherH = (PublisherHome)context.lookup(beanJNDI);
- publisher = publisherH.create();
-
- QueueConnectionFactory factory = (QueueConnectionFactory)
- context.lookup(QUEUE_FACTORY);
- queueConnection = factory.createQueueConnection();
- queueSession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
- queue = (Queue)context.lookup(QUEUE);
- queueReceiver = queueSession.createReceiver(queue);
- //queueSession.setMessageListener(this);
- queueConnection.start();
+
+ /**
+ * Check if we got a message.
+ *
+ * @return Publisher.JMS_MESSAGE_NR int property or -1 if no message
+ * was received.
+ */
+ protected int getJmsMessage() throws Exception {
+ return getJmsMessage(DEFAULT_TIMEOUT);
}
+
/**
- * Check if we got a message
+ * Check if we got a message.
+ *
+ * @param timeout The time to wait for a message.
+ *
+ * @return Publisher.JMS_MESSAGE_NR int property or -1 if no message
+ * was received.
*/
- private int getJmsMessage() throws Exception {
- Message m = queueReceiver.receive(5000L);
- if (m != null)
- {
- System.out.println("Recived message");
- return m.getIntProperty(Publisher.JMS_MESSAGE_NR);
- } else
- {
+ protected int getJmsMessage(long timeout) throws Exception {
+ Message msg = consumer.receive(timeout);
+ if (msg != null) {
+ System.out.println("Recived message: " + msg);
+ int nr = msg.getIntProperty(Publisher.JMS_MESSAGE_NR);
+ System.out.println("nr: " + nr);
+ return nr;
+ }
+ else {
System.out.println("NO message recived");
return -1;
}
}
-
+
+ protected void flush() throws Exception {
+ System.out.println("---- Flushing Destination");
+ int nr;
+ while ((nr = getJmsMessage(FLUSH_TIMEOUT)) != -1) {
+ System.out.println("ignoring message on queue with nr: " + nr);
+ }
+ System.out.println("---- Flushed");
+ }
+
public void testSimple() throws Exception {
printHeader();
System.out.println("Verify simple send of message");
publisher.simple(1);
- assert(1 == getJmsMessage() );
+ assert(1 == getJmsMessage());
printOK();
}
@@ -107,7 +152,7 @@
System.out.println("Verify simple failed transaction");
publisher.simpleFail(2);
- assert(-1 == getJmsMessage() );
+ assert(-1 == getJmsMessage());
printOK();
}
@@ -116,29 +161,20 @@
System.out.println("Verify bean ok");
publisher.beanOk(3);
- assert(3 == getJmsMessage() );
+ assert(3 == getJmsMessage());
printOK();
}
public void testBeanError() throws Exception {
printHeader();
System.out.println("Verify bean eroor failed transaction");
- try
- {
+
+ try {
publisher.beanError(4);
- } catch (Exception ex)
- {
}
+ catch (Exception ignore) {}
- assert(-1 == getJmsMessage() );
+ assert(-1 == getJmsMessage());
printOK();
- }
- public void onMessage(Message message) {
- System.out.println("Got message");
}
-
- public static void main(String[] args) {
-
- }
-
-} // RaTest
+}
1.1 jbosstest/src/main/org/jboss/test/jmsra/test/RaQueueTest.java
Index: RaQueueTest.java
===================================================================
/*
* Copyright (c) 2001 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.jmsra.test;
import javax.naming.Context;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueConnection;
import javax.jms.QueueSession;
import javax.jms.Queue;
import javax.jms.MessageConsumer;
import javax.jms.Session;
/**
* Test cases for JMS Resource Adapter use a <em>Queue</em>.
*
* <p>Created: Mon Apr 23 21:35:25 2001
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
* @version $Revision: 1.1 $
*/
public class RaQueueTest
extends RaTest
{
private static final String QUEUE_FACTORY = "QueueConnectionFactory";
private static final String QUEUE = "queue/testQueue";
private static final String JNDI = "TxPublisher";
public RaQueueTest(String name) throws Exception {
super(name, JNDI);
}
protected void init(final Context context) throws Exception {
QueueConnectionFactory factory =
(QueueConnectionFactory)context.lookup(QUEUE_FACTORY);
connection = factory.createQueueConnection();
session = ((QueueConnection)connection).createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue)context.lookup(QUEUE);
consumer = ((QueueSession)session).createReceiver(queue);
}
}
1.1 jbosstest/src/main/org/jboss/test/jmsra/test/RaTopicTest.java
Index: RaTopicTest.java
===================================================================
/*
* Copyright (c) 2001 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.jmsra.test;
import javax.naming.Context;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicConnection;
import javax.jms.TopicSession;
import javax.jms.Topic;
import javax.jms.MessageConsumer;
import javax.jms.Session;
/**
* Test cases for JMS Resource Adapter using a <em>Topic</em>.
*
* <p>Created: Mon Apr 23 21:35:25 2001
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Antman</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
* @version $Revision: 1.1 $
*/
public class RaTopicTest
extends RaTest
{
private static final String TOPIC_FACTORY = "TopicConnectionFactory";
private static final String TOPIC = "topic/testTopic";
private static final String JNDI = "TxTopicPublisher";
public RaTopicTest(String name) throws Exception {
super(name, JNDI);
}
protected void init(final Context context) throws Exception {
TopicConnectionFactory factory =
(TopicConnectionFactory)context.lookup(TOPIC_FACTORY);
connection = factory.createTopicConnection();
session = ((TopicConnection)connection).createTopicSession(false,
Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic)context.lookup(TOPIC);
consumer = ((TopicSession)session).createSubscriber(topic);
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development