Forum Discussion

jedizippy's avatar
jedizippy
New Contributor
16 years ago

Retrieving Response from Test Step using Java API

Hi,

We are using the java API to invoke WSDL test requests for our web services using the WSDLTestCaseRunner. When the test competes (or fails) we can print out the reason codes or messages but we wish to pick up for the example the web service responses. How can this be achieved ? The code we are using is shown below but we cant seem to figure out how to get the test case step responses so that we can print them to log4j so we can see what is happening when for example the web service call fails or we got soap faults etc, or its successful in which case it would be nice to see the SOAP response ?.

project = new WsdlProject(projectName);
testSuite = project.getTestSuiteByName(testSuiteName);
testCase = testSuite.getTestCaseByName(TEST_CASE_NAME_JUNIT);
                 
runner = new WsdlTestCaseRunner(testCase, new StringToObjectMap());
runner.start(false);

List results = runner.getResults();
if (results != null && results.size() > 0) {
  Iterator it = results.iterator();
  while (it.hasNext()) {
      TestStepResult thisResult = (TestStepResult) it.next();
                               
      String[] messages = thisResult.getMessages();
      if (messages != null && messages.length > 0) {
          for(String message : messages) {
              logger.debug("SOAUP UI Message: " + message);    }
          }
                                           
          Throwable error = thisResult.getError();
          if (error != null) {
              Logger.error("Reason Message: " + thisResult.getError());
          }
      }
}

1 Reply

  • jedizippy's avatar
    jedizippy
    New Contributor
    Ok after some investigation I found the answer which is as simple as expected. The TestStepResult can be cast to an WSDLTestRequestStepResult and then the content can be accessed as follows:-

    if (thisResult instanceof WsdlTestRequestStepResult) {
        WsdlTestRequestStepResult wsdlResult = (WsdlTestRequestStepResult ) thisResult;
        logger.debug("Response Content: " + wsdlResult.getResponseContent();
    }