Search in sources :

Example 21 with LogEntry

use of org.mockserver.log.model.LogEntry in project mockserver by mock-server.

the class MockServerEventLogRequestLogEntryVerificationSequenceTest method shouldFailVerificationSequenceWithTwoRequestsSecondIncorrect.

@Test
public void shouldFailVerificationSequenceWithTwoRequestsSecondIncorrect() {
    // 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("one"), request("five"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + "  \"path\" : \"one\"" + NEW_LINE + "}, {" + NEW_LINE + "  \"path\" : \"five\"" + 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("multi"), request("five"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + "  \"path\" : \"multi\"" + NEW_LINE + "}, {" + NEW_LINE + "  \"path\" : \"five\"" + 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("three"), request("five"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + "  \"path\" : \"three\"" + NEW_LINE + "}, {" + NEW_LINE + "  \"path\" : \"five\"" + 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 + "} ]>"));
}
Also used : VerificationSequence(org.mockserver.verify.VerificationSequence) LogEntry(org.mockserver.log.model.LogEntry) Test(org.junit.Test)

Example 22 with LogEntry

use of org.mockserver.log.model.LogEntry in project mockserver by mock-server.

the class MockServerEventLogRequestLogEntryVerificationSequenceTest method shouldPassVerificationSequenceWithNoRequest.

@Test
public void shouldPassVerificationSequenceWithNoRequest() {
    // 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()), is(""));
}
Also used : VerificationSequence(org.mockserver.verify.VerificationSequence) LogEntry(org.mockserver.log.model.LogEntry) Test(org.junit.Test)

Example 23 with LogEntry

use of org.mockserver.log.model.LogEntry in project mockserver by mock-server.

the class MockServerEventLogRequestLogEntryVerificationSequenceTest method shouldFailVerificationSequenceWithOneRequest.

@Test
public void shouldFailVerificationSequenceWithOneRequest() {
    // 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("five"))), is("Request sequence not found, expected:<[ {" + NEW_LINE + "  \"path\" : \"five\"" + 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 + "} ]>"));
}
Also used : VerificationSequence(org.mockserver.verify.VerificationSequence) LogEntry(org.mockserver.log.model.LogEntry) Test(org.junit.Test)

Example 24 with LogEntry

use of org.mockserver.log.model.LogEntry in project mockserver by mock-server.

the class MockServerEventLogRequestLogEntryVerificationTest method shouldPassVerificationWithExactlyZeroTimes.

@Test
public void shouldPassVerificationWithExactlyZeroTimes() {
    // given
    HttpRequest httpRequest = new HttpRequest().withPath("some_path");
    HttpRequest otherHttpRequest = new HttpRequest().withPath("some_other_path");
    // when
    mockServerEventLog.add(new LogEntry().setHttpRequest(httpRequest).setType(RECEIVED_REQUEST));
    mockServerEventLog.add(new LogEntry().setHttpRequest(otherHttpRequest).setType(RECEIVED_REQUEST));
    mockServerEventLog.add(new LogEntry().setHttpRequest(httpRequest).setType(RECEIVED_REQUEST));
    // then
    assertThat(verify(verification().withRequest(new HttpRequest().withPath("some_non_matching_path")).withTimes(exactly(0))), is(""));
}
Also used : HttpRequest(org.mockserver.model.HttpRequest) LogEntry(org.mockserver.log.model.LogEntry) Test(org.junit.Test)

Example 25 with LogEntry

use of org.mockserver.log.model.LogEntry in project mockserver by mock-server.

the class MockServerEventLogRequestLogEntryVerificationTest method shouldFailVerificationWithNoInteractions.

@Test
public void shouldFailVerificationWithNoInteractions() {
    // given
    HttpRequest httpRequest = new HttpRequest();
    // when
    mockServerEventLog.add(new LogEntry().setHttpRequest(httpRequest).setType(RECEIVED_REQUEST));
    // then
    assertThat(verify(verification().withRequest(request()).withTimes(exactly(0))), is("Request not found exactly 0 times, expected:<{ }> but was:<{ }>"));
}
Also used : HttpRequest(org.mockserver.model.HttpRequest) LogEntry(org.mockserver.log.model.LogEntry) Test(org.junit.Test)

Aggregations

LogEntry (org.mockserver.log.model.LogEntry)269 Test (org.junit.Test)114 HttpRequest (org.mockserver.model.HttpRequest)79 HttpResponse (org.mockserver.model.HttpResponse)58 Level (org.slf4j.event.Level)34 MockServerLogger (org.mockserver.logging.MockServerLogger)32 Expectation (org.mockserver.mock.Expectation)32 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)25 VerificationSequence (org.mockserver.verify.VerificationSequence)20 DashboardLogEntryDTO (org.mockserver.dashboard.model.DashboardLogEntryDTO)17 OpenAPIExpectation.openAPIExpectation (org.mockserver.mock.OpenAPIExpectation.openAPIExpectation)16 MockServerEventLog (org.mockserver.log.MockServerEventLog)14 List (java.util.List)13 CompletableFuture (java.util.concurrent.CompletableFuture)13 IOException (java.io.IOException)12 InetSocketAddress (java.net.InetSocketAddress)12 ArrayList (java.util.ArrayList)10 Date (java.util.Date)9 ResponseWriter (org.mockserver.responsewriter.ResponseWriter)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8