Search in sources :

Example 6 with MockServerEventLog

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(""));
}
Also used : MockServerEventLog(org.mockserver.log.MockServerEventLog) CompletableFuture(java.util.concurrent.CompletableFuture) Verification(org.mockserver.verify.Verification) LogEntry(org.mockserver.log.model.LogEntry) Test(org.junit.Test)

Example 7 with MockServerEventLog

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(""));
}
Also used : MockServerEventLog(org.mockserver.log.MockServerEventLog) HttpRequest(org.mockserver.model.HttpRequest) VerificationSequence(org.mockserver.verify.VerificationSequence) LogEntry(org.mockserver.log.model.LogEntry) Test(org.junit.Test)

Example 8 with MockServerEventLog

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 + "} ]>"));
}
Also used : MockServerEventLog(org.mockserver.log.MockServerEventLog) HttpRequest(org.mockserver.model.HttpRequest) VerificationSequence(org.mockserver.verify.VerificationSequence) LogEntry(org.mockserver.log.model.LogEntry) Test(org.junit.Test)

Example 9 with MockServerEventLog

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(""));
}
Also used : MockServerEventLog(org.mockserver.log.MockServerEventLog) VerificationSequence(org.mockserver.verify.VerificationSequence) LogEntry(org.mockserver.log.model.LogEntry) Test(org.junit.Test)

Example 10 with MockServerEventLog

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 + "}>"));
}
Also used : MockServerEventLog(org.mockserver.log.MockServerEventLog) HttpRequest(org.mockserver.model.HttpRequest) Verification(org.mockserver.verify.Verification) LogEntry(org.mockserver.log.model.LogEntry) Test(org.junit.Test)

Aggregations

MockServerEventLog (org.mockserver.log.MockServerEventLog)11 LogEntry (org.mockserver.log.model.LogEntry)11 Test (org.junit.Test)10 Verification (org.mockserver.verify.Verification)5 VerificationSequence (org.mockserver.verify.VerificationSequence)5 CompletableFuture (java.util.concurrent.CompletableFuture)4 HttpRequest (org.mockserver.model.HttpRequest)4 TextWebSocketFrame (io.netty.handler.codec.http.websocketx.TextWebSocketFrame)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 MockServerLogger (org.mockserver.logging.MockServerLogger)1 HttpState (org.mockserver.mock.HttpState)1 RequestMatchers (org.mockserver.mock.RequestMatchers)1 Scheduler (org.mockserver.scheduler.Scheduler)1