Search in sources :

Example 26 with LiveHttpResponse

use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.

the class StyxToNettyResponseTranslatorTest method shouldCreateNettyResponseWithoutHeaders.

@Test
public void shouldCreateNettyResponseWithoutHeaders() throws Exception {
    LiveHttpResponse styxResponse = new LiveHttpResponse.Builder(OK).version(HTTP_1_1).build();
    io.netty.handler.codec.http.HttpResponse nettyResponse = translator.toNettyResponse(styxResponse);
    assertThat(nettyResponse.status(), equalTo(io.netty.handler.codec.http.HttpResponseStatus.OK));
    assertThat(nettyResponse.protocolVersion(), equalTo(io.netty.handler.codec.http.HttpVersion.HTTP_1_1));
}
Also used : LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 27 with LiveHttpResponse

use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.

the class StyxToNettyResponseTranslatorTest method shouldCreateNettyResponseWithHostHeader.

@Test
public void shouldCreateNettyResponseWithHostHeader() {
    LiveHttpResponse styxResponse = new LiveHttpResponse.Builder(OK).header("Host", "localhost").build();
    io.netty.handler.codec.http.HttpResponse nettyResponse = translator.toNettyResponse(styxResponse);
    assertTrue(nettyResponse.headers().containsValue("Host", "localhost", false));
}
Also used : LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) Test(org.junit.jupiter.api.Test)

Example 28 with LiveHttpResponse

use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.

the class StaticFileHandlerTest method setsTheContentTypeBasedOnFileExtension.

@ParameterizedTest
@MethodSource("fileTypesProvider")
public void setsTheContentTypeBasedOnFileExtension(String path, CharSequence mediaType) throws Exception {
    writeFile(path, mediaType.toString());
    handler = new StaticFileHandler(dir);
    LiveHttpResponse response = handle(get("/" + path).build());
    assertThat(response, hasStatus(OK));
    assertThat(response.contentType(), isValue(mediaType.toString()));
}
Also used : LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 29 with LiveHttpResponse

use of com.hotels.styx.api.LiveHttpResponse 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 30 with LiveHttpResponse

use of com.hotels.styx.api.LiveHttpResponse in project styx by ExpediaGroup.

the class HttpRequestMessageLoggerTest method responseLogUnexpectedArguments.

private static Stream<Arguments> responseLogUnexpectedArguments() {
    LiveHttpRequest normalRequest = get("http://www.hotels.com/foo/bar/request").build();
    LiveHttpResponse normalResponse = response(OK).build();
    return Stream.of(Arguments.of(normalRequest, null, WARN, "requestId=.*, response=null"), Arguments.of(null, normalResponse, INFO, "requestId=null, response=\\{version=HTTP/1.1, status=200 OK\\}"), Arguments.of(null, null, WARN, "requestId=null, response=null"));
}
Also used : LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse)

Aggregations

LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)80 Test (org.junit.jupiter.api.Test)69 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)25 Support.requestContext (com.hotels.styx.support.Support.requestContext)21 Eventual (com.hotels.styx.api.Eventual)15 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)15 HttpHandler (com.hotels.styx.api.HttpHandler)14 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)14 Mono (reactor.core.publisher.Mono)14 ByteStream (com.hotels.styx.api.ByteStream)13 Context (com.hotels.styx.api.HttpInterceptor.Context)13 OK (com.hotels.styx.api.HttpResponseStatus.OK)13 LiveHttpResponse.response (com.hotels.styx.api.LiveHttpResponse.response)13 TransportLostException (com.hotels.styx.api.exceptions.TransportLostException)12 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)12 CompletableFuture (java.util.concurrent.CompletableFuture)12 Matchers.is (org.hamcrest.Matchers.is)12 Buffer (com.hotels.styx.api.Buffer)11 LiveHttpRequest.get (com.hotels.styx.api.LiveHttpRequest.get)11 HttpInterceptorContext (com.hotels.styx.server.HttpInterceptorContext)11