https://github.com/t1/jax-rs-test-extension
JUnit-5 extension to help testing JAX-RS infrastructure classes
https://github.com/t1/jax-rs-test-extension
integration-testing jax-rs junit5
Last synced: 5 months ago
JSON representation
JUnit-5 extension to help testing JAX-RS infrastructure classes
- Host: GitHub
- URL: https://github.com/t1/jax-rs-test-extension
- Owner: t1
- License: apache-2.0
- Archived: true
- Created: 2019-10-04T12:46:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-31T17:49:13.000Z (about 4 years ago)
- Last Synced: 2025-07-10T00:47:44.347Z (12 months ago)
- Topics: integration-testing, jax-rs, junit5
- Language: Java
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
Awesome Lists containing this project
README
= JAX-RS Test Extension image:https://maven-badges.herokuapp.com/maven-central/com.github.t1/jax-rs-test-extension/badge.svg[link=https://search.maven.org/artifact/com.github.t1/jax-rs-test-extension]
[IMPORTANT]
This project has been archived!!!
http://com.github/t1/wunderbar[WunderBar] might be a better fit for your use-case.
Very simple (and fast) https://junit.org/junit5/[JUnit-5] extension to test JAX-RS infrastructure classes. Uses RestEasy + Undertow internally, but you shouldn't notice that too often; just stick to JAX-RS + JSON-B.
There are two use-cases:
== 1. Boundaries
These are your classes that provide a REST service using JAX-RS server API; i.e.:
[source,java]
---------------------------------------------------------------
@Path("/") public class MyBoundary {
@GET public String get() { return "foo"; }
}
---------------------------------------------------------------
Could be tested like this:
[source,java]
---------------------------------------------------------------
public class MyBoundaryTest {
@RegisterExtension static JaxRsClientTest jaxRs = new JaxRsClientTest(new MyBoundary());
@Test public void shouldGet() {
Response response = jaxRs.GET("/");
assertThat(response.getStatusInfo()).isEqualTo(OK);
assertThat(response.readEntity(String.class)).isEqualTo("foo");
}
}
---------------------------------------------------------------
== 2. Gateways
These are your classes that consume a REST service using the JAX-RS client API, and you don't want to integrate with the real external service; i.e.:
[source,java]
---------------------------------------------------------------
public class MyGateway {
Client client;
URI baseUri;
public String getFoo() {
Response response = client.target(baseUri).request(TEXT_PLAIN_TYPE).get();
assert 200 == response.getStatus();
return response.readEntity(String.class);
}
}
---------------------------------------------------------------
Could be tested like this:
[source,java]
---------------------------------------------------------------
public class MyGatewayTest {
@Path("/") public static class MockService {
@GET public String get() { return "foo"; }
}
@RegisterExtension static JaxRsTestExtension jaxRs = new JaxRsTestExtension(new MockService());
@Test void shouldGet() {
MyGateway gateway = new MyGateway();
gateway.client = jaxRs.client();
gateway.baseUri = jaxRs.baseUri();
String foo = gateway.getFoo();
assertThat(foo).isEqualTo("foo");
}
}
---------------------------------------------------------------
== Limitations
1. There is no dependency injection, etc. You'll have to pass in fully built JAX-RS service instances.
2. This is _not_ for integration tests! E.g. it uses it's own `Application` class. These test qualify as a unit tests: they only test your Boundary or Gateway in isolation.