JAX-RS Integration Testing with Apache CXF
The Jakarta RESTful Web Services (formerly Java API for RESTful Web Services) specification provides a robust framework for writing RESTful (and not-so-RESTful) web services in Java. The JAX-RS API allows for Resource (the service itself) and Provider (enrichers providing cross-cutting concerns) implementations to be written in a very modular, testable way.There are times, however, when the API requires a little “magic” that only works well when the code is running within the context of a real JAX-RS implementation. The Apache CXF project provides a JAX-RS implementation module which we can use to test our JAX-RS code in its native environment. First, we need to set up our local development environment.
An example project has been created for your convenience. To get started, simply clone the project to your local workstation:
The example project uses Apache Maven and it already contains all dependencies you will need for following along with the code in this article. You should just need to import the project into your IDE and we can get started creating our first JAX-RS resource.
A Simple Resource
Although not required, it’s best to define your JAX-RS API using an interface: