Search in sources :

Example 6 with ServeEvent

use of com.github.tomakehurst.wiremock.stubbing.ServeEvent in project irontest by zheng-wang.

the class HTTPStubHitAssertionVerifier method verify.

@Override
public AssertionVerificationResult verify(Object... inputs) {
    HTTPStubHitAssertionVerificationResult result = new HTTPStubHitAssertionVerificationResult();
    HTTPStubHitAssertionProperties otherProperties = (HTTPStubHitAssertionProperties) getAssertion().getOtherProperties();
    List<ServeEvent> allServeEvents = (List<ServeEvent>) inputs[0];
    UUID stubInstanceUUID = (UUID) inputs[1];
    short stubInstanceHitCount = 0;
    for (ServeEvent serveEvent : allServeEvents) {
        if (serveEvent.getStubMapping().getId().equals(stubInstanceUUID)) {
            // the stub instance has been hit
            stubInstanceHitCount++;
        }
    }
    result.setActualHitCount(stubInstanceHitCount);
    if (stubInstanceHitCount != otherProperties.getExpectedHitCount()) {
        result.setResult(TestResult.FAILED);
    } else {
        result.setResult(TestResult.PASSED);
    }
    return result;
}
Also used : HTTPStubHitAssertionVerificationResult(io.irontest.models.assertion.HTTPStubHitAssertionVerificationResult) HTTPStubHitAssertionProperties(io.irontest.models.assertion.HTTPStubHitAssertionProperties) ServeEvent(com.github.tomakehurst.wiremock.stubbing.ServeEvent) List(java.util.List) UUID(java.util.UUID)

Example 7 with ServeEvent

use of com.github.tomakehurst.wiremock.stubbing.ServeEvent in project irontest by zheng-wang.

the class HTTPStubsHitInOrderAssertionVerifier method verify.

@Override
public AssertionVerificationResult verify(Object... inputs) {
    HTTPStubsHitInOrderAssertionVerificationResult result = new HTTPStubsHitInOrderAssertionVerificationResult();
    HTTPStubsHitInOrderAssertionProperties otherProperties = (HTTPStubsHitInOrderAssertionProperties) getAssertion().getOtherProperties();
    Map<Date, Short> hitMap = new TreeMap<>();
    List<ServeEvent> allServeEvents = (List<ServeEvent>) inputs[0];
    for (ServeEvent serveEvent : allServeEvents) {
        if (serveEvent.getWasMatched()) {
            StubMapping stubMapping = serveEvent.getStubMapping();
            hitMap.put(serveEvent.getRequest().getLoggedDate(), (Short) stubMapping.getMetadata().get(WIREMOCK_STUB_METADATA_ATTR_NAME_IRON_TEST_NUMBER));
        }
    }
    List<Short> actualHitOrder = new ArrayList(hitMap.values());
    result.setResult(otherProperties.getExpectedHitOrder().equals(actualHitOrder) ? TestResult.PASSED : TestResult.FAILED);
    result.setActualHitOrder(actualHitOrder);
    return result;
}
Also used : HTTPStubsHitInOrderAssertionVerificationResult(io.irontest.models.assertion.HTTPStubsHitInOrderAssertionVerificationResult) HTTPStubsHitInOrderAssertionProperties(io.irontest.models.assertion.HTTPStubsHitInOrderAssertionProperties) ServeEvent(com.github.tomakehurst.wiremock.stubbing.ServeEvent) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping)

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