I am using activemq and trying to send , whether it is possible to test that if my own created MOCK successfully sent a message to the Queue. I am using Activemq & want to automate the test where, mock send message to queue and with spock you make sure that message has been sent.
You can first create a QueueBrowser and then using enumeration get the number of messages. Than let a loop run till enumeration object has elements. Than check your message in that loop, if its there. Code should somehow looks like this
QueueBrowser qbrowser = session.createBrowser(QueueName);
Enumeration messages = qbrowser.getEnumeration();
while (messages.hasMoreElements())
{
TextMessage message = (TextMessage) messages.nextElement();
String a=message.getText();
if (Message is there)
{
return true;
}
}
Cheers :)