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 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(ExpectationId... expectationIds) throws AssertionError {
if (expectationIds == null || expectationIds.length == 0 || expectationIds[0] == null) {
throw new IllegalArgumentException("verify(RequestDefinition...) requires a non-null non-empty array of RequestDefinition objects");
}
try {
VerificationSequence verificationSequence = new VerificationSequence().withExpectationIds(expectationIds);
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 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 requestDefinitions the http requests that must be matched for this verification to pass
* @throws AssertionError if the request has not been found
*/
public MockServerClient verify(RequestDefinition... requestDefinitions) throws AssertionError {
if (requestDefinitions == null || requestDefinitions.length == 0 || requestDefinitions[0] == null) {
throw new IllegalArgumentException("verify(RequestDefinition...) requires a non-null non-empty array of RequestDefinition objects");
}
try {
VerificationSequence verificationSequence = new VerificationSequence().withRequests(requestDefinitions);
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 shouldPassVerificationWithNullRequest.
@Test
public void shouldPassVerificationWithNullRequest() {
// 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((VerificationSequence) null), is(""));
}
use of org.mockserver.verify.VerificationSequence in project mockserver by mock-server.
the class MockServerEventLogRequestLogEntryVerificationSequenceTest method shouldFailVerificationSequenceWithTwoRequestsFirstIncorrect.
@Test
public void shouldFailVerificationSequenceWithTwoRequestsFirstIncorrect() {
// 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("zero"), request("multi"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"zero\"" + 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 + "} ]>"));
assertThat(verify(new VerificationSequence().withRequests(request("zero"), request("three"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"zero\"" + 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 + "} ]>"));
assertThat(verify(new VerificationSequence().withRequests(request("zero"), request("four"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + " \"path\" : \"zero\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"four\"" + 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 shouldPassVerificationSequenceWithOneRequest.
@Test
public void shouldPassVerificationSequenceWithOneRequest() {
// 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("one"))), is(""));
assertThat(verify(new VerificationSequence().withRequests(request("multi"))), is(""));
assertThat(verify(new VerificationSequence().withRequests(request("three"))), is(""));
assertThat(verify(new VerificationSequence().withRequests(request("four"))), is(""));
}
Aggregations