User: pra
Date: 00/12/29 12:57:36
Added: src/main/org/jboss/test/mdb/test Main.java
Log:
Added test for MDB. OBS - this test does currently NOT work since it tests for
durableTopic and that does currently not work. Wich is a good thing to know
Revision Changes Path
1.1 jbosstest/src/main/org/jboss/test/mdb/test/Main.java
Index: Main.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 org.jboss.jms.jndi.*;
/**
* Main.java
*
* Some simple tests of MDB. These could be much more aloborated.
*
* In the future at least the following tests should be done some how
1. Queue
2. Topic
3. Durable topic
4. Bean TX - with AUTO_ACK and DUPS_OK
5. CMT Required
6. CMT NotSupported
7. Selector
8. User and password login
9. Al the stuff with the context
* Created: Fri Dec 29 16:53:26 2000
*
* @author
* @version
*/
public class Main extends junit.framework.TestCase {
// Static --------------------------------------------------------
static boolean deployed = false;
// Provider specific
static String TOPIC_FACTORY = "TopicConnectionFactory";
static String QUEUE_FACTORY ="QueueConnectionFactory";
//JMSProviderAdapter providerAdapter;
Context context;
public Main(String name) throws Exception{
super(name);
//Get JMS JNDI Adapter
//Class cls = Class.forName(providerAdapterClass);
//providerAdapter = (JMSProviderAdapter)cls.newInstance();
context = new InitialContext();
// This is not completly clean since it still have to use
// provider specific queue and topic names!!
}
/**
* Test sending messages to Topic testTopic
*/
public void testQueue()
throws Exception {
QueueSession session = getQueueSession();
// Non portable!!
Queue queue = (Queue)context.lookup("queue/testQueue");
QueueSender sender = session.createSender(queue);
System.out.println("TestQueue: Sending 10 messages 1-10");
for (int i = 1; i < 11; i++) {
TextMessage message = session.createTextMessage();
message.setText("Queue Message nr " + i);
sender.send(queue, message);
}
}
/**
* Test sending messages to Queue testQueue
*/
public void testTopic(String name) throws Exception {
TopicSession session = getTopicSession();
// Non portable!!
Topic topic = (Topic)context.lookup(name);
TopicPublisher pub = session.createPublisher(topic);
System.out.println("TestTopic: " + name + ": Sending 10st messages 1-10");
for (int i = 1; i < 11; i++) {
TextMessage message = session.createTextMessage();
message.setText("Topic Message " + name + " nr " + i);
pub.publish(topic, message);
}
}
private QueueSession getQueueSession() throws Exception {
QueueConnectionFactory queueFactory =
(QueueConnectionFactory)context.lookup(QUEUE_FACTORY);
QueueConnection queueConnection = queueFactory.createQueueConnection();
return queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
}
private TopicSession getTopicSession() throws Exception{
TopicConnectionFactory topicFactory =
(TopicConnectionFactory)context.lookup(TOPIC_FACTORY);
TopicConnection topicConnection = topicFactory.createTopicConnection();
return topicConnection.createTopicSession(
// No transaction
false,
// Auto ack
Session.AUTO_ACKNOWLEDGE);
}
protected void setUp()
throws Exception {
if (deployed) return;
System.out.println("Deploying");
new org.jboss.jmx.client.Deployer().deploy("../deploy/mdb.jar");
deployed = true;
}
public static void main(String arg[]) {
Main main = null;
try {
main = new Main("MDBTest");
main.setUp();
main.testQueue();
main.testTopic("topic/testTopic");
main.testTopic("topic/testDurableTopic");
} catch (Exception e) {
e.printStackTrace();
System.out.println();
System.out.println("_____________________________________________");
System.out.println("Sorry, test failed.");
}
}
} // Main