public void testSendMessageToDeadLetterAddress() throws Exception
{
String deadLetterQueue = RandomUtil.randomString();
serverManager.createQueue(false, deadLetterQueue, null, true, deadLetterQueue);
HornetQQueue dlq = (HornetQQueue)HornetQJMSClient.createQueue(deadLetterQueue);
Connection conn = createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = sess.createProducer(queue);
// send 2 messages on queue
Message message = sess.createMessage();
producer.send(message);
producer.send(sess.createMessage());
conn.close();
JMSQueueControl queueControl = createManagementControl();
JMSQueueControl dlqControl = ManagementControlHelper.createJMSQueueControl(dlq, mbeanServer);
Assert.assertEquals(2, queueControl.getMessageCount());
Assert.assertEquals(0, dlqControl.getMessageCount());
queueControl.setDeadLetterAddress(dlq.getAddress());
boolean movedToDeadLetterAddress = queueControl.sendMessageToDeadLetterAddress(message.getJMSMessageID());
Assert.assertTrue(movedToDeadLetterAddress);
Assert.assertEquals(1, queueControl.getMessageCount());
Assert.assertEquals(1, dlqControl.getMessageCount());