bmarwell / jaxrs-test-showcase

How to test JAX-RS using various means. Be it unit tests, arquillian, starting a server or fireing up a container

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JAX-RS Test Showcase

Maven CI renovate Apache License v2.0 codecov

JAX-RS is a popular JavaEE standard to create RESTful endpoints in Java easily. However, it is not always clear for new learners how to test those endpoints properly.

Project setup

JSON-P, JSON-B and JAX-RS implementations

As JAX-RS is only a standard and is usually used in conjunction with JSON, there are unsurprisingly multiple implementations for those standards available.

Table 1. JAX-RS implementations
Vendor Library Name License

Apache Foundation

Apache CXF

Apache License 2.0

Eclipse Foundation

Eclipse Jersey (reference implementation)

Eclipse Public License 2.0

JBoss by RedHat

JBoss restEasy

Apache License 2.0

You can also switch the JSON-B and JSON-P implementations. However, both of them can only be switched at the same time.

Table 2. JSON implementations
Vendor Library Name License

Apache Foundation

Apache Johnzon

Apache License 2.0

Eclipse Foundation

Eclipse Yasson (reference implementation)

Eclipse Public License 2.0

Where useful, tests are duplicated to be run on all combinations of implementations.

Web-API and Web-Impl projects

First we need an endpoint to test. For this reason, there are the modules web/rest-api and web/rest-impl. Please note that it is often not required to have a separate api project. This is YAGNI (you ain’t gonna need it) in most cases. However, separating the API from the implementation allows you (or others) to re-use the jar file from the API project for the Proxy-based API.

Test projects

Table 3. System tests
module path JAX-RS impl JSON impl

systemtests/cxf-localtp-johnzon

Apache CXF

Apache Johnzon

systemtests/jersey-grizzly2-johnzon

Eclipse Jersey

Apache Johnzon

systemtests/jersey-grizzly2-yasson

Eclipse Jersey

Eclipse Yasson

Table 4. Integration tests
module path Container/App server

Built with Toolchains

This project makes use of both the maven-toolchain-plugin to accept IBM Semeru Runtimes for tests and the toolchains-maven-plugin for downloading the JDK first (if required).

About

How to test JAX-RS using various means. Be it unit tests, arquillian, starting a server or fireing up a container

License:Apache License 2.0


Languages

Language:Java 100.0%