Quarkus WireMock
Quarkus WireMock extension for tests and local development.
Installation
If you want to use this extension, you need to add the io.quarkiverse.wiremock:quarkus-wiremock
extension first to your build file.
For instance, with Maven, add the following dependency to your POM file:
<dependency>
<groupId>io.quarkiverse.wiremock</groupId>
<artifactId>quarkus-wiremock</artifactId>
<version>0.1.2</version>
<scope>test</scope>
</dependency>
Usage
The extension is designed to run in dev and test mode only! Please don’t specify any attributes applicable for the prod profile, otherwise unknown property warnings will show up when executing the production build.
|
Example (default) configuration for testing and local development:
%dev,test.quarkus.wiremock.devservices.enabled=true
%dev,test.quarkus.wiremock.devservices.reload=false
%dev,test.quarkus.wiremock.devservices.files-mapping=src/test/resources
%dev,test.quarkus.wiremock.devservices.port=8089
%dev,test.quarkus.wiremock.devservices.service-name=wiremock-server
%dev,test.quarkus.wiremock.devservices.global-response-templating=false
Testing
In addition, you might want to configure WireMock
programmatically. To do so, please add the following dependency to the target project:
<dependency>
<groupId>io.quarkiverse.wiremock</groupId>
<artifactId>quarkus-wiremock-test</artifactId>
<version>0.1.2</version>
<scope>test</scope>
</dependency>
After that, you are able to inject a WireMock
reference along with your test execution lifecycle has shown below:
@QuarkusTest
@QuarkusTestResource(WireMockServerTestResource.class)
class WireMockDevServiceResourceTest {
private static final String MOCK_MSG = "Hello from WireMock!";
@InjectWireMock
WireMock wiremock;
@Test
void testHelloEndpoint() {
Assertions.assertNotNull(wiremock);
wiremock.register(get(urlEqualTo("/mock-me"))
.willReturn(aResponse().withStatus(200).withBody(MOCK_MSG)));
...
}
}
You can also reuse a @QuarkusTest
as a @QuarkusIntegrationTest
:
@QuarkusIntegrationTest
public class WireMockDevServiceResourceIT extends WireMockDevServiceResourceTest {
// re-use Quarkus tests as integration tests
}
Extension Configuration Reference
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Type |
Default |
|
---|---|---|
If DevServices has been explicitly enabled or disabled. DevServices is generally enabled by default, unless there is an existing configuration present. Environment variable: |
boolean |
|
Name of the WireMock Dev Service. Environment variable: |
string |
|
Optional fixed port the dev service will listen to. Environment variable: |
int |
8089 |
Restart WireMock whenever Quarkus is reloaded. Otherwise, whenever files are changed in the Environment variable: |
boolean |
|
Path to root dir with Environment variable: |
string |
|
If global response templating should be enabled for WireMock, see https://wiremock.org/2.x/docs/response-templating/ Environment variable: |
boolean |
|