nagendra
nagendra

Reputation: 593

How to write some standalone restful tests for a web application

Any framework in java to write simple rest tests for testing some restful calls.

I came across JerseyTest. But didn't find an example how to write a simple test

Upvotes: 1

Views: 2123

Answers (2)

Jay
Jay

Reputation: 9477

You could test the Rest API using Apache HttpClient libraries. An example Java code would looks like below.

            String uri = "http://localhost:7001/myapis/search/json";
            URIBuilder uriBuilder = new URIBuilder(uri);
            uriBuilder.addParameter("institutionName", "HSBC%");
            uriBuilder.addParameter("isoCountryCode", "GB");

            HttpGet httpGet = new HttpGet(uriBuilder.build());
            HttpClient httpClient = new DefaultHttpClient();
            HttpResponse httpResponse = httpClient.execute(httpGet);
            HttpEntity httpEntity = httpResponse.getEntity();
            String result = EntityUtils.toString(httpEntity);

Upvotes: 0

TheEwook
TheEwook

Reputation: 11117

Yes you can use Jersey-Test-Framework.

You can find an example here:

http://www.hascode.com/2011/09/rest-assured-vs-jersey-test-framework-testing-your-restful-web-services/

You can also use REST Assured. With an example here

http://www.hascode.com/2011/10/testing-restful-web-services-made-easy-using-the-rest-assured-framework/

Upvotes: 2

Related Questions