use of com.github.tomakehurst.wiremock.stubbing.ServeEvent in project irontest by zheng-wang.
the class AllHTTPStubRequestsMatchedAssertionVerifier method verify.
@Override
public AssertionVerificationResult verify(Object... inputs) {
AllHTTPStubRequestsMatchedAssertionVerificationResult result = new AllHTTPStubRequestsMatchedAssertionVerificationResult();
List<ServeEvent> allStubRequests = (List<ServeEvent>) inputs[0];
List<ServeEvent> unmatchedStubRequests = new ArrayList<>();
for (ServeEvent serveEvent : allStubRequests) {
if (!serveEvent.getWasMatched()) {
unmatchedStubRequests.add(serveEvent);
}
}
result.setUnmatchedStubRequests(unmatchedStubRequests);
if (unmatchedStubRequests.isEmpty()) {
result.setResult(TestResult.PASSED);
} else {
result.setResult(TestResult.FAILED);
}
return result;
}
use of com.github.tomakehurst.wiremock.stubbing.ServeEvent in project irontest by zheng-wang.
the class MockServerResource method findAllUnmatchedStubRequests.
@GET
@Path("unmatchedStubRequests")
@JsonView(ResourceJsonViews.MockServerUnmatchedRequestList.class)
public List<ServeEvent> findAllUnmatchedStubRequests() {
List<ServeEvent> result = new ArrayList<>();
List<ServeEvent> serveEvents = wireMockServer.getAllServeEvents();
for (ServeEvent serveEvent : serveEvents) {
if (!serveEvent.getWasMatched()) {
result.add(serveEvent);
}
}
return result;
}
use of com.github.tomakehurst.wiremock.stubbing.ServeEvent in project irontest by zheng-wang.
the class MockServerResource method findMatchedRequestsForStubInstance.
@GET
@Path("stubInstances/{stubInstanceId}/stubRequests")
@JsonView(ResourceJsonViews.MockServerStubRequestList.class)
public List<ServeEvent> findMatchedRequestsForStubInstance(@PathParam("stubInstanceId") UUID stubInstanceId) {
List<ServeEvent> result = new ArrayList<>();
List<ServeEvent> serveEvents = wireMockServer.getAllServeEvents();
for (ServeEvent serveEvent : serveEvents) {
if (serveEvent.getStubMapping().getId().equals(stubInstanceId)) {
result.add(serveEvent);
}
}
return result;
}
use of com.github.tomakehurst.wiremock.stubbing.ServeEvent in project irontest by zheng-wang.
the class IronTestUtils method updateUnmatchedStubRequest.
/**
* By default, unmatched WireMock stub request (ServeEvent) does not have the actual response headers or response body.
* This method update the unmatched serveEvent obtained from the WireMockServer by changing its response headers and body to the actual values.
* @param serveEvent
* @return the input serveEvent if it was matched;
* a new ServeEvent object with all fields same as the input serveEvent, except for the response headers and body, if it was unmatched.
*/
public static ServeEvent updateUnmatchedStubRequest(ServeEvent serveEvent, WireMockServer wireMockServer) {
if (serveEvent.getWasMatched()) {
return serveEvent;
} else {
PlainTextStubNotMatchedRenderer renderer = (PlainTextStubNotMatchedRenderer) wireMockServer.getOptions().getNotMatchedRenderer();
ResponseDefinition responseDefinition = renderer.render(wireMockServer, serveEvent.getRequest());
LoggedResponse response = serveEvent.getResponse();
com.github.tomakehurst.wiremock.http.HttpHeaders updatedHeaders = responseDefinition.getHeaders();
// remove the leading \r\n
String updatedBody = responseDefinition.getBody().substring(2);
LoggedResponse updatedResponse = new LoggedResponse(response.getStatus(), updatedHeaders, Encoding.encodeBase64(updatedBody.getBytes()), response.getFault(), null);
ServeEvent updatedServeEvent = new ServeEvent(serveEvent.getId(), serveEvent.getRequest(), serveEvent.getStubMapping(), serveEvent.getResponseDefinition(), updatedResponse, serveEvent.getWasMatched(), serveEvent.getTiming());
return updatedServeEvent;
}
}
use of com.github.tomakehurst.wiremock.stubbing.ServeEvent in project irontest by zheng-wang.
the class HTTPStubRequestsCheckTeststepRunner method run.
@Override
public BasicTeststepRun run() {
BasicTeststepRun basicTeststepRun = new BasicTeststepRun();
WireMockServer wireMockServer = getTestcaseRunContext().getWireMockServer();
WireMockServerAPIResponse response = new WireMockServerAPIResponse();
List<ServeEvent> allServeEvents = wireMockServer.getAllServeEvents();
for (ServeEvent serveEvent : allServeEvents) {
response.getAllServeEvents().add(IronTestUtils.updateUnmatchedStubRequest(serveEvent, wireMockServer));
}
basicTeststepRun.setResponse(response);
return basicTeststepRun;
}
Aggregations