Commit 5a618b9a authored by Andre Freyssinet's avatar Andre Freyssinet

Cleaning code.

parent 3adb2c45
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2007 ScalAgent Distributed Technologies
* Copyright (C) 2007 - 2019 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -33,101 +33,93 @@ import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import framework.TestCase;
import org.objectweb.joram.client.jms.admin.AdminModule;
import org.objectweb.joram.client.jms.admin.User;
import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
import framework.TestCase;
/**
* Test the functioning of Temporary Topic
*
* Test the functioning of Temporary Topic
* Creates e temporary topic then exchanges a message.
*/
public class Test_Temp_T extends TestCase implements javax.jms.MessageListener {
public static void main(String[] args) {
new Test_Temp_T().run();
}
public void run() {
try {
System.out.println("server start");
startAgentServer((short)0);
admin();
System.out.println("admin config ok");
Context ictx = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf");
ictx.close();
Connection cnx = cf.createConnection();
Session sessionp = cnx.createSession(false,
Session.AUTO_ACKNOWLEDGE);
Session sessionc = cnx.createSession(false,
Session.AUTO_ACKNOWLEDGE);
// temporary topic is creating by a session
TemporaryTopic temptopic = sessionp.createTemporaryTopic();
cnx.start();
// create a producer and a consumer
MessageProducer producer = sessionp.createProducer(temptopic);
MessageConsumer consumer = sessionc.createConsumer(temptopic);
// the consumer records on the topic
consumer.setMessageListener(this);
TextMessage msg = sessionp.createTextMessage();
msg.setText("test_temporary_topic");
producer.send(msg);
cnx.close();
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
System.out.println("Server stop ");
stopAgentServer((short)0);
endTest();
}
}
/**
* Admin : Create a user anonymous
* use jndi
*/
public void admin() throws Exception {
// conexion
org.objectweb.joram.client.jms.admin.AdminModule.connect("localhost", 2560,
"root", "root", 60);
// create a user
org.objectweb.joram.client.jms.admin.User user =
org.objectweb.joram.client.jms.admin.User.create("anonymous", "anonymous");
javax.jms.ConnectionFactory cf =
org.objectweb.joram.client.jms.tcp.TcpConnectionFactory.create("localhost", 2560);
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
jndiCtx.bind("cf", cf);
jndiCtx.close();
org.objectweb.joram.client.jms.admin.AdminModule.disconnect();
public static void main(String[] args) {
new Test_Temp_T().run();
}
public void run() {
try {
System.out.println("server start");
startAgentServer((short)0);
admin();
System.out.println("admin config ok");
Context ictx = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf");
ictx.close();
Connection cnx = cf.createConnection();
Session sessionp = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session sessionc = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
// temporary topic is creating by a session
TemporaryTopic temptopic = sessionp.createTemporaryTopic();
cnx.start();
// create a producer and a consumer
MessageProducer producer = sessionp.createProducer(temptopic);
MessageConsumer consumer = sessionc.createConsumer(temptopic);
// the consumer records on the topic
consumer.setMessageListener(this);
TextMessage msg = sessionp.createTextMessage();
msg.setText("test_temporary_topic");
producer.send(msg);
cnx.close();
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
System.out.println("Server stop ");
stopAgentServer((short)0);
endTest();
}
}
/**
* Admin : Create a user anonymous
* use jndi
*/
public void admin() throws Exception {
// Connexion to the Joram server
AdminModule.connect("localhost", 2560, "root", "root", 60);
// Creates a user
User user = User.create("anonymous", "anonymous");
// Initializes the ConnectionFactory
javax.jms.ConnectionFactory cf = TcpConnectionFactory.create("localhost", 2560);
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
jndiCtx.bind("cf", cf);
jndiCtx.close();
org.objectweb.joram.client.jms.admin.AdminModule.disconnect();
}
public void onMessage(Message message) {
System.out.println("message receive");
try{
TextMessage msg = (TextMessage) message;
//test messages
assertEquals("test_temporary_topic",msg.getText());
}catch(javax.jms.JMSException JE){
JE.printStackTrace( );
}
public void onMessage(Message message) {
System.out.println("message receive");
try{
TextMessage msg = (TextMessage) message;
//test messages
assertEquals("test_temporary_topic", msg.getText());
}catch(javax.jms.JMSException JE){
JE.printStackTrace( );
}
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2007 - 2009 ScalAgent Distributed Technologies
* Copyright (C) 2007 - 2019 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -37,26 +37,34 @@ import org.objectweb.joram.client.jms.admin.AdminModule;
import framework.TestCase;
import org.objectweb.joram.client.jms.admin.AdminModule;
import org.objectweb.joram.client.jms.admin.User;
import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
/**
* Test delete of Temporary Topic
*
* Test the desletion of a Temporary Topic.
* Verify that the remaining messages are not sent to the DMQ.
*/
public class Test_Temp_T2 extends TestCase {
static Topic adminTopic= null;
public class Test_Temp_T2 extends TestCase {
static Destination adminTopic = null;
public static void main(String[] args) {
new Test_Temp_T2().run();
}
public static void printDestinations(Destination[] destinations) {
System.out.print("destinations=[");
for (Destination destination : destinations) {
System.out.print(destination + " ");
}
System.out.println("]");
}
public void run() {
try {
System.out.println("server start");
startAgentServer((short)0);
admin();
System.out.println("admin config ok");
......@@ -64,38 +72,35 @@ public class Test_Temp_T2 extends TestCase {
ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf");
ictx.close();
Connection cnx = cf.createConnection();
org.objectweb.joram.client.jms.admin.AdminModule.connect("localhost", 2560, "root", "root", 60);
Destination[] destinations = AdminModule.getDestinations();
TemporaryTopic topic = (TemporaryTopic) destinations[0];
adminTopic=topic;
printDestinations(destinations);
adminTopic = destinations[0];
// temporary topic is creating by a session
Connection cnx = cf.createConnection();
cnx.start();
Session sessionp = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryTopic temptopic = sessionp.createTemporaryTopic();
sessionp.createTemporaryTopic();
cnx.close();
Thread.sleep(1000L);
testTempTopic();
cnx = cf.createConnection();
cnx.start();
sessionp = cnx.createSession(false,
Session.AUTO_ACKNOWLEDGE);
temptopic = sessionp.createTemporaryTopic();
TemporaryTopic temptopic1 = sessionp.createTemporaryTopic();
TemporaryTopic temptopic2 = sessionp.createTemporaryTopic();
TemporaryTopic temptopic3 = sessionp.createTemporaryTopic();
TemporaryTopic temptopic4 = sessionp.createTemporaryTopic();
sessionp = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
sessionp.createTemporaryTopic();
sessionp.createTemporaryTopic();
sessionp.createTemporaryTopic();
sessionp.createTemporaryTopic();
sessionp.createTemporaryTopic();
cnx.close();
Thread.sleep(1000L);
testTempTopic();
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
......@@ -111,37 +116,27 @@ public class Test_Temp_T2 extends TestCase {
* use jndi
*/
public void admin() throws Exception {
// conexion
org.objectweb.joram.client.jms.admin.AdminModule.connect("localhost", 2560, "root", "root", 60);
// create a user
org.objectweb.joram.client.jms.admin.User user =
org.objectweb.joram.client.jms.admin.User.create("anonymous", "anonymous");
javax.jms.ConnectionFactory cf =
org.objectweb.joram.client.jms.tcp.TcpConnectionFactory.create("localhost", 2560);
// Connexion to the Joram server
AdminModule.connect("localhost", 2560, "root", "root", 60);
// Creates a user
User user = User.create("anonymous", "anonymous");
// Initializes the ConnectionFactory
javax.jms.ConnectionFactory cf = TcpConnectionFactory.create("localhost", 2560);
javax.naming.Context jndiCtx = new javax.naming.InitialContext();
jndiCtx.bind("cf", cf);
jndiCtx.close();
org.objectweb.joram.client.jms.admin.AdminModule.disconnect();
}
private static void testTempTopic() throws Exception{
int j=0;
Destination[] destinations = AdminModule.getDestinations();
printDestinations(destinations);
assertEquals(1, destinations.length);
for (Destination destination : destinations) {
j++;
TemporaryTopic topic = (TemporaryTopic)destination;
assertEquals(adminTopic,topic);
assertEquals(adminTopic, destination);
}
assertEquals(1,j);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment