Search in sources :

Example 1 with ServeEvent

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;
}
Also used : AllHTTPStubRequestsMatchedAssertionVerificationResult(io.irontest.models.assertion.AllHTTPStubRequestsMatchedAssertionVerificationResult) ArrayList(java.util.ArrayList) ServeEvent(com.github.tomakehurst.wiremock.stubbing.ServeEvent) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with ServeEvent

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;
}
Also used : ArrayList(java.util.ArrayList) ServeEvent(com.github.tomakehurst.wiremock.stubbing.ServeEvent) JsonView(com.fasterxml.jackson.annotation.JsonView)

Example 3 with ServeEvent

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;
}
Also used : ArrayList(java.util.ArrayList) ServeEvent(com.github.tomakehurst.wiremock.stubbing.ServeEvent) JsonView(com.fasterxml.jackson.annotation.JsonView)

Example 4 with ServeEvent

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;
    }
}
Also used : PlainTextStubNotMatchedRenderer(com.github.tomakehurst.wiremock.verification.notmatched.PlainTextStubNotMatchedRenderer) LoggedResponse(com.github.tomakehurst.wiremock.http.LoggedResponse) ResponseDefinition(com.github.tomakehurst.wiremock.http.ResponseDefinition) ServeEvent(com.github.tomakehurst.wiremock.stubbing.ServeEvent)

Example 5 with ServeEvent

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;
}
Also used : ServeEvent(com.github.tomakehurst.wiremock.stubbing.ServeEvent) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer)

Aggregations

ServeEvent (com.github.tomakehurst.wiremock.stubbing.ServeEvent)7 ArrayList (java.util.ArrayList)3 JsonView (com.fasterxml.jackson.annotation.JsonView)2 List (java.util.List)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 LoggedResponse (com.github.tomakehurst.wiremock.http.LoggedResponse)1 ResponseDefinition (com.github.tomakehurst.wiremock.http.ResponseDefinition)1 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)1 PlainTextStubNotMatchedRenderer (com.github.tomakehurst.wiremock.verification.notmatched.PlainTextStubNotMatchedRenderer)1 AllHTTPStubRequestsMatchedAssertionVerificationResult (io.irontest.models.assertion.AllHTTPStubRequestsMatchedAssertionVerificationResult)1 HTTPStubHitAssertionProperties (io.irontest.models.assertion.HTTPStubHitAssertionProperties)1 HTTPStubHitAssertionVerificationResult (io.irontest.models.assertion.HTTPStubHitAssertionVerificationResult)1 HTTPStubsHitInOrderAssertionProperties (io.irontest.models.assertion.HTTPStubsHitInOrderAssertionProperties)1 HTTPStubsHitInOrderAssertionVerificationResult (io.irontest.models.assertion.HTTPStubsHitInOrderAssertionVerificationResult)1 UUID (java.util.UUID)1