Search in sources :

Example 26 with LogEntry

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

the class MockServerEventLogRequestLogEntryVerificationTest method shouldPassVerificationWithExactlyTwoTimes.

@Test
public void shouldPassVerificationWithExactlyTwoTimes() {
    // 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_path")).withTimes(exactly(2))), is(""));
}
Also used : HttpRequest(org.mockserver.model.HttpRequest) LogEntry(org.mockserver.log.model.LogEntry) Test(org.junit.Test)

Example 27 with LogEntry

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

the class MockServerEventLogRequestLogEntryVerificationTest method shouldFailVerificationWithDefaultTimes.

@Test
public void shouldFailVerificationWithDefaultTimes() {
    // 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"))), is("Request not found at least once, expected:<{" + NEW_LINE + "  \"path\" : \"some_non_matching_path\"" + NEW_LINE + "}> but was:<[ {" + NEW_LINE + "  \"path\" : \"some_path\"" + NEW_LINE + "}, {" + NEW_LINE + "  \"path\" : \"some_other_path\"" + NEW_LINE + "}, {" + NEW_LINE + "  \"path\" : \"some_path\"" + NEW_LINE + "} ]>"));
}
Also used : HttpRequest(org.mockserver.model.HttpRequest) LogEntry(org.mockserver.log.model.LogEntry) Test(org.junit.Test)

Example 28 with LogEntry

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

the class MockServerEventLogRequestLogEntryVerificationTest method shouldPassVerificationWithAtLeastTwoTimes.

@Test
public void shouldPassVerificationWithAtLeastTwoTimes() {
    // 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_path")).withTimes(atLeast(2))), is(""));
}
Also used : HttpRequest(org.mockserver.model.HttpRequest) LogEntry(org.mockserver.log.model.LogEntry) Test(org.junit.Test)

Example 29 with LogEntry

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

the class MockServerEventLogRequestLogEntryVerificationTest method shouldFailVerificationWithLimitedReturnedRequestsViaConfiguration.

@Test
public void shouldFailVerificationWithLimitedReturnedRequestsViaConfiguration() {
    Integer originalMaximumNumberOfRequestToReturnInVerificationFailure = ConfigurationProperties.maximumNumberOfRequestToReturnInVerificationFailure();
    try {
        // given
        HttpRequest httpRequest = new HttpRequest().withPath("some_path");
        HttpRequest otherHttpRequest = new HttpRequest().withPath("some_other_path");
        ConfigurationProperties.maximumNumberOfRequestToReturnInVerificationFailure(1);
        // 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_other_path")).withTimes(atLeast(2))), is("Request not found at least 2 times, expected:<{" + NEW_LINE + "  \"path\" : \"some_other_path\"" + NEW_LINE + "}> but was not found, found 3 other requests"));
    } finally {
        ConfigurationProperties.maximumNumberOfRequestToReturnInVerificationFailure(originalMaximumNumberOfRequestToReturnInVerificationFailure);
    }
}
Also used : HttpRequest(org.mockserver.model.HttpRequest) LogEntry(org.mockserver.log.model.LogEntry) Test(org.junit.Test)

Example 30 with LogEntry

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

the class MockServerEventLogRequestLogEntryVerificationTest method shouldFailVerificationWithAtLeastTwoTimes.

@Test
public void shouldFailVerificationWithAtLeastTwoTimes() {
    // 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_other_path")).withTimes(atLeast(2))), is("Request not found at least 2 times, expected:<{" + NEW_LINE + "  \"path\" : \"some_other_path\"" + NEW_LINE + "}> but was:<[ {" + NEW_LINE + "  \"path\" : \"some_path\"" + NEW_LINE + "}, {" + NEW_LINE + "  \"path\" : \"some_other_path\"" + NEW_LINE + "}, {" + NEW_LINE + "  \"path\" : \"some_path\"" + NEW_LINE + "} ]>"));
}
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