public class OpenApiValidationListener extends Object implements com.github.tomakehurst.wiremock.http.RequestListener
The listener can be added to a WireMockRule or
WireMockServer instance
(see Extending WireMock). The current validation report
can be accessed with getReport(), and the convenience method assertValidationPassed() can be used
to check for validation errors and throw an exception if any are found.
Important: The listener will continue accumulating validation errors on each call to the WireMock server.
Call reset() before your test to ensure you only get validation errors for the current test execution.
E.g.
@Rule
public WireMockRule wireMockRule;
private OpenApiValidationListener validationListener;
public ValidatedWireMockTestExample() {
this.validationListener = new OpenApiValidationListener(SPEC_URL);
this.wireMockRule = new WireMockRule(PORT);
this.wireMockRule.addMockServiceRequestListener(validationListener);
}
@After
public void teardown() {
this.validationListener.reset();
}
@Test
public void testFoo() {
// Some interactions with the WireMock server
...
this.validationListener.assertValidationPassed();
}
ValidatedWireMockRule| Modifier and Type | Class and Description |
|---|---|
static class |
OpenApiValidationListener.OpenApiValidationException |
| Constructor and Description |
|---|
OpenApiValidationListener(OpenApiInteractionValidator validator) |
OpenApiValidationListener(String specUrlOrDefinition) |
| Modifier and Type | Method and Description |
|---|---|
void |
assertValidationPassed()
Assert that the current validation report contains no errors and fail if it does.
|
ValidationReport |
getReport()
Access the current validation report.
|
void |
requestReceived(com.github.tomakehurst.wiremock.http.Request request,
com.github.tomakehurst.wiremock.http.Response response) |
void |
reset()
Reset this listener instance and remove validation messages from the validation report.
|
public OpenApiValidationListener(String specUrlOrDefinition)
public OpenApiValidationListener(OpenApiInteractionValidator validator)
public void requestReceived(com.github.tomakehurst.wiremock.http.Request request,
com.github.tomakehurst.wiremock.http.Response response)
requestReceived in interface com.github.tomakehurst.wiremock.http.RequestListenerpublic ValidationReport getReport()
reset().
Most often clients will simply want to invoke assertValidationPassed() rather than access
the report directly.
public void reset()
This method should be invoked between tests to ensure validation messages don't carry over between test runs e.g.
@After
public void tearDown() {
validationListener.reset();
}
public void assertValidationPassed()
OpenApiValidationListener.OpenApiValidationException - if the current validation report contains any errors.Copyright © 2016–2019 Atlassian. All rights reserved.