use of org.mockserver.log.MockServerEventLog in project mockserver by mock-server.
the class HttpStateTest method shouldVerifyWithCallback.
@Test
public void shouldVerifyWithCallback() throws Exception {
// given
MockServerEventLog mockServerEventLog = httpState.getMockServerLog();
mockServerEventLog.add(new LogEntry().setHttpRequest(request("one")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("two")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("three")).setType(RECEIVED_REQUEST));
CompletableFuture<String> verificationResult = new CompletableFuture<>();
// when
httpState.verify(new Verification().withRequest(request("two")), verificationResult::complete);
// then
assertThat(verificationResult.get(5, SECONDS), is(""));
}
use of org.mockserver.log.MockServerEventLog in project mockserver by mock-server.
the class HttpStateTest method shouldHandleVerifySequenceRequest.
@Test
public void shouldHandleVerifySequenceRequest() {
// given
MockServerEventLog mockServerEventLog = httpState.getMockServerLog();
mockServerEventLog.add(new LogEntry().setHttpRequest(request("one")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("two")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("three")).setType(RECEIVED_REQUEST));
HttpRequest expectationRetrieveExpectationsRequest = request("/mockserver/verifySequence").withMethod("PUT").withBody(verificationSequenceSerializer.serialize(new VerificationSequence().withRequests(request("one"), request("three"))));
FakeResponseWriter responseWriter = new FakeResponseWriter();
// when
boolean handle = httpState.handle(expectationRetrieveExpectationsRequest, responseWriter, false);
// then
assertThat(handle, is(true));
assertThat(responseWriter.response.getStatusCode(), is(202));
assertThat(responseWriter.response.getBodyAsString(), is(""));
}
use of org.mockserver.log.MockServerEventLog in project mockserver by mock-server.
the class HttpStateTest method shouldHandleVerifySequenceFailureRequest.
@Test
public void shouldHandleVerifySequenceFailureRequest() {
// given
MockServerEventLog mockServerEventLog = httpState.getMockServerLog();
mockServerEventLog.add(new LogEntry().setHttpRequest(request("one")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("two")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("three")).setType(RECEIVED_REQUEST));
HttpRequest expectationRetrieveExpectationsRequest = request("/mockserver/verifySequence").withMethod("PUT").withBody(verificationSequenceSerializer.serialize(new VerificationSequence().withRequests(request("three"), request("one"))));
FakeResponseWriter responseWriter = new FakeResponseWriter();
// when
boolean handle = httpState.handle(expectationRetrieveExpectationsRequest, responseWriter, false);
// then
assertThat(handle, is(true));
assertThat(responseWriter.response.getStatusCode(), is(406));
assertThat(responseWriter.response.getBodyAsString(), 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\" : \"two\"" + NEW_LINE + "}, {" + NEW_LINE + " \"path\" : \"three\"" + NEW_LINE + "} ]>"));
}
use of org.mockserver.log.MockServerEventLog in project mockserver by mock-server.
the class HttpStateTest method shouldVerifySequenceWithFuture.
@Test
public void shouldVerifySequenceWithFuture() throws Exception {
// given
MockServerEventLog mockServerEventLog = httpState.getMockServerLog();
mockServerEventLog.add(new LogEntry().setHttpRequest(request("one")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("two")).setType(RECEIVED_REQUEST));
mockServerEventLog.add(new LogEntry().setHttpRequest(request("three")).setType(RECEIVED_REQUEST));
// when
String result = httpState.verify(new VerificationSequence().withRequests(request("one"), request("three"))).get(5, SECONDS);
// then
assertThat(result, is(""));
}
use of org.mockserver.log.MockServerEventLog in project mockserver by mock-server.
the class HttpStateTest method shouldHandleVerifyFailureRequest.
@Test
public void shouldHandleVerifyFailureRequest() {
// given
MockServerEventLog mockServerEventLog = httpState.getMockServerLog();
mockServerEventLog.add(new LogEntry().setHttpRequest(request("one")).setType(RECEIVED_REQUEST));
HttpRequest expectationRetrieveExpectationsRequest = request("/mockserver/verify").withMethod("PUT").withBody(verificationSerializer.serialize(new Verification().withRequest(request("two"))));
FakeResponseWriter responseWriter = new FakeResponseWriter();
// when
boolean handle = httpState.handle(expectationRetrieveExpectationsRequest, responseWriter, false);
// then
assertThat(handle, is(true));
assertThat(responseWriter.response.getStatusCode(), is(406));
assertThat(responseWriter.response.getBodyAsString(), is("Request not found at least once, expected:<{" + NEW_LINE + " \"path\" : \"two\"" + NEW_LINE + "}> but was:<{" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "}>"));
}
Aggregations