String invalidMsg = String.format(invalidMsgFormat, value);
int consumerPort = TestUtilServer.getAvailablePort();
String brokerEPR = "http://localhost:" + TestUtilServer.TESTING_PORT + "/axis2/services/EventingService";
WseMsgBrokerClient msgBrokerClient = new WseMsgBrokerClient();
msgBrokerClient.init(brokerEPR);
String[] consumerEPRs = msgBrokerClient.startConsumerService(consumerPort, this);
assertTrue(consumerEPRs.length > 0);
String xpathExpression = "/c/b/a";
String subscriptionID = msgBrokerClient.subscribe(consumerEPRs[0], null, xpathExpression);
try {
msgBrokerClient.publish(null, AXIOMUtil.stringToOM(validMsg));
msgBrokerClient.publish(null, AXIOMUtil.stringToOM(invalidMsg));
SOAPEnvelope env = getMsgQueue().take();
assertNotNull(env.getBody());
assertNotNull(env.getBody().getChildrenWithLocalName("c"));
OMElement element = (OMElement) env.getBody().getChildrenWithLocalName("c").next();
String text = element.toStringWithConsume();
assertTrue("round trip of message failed" + " - due to invalid messege content",
text.indexOf(new Long(value).toString()) > 0);
Thread.sleep(5000);
assertTrue("unexpected msg recieved", getMsgQueue().isEmpty());
} catch (InterruptedException e) {
fail("interrupted while waiting for message");
} catch (XMLStreamException e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail("invalid xml recieved: " + e.getMessage());
}
msgBrokerClient.unSubscribe(subscriptionID);
msgBrokerClient.shutdownConsumerService();
} catch (AxisFault e) {
e.printStackTrace();
fail("unexpected exception occured");
}