[jboss-cvs] joramtests/src/main/java/org/objectweb/jtests/jms/conform/connection ...
Scott Stark
scott.stark at jboss.com
Thu Mar 29 00:28:34 EDT 2007
User: starksm
Date: 07/03/29 00:28:34
Added: src/main/java/org/objectweb/jtests/jms/conform/connection
TopicConnectionTest.java ConnectionTest.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:34; author: starksm; state: Exp;joramtests/src/main/java/org/objectweb/jtests/jms/conform/connection/TopicConnectionTest.java
Index: TopicConnectionTest.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.connection;
import javax.jms.InvalidClientIDException;
import javax.jms.JMSException;
import javax.jms.TopicConnection;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.objectweb.jtests.jms.framework.PubSubTestCase;
/**
* Test topic-specific connection features.
*
* Test setting of client ID which is relevant only for Durable Subscribtion
*/
public class TopicConnectionTest extends PubSubTestCase
{
/**
* Test that a call to <code>setClientID</code> will throw an
* <code>IllegalStateException</code> if a client ID has already been set
* see JMS javadoc
* http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/Connection.html#setClientID(java.lang.String)
*/
public void testSetClientID_1()
{
try
{
// we start from a clean state for the connection
subscriberConnection.close();
subscriberConnection = null;
subscriberConnection = subscriberTCF.createTopicConnection();
// if the JMS provider does not set a client ID, we do.
if (subscriberConnection.getClientID() == null)
{
subscriberConnection.setClientID("testSetClientID_1");
assertEquals("testSetClientID_1", subscriberConnection.getClientID());
}
// now the connection has a client ID (either "testSetClientID_1" or one set by the provider
assertTrue(subscriberConnection.getClientID() != null);
// a attempt to set a client ID should now throw an IllegalStateException
subscriberConnection.setClientID("another client ID");
fail("Should raise a javax.jms.IllegalStateException");
}
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 a call to <code>setClientID</code> can occur only after connection creation
* and before any other action on the connection.
* <em>This test is relevant only if the ID is set by the JMS client</em>
* see JMS javadoc
* http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/Connection.html#setClientID(java.lang.String)
*/
public void testSetClientID_2()
{
try
{
// we start from a clean state for the first connection
subscriberConnection.close();
subscriberConnection = null;
subscriberConnection = subscriberTCF.createTopicConnection();
// if the JMS provider has set a client ID, this test is not relevant
if (subscriberConnection.getClientID() != null)
{
return;
}
//we start the connection
subscriberConnection.start();
// an attempt to set the client ID now should throw a IllegalStateException
subscriberConnection.setClientID("testSetClientID_2");
fail("Should throw a javax.jms.IllegalStateException");
}
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 if another connection with the same clientID is already running when
* <code>setClientID</code> is called, the JMS provider should detect the duplicate
* ID and throw an <code>InvalidClientIDException</code>
* <em>This test is relevant only if the ID is set by the JMS client</em>
* see JMS javadoc
* http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/Connection.html#setClientID(java.lang.String)
*/
public void testSetClientID_3()
{
try
{
// we start from a clean state for the first connection
subscriberConnection.close();
subscriberConnection = null;
subscriberConnection = subscriberTCF.createTopicConnection();
// if the JMS provider has set a client ID, this test is not relevant
if (subscriberConnection.getClientID() != null)
{
return;
}
// the JMS provider has not set a client ID, so we do
subscriberConnection.setClientID("testSetClientID_3");
assertEquals("testSetClientID_3", subscriberConnection.getClientID());
// we create a new connection and try to set the same ID than for subscriberConnection
TopicConnection connection_2 = subscriberTCF.createTopicConnection();
assertTrue(connection_2.getClientID() == null);
connection_2.setClientID("testSetClientID_3");
fail("Should throw a javax.jms.InvalidClientIDException");
}
catch (InvalidClientIDException e)
{
}
catch (JMSException e)
{
fail(e);
}
}
/**
* Method to use this class in a Test suite
*/
public static Test suite()
{
return new TestSuite(TopicConnectionTest.class);
}
public TopicConnectionTest(String name)
{
super(name);
}
}
1.1 date: 2007/03/29 04:28:34; author: starksm; state: Exp;joramtests/src/main/java/org/objectweb/jtests/jms/conform/connection/ConnectionTest.java
Index: ConnectionTest.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.connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
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 connections.
*
* See JMS specifications, §4.3.5 Closing a Connection
*
* @author Jeff Mesnil (jmesnil at inrialpes.fr)
* @version $Id: ConnectionTest.java,v 1.1 2007/03/29 04:28:34 starksm Exp $
*/
public class ConnectionTest extends PTPTestCase
{
/**
* Test that invoking the <code>acknowledge()</code> method of a received message
* from a closed connection's session must throw an <code>IllegalStateException</code>.
*/
public void testAcknowledge()
{
try
{
receiverConnection.stop();
receiverSession = receiverConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
receiver = receiverSession.createReceiver(receiverQueue);
receiverConnection.start();
Message message = senderSession.createMessage();
sender.send(message);
Message m = receiver.receive(TestConfig.TIMEOUT);
receiverConnection.close();
m.acknowledge();
fail("§4.3.5 Invoking the acknowledge method of a received message from a closed "
+ "connection's session must throw a [javax.jms.]IllegalStateException.\n");
}
catch (javax.jms.IllegalStateException e)
{
}
catch (JMSException e)
{
fail("§4.3.5 Invoking the acknowledge method of a received message from a closed "
+ "connection's session must throw a [javax.jms.]IllegalStateException, not a " + e);
}
catch (java.lang.IllegalStateException e)
{
fail("§4.3.5 Invoking the acknowledge method of a received message from a closed "
+ "connection's session must throw an [javax.jms.]IllegalStateException "
+ "[not a java.lang.IllegalStateException]");
}
}
/**
* Test that an attempt to use a <code>Connection</code> which has been closed
* throws a <code>javax.jms.IllegalStateException</code>.
*/
public void testUseClosedConnection()
{
try
{
senderConnection.close();
senderConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
fail("Should raise a javax.jms.IllegalStateException");
}
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 a <code>MessageProducer</code> can send messages while a
* <code>Connection</code> is stopped.
*/
public void testMessageSentWhenConnectionClosed()
{
try
{
senderConnection.stop();
Message message = senderSession.createTextMessage();
sender.send(message);
receiver.receive(TestConfig.TIMEOUT);
}
catch (JMSException e)
{
fail(e);
}
}
/**
* Test that closing a closed connectiondoes not throw an exception.
*/
public void testCloseClosedConnection()
{
try
{
// senderConnection is already started
// we close it once
senderConnection.close();
// we close it a second time
senderConnection.close();
}
catch (Exception e)
{
fail("§4.3.5 Closing a closed connection must not throw an exception.\n");
}
}
/**
* Test that starting a started connection is ignored
*/
public void testStartStartedConnection()
{
try
{
// senderConnection is already started
// start it again should be ignored
senderConnection.start();
}
catch (JMSException e)
{
fail(e);
}
}
/**
* Test that stopping a stopped connection is ignored
*/
public void testStopStoppedConnection()
{
try
{
// senderConnection is started
// we stop it once
senderConnection.stop();
// stopping it a second time is ignored
senderConnection.stop();
}
catch (JMSException e)
{
fail(e);
}
}
/**
* Test that delivery of message is stopped if the message consumer connection is stopped
*/
public void testStopConsumerConnection()
{
try
{
receiverConnection.stop();
receiver.setMessageListener(new MessageListener()
{
public void onMessage(Message m)
{
try
{
fail("The message must not be received, the consumer connection is stopped");
assertEquals("test", ((TextMessage) m).getText());
}
catch (JMSException e)
{
fail(e);
}
}
});
TextMessage message = senderSession.createTextMessage();
message.setText("test");
sender.send(message);
synchronized (this)
{
try
{
wait(1000);
}
catch (Exception e)
{
fail(e);
}
}
}
catch (JMSException e)
{
fail(e);
}
}
/**
* Method to use this class in a Test suite
*/
public static Test suite()
{
return new TestSuite(ConnectionTest.class);
}
public ConnectionTest(String name)
{
super(name);
}
}
1.1 date: 2007/03/29 04:28:34; author: starksm; state: Exp;joramtests/src/main/java/org/objectweb/jtests/jms/conform/connection/package.html
Index: package.html
===================================================================
<body>
Tests JMS <em>Connection</em> features.
</body>
More information about the jboss-cvs-commits
mailing list