Search in sources :

Example 6 with HttpServletRequestEx

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"));
}
Also used : Expectations(mockit.Expectations) HttpHeaders(org.springframework.http.HttpHeaders) HashMap(java.util.HashMap) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx) Test(org.junit.Test)

Example 7 with HttpServletRequestEx

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"));
}
Also used : Expectations(mockit.Expectations) HttpHeaders(org.springframework.http.HttpHeaders) HashMap(java.util.HashMap) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx) Test(org.junit.Test)

Example 8 with HttpServletRequestEx

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());
}
Also used : Expectations(mockit.Expectations) HttpHeaders(org.springframework.http.HttpHeaders) HashMap(java.util.HashMap) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx) Test(org.junit.Test)

Example 9 with HttpServletRequestEx

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"));
}
Also used : HashMap(java.util.HashMap) List(java.util.List) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx) Test(org.junit.Test)

Example 10 with HttpServletRequestEx

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"));
}
Also used : HashMap(java.util.HashMap) List(java.util.List) HttpServletRequestEx(org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx) Test(org.junit.Test)

Aggregations

HttpServletRequestEx (org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx)13 Test (org.junit.Test)9 HashMap (java.util.HashMap)5 Expectations (mockit.Expectations)4 Invocation (org.apache.servicecomb.core.Invocation)3 HttpHeaders (org.springframework.http.HttpHeaders)3 List (java.util.List)2 HttpServletResponseEx (org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx)2 StandardHttpServletRequestEx (org.apache.servicecomb.foundation.vertx.http.StandardHttpServletRequestEx)2 Buffer (io.vertx.core.buffer.Buffer)1 HttpClientRequest (io.vertx.core.http.HttpClientRequest)1 PrintWriter (java.io.PrintWriter)1 AsyncContext (javax.servlet.AsyncContext)1 ServletRequest (javax.servlet.ServletRequest)1 ServletResponse (javax.servlet.ServletResponse)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 MockUp (mockit.MockUp)1 RestProducerInvocation (org.apache.servicecomb.common.rest.RestProducerInvocation)1 RestClientRequestImpl (org.apache.servicecomb.common.rest.codec.param.RestClientRequestImpl)1 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)1