*/
@Test
public void sendAndReceiveMessage()
{
drainQueue();
QueueConnection connection = null;
QueueSession session = null;
MessageProducer messageProducer = null;
MessageConsumer messageConsumer = null;
try {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.soa.esb.oracle.aq.AQInitialContextFactory");
properties.put(AQInitialContextFactory.DB_SERVER, server);
properties.put(AQInitialContextFactory.DB_INSTANCE, instance);
properties.put(AQInitialContextFactory.DB_PORT, portStr);
properties.put(AQInitialContextFactory.DB_USER, user);
properties.put(AQInitialContextFactory.DB_PASSWD, password);
properties.put(AQInitialContextFactory.DB_SCHEMA, schema);
properties.put(AQInitialContextFactory.DB_DRIVER, driver);
MockContextFactory.setAsInitial();
Context context = new InitialContext(properties);
XAQueueConnectionFactory xaQueueConnectionFactory = (XAQueueConnectionFactory)
context.lookup(AQInitialContextFactory.XA_QUEUE_CONNECTION_FACTORY);
connection = xaQueueConnectionFactory.createXAQueueConnection();
session = connection.createQueueSession(false,
QueueSession.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) context.lookup(qName);
messageProducer = session.createSender(queue);
messageConsumer = session.createReceiver(queue);
connection.start();
TextMessage sendMessage = session.createTextMessage(MESSAGE_CONTENT);
messageProducer.send(sendMessage);
TextMessage receiveMessage = (TextMessage) messageConsumer.receive(2000);
String receiveContent = receiveMessage.getText();
assertEquals(MESSAGE_CONTENT, receiveContent);
} catch (Exception e) {
e.printStackTrace();
assertTrue(false);
} finally {
if (messageProducer!=null) {
try { messageProducer.close();
} catch (Exception e) {}
}
if (messageConsumer!=null) {
try { messageConsumer.close();
} catch (Exception e) {}
}
if (session!=null) {
try { session.close();
} catch (Exception e) {}
}
if (connection!=null) {
try { connection.close();
} catch (Exception e) {}
}
}
}