Search in sources :

Example 1 with HttpRequestMessageLogger

use of com.hotels.styx.common.logging.HttpRequestMessageLogger in project styx by ExpediaGroup.

the class HttpRequestMessageLoggerTest method requestLoggingDoesNotThrowExceptionWhenReceivingNullArguments.

@Test
public void requestLoggingDoesNotThrowExceptionWhenReceivingNullArguments() {
    new HttpRequestMessageLogger("com.hotels.styx.http-messages.outbound", false, httpMessageFormatter).logRequest(null, origin, true);
    assertThat(log.lastMessage(), is(loggingEvent(WARN, "requestId=N/A, origin=MyApp:h1:hostA:80, request=null")));
}
Also used : HttpRequestMessageLogger(com.hotels.styx.common.logging.HttpRequestMessageLogger) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with HttpRequestMessageLogger

use of com.hotels.styx.common.logging.HttpRequestMessageLogger in project styx by ExpediaGroup.

the class HttpRequestMessageLoggerTest method logsClientSideResponseDetailsLongFormat.

@Test
public void logsClientSideResponseDetailsLongFormat() {
    LiveHttpRequest styxRequest = get("http://www.hotels.com/foo/bar/request").build();
    LiveHttpResponse styxResponse = response(OK).build();
    new HttpRequestMessageLogger("com.hotels.styx.http-messages.outbound", true, httpMessageFormatter).logResponse(styxRequest, styxResponse);
    assertThat(log.lastMessage(), is(loggingEvent(INFO, format("requestId=%s, response=" + FORMATTED_RESPONSE, styxRequest.id()))));
}
Also used : HttpRequestMessageLogger(com.hotels.styx.common.logging.HttpRequestMessageLogger) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with HttpRequestMessageLogger

use of com.hotels.styx.common.logging.HttpRequestMessageLogger in project styx by ExpediaGroup.

the class HttpRequestMessageLoggerTest method logsClientSideResponseDetailsShortFormat.

@Test
public void logsClientSideResponseDetailsShortFormat() {
    LiveHttpRequest styxRequest = get("http://www.hotels.com/foo/bar/request").build();
    LiveHttpResponse styxResponse = response(OK).build();
    new HttpRequestMessageLogger("com.hotels.styx.http-messages.outbound", false, httpMessageFormatter).logResponse(styxRequest, styxResponse);
    assertThat(log.lastMessage(), is(loggingEvent(INFO, format("requestId=%s, response=\\{version=HTTP/1.1, status=200 OK\\}", styxRequest.id()))));
}
Also used : HttpRequestMessageLogger(com.hotels.styx.common.logging.HttpRequestMessageLogger) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with HttpRequestMessageLogger

use of com.hotels.styx.common.logging.HttpRequestMessageLogger in project styx by ExpediaGroup.

the class HttpRequestMessageLoggerTest method responseLoggingDoesNotThrowExceptionWhenReceivingNullArguments.

@ParameterizedTest
@MethodSource("responseLogUnexpectedArguments")
public void responseLoggingDoesNotThrowExceptionWhenReceivingNullArguments(LiveHttpRequest request, LiveHttpResponse response, Level expectedLogLevel, String expectedLogMessage) {
    new HttpRequestMessageLogger("com.hotels.styx.http-messages.outbound", false, httpMessageFormatter).logResponse(request, response);
    assertThat(log.lastMessage(), is(loggingEvent(expectedLogLevel, expectedLogMessage)));
}
Also used : HttpRequestMessageLogger(com.hotels.styx.common.logging.HttpRequestMessageLogger) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with HttpRequestMessageLogger

use of com.hotels.styx.common.logging.HttpRequestMessageLogger in project styx by ExpediaGroup.

the class HttpRequestMessageLoggerTest method logsClientSideRequestLongFormat.

@Test
public void logsClientSideRequestLongFormat() {
    LiveHttpRequest styxRequest = get("http://www.hotels.com/foo/bar/request").build();
    new HttpRequestMessageLogger("com.hotels.styx.http-messages.outbound", true, httpMessageFormatter).logRequest(styxRequest, origin, true);
    assertThat(log.lastMessage(), is(loggingEvent(INFO, format("requestId=%s, secure=true, origin=%s, request=" + FORMATTED_REQUEST, styxRequest.id(), origin))));
}
Also used : HttpRequestMessageLogger(com.hotels.styx.common.logging.HttpRequestMessageLogger) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

HttpRequestMessageLogger (com.hotels.styx.common.logging.HttpRequestMessageLogger)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Test (org.junit.jupiter.api.Test)5 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)4 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)1