use of org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx in project incubator-servicecomb-java-chassis by apache.
the class TestRestTemplateCopyHeaderFilter method beforeSendRequestHaveHeader.
@Test
public void beforeSendRequestHaveHeader(@Mocked Invocation invocation) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("name", "value");
Map<String, Object> context = new HashMap<>();
context.put(RestConst.CONSUMER_HEADER, httpHeaders);
new Expectations() {
{
invocation.getHandlerContext();
result = context;
}
};
HttpServletRequestEx requestEx = new CommonToHttpServletRequest(null, null, new HttpHeaders(), null, false);
filter.beforeSendRequest(invocation, requestEx);
Assert.assertThat(Collections.list(requestEx.getHeaders("name")), Matchers.contains("value"));
}
use of org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx in project incubator-servicecomb-java-chassis by apache.
the class TestRestTemplateCopyHeaderFilter method beforeSendRequestWithNullHeader.
@Test
public void beforeSendRequestWithNullHeader(@Mocked Invocation invocation) {
Map<String, Object> context = new HashMap<>(1);
HttpHeaders httpHeaders = new HttpHeaders();
context.put(RestConst.CONSUMER_HEADER, httpHeaders);
httpHeaders.add("headerName0", "headerValue0");
httpHeaders.add("headerName1", null);
httpHeaders.add("headerName2", "headerValue2");
new Expectations() {
{
invocation.getHandlerContext();
result = context;
}
};
HttpServletRequestEx requestEx = new CommonToHttpServletRequest(null, null, new HttpHeaders(), null, false);
filter.beforeSendRequest(invocation, requestEx);
Assert.assertEquals("headerValue0", requestEx.getHeader("headerName0"));
Assert.assertEquals("headerValue2", requestEx.getHeader("headerName2"));
Assert.assertNull(requestEx.getHeader("headerName1"));
}
use of org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx in project incubator-servicecomb-java-chassis by apache.
the class TestRestTemplateCopyHeaderFilter method beforeSendRequestNoHeader.
@Test
public void beforeSendRequestNoHeader(@Mocked Invocation invocation) {
Map<String, Object> context = new HashMap<>();
new Expectations() {
{
invocation.getHandlerContext();
result = context;
}
};
HttpServletRequestEx requestEx = new CommonToHttpServletRequest(null, null, new HttpHeaders(), null, false);
filter.beforeSendRequest(invocation, requestEx);
Assert.assertFalse(requestEx.getHeaderNames().hasMoreElements());
}
use of org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx in project incubator-servicecomb-java-chassis by apache.
the class TestCommonToHttpServletRequest method testSetHeader.
@Test
public void testSetHeader() {
Map<String, List<String>> httpHeaders = new HashMap<>();
HttpServletRequestEx request = new CommonToHttpServletRequest(null, null, httpHeaders, null, false);
request.setHeader("name", "v1");
request.setHeader("name", "v2");
Assert.assertEquals("v2", request.getHeader("name"));
}
use of org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx in project incubator-servicecomb-java-chassis by apache.
the class TestCommonToHttpServletRequest method testAddHeader.
@Test
public void testAddHeader() {
Map<String, List<String>> httpHeaders = new HashMap<>();
HttpServletRequestEx request = new CommonToHttpServletRequest(null, null, httpHeaders, null, false);
request.addHeader("name", "v1");
request.addHeader("name", "v2");
Assert.assertThat(Collections.list(request.getHeaders("name")), Matchers.contains("v1", "v2"));
}
Aggregations