ReXSL

07-May-2013 0.4.12

RESTful Java Client

The module contains a collection of usable tools for testing of ReXSL-powered application (or any other RESTful server). RestTester is a RESTful Java client with a fluent interface:

public class Main {
  public void main() {
    String body = RestTester.start("http://www.rexsl.com")
      .header(HttpHeaders.USER_AGENT, "Safari 4")
      .header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML)
      .get("reading front page of ReXSL.com")
      .assertStatus(HttpURLConnection.HTTP_OK)
      .assertBody(Matchers.containsString("ReXSL"))
      .assertXPath("//xhtml:body")
      .getBody();
  }
}

The beauty of this RESTful Java client (comparing to others) is that it retrieves data and makes test assertions at the same time. Your integration tests will automatically validate your RESTful client against the contract (API) of the server.

Other important classes in this module:

Include this dependency into your project (or download rexsl-test-0.4.12.jar and add to classpath):

<dependency>
  <groupId>com.rexsl</groupId>
  <artifactId>rexsl-test</artifactId>
  <version>0.4.12</version>
  <scope>test</scope>
</dependency>

This RESTful Java client module also contains a very useful Mocking tool in com.rexsl.test.ContainerMocker. To use it you should include this dependencies into your project (or download rexsl-test-0.4.12-mock.jar and add to classpath):

<dependency>
  <groupId>com.rexsl</groupId>
  <artifactId>rexsl-test</artifactId>
  <version>0.4.12</version>
  <classifier>mock</classifier>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>com.sun.grizzly</groupId>
  <artifactId>grizzly-servlet-webserver</artifactId>
  <version>1.9.10</version>
  <scope>test</scope>
</dependency>

Copyright © 2011-2013 ReXSL.com, All Rights Reserved. Privacy Policy.

site is built by Apache Maven