Arquillian REST Extension 1.0.0.Alpha1 Released

Since we wrote this post we didn't laze around. Check our latest announcement.

The Arquillian team is proud to announce the 1.0.0.Alpha1 release of the Arquillian REST Extension component!

This is the first release of the Arquillian REST extension.

At the moment it consist of two complementary parts:

REST client

Simplifies writing the client side of testing REST services

Warp REST extension

An extension, that with a bit of magic allows you to intercept the state of the Service prior or after to it’s execution

REST client

Sometimes you need to test your REST app as a black box. You know the interface (the contract), you have some input and know what results you expect. For this purpose Arquillian REST Client Extension is your friend. It makes your code shorter by injecting configured artifacts. The extension is based on the RestEasy client library. Both RestEasy 2.x and 3.x are supported. You only need to add the proper dependency to your classpath.

@RunWith(Arquillian.class)
public class RestClientTestCase {

  @ArquillianResource
  private URL deploymentURL;

  @Deployment(testable = false)
  public static WebArchive create()
  {
      return ShrinkWrap.create(WebArchive.class)
          .addPackage(Customer.class.getPackage())
          .addClasses(CustomerResource.class, CustomerResourceImpl.class, JaxRsActivator.class);
  }

  /**
   * Arquillian calculates resource path by using deployment URL+ArquillianResteasyResource.value
   * which is by default "rest". If your API is located under different root i.e.
   * "api_v2" then use @ArquillianResteasyResource("api_v2")
   *
   * @param customerResource configured resource ready for use, injected by Arquillian
   */
  @Test
  public void getCustomerById(@ArquillianResteasyResource CustomerResource customerResource)
  {
      // Given
      final String name = "Acme Corporation";
      final long customerId = 1L;

      // When
      final Customer result = customerResource.getCustomerById(customerId);

      // Then
      assertNotNull(result);
      assertNotNull(result.getId());
      assertEquals(name, result.getName());
  }
}

For more examples on how to use these extensions and quickly get started with development you can take a look at the integration tests that are part of project source code.

Warp REST

Arquillian Warp makes it possible to perform a gray-box testing of any servlet based in-container application. Now we are introducing an API that allows you to intercept the state of the REST services and validate the generated response including, but not limiting to the security context, response HTTP status code, HTTP headers and the response entities. The actual HTTP servlet request and responses are also being recorded, allowing you to verify them directly on the server. All of this happens in the application container, before the response is returned to the invoking client!

The WARP extension targets JAX-RS major versions and already has support for JAX-RS 1.1 and 2.0.

The JAX-RS 1.1 specification did not define any support for request interception, while this has been widely supported through implementation specific hooks, that is why in order to use the extension with JAX-RS 1.1 one of JAX-RS provider specific implementation need to be chosen. Fortunately we already support most the popular providers:

  • RESTEasy
  • Jersey
  • CXF

Now, let’s write some code:

StockServiceResourceTestCase.java
@Test
@RunAsClient
public void testStockGetWarp() {

  Warp.initiate(new Activity() {
      @Override
      public void perform() {

          // invokes the service
          stockService.getStock(1L);
      }
  }).inspect(new Inspection() {

      private static final long serialVersionUID = 1L;

      @ArquillianResource
      private RestContext restContext;

      @AfterServlet
      public void testGetStock() {

          // validates the service response
          assertEquals(HttpMethod.GET, restContext.getHttpRequest().getMethod());
          assertEquals(200, restContext.getHttpResponse().getStatusCode());
          assertEquals("application/json", restContext.getHttpResponse().getContentType());
          assertNotNull(restContext.getHttpResponse().getEntity());
      }
  });
}

For more examples on how to use these extensions and quickly get started with development you can take a look at the integration tests that are part of the projects source code.

We look forward to hearing your feedback about this release in the community forums!

What is Arquillian?

Arquillian is open source software that empowers you to test JVM-based applications more effectively. Created to defend the software galaxy from bugs, Arquillian brings your test to the runtime so you can focus on testing your application's behavior rather than managing the runtime. Using Arquillian, you can develop a comprehensive suite of tests from the convenience of your IDE and run them in any IDE, build tool or continuous integration environment.

Release details

Component Arquillian REST Extension
Version 1.0.0.Alpha1 view tag
Release date 2013-10-23
Released by Aslak Knutsen
Compiled against

Published artifacts org.jboss.arquillian.extension

  • org.jboss.arquillian.extension » arquillian-rest-client-api jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-rest-client-impl-base jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-rest-client-impl-2x jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-rest-client-impl-3x jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-rest-warp-api jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-rest-warp-spi jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-rest-warp-impl-base jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-rest-warp-impl-resteasy jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-rest-warp-impl-jersey jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-rest-warp-impl-cxf jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-rest-warp-impl-jaxrs-2.0 jar javadoc pom
  • org.jboss.arquillian.extension » arquillian-rest-warp-bom pom

Release notes and resolved issues 3

Feature Request
  • ARQ-912 - Setup a declarative REST testing extension
  • ARQ-1341 - Warp JAX-RS testing

Thanks to the following list of contributors: Bernard Labno, Aslak Knutsen, Jakub Narloch, Lukas Fryc