use of org.mockserver.log.model.LogEntry in project mockserver by mock-server.
the class MockServerLoggerTest method shouldFormatErrorLogMessagesForRequest.
@Test
public void shouldFormatErrorLogMessagesForRequest() {
Level originalLevel = logLevel();
try {
// given
logLevel("INFO");
Logger mockLogger = mock(Logger.class);
MockServerLogger logFormatter = new MockServerLogger(mockLogger);
HttpRequest request = request("some_path");
// when
logFormatter.logEvent(new LogEntry().setLogLevel(Level.ERROR).setHttpRequest(request).setMessageFormat("some random message with{}and{}").setArguments("some" + NEW_LINE + "multi-line" + NEW_LINE + "object", "another" + NEW_LINE + "multi-line" + NEW_LINE + "object"));
// then
String message = "some random message with" + NEW_LINE + NEW_LINE + " some" + NEW_LINE + " multi-line" + NEW_LINE + " object" + NEW_LINE + NEW_LINE + " and" + NEW_LINE + NEW_LINE + " another" + NEW_LINE + " multi-line" + NEW_LINE + " object" + NEW_LINE;
verify(mockLogger).error(message, (Throwable) null);
} finally {
logLevel(originalLevel.toString());
}
}
use of org.mockserver.log.model.LogEntry in project mockserver by mock-server.
the class MockServerLoggerTest method shouldSendEventToStateHandler.
@Test
public void shouldSendEventToStateHandler() {
Level originalLevel = logLevel();
try {
// given
logLevel("INFO");
HttpState mockHttpStateHandler = mock(HttpState.class);
MockServerLogger logFormatter = new MockServerLogger(mockHttpStateHandler);
HttpRequest request = request("some_path");
// when
logFormatter.logEvent(new LogEntry().setLogLevel(Level.INFO).setHttpRequest(request).setMessageFormat("some random message with{}and{}").setArguments("some" + NEW_LINE + "multi-line" + NEW_LINE + "object", "another" + NEW_LINE + "multi-line" + NEW_LINE + "object"));
// then
ArgumentCaptor<LogEntry> captor = ArgumentCaptor.forClass(LogEntry.class);
verify(mockHttpStateHandler, times(1)).log(captor.capture());
LogEntry messageLogEntry = captor.getValue();
assertThat(messageLogEntry.getHttpRequests(), is(new HttpRequest[] { request }));
assertThat(messageLogEntry.getMessage(), containsString("some random message with" + NEW_LINE + NEW_LINE + " some" + NEW_LINE + " multi-line" + NEW_LINE + " object" + NEW_LINE + NEW_LINE + " and" + NEW_LINE + NEW_LINE + " another" + NEW_LINE + " multi-line" + NEW_LINE + " object" + NEW_LINE));
assertThat(messageLogEntry.getMessageFormat(), containsString("some random message with{}and{}"));
assertThat(messageLogEntry.getArguments(), arrayContaining(new Object[] { "some" + NEW_LINE + "multi-line" + NEW_LINE + "object", "another" + NEW_LINE + "multi-line" + NEW_LINE + "object" }));
} finally {
logLevel(originalLevel.toString());
}
}
use of org.mockserver.log.model.LogEntry 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.log.model.LogEntry 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.log.model.LogEntry 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