Commit 03eeef14 authored by Pierre-Yves Gibello's avatar Pierre-Yves Gibello
Browse files

JMS tests ported to JUnit

parent 98203189
target/
work/
classes/
bin/
ship/
# IntelliJ project files
*.iml
*.ipr
*.iws
.idea/
# eclipse project files
.classpath
.project
.settings/
build/
# Joram miscellaneous
s0/
*.log.*
log.config.classname org.objectweb.util.monolog.wrapper.javaLog.LoggerFactory
# ==============================
# tty : console handler
# handler.tty.type Console
# handler.tty.output System.err
# handler.tty.pattern %l %h %d, %m%n
# ==============================
# logf : rolling file handler
handler.logf.type RollingFile
handler.logf.output server.log
handler.logf.pattern %l %h %d, %m%n
handler.logf.fileNumber 2
handler.logf.maxSize 100000000
# ==============================
# logger definitions
# logger.root.handler.0 tty
logger.root.handler.0 logf
logger.root.level DEBUG
# ==============================
# ScalAgent middleware
# logger.fr.dyade.aaa.level DEBUG
# logger.fr.dyade.aaa.agent.Agent.level WARN
# logger.fr.dyade.aaa.agent.AgentServer.level DEBUG
# logger.fr.dyade.aaa.agent.Engine.level WARN
# logger.fr.dyade.aaa.agent.Network.level DEBUG
# logger.org.objectweb.joram.mom.dest.level DEBUG
# logger.fr.dyade.aaa.agent.Transaction.level WARN
# logger.org.objectweb.joram.client.level DEBUG
# logger.com.scalagent.level DEBUG
# ==============================
# Joram middleware
# logger.org.objectweb.joram.level DEBUG
# logger.fr.dyade.aaa.util.ReliableTcpConnection.level DEBUG
<?xml version="1.0"?>
<config>
<!--property name="Transaction" value="fr.dyade.aaa.util.NullTransaction"/-->
<property name="joram.jms.redeliveryDelay" value="5"/>
<server id="0" name="s0" hostname="localhost">
<service class="fr.dyade.aaa.agent.AdminProxy" args="7890"/>
<service class="org.objectweb.joram.mom.proxies.ConnectionManager" args="root root"/>
<service class="org.objectweb.joram.mom.proxies.tcp.TcpProxyService" args="16010"/>
<service class="fr.dyade.aaa.jndi2.server.JndiServer" args="16400"/>
</server>
</config>
felix.auto.deploy.action=install,start
felix.auto.deploy.dir=/home/gibello/STAMP/JORAM_NEW/joram/joram/ship/bundle
felix.log.level=1
......@@ -115,6 +115,24 @@
<artifactId>joram-mom-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.joram</groupId>
<artifactId>a3-osgi</artifactId>
<version>${project.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>1.5.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
</project>
package aastart;
import org.junit.jupiter.api.Test;
import org.ow2.joram.testutils.AgentManager;
import junit.framework.TestCase;
public class AAATest extends TestCase {
@Test
public void testStartAgent() throws Exception {
System.setProperty("felix.dir", "../../../ship/bin");
AgentManager.startAgentServer();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
* Copyright (C) 2002 INRIA
* Contact: joram-team@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 (Inria)
* Contributor(s): Nicolas Tachker (ScalAgent D.T.)
*/
package jms.admin;
import java.net.ConnectException;
import javax.jms.JMSException;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.QueueConnectionFactory;
import javax.jms.TopicConnectionFactory;
import org.objectweb.joram.client.jms.Queue;
import org.objectweb.joram.client.jms.Topic;
import org.objectweb.joram.client.jms.admin.AdminException;
/**
* Simple Administration interface.
* <br />
* JMS Provider has to implement this
* simple interface to be able to use the test suite.
*/
public interface Admin {
/**
* Returns the name of the JMS Provider.
*
* @return name of the JMS Provider
*/
public String getName();
/**
* Creates a <code>ConnectionFactory</code>.
*
* @since JMS 1.1
* @param name of the <code>ConnectionFactory</code>
*/
public ConnectionFactory createConnectionFactory(String name) throws ConnectException;
/**
* Creates a <code>QueueConnectionFactory</code>.
*
* @param name of the <code>QueueConnectionFactory</code>
*/
public QueueConnectionFactory createQueueConnectionFactory(String name) throws ConnectException;
/**
* Creates a <code>TopicConnectionFactory</code>.
*
* @param name of the <code>TopicConnectionFactory</code>
*/
public TopicConnectionFactory createTopicConnectionFactory(String name) throws ConnectException;
/**
* Creates a <code>Queue</code>.
*
* @param name of the <code>Queue</code>
*/
public Queue createQueue(String name) throws ConnectException, AdminException;
/**
* Creates a <code>Topic</code>.
*
* @param name of the <code>Topic</code>
*/
public Topic createTopic(String name) throws ConnectException, AdminException;
/**
* Removes the <code>Queue</code>
*
* @param queue
*/
public void deleteQueue(Destination queue) throws ConnectException, AdminException, JMSException;
/**
* Removes the <code>Topic</code>
*
* @param topic
*/
public void deleteTopic(Destination topic) throws ConnectException, AdminException, JMSException;
/**
* Removes the <code>ConnectionFactory</code> of name <code>name</code> from JNDI and deletes it
*
* @since JMS 1.1
* @param name JNDI name of the <code>ConnectionFactory</code>
*/
public void deleteConnectionFactory (String name);
/**
* Removes the <code>QueueConnectionFactory</code> of name <code>name</code> from JNDI and deletes it
*
* @param name JNDI name of the <code>QueueConnectionFactory</code>
*/
public void deleteQueueConnectionFactory (String name);
/**
* Removes the <code>TopicConnectionFactory</code> of name <code>name</code> from JNDI and deletes it
*
* @param name JNDI name of the <code>TopicConnectionFactory</code>
*/
public void deleteTopicConnectionFactory (String name);
public void disconnect();
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
* Copyright (C) 2002 INRIA
* Contact: joram-team@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 (Inria)
* Contributor(s): Nicolas Tachker (ScalAgent D.T.)
*/
package jms.admin;
import jms.providers.admin.JoramAdmin;
public class AdminFactory {
public static Admin getAdmin() {
return new JoramAdmin();
}
}
felix.auto.deploy.action=install,start
felix.auto.deploy.dir=@BUNDLE_DIR@
felix.log.level=1
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2002 - 2013 ScalAgent Distributed Technologies
* Copyright (C) 2002 INRIA
* Contact: joram-team@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 (Inria)
* Contributor(s): Nicolas Tachker (ScalAgent D.T.)
*/
package jms.conform.connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.junit.jupiter.api.Test;
import jms.framework.PTPTestCase;
import jms.framework.TestConfig;
/**
* Test connections.
*
* See JMS specifications, 4.3.5 Closing a Connection
*
*/
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>.
*/
@Test
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>.
*/
@Test
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 session creation without using parameters
*/
@Test
public void testSessionCreation() {
try {senderConnection.start();
javax.jms.Session session=senderConnection.createSession();
assertTrue("Sesssion is created", (session!=null));
} catch (JMSException e) {
fail("Unable to create session without parameters "+e);
}
}
/**
* Test session creation without using parameters
*/
@Test
public void testSessionCreationSessionMode() {
try {senderConnection.start();
javax.jms.Session session=senderConnection.createSession(Session.SESSION_TRANSACTED);
assertTrue("Sesssion is created", (session!=null));
assertTrue("Sesssion transacted is true", (session.getTransacted()==true));
} catch (JMSException e) {
fail("Unable to create session with session mode as parameter "+e);
}
}
/**
* Test that a <code>MessageProducer</code> can send messages while a
* <code>Connection</code> is stopped.
*/
@Test
public void testMessageSentWhenConnectionClosed() {
try {
senderConnection.stop();
Message message = senderSession.createTextMessage();
sender.send(message);
Message m = receiver.receive(TestConfig.TIMEOUT);
} catch (JMSException e) {
fail(e);
}
}
/**
* Test that closing a closed connectiondoes not throw an exception.
*/
@Test
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
*/
@Test
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
*/
@Test
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
*/
@Test
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);
}
}
public ConnectionTest() {
super();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
* Copyright (C) 2002 INRIA
* Contact: joram-team@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 (Inria)
* Contributor(s): Nicolas Tachker (ScalAgent D.T.)
* Andreas Mueller <am@iit.de>
*/
package jms.conform.connection;
import javax.jms.InvalidClientIDException;
import javax.jms.JMSException;
import javax.jms.TopicConnection;
import org.junit.jupiter.api.Test;
import 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)
*/
@Test
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);