use of org.mockserver.log.MockServerEventLog in project mockserver by mock-server.
the class HttpStateTest method shouldVerifySequenceWithCallback.
@Test
public void shouldVerifySequenceWithCallback() 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 VerificationSequence().withRequests(request("one"), request("three")), 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 shouldVerifyWithFuture.
@Test
public void shouldVerifyWithFuture() 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 Verification().withRequest(request("two"))).get(5, SECONDS);
// then
assertThat(result, is(""));
}
use of org.mockserver.log.MockServerEventLog in project mockserver by mock-server.
the class HttpStateTest method shouldVerifyFailureWithCallback.
@Test
public void shouldVerifyFailureWithCallback() throws Exception {
// given
MockServerEventLog mockServerEventLog = httpState.getMockServerLog();
mockServerEventLog.add(new LogEntry().setHttpRequest(request("one")).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("Request not found at least once, expected:<{" + NEW_LINE + " \"path\" : \"two\"" + NEW_LINE + "}> but was:<{" + NEW_LINE + " \"path\" : \"one\"" + NEW_LINE + "}>"));
}
use of org.mockserver.log.MockServerEventLog in project mockserver by mock-server.
the class HttpStateTest method shouldHandleVerifyRequest.
@Test
public void shouldHandleVerifyRequest() {
// 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/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(202));
assertThat(responseWriter.response.getBodyAsString(), is(""));
}
use of org.mockserver.log.MockServerEventLog in project mockserver by mock-server.
the class DashboardWebSocketHandlerTest method shouldRenderFilteredLogEntriesCorrectly.
private void shouldRenderFilteredLogEntriesCorrectly(boolean contains, RequestDefinition requestFilter, List<LogEntry> logEntries, List<Expectation> expectations, String... renderListSections) throws InterruptedException {
// given
MockServerLogger mockServerLogger = new MockServerLogger(DashboardWebSocketHandlerTest.class);
Scheduler scheduler = new Scheduler(configuration(), mockServerLogger, true);
HttpState httpState = new HttpState(configuration(), mockServerLogger, scheduler);
new Scheduler.SchedulerThreadFactory("MockServer Test " + this.getClass().getSimpleName()).newThread(() -> {
MockServerEventLog mockServerEventLog = httpState.getMockServerLog();
for (LogEntry logEntry : logEntries) {
mockServerEventLog.add(logEntry);
}
RequestMatchers requestMatchers = httpState.getRequestMatchers();
if (!expectations.isEmpty()) {
requestMatchers.update(expectations.toArray(new Expectation[0]), MockServerMatcherNotifier.Cause.API);
}
}).start();
SECONDS.sleep(1);
DashboardWebSocketHandler handler = new DashboardWebSocketHandler(httpState, false, true).registerListeners();
MockChannelHandlerContext mockChannelHandlerContext = new MockChannelHandlerContext();
handler.getClientRegistry().put(mockChannelHandlerContext, request());
// when
handler.sendUpdate(mockChannelHandlerContext, requestFilter);
SECONDS.sleep(1);
// then
TextWebSocketFrame textWebSocketFrame = mockChannelHandlerContext.textWebSocketFrame;
for (String renderListSection : renderListSections) {
assertThat(textWebSocketFrame.text(), contains ? containsString(renderListSection) : is(renderListSection));
}
}
Aggregations