Hi,
I would like to propose a new Quarkiverse extension for Testcontainer MockServer. It uses devservices to start MockServer container for testing/developing. There is a simple configuration and integration in the Quarkus test.
@QuarkusTest
@QuarkusTestResource(MockServerTestResource.class)
public class TestRestControllerTest {
@InjectMockServerClient
MockServerClient mockServerClient;
@Test
public void test() {
Map<String, Object> data = new HashMap<>(Map.of(
"key-A", "value-A",
"key-B", 1));
// create mock rest endpoint
mockServerClient.when(request().withPath("/activity/data").withMethod("POST"))
.respond(httpRequest -> response().withStatusCode(200)
.withHeader("Content-Type", "application/json")
.withBody(JsonBody.json(data)));
TestRestController.Data request = new TestRestController.Data();
request.key = "k1";
request.value = "v1";
Map result = given()
.contentType(MediaType.APPLICATION_JSON)
.body(request)
.post("/test")
.prettyPeek()
.then()
.statusCode(Response.Status.OK.getStatusCode())
.extract().body().as(Map.class);
System.out.println(result);
}
}
Description
Hi, I would like to propose a new Quarkiverse extension for Testcontainer MockServer. It uses devservices to start MockServer container for testing/developing. There is a simple configuration and integration in the Quarkus test.
My PoC: https://github.com/lorislab/quarkus-mockserver
Configuration suggestion
The rest-client could be configured in application.properties like this %test.activity-client/mp-rest/url=${quarkus.mockserver.endpoint}
Additional context
You can define multiple mock static endpoints with
mock-server-client
andinit json
file or use callbacks to define response dynamically in the test. https://mock-server.com/mock_server/getting_started.html#button_response_class_callback