Skip to content

dlucasd/quarkus-mockserver

 
 

Repository files navigation

Quarkus MockServer

Build License Central All Contributors

Quarkus MockServer extension for tests and local development.

Usage

To use this extension for local development, add the dependency to the target project:

<dependency>
    <groupId>io.quarkiverse.mockserver</groupId>
    <artifactId>quarkus-mockserver</artifactId>
    <scope>provided</scope>
</dependency>

Example project

Configuration

# enable or disable mockserver devservices
quarkus.mockserver.devservices.enabled=true|false
# mockserver configuration properties file, container file '/config/mockserver.properties'
quarkus.mockserver.devservices.config-file=src/test/resources/mockserver.properties
# mockserver configuration directory for the expectation initializers, container directory '/<last_name_from_path>'.
quarkus.mockserver.devservices.config-dir=src/test/resources/mockserver
# enable or disable logs of the mockserver container
quarkus.mockserver.devservices.log=true|false
# mockserver docker image name
quarkus.mockserver.devservices.imageName=jamesdbloom/mockserver:mockserver-5.13.0
# mockserver container fix port
quarkus.mockserver.devservices.port=
# container shared mode
quarkus.mockserver.devservices.shared=true|false
# mockserver devservices service name
quarkus.mockserver.devservices.serviceName=mockserver

Runtime configuration values will be set up during start of the mockserver container. These values could be used to configure rest-client in your application.

# mockserver endpoint is random port http://localhost:44556 or http://mockserver:1080 for shared containers. 
quarkus.mockserver.endpoint=
# mockserver port is random testcontainers port or 1080 for shared containers
quarkus.mockserver.port=
# mockserver port is localhost or mockserver for shared containers
quarkus.mockserver.host=
# mockserver host for the test client, docker host
quarkus.mockserver.client.host=
# mockserver port for the test client, testcontainers random port
quarkus.mockserver.client.port=

Rest client configuration example:

%dev.activity-client/mp-rest/url=${quarkus.mockserver.endpoint}
%test.activity-client/mp-rest/url=${quarkus.mockserver.endpoint}

MockServer documentation:

  • Configuration properties file link
  • Expectation Initializer JSON link

Testing

To use the extension for test, add the dependency to the target project:

<dependency>
    <groupId>io.quarkiverse.mockserver</groupId>
    <artifactId>quarkus-mockserver-test</artifactId>
    <scope>test</scope>
</dependency>

Test example

import io.quarkiverse.mockserver.test.MockServerResource;
import io.quarkus.test.common.QuarkusTestResource;

@QuarkusTest
@QuarkusTestResource(MockServerResource.class)
public class BaseTest extends AbstractTest {

}

We can reuse the test for the integration test.

import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
public class BaseIT extends BaseTest {

}

For more information check examples in the integration-tests directory in this repo.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Andrej Petras

💻 🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

About

Quarkus MockServer Extension

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%