Search in sources :

Example 1 with HttpServerConfiguration

use of io.micronaut.http.server.HttpServerConfiguration in project micronaut-core by micronaut-projects.

the class HttpRequestTest method testForEach2.

public void testForEach2() {
    final DefaultFullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, io.netty.handler.codec.http.HttpMethod.GET, "/test");
    nettyRequest.headers().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    nettyRequest.headers().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML);
    HttpRequest<?> request = new NettyHttpRequest(nettyRequest, new DetachedMockFactory().Mock(ChannelHandlerContext.class), ConversionService.SHARED, new HttpServerConfiguration());
    final HttpHeaders headers = request.getHeaders();
    headers.forEach((name, values) -> {
        assertEquals(HttpHeaders.CONTENT_TYPE, name);
        assertEquals(2, values.size());
        assertTrue(values.contains(MediaType.APPLICATION_JSON));
        assertTrue(values.contains(MediaType.APPLICATION_XML));
    });
    AtomicInteger integer = new AtomicInteger(0);
    headers.forEachValue((s, s2) -> integer.incrementAndGet());
    assertEquals(2, integer.get());
}
Also used : HttpHeaders(io.micronaut.http.HttpHeaders) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpServerConfiguration(io.micronaut.http.server.HttpServerConfiguration) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) NettyHttpRequest(io.micronaut.http.server.netty.NettyHttpRequest) DetachedMockFactory(spock.mock.DetachedMockFactory)

Example 2 with HttpServerConfiguration

use of io.micronaut.http.server.HttpServerConfiguration in project micronaut-core by micronaut-projects.

the class HttpRequestTest method testForEach.

public void testForEach() {
    final DefaultFullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, io.netty.handler.codec.http.HttpMethod.GET, "/test");
    nettyRequest.headers().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    HttpRequest<?> request = new NettyHttpRequest(nettyRequest, new DetachedMockFactory().Mock(ChannelHandlerContext.class), ConversionService.SHARED, new HttpServerConfiguration());
    final HttpHeaders headers = request.getHeaders();
    headers.forEach((name, values) -> {
        assertEquals(HttpHeaders.CONTENT_TYPE, name);
        assertEquals(1, values.size());
        assertEquals(MediaType.APPLICATION_JSON, values.iterator().next());
    });
}
Also used : HttpHeaders(io.micronaut.http.HttpHeaders) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpServerConfiguration(io.micronaut.http.server.HttpServerConfiguration) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) NettyHttpRequest(io.micronaut.http.server.netty.NettyHttpRequest) DetachedMockFactory(spock.mock.DetachedMockFactory)

Aggregations

HttpHeaders (io.micronaut.http.HttpHeaders)2 HttpServerConfiguration (io.micronaut.http.server.HttpServerConfiguration)2 NettyHttpRequest (io.micronaut.http.server.netty.NettyHttpRequest)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)2 DetachedMockFactory (spock.mock.DetachedMockFactory)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1