QAF provides support classes for Webservice Testing. It displays all details of web services request/response in QAF Report.

You can create a new test case or suit by extending RestWSTestCase class.

On extending RestWSTestCase following object will be available to use in your test.

  1. WebResource

    WebResource instance can be accessed using getWebResource method. WebResource is a useful class to specify request body, headers and invoking Http Requests.

  2. Client

    Client instance can be accessed using getClient method. Client instance is useful for configuring the properties of connections and requests.

  3. Response

    Response instance can be accessed using getResponse method. Using response class user can access response status code, response body and response headers.

  4. Validation Methods

    All the methods of Validator can be accessed directly in testcase or suite.


Below is an sample example to invoke http request and verify response code using QAF.

public class Wstest extends RestWSTestCase {

	@Test(testName = "create order")
	public void createOrder() {

		//request data
		Map<String, String> data = new HashMap<String, String>();
		data.put("clientName", "Amit");
		data.put("amount", "100");
		//create post request
		getWebResource("/orders.json").post(new Gson().toJson(data));
		//verify response
		verifyThat("Response Status", getResponse().getStatus(), Matchers.equalTo(Status.CREATED));

For more reference visit Jersey Client API Documentation.

Tags: java