use of org.mockserver.log.model.LogEntry in project mockserver by mock-server.
the class MockServerEventLogRequestLogEntryVerificationTest method shouldFailVerificationWithLimitedReturnedRequests.
@Test
public void shouldFailVerificationWithLimitedReturnedRequests() {
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);
}
}
use of org.mockserver.log.model.LogEntry in project mockserver by mock-server.
the class HttpActionHandlerTest method shouldHandleResponseTemplateActionException.
@Test
public void shouldHandleResponseTemplateActionException() {
// given
HttpTemplate template = template(HttpTemplate.TemplateType.JAVASCRIPT, "some_template").withDelay(milliseconds(1));
expectation = new Expectation(request).thenRespond(template);
when(mockHttpStateHandler.firstMatchingExpectation(request)).thenReturn(expectation);
RuntimeException throwable = new RuntimeException("TEST_EXCEPTION");
when(mockHttpResponseTemplateActionHandler.handle(any(HttpTemplate.class), any(HttpRequest.class))).thenThrow(throwable);
// when
actionHandler.processAction(request, mockResponseWriter, null, new HashSet<>(), false, true);
// then
verify(mockHttpResponseTemplateActionHandler).handle(template, request);
verify(mockResponseWriter).writeResponse(request, notFoundResponse(), false);
verify(mockServerLogger).logEvent(new LogEntry().setType(RECEIVED_REQUEST).setLogLevel(Level.INFO).setHttpRequest(request).setMessageFormat(RECEIVED_REQUEST_MESSAGE_FORMAT).setArguments(request));
verify(mockServerLogger).logEvent(new LogEntry().setType(EXPECTATION_RESPONSE).setLogLevel(Level.INFO).setHttpRequest(request).setHttpResponse(notFoundResponse()).setMessageFormat("returning response:{}for request:{}for action:{}from expectation:{}").setArguments(notFoundResponse(), request, expectation.getAction(), expectation.getId()));
verify(mockServerLogger).logEvent(new LogEntry().setType(WARN).setLogLevel(Level.INFO).setHttpRequest(request).setMessageFormat(throwable.getMessage()).setThrowable(throwable));
}
use of org.mockserver.log.model.LogEntry in project mockserver by mock-server.
the class HttpActionHandlerTest method shouldHandleForwardTemplateActionException.
@Test
public void shouldHandleForwardTemplateActionException() {
// given
HttpTemplate template = template(HttpTemplate.TemplateType.JAVASCRIPT, "some_template");
expectation = new Expectation(request).thenForward(template);
when(mockHttpStateHandler.firstMatchingExpectation(request)).thenReturn(expectation);
RuntimeException throwable = new RuntimeException("TEST_EXCEPTION");
when(mockHttpForwardTemplateActionHandler.handle(any(HttpTemplate.class), any(HttpRequest.class))).thenThrow(throwable);
// when
actionHandler.processAction(request, mockResponseWriter, null, new HashSet<>(), false, true);
// then
verify(mockHttpForwardTemplateActionHandler).handle(template, request);
verify(mockResponseWriter).writeResponse(request, notFoundResponse(), false);
verify(mockServerLogger).logEvent(new LogEntry().setType(RECEIVED_REQUEST).setLogLevel(Level.INFO).setHttpRequest(request).setMessageFormat(RECEIVED_REQUEST_MESSAGE_FORMAT).setArguments(request));
verify(mockServerLogger).logEvent(new LogEntry().setType(EXPECTATION_RESPONSE).setLogLevel(Level.INFO).setHttpRequest(request).setHttpResponse(notFoundResponse()).setMessageFormat("returning response:{}for request:{}for action:{}from expectation:{}").setArguments(notFoundResponse(), request, expectation.getAction(), expectation.getId()));
verify(mockServerLogger).logEvent(new LogEntry().setType(WARN).setLogLevel(Level.INFO).setHttpRequest(request).setMessageFormat(throwable.getMessage()).setThrowable(throwable));
}
use of org.mockserver.log.model.LogEntry in project mockserver by mock-server.
the class HttpActionHandlerTest method shouldProcessResponseAction.
@Test
public void shouldProcessResponseAction() {
// given
HttpResponse response = response("some_body").withDelay(milliseconds(1));
expectation = new Expectation(request).thenRespond(response);
when(mockHttpStateHandler.firstMatchingExpectation(request)).thenReturn(expectation);
// when
actionHandler.processAction(request, mockResponseWriter, null, new HashSet<>(), false, true);
// then
verify(mockHttpResponseActionHandler).handle(response);
verify(mockResponseWriter).writeResponse(request, this.response, false);
verify(mockServerLogger).logEvent(new LogEntry().setType(RECEIVED_REQUEST).setLogLevel(Level.INFO).setHttpRequest(request).setMessageFormat(RECEIVED_REQUEST_MESSAGE_FORMAT).setArguments(request));
verify(mockServerLogger).logEvent(new LogEntry().setLogLevel(INFO).setType(EXPECTATION_RESPONSE).setHttpRequest(request).setHttpResponse(this.response).setMessageFormat("returning response:{}for request:{}for action:{}from expectation:{}").setArguments(this.response, request, response, expectation.getId()));
verify(scheduler).schedule(any(Runnable.class), eq(true), eq(milliseconds(0)));
verify(scheduler).schedule(any(Runnable.class), eq(true), eq(milliseconds(0)));
}
use of org.mockserver.log.model.LogEntry in project mockserver by mock-server.
the class VelocityTemplateEngineTest method shouldHandleHttpRequestsWithVelocityForwardTemplateFirstExample.
@Test
public void shouldHandleHttpRequestsWithVelocityForwardTemplateFirstExample() throws JsonProcessingException {
// given
String template = "{" + NEW_LINE + " 'path' : \"/somePath\"," + NEW_LINE + " 'cookies' : [ {" + NEW_LINE + " 'name' : \"$!request.cookies['someCookie']\"," + NEW_LINE + " 'value' : \"someCookie\"" + NEW_LINE + " }, {" + NEW_LINE + " 'name' : \"someCookie\"," + NEW_LINE + " 'value' : \"$!request.cookies['someCookie']\"" + NEW_LINE + " } ]," + NEW_LINE + " 'keepAlive' : true," + NEW_LINE + " 'secure' : true," + NEW_LINE + " 'body' : \"some_body\"" + NEW_LINE + "}";
HttpRequest request = request().withPath("/somePath").withCookie("someCookie", "someValue").withMethod("POST").withBody("some_body");
// when
HttpRequest actualHttpRequest = new VelocityTemplateEngine(logFormatter).executeTemplate(template, request, HttpRequestDTO.class);
// then
assertThat(actualHttpRequest, is(request().withPath("/somePath").withCookie("someCookie", "someValue").withCookie("someValue", "someCookie").withKeepAlive(true).withSecure(true).withBody("some_body")));
verify(logFormatter).logEvent(new LogEntry().setType(TEMPLATE_GENERATED).setLogLevel(INFO).setHttpRequest(request).setMessageFormat("generated output:{}from template:{}for request:{}").setArguments(OBJECT_MAPPER.readTree("" + "{" + NEW_LINE + " 'path' : \"/somePath\"," + NEW_LINE + " 'cookies' : [ {" + NEW_LINE + " 'name' : \"someValue\"," + NEW_LINE + " 'value' : \"someCookie\"" + NEW_LINE + " }, {" + NEW_LINE + " 'name' : \"someCookie\"," + NEW_LINE + " 'value' : \"someValue\"" + NEW_LINE + " } ]," + NEW_LINE + " 'keepAlive' : true," + NEW_LINE + " 'secure' : true," + NEW_LINE + " 'body' : \"some_body\"" + NEW_LINE + "}"), template, request));
}
Aggregations