An open-source JUnit extension to test HTTP/REST APIs

Everything you need to know to get started is displayed in the snippet below which is a fully functional HTTP Test.

This test sends a request to restfuse.com before the test method will be executed. After the request returns the response will be injected by assigning the @Context annotated response field before the test method will be executed. This field can be used within the test method to test the content of the response. By the way, restfuse also supports the testing of asynchronous REST services.

Regardless for what you are using asynchronous mechanisms, you only have two options to deal with it: Polling or Callbacks. Both methods are supported by restfuse.

Polling

When you need to poll an asynchronous service more than once you can use the @Poll annotation. A simple example looks like the one below. The service in this example will be called 5 times as the same as the test method. The response for each request will be injected into the test object and can be tested.

Callbacks

To use a callback to test an asynchronous service you can use the @Callback annotation on you test method. Restfuse will start a server on the defined port and registers a resource. The test fails if the attached resource was not called. Within the resource you can test the incoming request. A simple callback example looks like this.