Java Code Examples for org.wso2.carbon.automation.test.utils.axis2client.AxisServiceClient#sendReceive()

The following examples show how to use org.wso2.carbon.automation.test.utils.axis2client.AxisServiceClient#sendReceive() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test(groups = { "wso2.dss" }, dependsOnMethods = { "addOffice" })
public void getOffices() throws AxisFault, XPathExpressionException {
    AxisServiceClient serviceClient = new AxisServiceClient();
    OMElement response = serviceClient
            .sendReceive(getPayloadGetOffice(), getServiceUrlHttp(serviceName), "showAllOffices");
    Assert.assertNotNull(response, "Response Message in null");
    Iterator<OMElement> itr = response.getChildrenWithName(new QName("Office"));
    int recordCount = 0;
    while (itr.hasNext()) {
        OMElement office = itr.next();
        Assert.assertNotNull(office.getAttribute(new QName("officeCode")),
                "officeCode attribute not found with response");
        Assert.assertFalse(office.getAttributeValue(new QName("officeCode")).equalsIgnoreCase(""),
                "Attribute Name officeCode value empty");

        if (office.getAttribute(new QName("country")) != null) {
            Assert.assertFalse(office.getAttributeValue(new QName("country")).equalsIgnoreCase(""),
                    "Attribute Name country value empty");
        }

        ++recordCount;
    }
    Assert.assertEquals(recordCount, 10, "All offices on the table not in response.invalid response. "
            + "because one of attribute value is null");

}
 
Example 2
@Test(groups = "wso2.dss", dependsOnMethods = {
        "serviceReDeployment" }, description = "send requests to redeployed service")
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
public void serviceInvocation() throws RemoteException, ServiceAdminException, XPathExpressionException {
    OMElement response;
    String serviceEndPoint = getServiceUrlHttp(serviceName) + "/";
    AxisServiceClient axisServiceClient = new AxisServiceClient();
    for (int i = 0; i < 5; i++) {
        response = axisServiceClient.sendReceive(getPayload(), serviceEndPoint, "showAllOffices");
        Assert.assertTrue(response.toString().contains("<Office>"), "Expected Result not Found");
        Assert.assertTrue(response.toString().contains("<officeCode>"), "Expected Result not Found");
        Assert.assertTrue(response.toString().contains("<city>"), "Expected Result not Found");
        Assert.assertTrue(response.toString().contains("<phone>"), "Expected Result not Found");
        Assert.assertTrue(response.toString().contains("</Office>"), "Expected Result not Found");
    }
    log.info("service invocation success");
}
 
Example 3
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = "wso2.esb", description = "<property name=\"RETRY_ON_SOAPFAULT\" value=\"false\"/>")
public void testRetryOnSOAPFaultWithInOutFalse() throws Exception {

    loadESBConfigurationFromClasspath(
            File.separator + "artifacts" + File.separator + "ESB" + File.separator + "synapseconfig"
                    + File.separator + "processor" + File.separator + "forwarding" + File.separator
                    + "Retry_On_SOAPFault_In_Out.xml");

    AxisServiceClient serviceClient = new AxisServiceClient();
    serviceClient.fireAndForget(clearCountRequest(), getBackEndServiceUrl(), "clearRequestCount");
    OMElement requestCount = serviceClient
            .sendReceive(getCountRequest(), getBackEndServiceUrl(), "getRequestCount");
    Assert.assertEquals(requestCount.getFirstElement().getText(), "0", "Request Cunt not clear");

    serviceClient.sendRobust(getThrowAxisFaultRequest(), getMainSequenceURL(), "urn:throwAxisFault");
    Thread.sleep(5000);
    requestCount = serviceClient.sendReceive(getCountRequest(), getBackEndServiceUrl(), "getRequestCount");
    Assert.assertEquals(requestCount.getFirstElement().getText(), "1",
            "Request Count mismatched. Sent more than one request");

}
 
Example 4
public void testRetryOnSOAPFaultWithInOutTrue() throws Exception {

        loadESBConfigurationFromClasspath(
                File.separator + "artifacts" + File.separator + "ESB" + File.separator + "synapseconfig"
                        + File.separator + "processor" + File.separator + "forwarding" + File.separator
                        + "Retry_On_SOAPFault_true_In_Out.xml");

        AxisServiceClient serviceClient = new AxisServiceClient();
        serviceClient.fireAndForget(clearCountRequest(), getBackEndServiceUrl(), "clearRequestCount");
        OMElement requestCount = serviceClient
                .sendReceive(getCountRequest(), getBackEndServiceUrl(), "getRequestCount");
        Assert.assertEquals(requestCount.getFirstElement().getText(), "0", "Request Cunt not clear");

        serviceClient.sendRobust(getThrowAxisFaultRequest(), getMainSequenceURL(), "throwAxisFault");
        Thread.sleep(5000);
        requestCount = serviceClient.sendReceive(getCountRequest(), getBackEndServiceUrl(), "getRequestCount");
        Assert.assertEquals(requestCount.getFirstElement().getText(), "5",
                "Request Count mismatched. Not sent all request");

    }
 
Example 5
@Test(groups = {"wso2.dss"}, dependsOnMethods = {"addOffice"})
public void getOffices() throws AxisFault, XPathExpressionException {
    AxisServiceClient serviceClient = new AxisServiceClient();
    OMElement response = serviceClient.sendReceive(getPayloadGetOffice(), getServiceUrlHttp(serviceName), "showAllOffices");
    Assert.assertNotNull(response, "Response Message in null");
    Iterator<OMElement> itr = response.getChildrenWithName(new QName("Office"));
    int recordCount = 0;
    while (itr.hasNext()) {
        OMElement office = itr.next();
        Assert.assertNotNull(office.getAttribute(new QName("officeCode")), "officeCode attribute not found with response");
        Assert.assertFalse(office.getAttributeValue(new QName("officeCode")).equalsIgnoreCase(""), "Attribute Name officeCode value empty");

        if (office.getAttribute(new QName("country")) != null) {
            Assert.assertFalse(office.getAttributeValue(new QName("country")).equalsIgnoreCase(""), "Attribute Name country value empty");
        }

        ++recordCount;
    }
    Assert.assertEquals(recordCount, 10, "All offices on the table not in response.invalid response. " +
                                         "because one of attribute value is null");

}
 
Example 6
@Test(groups = "wso2.dss", dependsOnMethods = {"serviceReDeployment"},
      description = "send requests to redeployed service")
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
public void serviceInvocation()
        throws RemoteException, ServiceAdminException, XPathExpressionException {
    OMElement response;
    String serviceEndPoint = getServiceUrlHttp(serviceName) +"/";
    AxisServiceClient axisServiceClient = new AxisServiceClient();
    for (int i = 0; i < 5; i++) {
        response = axisServiceClient.sendReceive(getPayload(), serviceEndPoint, "showAllOffices");
        Assert.assertTrue(response.toString().contains("<Office>"), "Expected Result not Found");
        Assert.assertTrue(response.toString().contains("<officeCode>"), "Expected Result not Found");
        Assert.assertTrue(response.toString().contains("<city>"), "Expected Result not Found");
        Assert.assertTrue(response.toString().contains("<phone>"), "Expected Result not Found");
        Assert.assertTrue(response.toString().contains("</Office>"), "Expected Result not Found");
    }
    log.info("service invocation success");
}
 
Example 7
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = "wso2.esb", description = "<property name=\"RETRY_ON_SOAPFAULT\" value=\"false\"/>")
public void testRetryOnSOAPFaultWithInOutFalse() throws Exception {

    loadESBConfigurationFromClasspath(File.separator + "artifacts" + File.separator + "ESB" + File.separator
                                      + "synapseconfig" + File.separator + "processor" + File.separator +
                                      "forwarding" + File.separator + "Retry_On_SOAPFault_In_Out.xml");

    AxisServiceClient serviceClient = new AxisServiceClient();
    serviceClient.fireAndForget(clearCountRequest(), getBackEndServiceUrl(), "clearRequestCount");
    OMElement requestCount = serviceClient.sendReceive(getCountRequest(), getBackEndServiceUrl(), "getRequestCount");
    Assert.assertEquals(requestCount.getFirstElement().getText(), "0", "Request Cunt not clear");

    serviceClient.sendRobust(getThrowAxisFaultRequest(), getMainSequenceURL(), "urn:throwAxisFault");
    Thread.sleep(5000);
    requestCount = serviceClient.sendReceive(getCountRequest(), getBackEndServiceUrl(), "getRequestCount");
    Assert.assertEquals(requestCount.getFirstElement().getText(), "1", "Request Count mismatched. Sent more than one request");

}
 
Example 8
public void testRetryOnSOAPFaultWithInOutTrue() throws Exception {

        loadESBConfigurationFromClasspath(File.separator + "artifacts" + File.separator + "ESB" + File.separator
                                          + "synapseconfig" + File.separator + "processor" + File.separator +
                                          "forwarding" + File.separator + "Retry_On_SOAPFault_true_In_Out.xml");

        AxisServiceClient serviceClient = new AxisServiceClient();
        serviceClient.fireAndForget(clearCountRequest(), getBackEndServiceUrl(), "clearRequestCount");
        OMElement requestCount = serviceClient.sendReceive(getCountRequest(), getBackEndServiceUrl(), "getRequestCount");
        Assert.assertEquals(requestCount.getFirstElement().getText(), "0", "Request Cunt not clear");

        serviceClient.sendRobust(getThrowAxisFaultRequest(), getMainSequenceURL(), "throwAxisFault");
        Thread.sleep(5000);
        requestCount = serviceClient.sendReceive(getCountRequest(), getBackEndServiceUrl(), "getRequestCount");
        Assert.assertEquals(requestCount.getFirstElement().getText(), "5", "Request Count mismatched. Not sent all request");

    }
 
Example 9
@Test(groups = "wso2.esb", description = "invoke service - operation echoString")
public void invokeServiceFromXmlRequest() throws AxisFault {

    AxisServiceClient axisServiceClient = new AxisServiceClient();

    OMElement response = axisServiceClient.sendReceive(createPayload(),
            contextUrls.getServiceUrl() + "/ProxyPF", "echoString");

    assertTrue(response.toString().contains("[email protected]"), "Response mismatch. " +
            "Actual Response " + response.toString());
}
 
Example 10
@Test(groups = "wso2.esb", description = "invoke service - operation echoString")
public void invokeServiceFromXmlRequest() throws AxisFault {

    AxisServiceClient axisServiceClient = new AxisServiceClient();
    OMElement response = axisServiceClient.sendReceive(createPayload(),
            contextUrls.getServiceUrl() + "/ProxyPF", "echoString");
    assertTrue(response.toString().contains("Wso2 Test Automation"),"Response mismatch. " +
            "Actual Response "+response.toString());
}
 
Example 11
@Test(groups = "wso2.dss", dependsOnMethods = { "requestStatusNameSpaceQualifiedForDeleteOperation" }, timeOut =
        1000 * 60 * 2)
public void inOperationConcurrencyTest() throws InterruptedException, ConcurrencyTestFailedError {

    final ExceptionHandler handler = new ExceptionHandler();
    final int concurrencyNumber = 50;
    final int numberOfIterations = 1;
    Thread[] clientThread = new Thread[concurrencyNumber];
    final AxisServiceClient serviceClient = new AxisServiceClient();
    for (int i = 0; i < concurrencyNumber; i++) {
        final int empNo = i + 50;
        clientThread[i] = new Thread(() -> {
            for (int j = 0; j < numberOfIterations; j++) {
                try {
                    OMElement response = serviceClient
                            .sendReceive(getAddEmployeePayload(empNo + ""), serviceEndPoint, "addEmployee");
                    assertTrue(response.toString().contains("SUCCESSFUL"), "Response Not Successful");
                    OMNamespace nameSpace = response.getNamespace();
                    Assert.assertNotNull(nameSpace, "Response Message NameSpace not qualified");
                } catch (AxisFault axisFault) {
                    log.error(axisFault);
                    handler.setException(axisFault);
                }
            }
        });
        clientThread[i].setUncaughtExceptionHandler(handler);

    }

    for (int i = 0; i < concurrencyNumber; i++) {
        clientThread[i].start();
    }

    for (int i = 0; i < concurrencyNumber; i++) {
        try {
            clientThread[i].join();
        } catch (InterruptedException e) {
            throw new InterruptedException("Exception Occurred while joining Thread");
        }
    }

    if (!handler.isTestPass()) {
        throw new ConcurrencyTestFailedError(handler.getFailCount() + " service invocation/s failed out of "
                + concurrencyNumber * numberOfIterations + " service invocations.\n"
                + "Concurrency Test Failed for Thread Group=" + concurrencyNumber + " and loop count="
                + numberOfIterations, handler.getException());
    }
}
 
Example 12
@Test(groups = "wso2.dss", dependsOnMethods = {"requestStatusNameSpaceQualifiedForDeleteOperation"}, timeOut = 1000 * 60 * 2)
public void inOperationConcurrencyTest() throws InterruptedException,
                                                ConcurrencyTestFailedError {

    final ExceptionHandler handler = new ExceptionHandler();
    final int concurrencyNumber = 50;
    final int numberOfIterations = 1;
    Thread[] clientThread = new Thread[concurrencyNumber];
    final AxisServiceClient serviceClient = new AxisServiceClient();
    for (int i = 0; i < concurrencyNumber; i++) {
        final int empNo = i + 50;
        clientThread[i] = new Thread(new Runnable() {
            public void run() {
                for (int j = 0; j < numberOfIterations; j++) {
                    try {
                        OMElement response = serviceClient.sendReceive(getAddEmployeePayload(empNo + ""),
                                                                       serviceEndPoint, "addEmployee");
                        Assert.assertTrue(response.toString().contains("SUCCESSFUL"), "Response Not Successful");
                        OMNamespace nameSpace = response.getNamespace();
                        Assert.assertNotNull(nameSpace, "Response Message NameSpace not qualified");
                    } catch (AxisFault axisFault) {
                        log.error(axisFault);
                        handler.setException(axisFault);
                    }
                }
            }
        });
        clientThread[i].setUncaughtExceptionHandler(handler);

    }

    for (int i = 0; i < concurrencyNumber; i++) {
        clientThread[i].start();
    }

    for (int i = 0; i < concurrencyNumber; i++) {
        try {
            clientThread[i].join();
        } catch (InterruptedException e) {
            throw new InterruptedException("Exception Occurred while joining Thread");
        }
    }

    if (!handler.isTestPass()) {
        throw new ConcurrencyTestFailedError(handler.getFailCount() + " service invocation/s failed out of "
                                             + concurrencyNumber * numberOfIterations + " service invocations.\n"
                                             + "Concurrency Test Failed for Thread Group=" + concurrencyNumber
                                             + " and loop count=" + numberOfIterations, handler.getException());
    }
}