use of org.mockserver.verify.VerificationSequence in project mockserver by mock-server.
the class MockServerClient method verify.
/**
* Verify a list of requests have been sent in the order specified for example:
* <pre>
* mockServerClient
* .verify(
* request()
* .withPath("/first_request")
* .withBody("some_request_body"),
* request()
* .withPath("/second_request")
* .withBody("some_request_body")
* );
* </pre>
*
* @param maximumNumberOfRequestToReturnInVerificationFailure the maximum number requests return in the error response when the verification fails
* @param expectationIds the http requests that must be matched for this verification to pass
* @throws AssertionError if the request has not been found
*/
public MockServerClient verify(Integer maximumNumberOfRequestToReturnInVerificationFailure, ExpectationId... expectationIds) throws AssertionError {
if (expectationIds == null || expectationIds.length == 0 || expectationIds[0] == null) {
throw new IllegalArgumentException("verify(ExpectationId...) requires a non-null non-empty array of ExpectationId objects");
}
try {
VerificationSequence verificationSequence = new VerificationSequence().withExpectationIds(expectationIds).withMaximumNumberOfRequestToReturnInVerificationFailure(maximumNumberOfRequestToReturnInVerificationFailure);
String result = sendRequest(request().withMethod("PUT").withContentType(APPLICATION_JSON_UTF_8).withPath(calculatePath("verifySequence")).withBody(verificationSequenceSerializer.serialize(verificationSequence), StandardCharsets.UTF_8)).getBodyAsString();
if (result != null && !result.isEmpty()) {
throw new AssertionError(result);
}
} catch (AuthenticationException authenticationException) {
throw authenticationException;
} catch (Throwable throwable) {
throw new AssertionError(throwable.getMessage());
}
return clientClass.cast(this);
}
use of org.mockserver.verify.VerificationSequence in project mockserver by mock-server.
the class MockServerEventLogRequestLogEntryVerificationSequenceTest method shouldFailVerificationSequenceWithThreeRequestsDuplicateMissing.
@Test
public void shouldFailVerificationSequenceWithThreeRequestsDuplicateMissing() {
// when
mockServerEventLog.add(new LogEntry().setHttpRequest(request("one")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("multi")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("three")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("multi")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("four")).setType(RECEIVED_REQUEST));
// then
assertThat(verify(new VerificationSequence().withRequests(request("multi"), request("multi"), request("multi"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "} ]> but was:<[ {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"three\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "} ]>"));
}
use of org.mockserver.verify.VerificationSequence in project mockserver by mock-server.
the class MockServerEventLogRequestLogEntryVerificationSequenceTest method shouldFailVerificationSequenceWithLimitedReturnedRequestsViaVerificationSequence.
@Test
public void shouldFailVerificationSequenceWithLimitedReturnedRequestsViaVerificationSequence() {
// when
mockServerEventLog.add(new LogEntry().setHttpRequest(request("one")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("multi")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("three")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("multi")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("four")).setType(RECEIVED_REQUEST));
// then - next to each other
assertThat(verify(new VerificationSequence().withRequests(request("multi"), request("one")).withMaximumNumberOfRequestToReturnInVerificationFailure(1)), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "} ]> but was not found, found 5 other requests"));
assertThat(verify(new VerificationSequence().withRequests(request("four"), request("multi")).withMaximumNumberOfRequestToReturnInVerificationFailure(1)), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "} ]> but was not found, found 5 other requests"));
// then - not next to each other
assertThat(verify(new VerificationSequence().withRequests(request("three"), request("one")).withMaximumNumberOfRequestToReturnInVerificationFailure(1)), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"three\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "} ]> but was not found, found 5 other requests"));
assertThat(verify(new VerificationSequence().withRequests(request("four"), request("one")).withMaximumNumberOfRequestToReturnInVerificationFailure(1)), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "} ]> but was not found, found 5 other requests"));
assertThat(verify(new VerificationSequence().withRequests(request("four"), request("three")).withMaximumNumberOfRequestToReturnInVerificationFailure(1)), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"three\"" + NEW_LINE + "} ]> but was not found, found 5 other requests"));
}
use of org.mockserver.verify.VerificationSequence in project mockserver by mock-server.
the class MockServerEventLogRequestLogEntryVerificationSequenceTest method shouldFailVerificationSequenceWithLimitedReturnedRequestsViaConfiguration.
@Test
public void shouldFailVerificationSequenceWithLimitedReturnedRequestsViaConfiguration() {
Integer originalMaximumNumberOfRequestToReturnInVerificationFailure = ConfigurationProperties.maximumNumberOfRequestToReturnInVerificationFailure();
try {
// given
ConfigurationProperties.maximumNumberOfRequestToReturnInVerificationFailure(1);
// when
mockServerEventLog.add(new LogEntry().setHttpRequest(request("one")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("multi")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("three")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("multi")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("four")).setType(RECEIVED_REQUEST));
// then - next to each other
assertThat(verify(new VerificationSequence().withRequests(request("multi"), request("one"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "} ]> but was not found, found 5 other requests"));
assertThat(verify(new VerificationSequence().withRequests(request("four"), request("multi"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "} ]> but was not found, found 5 other requests"));
// then - not next to each other
assertThat(verify(new VerificationSequence().withRequests(request("three"), request("one"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"three\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "} ]> but was not found, found 5 other requests"));
assertThat(verify(new VerificationSequence().withRequests(request("four"), request("one"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "} ]> but was not found, found 5 other requests"));
assertThat(verify(new VerificationSequence().withRequests(request("four"), request("three"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"three\"" + NEW_LINE + "} ]> but was not found, found 5 other requests"));
} finally {
ConfigurationProperties.maximumNumberOfRequestToReturnInVerificationFailure(originalMaximumNumberOfRequestToReturnInVerificationFailure);
}
}
use of org.mockserver.verify.VerificationSequence in project mockserver by mock-server.
the class MockServerEventLogRequestLogEntryVerificationSequenceTest method shouldFailVerificationSequenceWithTwoRequestsWrongOrder.
@Test
public void shouldFailVerificationSequenceWithTwoRequestsWrongOrder() {
// when
mockServerEventLog.add(new LogEntry().setHttpRequest(request("one")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("multi")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("three")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("multi")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("four")).setType(RECEIVED_REQUEST));
// then - next to each other
assertThat(verify(new VerificationSequence().withRequests(request("multi"), request("one"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "} ]> but was:<[ {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"three\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "} ]>"));
assertThat(verify(new VerificationSequence().withRequests(request("four"), request("multi"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "} ]> but was:<[ {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"three\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "} ]>"));
// then - not next to each other
assertThat(verify(new VerificationSequence().withRequests(request("three"), request("one"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"three\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "} ]> but was:<[ {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"three\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "} ]>"));
assertThat(verify(new VerificationSequence().withRequests(request("four"), request("one"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "} ]> but was:<[ {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"three\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "} ]>"));
assertThat(verify(new VerificationSequence().withRequests(request("four"), request("three"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"three\"" + NEW_LINE + "} ]> but was:<[ {" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"three\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"four\"" + NEW_LINE + "} ]>"));
}
Aggregations