This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.

Using WireMonitorServer in Integration Tests

Wire Monitor Server can be used to capture messages sent from your carbon server to the backend server. You can configure carbon servers to send messages to the wire monitor endpoint instead of the real backend and check whether the wire level message contains the correct information.

Shown below is a sample test case using the wire monitor for message tracing:

public class EnrichIntegrationAddSiblingInOutMessageTestCase extends ESBIntegrationTest {
    private WireMonitorServer wireMonitorServer;

     @BeforeClass(alwaysRun = true)
    public void uploadSynapseConfig() throws Exception {
        super.init();
        loadESBConfigurationFrom("/artifacts/ESB/mediatorconfig/enrich/enrich_add_sibling_in_out_msg.xml");
        wireMonitorServer = new WireMonitorServer(8991);
    }

     @SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
    @Test(groups = {"wso2.esb"}, description = "Enrich mediator:Add as a sibling to message body")
    public void addAsSiblingToMessageBody() throws Exception {
        wireMonitorServer.start();
        String payload = "<m:getQuote xmlns:m=\"http://services.samples\">" +
                "<m:request>" +
                "</m:request>" +
                "</m:getQuote>";
        OMElement payloadOM = AXIOMUtil.stringToOM(payload);
        try {
            OMElement response = axis2Client.sendSimpleStockQuoteRequest(getProxyServiceURLHttp("enrichSample3")
                    , null, payloadOM);
        } catch (Exception e) {
        }
        String wireResponse = wireMonitorServer.getCapturedMessage();
        String expectedSoapBody = "<soapenv:Body>" +
                "<m:symbol1 xmlns:m=\"http://services.samples\">IBM</m:symbol1>" +
                "<m:symbol2 xmlns:m=\"http://services.samples\">WSO2</m:symbol2>" +
                "</soapenv:Body>";
        assertTrue(wireResponse.contains(expectedSoapBody), "Invalid soap body");
    }

     @AfterClass
    private void destroy() throws Exception {
        super.cleanup();
    }
}