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/.
Writing a Test Case for Multiple Axis2 Servers
The test class given below demonstrates how to use multiple axis2 servers in integration tests. You can start any number of axis2 server instances and deploy service files.
Two axis2 server instances are started under the startAxis2Server method. In order to start the server, you need to provide the axis.xml configuration. As this sample test_axis2_server_9003.xml and test_axis2_server_9004.xml must exist in the resources/artifacts/AXIS2/config directory and the ports must be configured properly.
You need to place the service files in the directory at resources/artifacts/AXIS2/aar
.
public class Axis2ServerTest { private Axis2ServerManager axis2Server1; private Axis2ServerManager axis2Server2; @BeforeClass(alwaysRun = true) public void startAxis2Server() throws IOException { axis2Server1 = new Axis2ServerManager("test_axis2_server_9003.xml"); axis2Server2 = new Axis2ServerManager("test_axis2_server_9004.xml"); axis2Server1.deployService("SimpleStockQuoteService"); axis2Server1.start(); axis2Server2.deployService("SimpleStockQuoteService"); axis2Server2.start(); } @Test() public void invokeServiceInAxis2Server1() throws AxisFault { StockQuoteClient client = new StockQuoteClient(); OMElement response = client.sendSimpleStockQuoteRequest("http://localhost:9003/services/SimpleStockQuoteService", null, "WSO2"); String company = response.getFirstElement().getFirstChildWithName(new QName("http://services.samples/xsd", "name")).getText(); Assert.assertEquals(company, "WSO2 Company", "Invalid response"); } @Test() public void invokeServiceInAxis2Server2() throws AxisFault { StockQuoteClient client = new StockQuoteClient(); OMElement response = client.sendSimpleStockQuoteRequest("http://localhost:9004/services/SimpleStockQuoteService", null, "WSO2"); String company = response.getFirstChildWithName(new QName("http://services.samples/xsd", "name")).getText(); Assert.assertEquals(company, "WSO2 Company", "Invalid response"); } @AfterClass(alwaysRun = true) public void stopAxi2Server() { if (axis2Server1 != null) { axis2Server1.stop(); } if (axis2Server2 != null) { axis2Server2.stop(); } } }