[jboss-cvs] joramtests/src/main/java/org/objectweb/jtests/jms/conform/session ...
Scott Stark
scott.stark at jboss.com
Thu Mar 29 00:28:37 EDT 2007
User: starksm
Date: 07/03/29 00:28:37
Added: src/main/java/org/objectweb/jtests/jms/conform/session
SessionTest.java UnifiedSessionTest.java
TopicSessionTest.java QueueSessionTest.java
package.html
Log:
+ covert to mvn
+ Drop the poor properties file setup logic and require that the properties be passed in
Revision Changes Path
1.1 date: 2007/03/29 04:28:37; author: starksm; state: Exp;joramtests/src/main/java/org/objectweb/jtests/jms/conform/session/SessionTest.java
Index: SessionTest.java
===================================================================
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2002 INRIA
* Contact: joram-team at objectweb.org
*
* 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.1 of the License, or 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
*
* Initial developer(s): Jeff Mesnil (jmesnil at inrialpes.fr)
* Contributor(s): ______________________________________.
*/
package org.objectweb.jtests.jms.conform.session;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.objectweb.jtests.jms.framework.PTPTestCase;
import org.objectweb.jtests.jms.framework.TestConfig;
/**
* Test sessions
* <br />
* See JMS specifications, §4.4 Session
*
* @author Jeff Mesnil (jmesnil at inrialpes.fr)
* @version $Id: SessionTest.java,v 1.1 2007/03/29 04:28:37 starksm Exp $
*/
public class SessionTest extends PTPTestCase
{
/**
* Test that an attempt to call the <code>recover()</code> method on a
* <strong>transacted </strong> <code>Session</code> throws a
* <code>javax.jms.IllegalStateException</code>.
*/
public void testRecoverTransactedSession()
{
try
{
// senderSession has been created as non transacted
assertEquals(false, senderSession.getTransacted());
// we create it again but as a transacted session
senderSession = senderConnection.createQueueSession(true, 0);
assertEquals(true, senderSession.getTransacted());
senderSession.recover();
fail("Should raise an IllegalStateException, the session is not transacted.\n");
}
catch (javax.jms.IllegalStateException e)
{
}
catch (java.lang.IllegalStateException e)
{
fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException.\n");
}
catch (Exception e)
{
fail("Should raise a javax.jms.IllegalStateException, not a " + e);
}
}
/**
* Test that a call to the <code>rollback()</code> method on a
* <strong>transacted</strong> <code>Session</code> rollbacks all
* the messages sent in the transaction.
*/
public void testRollbackTransactedSession()
{
try
{
// re-create senderSession as a transacted session
senderSession = senderConnection.createQueueSession(true, 0);
sender = senderSession.createSender(senderQueue);
assertEquals(true, senderSession.getTransacted());
TextMessage message = senderSession.createTextMessage();
message.setText("testRollbackTransactedSession");
// send a message within a transacted session
sender.send(message);
// rollback the transaction -> the sent message shouldn't be received
senderSession.rollback();
TextMessage m = (TextMessage) receiver.receiveNoWait();
// test that no message has been received
assertEquals(null, m);
}
catch (Exception e)
{
fail(e);
}
}
/**
* Test that a call to the <code>rollback()</code> method on a
* <strong>transacted</strong> <code>Session</code> rollbacks all
* the messages sent in the transaction.
*/
public void testCommitTransactedSession()
{
try
{
// re-create senderSession as a transacted session
senderSession = senderConnection.createQueueSession(true, 0);
sender = senderSession.createSender(senderQueue);
assertEquals(true, senderSession.getTransacted());
TextMessage message = senderSession.createTextMessage();
message.setText("testCommitTransactedSession");
// send a message within a transacted session
sender.send(message);
TextMessage m = (TextMessage) receiver.receiveNoWait();
// test that no message has been received (the transaction has not been committed yet)
assertEquals(null, m);
// commit the transaction -> the sent message should be received
senderSession.commit();
m = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
assertTrue(m != null);
assertEquals("testCommitTransactedSession", m.getText());
}
catch (Exception e)
{
fail(e);
}
}
/**
* Test that an attempt to call the <code>roolback()</code> method on a
* <strong>non transacted</strong> <code>Session</code> throws a
* <code>javax.jms.IllegalStateException</code>.
*/
public void testRollbackNonTransactedSession()
{
try
{
// senderSession has been created as non transacted in the setUp() method
assertEquals(false, senderSession.getTransacted());
senderSession.rollback();
fail("Should raise an IllegalStateException, the session is not transacted.\n");
}
catch (javax.jms.IllegalStateException e)
{
}
catch (java.lang.IllegalStateException e)
{
fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException.\n");
}
catch (Exception e)
{
fail("Should raise a javax.jms.IllegalStateException, not a " + e);
}
}
/**
* Test that an attempt to call the <code>commit()</code> method on a
* <strong>non transacted</strong> <code>Session</code> throws a
* <code>javax.jms.IllegalStateException</code>.
*/
public void testCommitNonTransactedSession()
{
try
{
// senderSession has been created as non transacted in the setUp() method
assertEquals(false, senderSession.getTransacted());
senderSession.commit();
fail("Should raise an IllegalStateException, the session is not transacted.\n");
}
catch (javax.jms.IllegalStateException e)
{
}
catch (java.lang.IllegalStateException e)
{
fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException.\n");
}
catch (Exception e)
{
fail("Should raise a javax.jms.IllegalStateException, not a " + e);
}
}
/**
* Test that the <code>getTransacted()</code> method of a <code>Session</code> returns <code>true</code>
* if the session is transacted, <code>false</code> else.
*/
public void testGetTransacted()
{
try
{
// senderSession has been created as non transacted
assertEquals(false, senderSession.getTransacted());
// we re-create senderSession as a transacted session
senderSession = senderConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
assertEquals(true, senderSession.getTransacted());
}
catch (Exception e)
{
fail(e);
}
}
/**
* Test that invoking the <code>acknowledge()</code> method of a received message
* from a closed session must throw an <code>IllegalStateException</code>.
*/
public void testAcknowledge()
{
try
{
receiverSession = receiverConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
receiver = receiverSession.createReceiver(receiverQueue);
Message message = senderSession.createMessage();
sender.send(message);
Message m = receiver.receive(TestConfig.TIMEOUT);
receiverSession.close();
m.acknowledge();
fail("§4.4.1 Invoking the acknowledge method of a received message from a closed "
+ " session must throw an [javax.jms.]IllegalStateException.\n");
}
catch (javax.jms.IllegalStateException e)
{
}
catch (JMSException e)
{
fail("Should raise a javax.jms.IllegalStateException, not a " + e);
}
catch (java.lang.IllegalStateException e)
{
fail("§4.4.1 Invoking the acknowledge method of a received message from a closed "
+ "session must throw an [javax.jms.]IllegalStateException, "
+ "[not a java.lang.IllegalStateException]");
}
}
/**
* Test that it is valid to use message objects created or received via the [closed] session with the
* exception of a received message <code>acknowledge()</code> method.
*/
public void testUseMessage()
{
try
{
TextMessage message = senderSession.createTextMessage();
message.setText("testUseMessage");
sender.send(message);
TextMessage m = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
receiverSession.close();
assertEquals("testUseMessage", m.getText());
}
catch (Exception e)
{
fail("§4.4.1 It is valid to continue to use message objects created or received via "
+ "the [closed] session.\n");
}
}
/**
* Test that an attempt to use a <code>Session</code> which has been closed
* throws a <code>javax.jms.IllegalStateException</code>.
*/
public void testUsedClosedSession()
{
try
{
senderSession.close();
senderSession.createMessage();
fail("§4.4.1 An attempt to use [a closed session] must throw a [javax.jms.]IllegalStateException.\n");
}
catch (javax.jms.IllegalStateException e)
{
}
catch (JMSException e)
{
fail("Should raise a javax.jms.IllegalStateException, not a " + e);
}
catch (java.lang.IllegalStateException e)
{
fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException");
}
}
/**
* Test that closing a closed session does <strong>not</strong> throw
* an exception.
*/
public void testCloseClosedSession()
{
try
{
// senderSession is already started
// we close it once
senderSession.close();
// we close it a second time
senderSession.close();
}
catch (Exception e)
{
fail("§4.4.1 Closing a closed session must NOT throw an exception.\n");
}
}
/**
* Method to use this class in a Test suite
*/
public static Test suite()
{
return new TestSuite(SessionTest.class);
}
public SessionTest(String name)
{
super(name);
}
}
1.1 date: 2007/03/29 04:28:37; author: starksm; state: Exp;joramtests/src/main/java/org/objectweb/jtests/jms/conform/session/UnifiedSessionTest.java
Index: UnifiedSessionTest.java
===================================================================
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2002 INRIA
* Contact: joram-team at objectweb.org
*
* 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.1 of the License, or 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
*
* Initial developer(s): Jeff Mesnil (jmesnil at inrialpes.fr)
* Contributor(s): ______________________________________.
*/
package org.objectweb.jtests.jms.conform.session;
import javax.jms.JMSException;
import javax.jms.QueueConnection;
import javax.jms.QueueSession;
import javax.jms.ServerSessionPool;
import javax.jms.Session;
import javax.jms.TopicConnection;
import javax.jms.TopicSession;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jboss.util.NestedRuntimeException;
import org.objectweb.jtests.jms.framework.UnifiedTestCase;
/**
* Test unified JMS 1.1 sessions.
* <br />
* See JMS 1.1 specifications
*
* @author Jeff Mesnil (jmesnil at inrialpes.fr)
* @version $Id: UnifiedSessionTest.java,v 1.1 2007/03/29 04:28:37 starksm Exp $
* @since JMS 1.1
*/
public class UnifiedSessionTest extends UnifiedTestCase
{
/**
* QueueConnection
*/
protected QueueConnection queueConnection;
/**
* QueueSession (non transacted, AUTO_ACKNOWLEDGE)
*/
protected QueueSession queueSession;
/**
* TopicConnection
*/
protected TopicConnection topicConnection;
/**
* TopicSession (non transacted, AUTO_ACKNOWLEDGE)
*/
protected TopicSession topicSession;
/**
* Test that a call to <code>createDurableConnectionConsumer()</code> method
* on a <code>QueueConnection</code> throws a
* <code>javax.jms.IllegalStateException</code>.
* (see JMS 1.1 specs, table 4-1).
*
* @since JMS 1.1
*/
public void testCreateDurableConnectionConsumerOnQueueConnection()
{
try
{
queueConnection.createDurableConnectionConsumer(topic, "subscriptionName", "", (ServerSessionPool) null, 1);
fail("Should throw a javax.jms.IllegalStateException");
}
catch (javax.jms.IllegalStateException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.IllegalStateException, not a " + e);
}
}
/**
* Test that a call to <code>createDurableSubscriber()</code> method
* on a <code>QueueSession</code> throws a
* <code>javax.jms.IllegalStateException</code>.
* (see JMS 1.1 specs, table 4-1).
*
* @since JMS 1.1
*/
public void testCreateDurableSubscriberOnQueueSession()
{
try
{
queueSession.createDurableSubscriber(topic, "subscriptionName");
fail("Should throw a javax.jms.IllegalStateException");
}
catch (javax.jms.IllegalStateException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.IllegalStateException, not a " + e);
}
}
/**
* Test that a call to <code>createTemporaryTopic()</code> method
* on a <code>QueueSession</code> throws a
* <code>javax.jms.IllegalStateException</code>.
* (see JMS 1.1 specs, table 4-1).
*
* @since JMS 1.1
*/
public void testCreateTemporaryTopicOnQueueSession()
{
try
{
queueSession.createTemporaryTopic();
fail("Should throw a javax.jms.IllegalStateException");
}
catch (javax.jms.IllegalStateException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.IllegalStateException, not a " + e);
}
}
/**
* Test that a call to <code>createTopic()</code> method
* on a <code>QueueSession</code> throws a
* <code>javax.jms.IllegalStateException</code>.
* (see JMS 1.1 specs, table 4-1).
*
* @since JMS 1.1
*/
public void testCreateTopicOnQueueSession()
{
try
{
queueSession.createTopic("topic_name");
fail("Should throw a javax.jms.IllegalStateException");
}
catch (javax.jms.IllegalStateException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.IllegalStateException, not a " + e);
}
}
/**
* Test that a call to <code>unsubscribe()</code> method
* on a <code>QueueSession</code> throws a
* <code>javax.jms.IllegalStateException</code>.
* (see JMS 1.1 specs, table 4-1).
*
* @since JMS 1.1
*/
public void testUnsubscribeOnQueueSession()
{
try
{
queueSession.unsubscribe("subscriptionName");
fail("Should throw a javax.jms.IllegalStateException");
}
catch (javax.jms.IllegalStateException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.IllegalStateException, not a " + e);
}
}
/**
* Test that a call to <code>createBrowser()</code> method
* on a <code>TopicSession</code> throws a
* <code>javax.jms.IllegalStateException</code>.
* (see JMS 1.1 specs, table 4-1).
*
* @since JMS 1.1
*/
public void testCreateBrowserOnTopicSession()
{
try
{
topicSession.createBrowser(queue);
fail("Should throw a javax.jms.IllegalStateException");
}
catch (javax.jms.IllegalStateException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.IllegalStateException, not a " + e);
}
}
/**
* Test that a call to <code>createQueue()</code> method
* on a <code>TopicSession</code> throws a
* <code>javax.jms.IllegalStateException</code>.
* (see JMS 1.1 specs, table 4-1).
*
* @since JMS 1.1
*/
public void testCreateQueueOnTopicSession()
{
try
{
topicSession.createQueue("queue_name");
fail("Should throw a javax.jms.IllegalStateException");
}
catch (javax.jms.IllegalStateException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.IllegalStateException, not a " + e);
}
}
/**
* Test that a call to <code>createTemporaryQueue()</code> method
* on a <code>TopicSession</code> throws a
* <code>javax.jms.IllegalStateException</code>.
* (see JMS 1.1 specs, table 4-1).
*
* @since JMS 1.1
*/
public void testCreateTemporaryQueueOnTopicSession()
{
try
{
topicSession.createTemporaryQueue();
fail("Should throw a javax.jms.IllegalStateException");
}
catch (javax.jms.IllegalStateException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.IllegalStateException, not a " + e);
}
}
public void setUp()
{
super.setUp();
try
{
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
topicConnection = topicConnectionFactory.createTopicConnection();
topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
queueConnection.start();
topicConnection.start();
}
catch (Exception e)
{
throw new NestedRuntimeException(e);
}
}
public void tearDown()
{
try
{
queueConnection.close();
topicConnection.close();
}
catch (Exception ignored)
{
}
finally
{
queueConnection = null;
queueSession = null;
topicConnection = null;
topicSession = null;
super.tearDown();
}
}
/**
* Method to use this class in a Test suite
*/
public static Test suite()
{
return new TestSuite(UnifiedSessionTest.class);
}
public UnifiedSessionTest(String name)
{
super(name);
}
}
1.1 date: 2007/03/29 04:28:37; author: starksm; state: Exp;joramtests/src/main/java/org/objectweb/jtests/jms/conform/session/TopicSessionTest.java
Index: TopicSessionTest.java
===================================================================
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2002 INRIA
* Contact: joram-team at objectweb.org
*
* 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.1 of the License, or 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
*
* Initial developer(s): Jeff Mesnil (jmesnil at inrialpes.fr)
* Contributor(s): Andreas Mueller <am at iit.de>.
*/
package org.objectweb.jtests.jms.conform.session;
import javax.jms.InvalidDestinationException;
import javax.jms.InvalidSelectorException;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.objectweb.jtests.jms.framework.PubSubTestCase;
import org.objectweb.jtests.jms.framework.TestConfig;
/**
* Test topic sessions
* <br />
* See JMS specifications, §4.4 Session
*
* @author Jeff Mesnil (jmesnil at inrialpes.fr)
* @version $Id: TopicSessionTest.java,v 1.1 2007/03/29 04:28:37 starksm Exp $
*/
public class TopicSessionTest extends PubSubTestCase
{
/**
* Test that if we rollback a transaction which has consumed a message,
* the message is effectively redelivered.
*/
public void testRollbackReceivedMessage()
{
try
{
publisherConnection.stop();
// publisherSession has been declared has non transacted
// we recreate it as a transacted session
publisherSession = publisherConnection.createTopicSession(true, 0);
assertEquals(true, publisherSession.getTransacted());
// we also recreate the publisher
publisher = publisherSession.createPublisher(publisherTopic);
publisherConnection.start();
subscriberConnection.stop();
// subscriberSession has been declared has non transacted
// we recreate it as a transacted session
subscriberSession = subscriberConnection.createTopicSession(true, 0);
assertEquals(true, subscriberSession.getTransacted());
// we also recreate the subscriber
subscriber = subscriberSession.createSubscriber(subscriberTopic);
subscriberConnection.start();
// we create a message...
TextMessage message = publisherSession.createTextMessage();
message.setText("testRollbackReceivedMessage");
// ... publish it ...
publisher.publish(message);
// ... and commit the transaction
publisherSession.commit();
// we receive it
Message msg1 = subscriber.receive(TestConfig.TIMEOUT);
assertTrue("no message received", msg1 != null);
assertTrue(msg1 instanceof TextMessage);
assertEquals("testRollbackReceivedMessage", ((TextMessage) msg1).getText());
// we rollback the transaction of subscriberSession
subscriberSession.rollback();
// we expect to receive a second time the message
Message msg2 = subscriber.receive(TestConfig.TIMEOUT);
assertTrue("no message received after rollbacking subscriber session.", msg2 != null);
assertTrue(msg2 instanceof TextMessage);
assertEquals("testRollbackReceivedMessage", ((TextMessage) msg2).getText());
// finally we commit the subscriberSession transaction
subscriberSession.commit();
}
catch (Exception e)
{
fail(e);
}
}
/**
* Test that a durable subscriber effectively receives the messages sent to its
* topic while it was inactive.
*/
public void testDurableSubscriber()
{
try
{
subscriber = subscriberSession.createDurableSubscriber(subscriberTopic, "testTopic");
subscriberConnection.close();
subscriberConnection = null;
TextMessage message = publisherSession.createTextMessage();
message.setText("test");
publisher.publish(message);
subscriberConnection = subscriberTCF.createTopicConnection();
if (subscriberConnection.getClientID() == null)
{
subscriberConnection.setClientID("subscriberConnection");
}
subscriberSession = subscriberConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
subscriber = subscriberSession.createDurableSubscriber(subscriberTopic, "testTopic");
subscriberConnection.start();
TextMessage m = (TextMessage) subscriber.receive(TestConfig.TIMEOUT);
assertTrue(m != null);
assertEquals("test", m.getText());
}
catch (JMSException e)
{
fail(e);
}
}
/**
* Test the unsubscription of a durable subscriber.
*/
public void testUnsubscribe()
{
try
{
subscriber = subscriberSession.createDurableSubscriber(subscriberTopic, "topic");
subscriber.close();
// nothing should happen when unsubscribing the durable subscriber
subscriberSession.unsubscribe("topic");
}
catch (JMSException e)
{
fail(e);
}
}
/**
* Test that a call to the <code>createDurableSubscriber()</code> method with an invalid
* message selector throws a <code>javax.jms.InvalidSelectorException</code>.
*/
public void testCreateDurableSubscriber_2()
{
try
{
subscriberSession
.createDurableSubscriber(subscriberTopic, "topic", "definitely not a message selector!", true);
fail("Should throw a javax.jms.InvalidSelectorException.\n");
}
catch (InvalidSelectorException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.InvalidSelectorException, not a " + e);
}
}
/**
* Test that a call to the <code>createDurableSubscriber()</code> method with an invalid
* <code>Topic</code> throws a <code>javax.jms.InvalidDestinationException</code>.
*/
public void testCreateDurableSubscriber_1()
{
try
{
subscriberSession.createDurableSubscriber((Topic) null, "topic");
fail("Should throw a javax.jms.InvalidDestinationException.\n");
}
catch (InvalidDestinationException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.InvalidDestinationException, not a " + e);
}
}
/**
* Test that a call to the <code>createSubscriber()</code> method with an invalid
* message selector throws a <code>javax.jms.InvalidSelectorException</code>.
*/
public void testCreateSubscriber_2()
{
try
{
subscriberSession.createSubscriber(subscriberTopic, "definitely not a message selector!", true);
fail("Should throw a javax.jms.InvalidSelectorException.\n");
}
catch (InvalidSelectorException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.InvalidSelectorException, not a " + e);
}
}
/**
* Test that a call to the <code>createSubscriber()</code> method with an invalid
* <code>Topic</code> throws a <code>javax.jms.InvalidDestinationException</code>.
*/
public void testCreateSubscriber_1()
{
try
{
subscriberSession.createSubscriber((Topic) null);
fail("Should throw a javax.jms.InvalidDestinationException.\n");
}
catch (InvalidDestinationException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.InvalidDestinationException, not a " + e);
}
}
/**
* Method to use this class in a Test suite
*/
public static Test suite()
{
return new TestSuite(TopicSessionTest.class);
}
public TopicSessionTest(String name)
{
super(name);
}
}
1.1 date: 2007/03/29 04:28:37; author: starksm; state: Exp;joramtests/src/main/java/org/objectweb/jtests/jms/conform/session/QueueSessionTest.java
Index: QueueSessionTest.java
===================================================================
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2002 INRIA
* Contact: joram-team at objectweb.org
*
* 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.1 of the License, or 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
*
* Initial developer(s): Jeff Mesnil (jmesnil at inrialpes.fr)
* Contributor(s): ______________________________________.
*/
package org.objectweb.jtests.jms.conform.session;
import javax.jms.InvalidDestinationException;
import javax.jms.InvalidSelectorException;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.TextMessage;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.objectweb.jtests.jms.framework.PTPTestCase;
import org.objectweb.jtests.jms.framework.TestConfig;
/**
* Test queue sessions
* <br />
* See JMS specifications, §4.4 Session
*
* @author Jeff Mesnil (jmesnil at inrialpes.fr)
* @version $Id: QueueSessionTest.java,v 1.1 2007/03/29 04:28:37 starksm Exp $
*/
public class QueueSessionTest extends PTPTestCase
{
/**
* Test that if we rollback a transaction which has consumed a message,
* the message is effectively redelivered.
*/
public void testRollbackRececeivedMessage()
{
try
{
senderConnection.stop();
// senderSession has been created as non transacted
// we create it again but as a transacted session
senderSession = senderConnection.createQueueSession(true, 0);
assertEquals(true, senderSession.getTransacted());
// we create again the sender
sender = senderSession.createSender(senderQueue);
senderConnection.start();
receiverConnection.stop();
// receiverSession has been created as non transacted
// we create it again but as a transacted session
receiverSession = receiverConnection.createQueueSession(true, 0);
assertEquals(true, receiverSession.getTransacted());
// we create again the receiver
receiver = receiverSession.createReceiver(receiverQueue);
receiverConnection.start();
// we send a message...
TextMessage message = senderSession.createTextMessage();
message.setText("testRollbackRececeivedMessage");
sender.send(message);
// ... and commit the *producer* transaction
senderSession.commit();
// we receive a message...
Message m = receiver.receive(TestConfig.TIMEOUT);
assertTrue(m != null);
assertTrue(m instanceof TextMessage);
TextMessage msg = (TextMessage) m;
// ... which is the one which was sent...
assertEquals("testRollbackRececeivedMessage", msg.getText());
// ...and has not been redelivered
assertEquals(false, msg.getJMSRedelivered());
// we rollback the *consumer* transaction
receiverSession.rollback();
// we receive again a message
m = receiver.receive(TestConfig.TIMEOUT);
assertTrue(m != null);
assertTrue(m instanceof TextMessage);
msg = (TextMessage) m;
// ... which is still the one which was sent...
assertEquals("testRollbackRececeivedMessage", msg.getText());
// .. but this time, it has been redelivered
assertEquals(true, msg.getJMSRedelivered());
}
catch (Exception e)
{
fail(e);
}
}
/**
* Test that a call to the <code>createBrowser()</code> method with an invalid
* messaeg session throws a <code>javax.jms.InvalidSelectorException</code>.
*/
public void testCreateBrowser_2()
{
try
{
senderSession.createBrowser(senderQueue, "definitely not a message selector!");
fail("Should throw a javax.jms.InvalidSelectorException.\n");
}
catch (InvalidSelectorException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.InvalidSelectorException, not a " + e);
}
}
/**
* Test that a call to the <code>createBrowser()</code> method with an invalid
* <code>Queue</code> throws a <code>javax.jms.InvalidDestinationException</code>.
*/
public void testCreateBrowser_1()
{
try
{
senderSession.createBrowser((Queue) null);
fail("Should throw a javax.jms.InvalidDestinationException.\n");
}
catch (InvalidDestinationException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.InvalidDestinationException, not a " + e);
}
}
/**
* Test that a call to the <code>createReceiver()</code> method with an invalid
* message selector throws a <code>javax.jms.InvalidSelectorException</code>.
*/
public void testCreateReceiver_2()
{
try
{
receiver = senderSession.createReceiver(senderQueue, "definitely not a message selector!");
fail("Should throw a javax.jms.InvalidSelectorException.\n");
}
catch (InvalidSelectorException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.InvalidSelectorException, not a " + e);
}
}
/**
* Test that a call to the <code>createReceiver()</code> method with an invalid
* <code>Queue</code> throws a <code>javax.jms.InvalidDestinationException</code>>
*/
public void testCreateReceiver_1()
{
try
{
receiver = senderSession.createReceiver((Queue) null);
fail("Should throw a javax.jms.InvalidDestinationException.\n");
}
catch (InvalidDestinationException e)
{
}
catch (JMSException e)
{
fail("Should throw a javax.jms.InvalidDestinationException, not a " + e);
}
}
/**
* Method to use this class in a Test suite
*/
public static Test suite()
{
return new TestSuite(QueueSessionTest.class);
}
public QueueSessionTest(String name)
{
super(name);
}
}
1.1 date: 2007/03/29 04:28:37; author: starksm; state: Exp;joramtests/src/main/java/org/objectweb/jtests/jms/conform/session/package.html
Index: package.html
===================================================================
<body>
Tests JMS <em>Session</em> features.
</body>
More information about the jboss-cvs-commits
mailing list