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);
}
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);
}
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));
}
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()));
}
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));
}
Aggregations