use of javax.jms.Message in project wildfly by wildfly.
the class MDB21TestCase method testSimple21MDB.
/**
* Test a simple 2.1 MDB.
*/
@Test
public void testSimple21MDB() {
sendTextMessage("Say hello to " + EJB2xMDB.class.getName(), queue, replyQueue);
final Message reply = receiveMessage(replyQueue, TimeoutUtil.adjust(1000));
Assert.assertNotNull("Reply message was null on reply queue: " + replyQueue, reply);
}
use of javax.jms.Message in project wildfly by wildfly.
the class RunAsTestCaseEJBMDB method testSendMessage.
@Test
public void testSendMessage() throws Exception {
ConnectionFactory cf = null;
Connection connection = null;
Session session = null;
try {
cf = (ConnectionFactory) initialContext.lookup("jms/RemoteConnectionFactory");
Queue queue = (Queue) initialContext.lookup(QUEUE_NAME);
connection = cf.createConnection("guest", "guest");
//for consumer we need to start connection
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer sender = session.createProducer(queue);
TemporaryQueue replyQueue = session.createTemporaryQueue();
TextMessage message = session.createTextMessage("hello goodbye");
message.setJMSReplyTo(replyQueue);
sender.send(message);
log.trace("testSendMessage(): Message sent!");
MessageConsumer consumer = session.createConsumer(replyQueue);
Message replyMsg = consumer.receive(5000);
Assert.assertNotNull(replyMsg);
Assert.assertTrue(replyMsg instanceof TextMessage);
String actual = ((TextMessage) replyMsg).getText();
Assert.assertEquals("Howdy Fred! GoodBye user1", actual);
} finally {
if (session != null) {
session.close();
}
closeConnection(connection);
}
}
use of javax.jms.Message in project wildfly by wildfly.
the class RunAsMDBUnitTestCase method testSendMessage.
@Test
public void testSendMessage() throws Exception {
ConnectionFactory connFactory = lookup("ConnectionFactory", ConnectionFactory.class);
Connection conn = connFactory.createConnection();
conn.start();
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue replyQueue = session.createTemporaryQueue();
TextMessage msg = session.createTextMessage("Hello world");
msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
msg.setJMSReplyTo(replyQueue);
Queue queue = lookup("java:jboss/" + queueName, Queue.class);
MessageProducer producer = session.createProducer(queue);
producer.send(msg);
MessageConsumer consumer = session.createConsumer(replyQueue);
Message replyMsg = consumer.receive(5000);
Assert.assertNotNull(replyMsg);
if (replyMsg instanceof ObjectMessage) {
Exception e = (Exception) ((ObjectMessage) replyMsg).getObject();
throw e;
}
Assert.assertTrue(replyMsg instanceof TextMessage);
String actual = ((TextMessage) replyMsg).getText();
Assert.assertEquals("SUCCESS", actual);
consumer.close();
producer.close();
session.close();
conn.close();
}
use of javax.jms.Message in project wildfly by wildfly.
the class GetCallerPrincipalTestCase method testMDBLifecycle.
/**
* Run this one in the container so it can lookup the queue
* @throws Exception
*/
@OperateOnDeployment("test")
@Test
public void testMDBLifecycle() throws Exception {
deployer.deploy("mdb");
SecurityClient client = this.login();
ITestResultsSingleton results = this.getResultsSingleton();
MessageProducer producer = null;
MessageConsumer consumer = null;
QueueConnection conn = null;
Session session = null;
try {
QueueConnectionFactory qcf = (QueueConnectionFactory) new InitialContext().lookup("java:/ConnectionFactory");
Queue queue = (Queue) new InitialContext().lookup("java:jboss/" + QUEUE_NAME);
conn = qcf.createQueueConnection("guest", "guest");
conn.start();
session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
TemporaryQueue replyQueue = session.createTemporaryQueue();
TextMessage msg = session.createTextMessage("Hello world");
msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
msg.setJMSReplyTo(replyQueue);
producer = session.createProducer(queue);
producer.send(msg);
consumer = session.createConsumer(replyQueue);
Message replyMsg = consumer.receive(5000);
Object obj = ((ObjectMessage) replyMsg).getObject();
log.trace("MDB message get: " + obj);
Assert.assertEquals(OK + "start", results.getMdb("postconstruct"));
deployer.undeploy("mdb");
Assert.assertEquals(OK + "stop", results.getMdb("predestroy"));
} finally {
if (consumer != null) {
consumer.close();
}
if (producer != null) {
producer.close();
}
if (session != null) {
session.close();
}
if (conn != null) {
conn.close();
}
client.logout();
}
}
use of javax.jms.Message in project wildfly by wildfly.
the class JMSQueueManagementTestCase method testChangeMessagePriority.
@Test
public void testChangeMessagePriority() throws Exception {
MessageProducer producer = session.createProducer(queue);
Message msgA = session.createTextMessage("A");
producer.send(msgA);
producer.send(session.createTextMessage("B"));
producer.send(session.createTextMessage("C"));
Set<Integer> priorities = new HashSet<Integer>();
ModelNode result = execute(getQueueOperation("list-messages"), true);
Assert.assertEquals(3, result.asInt());
for (ModelNode node : result.asList()) {
priorities.add(node.get("JMSPriority").asInt());
}
int newPriority = -1;
for (int i = 0; i < 10; i++) {
if (!priorities.contains(i)) {
newPriority = i;
break;
}
}
ModelNode op = getQueueOperation("change-message-priority");
op.get("message-id").set(msgA.getJMSMessageID());
op.get("new-priority").set(newPriority);
result = execute(op, true);
Assert.assertTrue(result.isDefined());
Assert.assertTrue(result.asBoolean());
result = execute(getQueueOperation("list-messages"), true);
boolean found = false;
for (ModelNode node : result.asList()) {
if (msgA.getJMSMessageID().equals(node.get("JMSMessageID").asString())) {
Assert.assertEquals(newPriority, node.get("JMSPriority").asInt());
found = true;
break;
}
}
Assert.assertTrue(found);
op = getQueueOperation("change-messages-priority");
op.get("new-priority").set(newPriority);
result = execute(op, true);
Assert.assertTrue(result.isDefined());
Assert.assertTrue(result.asInt() > 1 && result.asInt() < 4);
result = execute(getQueueOperation("list-messages"), true);
for (ModelNode node : result.asList()) {
Assert.assertEquals(newPriority, node.get("JMSPriority").asInt());
}
}
Aggregations