Search in sources :

Example 16 with HttpHeaders

use of io.netty.handler.codec.http.HttpHeaders in project riposte by Nike-Inc.

the class HttpServletRequestWrapperForRequestInfoTest method getHeaders_delegates_to_requestInfo_headers.

@Test
public void getHeaders_delegates_to_requestInfo_headers() {
    // given
    HttpHeaders headersMock = mock(HttpHeaders.class);
    String headerKey = UUID.randomUUID().toString();
    List<String> headerVal = Arrays.asList(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    doReturn(headerVal).when(headersMock).getAll(headerKey);
    doReturn(headersMock).when(requestInfoMock).getHeaders();
    // when
    Enumeration<String> result = wrapper.getHeaders(headerKey);
    // then
    verify(headersMock).getAll(headerKey);
    assertThat(Collections.list(result)).isEqualTo(headerVal);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) Test(org.junit.Test)

Example 17 with HttpHeaders

use of io.netty.handler.codec.http.HttpHeaders in project riposte by Nike-Inc.

the class HttpServletRequestWrapperForRequestInfoTest method getHeader_delegates_to_requestInfo_headers.

@Test
public void getHeader_delegates_to_requestInfo_headers() {
    // given
    HttpHeaders headersMock = mock(HttpHeaders.class);
    String headerKey = UUID.randomUUID().toString();
    String headerVal = UUID.randomUUID().toString();
    doReturn(headerVal).when(headersMock).get(headerKey);
    doReturn(headersMock).when(requestInfoMock).getHeaders();
    // when
    String result = wrapper.getHeader(headerKey);
    // then
    verify(headersMock).get(headerKey);
    assertThat(result).isEqualTo(headerVal);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) Test(org.junit.Test)

Example 18 with HttpHeaders

use of io.netty.handler.codec.http.HttpHeaders in project riposte by Nike-Inc.

the class RequestInfoForLoggingRiposteAdapterTest method getHeaderMapReturnsEmptyMapIfNettyHeaderNamesReturnsNull.

@Test
public void getHeaderMapReturnsEmptyMapIfNettyHeaderNamesReturnsNull() {
    HttpHeaders headersMock = mock(HttpHeaders.class);
    doReturn(null).when(headersMock).names();
    setFieldOnRequestInfo("headers", headersMock);
    Map<String, List<String>> actualHeaderMap = adapter.getHeadersMap();
    assertThat(actualHeaderMap, notNullValue());
    assertThat(actualHeaderMap.isEmpty(), is(true));
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) List(java.util.List) Test(org.junit.Test)

Example 19 with HttpHeaders

use of io.netty.handler.codec.http.HttpHeaders in project riposte by Nike-Inc.

the class RequestInfoForLoggingRiposteAdapterTest method getHeadersDelegatesToRequestInfo.

@Test
public void getHeadersDelegatesToRequestInfo() {
    Pair<String, List<String>> header1 = Pair.of("header1", Arrays.asList("h1val1"));
    Pair<String, List<String>> header2 = Pair.of("header2", Arrays.asList("h2val1", "h2val2"));
    Map<String, List<String>> expectedHeaderMap = new TreeMap<>(MapBuilder.<String, List<String>>builder().put(header1.getKey(), header1.getValue()).put(header2.getKey(), header2.getValue()).build());
    HttpHeaders headersMock = mock(HttpHeaders.class);
    doReturn(expectedHeaderMap.keySet()).when(headersMock).names();
    for (Map.Entry<String, List<String>> entry : expectedHeaderMap.entrySet()) {
        doReturn(entry.getValue()).when(headersMock).getAll(entry.getKey());
    }
    setFieldOnRequestInfo("headers", headersMock);
    assertThat(adapter.getHeaders(header1.getKey()), is(header1.getValue()));
    assertThat(adapter.getHeaders(header2.getKey()), is(header2.getValue()));
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) List(java.util.List) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 20 with HttpHeaders

use of io.netty.handler.codec.http.HttpHeaders in project riposte by Nike-Inc.

the class RequestInfoForLoggingRiposteAdapterTest method getHeaderMapDelegatesToRequestInfoAndCachesResult.

@Test
public void getHeaderMapDelegatesToRequestInfoAndCachesResult() {
    Map<String, List<String>> expectedHeaderMap = new TreeMap<>(MapBuilder.<String, List<String>>builder().put("header1", Arrays.asList("h1val1")).put("header2", Arrays.asList("h2val1", "h2val2")).build());
    HttpHeaders nettyHeaders = new DefaultHttpHeaders();
    for (Map.Entry<String, List<String>> headerEntry : expectedHeaderMap.entrySet()) {
        nettyHeaders.add(headerEntry.getKey(), headerEntry.getValue());
    }
    setFieldOnRequestInfo("headers", nettyHeaders);
    Map<String, List<String>> actualHeaderMap = adapter.getHeadersMap();
    assertThat(actualHeaderMap, is(expectedHeaderMap));
    assertThat(adapter.getHeadersMap(), sameInstance(actualHeaderMap));
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) List(java.util.List) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Aggregations

HttpHeaders (io.netty.handler.codec.http.HttpHeaders)248 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)119 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)67 Test (org.junit.Test)61 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)56 Test (org.testng.annotations.Test)51 Test (org.junit.jupiter.api.Test)50 HttpRequest (io.netty.handler.codec.http.HttpRequest)33 AsciiString (io.netty.util.AsciiString)29 ByteBuf (io.netty.buffer.ByteBuf)27 BStruct (org.ballerinalang.model.values.BStruct)26 HttpResponse (io.netty.handler.codec.http.HttpResponse)23 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)21 Cookie (io.netty.handler.codec.http.cookie.Cookie)20 HttpServletResponse (javax.servlet.http.HttpServletResponse)20 BValue (org.ballerinalang.model.values.BValue)19 ChannelPromise (io.netty.channel.ChannelPromise)18 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)18 BString (org.ballerinalang.model.values.BString)18 DefaultCookie (io.netty.handler.codec.http.cookie.DefaultCookie)17