This is a simple project which allows a unit testing for Jakarta REST endpoints using the SeBootstrap from
Jakarta REST 3.1.
For complete documentation including advanced features, extension points, and best practices, see the full documentation.
The documentation is also published to GitHub Pages with each release: https://resteasy.dev/resteasy-junit-extension/
To use this JUnit integration you simply need to add a @RestBootstrap(YourApplication.class) annotation to your test. A
SeBoostrap.Instance will be created and started based on the implementation you choose.
The first dependency you need is the JUnit extension.
<dependencies>
<dependency>
<groupId>dev.resteasy.junit.extension</groupId>
<artifactId>resteasy-junit-extension</artifactId>
<version>${version.dev.resteasy.junit.extension</version>
</dependency>
</dependencies>Next you need to define an implementation. This project chose not to be implementation specific and should work with any Jakarta REST 3.1+ implementation.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-bom</artifactId>
<version>${version.org.jboss.resteasy}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${version.org.junit}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-core-spi</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-undertow-cdi</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>@RestBootstrap(value = SimpleTest.TestApplication.class)
public class SimpleTest {
@RestResource
@RequestPath("/test/echo")
private WebTarget webTarget;
@Test
public void invokeResource(final UriBuilder builder) {
try (Client client = ClientBuilder.newClient()) {
final String result = client.target(builder.path("/test/echo/"))
.request()
.post(Entity.text("Hello"), String.class);
Assertions.assertEquals("Hello", result);
}
}
@Test
public void invokeResourceOnInjectedClient() {
final String result = webTarget.request()
.post(Entity.text("Hello"), String.class);
Assertions.assertEquals("Hello", result);
}
@ApplicationPath("/test")
public static class TestApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
return Set.of(EchoResource.class);
}
}
@Path("/echo")
public static class EchoResource {
@POST
public String echo(String text) {
return text;
}
}
}You can inject some types into your tests. For fields you use the @RestResource annotation. Constructor and
method parameters do not require the @RestResource annotation. The following types can be injected.
-
jakarta.ws.rs.SeBootstrap.ConfigurationThe configuration from the
SeBoostrap.Instancethat was started. -
jakarta.ws.rs.client.ClientA REST Client. This can have a qualifier of
@RestClientConfigwhich returns aRestClientBuilderProviderand allows the configuration to be overridden for the client. -
jakarta.ws.rs.core.UriBuilderInjects a URI builder. Given this is a mutable builder, this should likely only be injected as a method parameter.
-
java.net.URIThe base URI for
SeBootstrap.Instancethat was started. -
jakarta.ws.rs.client.WebTargetThis can be used with the
@RequestPathqualifier. It creates aWebTargetfrom a configured client.
| Type | Field | Parameter | Constructor | Qualifiers |
|---|---|---|---|---|
|
X |
X |
X |
|
|
X |
X |
X |
|
|
X |
X |
||
|
X |
X |
X |
|
|
X |
X |
X |
|
Releasing the project requires permission to deploy to Maven Central see Maven Central Release Requirements.
Once everything is setup, you simply need to run the ./release.sh script. There are two required parameters:
-
-ror--releasewhich is the version you want to release -
-dor--developmentwhich is the next development version.
By default the release version cannot contain SNAPSHOT and the development version, must container SNAPSHOT.
.Example Command| Argument | Requires Value | Description |
|---|---|---|
|
Yes |
The next version for the development cycle. |
|
No |
Forces to allow a SNAPSHOT suffix in release version and not require one for the development version. |
|
N/A |
Displays this help |
|
Unused |
Passes the |
|
Unused |
Passes the |
|
Yes |
The version to be released. Also used for the tag. |
|
No |
Executes the release in as a dry-run. Nothing will be updated or pushed. |
|
No |
Executes the release in, but doesn’t actually push the changes to GitHub or publish the release on Maven Central. Any next steps should you want to continue the release will need to be manual. |
|
No |
Prints verbose output. |
Any additional arguments are considered arguments for the Maven command.