Create JUnit5 Extension for Wiremock

Issue #386 resolved
Former user created an issue

The usage of the provided ValidatedWireMockRule forces the consumer of your API to use JUnit4 which is outdated. Therefore an JUnit5 compatible Extension - ValidatedWireMockExtension - should be implemented.

The base for the implementation could be: https://wiremock.org/docs/junit-jupiter/

A very simple Extension could look like this:

public class ValidatedWireMockExtension extends WireMockExtension {

    private final OpenApiValidationListener openApiValidationListener;

    public ValidatedWireMockExtension(String openApiSpecPath, Builder builder) {
        super(builder);
        this.openApiValidationListener = new OpenApiValidationListener(openApiSpecPath);
    }

    @Override
    protected void onBeforeAll(WireMockRuntimeInfo wireMockRuntimeInfo) {
        super.onBeforeAll(wireMockRuntimeInfo);

        if (this.stubbing instanceof WireMockServer wm) {
            wm.addMockServiceRequestListener(this.openApiValidationListener);
        } else {
            throw new RuntimeException("Failed to apply open api spec validation to wiremock");
        }
    }

    @Override
    protected void onBeforeEach(WireMockRuntimeInfo wireMockRuntimeInfo) {
        super.onBeforeEach(wireMockRuntimeInfo);
        this.openApiValidationListener.reset();
    }

    public void assertValidationPassed() {
        this.openApiValidationListener.assertValidationPassed();
    }

    public ValidationReport getReport() {
        return this.openApiValidationListener.getReport();
    }

}