Search in sources :

Example 26 with HttpServerRequest

use of io.vertx.core.http.HttpServerRequest in project java-chassis by ServiceComb.

the class TestVertxToServletMockRequest method testGetLocalPort.

@Test
public void testGetLocalPort() {
    try {
        init();
        HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
        Deencapsulation.setField(instance, "vertxRequest", httpServerRequest);
        SocketAddress socketAddress = Mockito.mock(SocketAddress.class);
        Mockito.when(httpServerRequest.localAddress()).thenReturn(socketAddress);
        Mockito.when(socketAddress.port()).thenReturn(8080);
        instance.getLocalPort();
    } catch (Exception e) {
        Assert.assertNotNull(e);
    } catch (Error e) {
        Assert.assertNotNull(e);
    }
}
Also used : HttpServerRequest(io.vertx.core.http.HttpServerRequest) SocketAddress(io.vertx.core.net.SocketAddress) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 27 with HttpServerRequest

use of io.vertx.core.http.HttpServerRequest in project java-chassis by ServiceComb.

the class TestVertxToServletMockRequest method testGetRemotePort.

@Test
public void testGetRemotePort() {
    try {
        init();
        HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
        Deencapsulation.setField(instance, "vertxRequest", httpServerRequest);
        SocketAddress socketAddress = Mockito.mock(SocketAddress.class);
        Mockito.when(httpServerRequest.remoteAddress()).thenReturn(socketAddress);
        Mockito.when(socketAddress.port()).thenReturn(8080);
        Assert.assertEquals(8080, instance.getRemotePort());
    } catch (Exception e) {
        Assert.assertNotNull(e);
    } catch (Error e) {
        Assert.assertNotNull(e);
    }
}
Also used : HttpServerRequest(io.vertx.core.http.HttpServerRequest) SocketAddress(io.vertx.core.net.SocketAddress) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 28 with HttpServerRequest

use of io.vertx.core.http.HttpServerRequest in project java-chassis by ServiceComb.

the class TestVertxToServletMockRequest method testGetParameterValues.

@Test
public void testGetParameterValues() {
    boolean validAssert = true;
    try {
        HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
        Deencapsulation.setField(instance, "vertxRequest", httpServerRequest);
        MultiMap multiMap = Mockito.mock(MultiMap.class);
        Mockito.when(httpServerRequest.params()).thenReturn(multiMap);
        List<String> stringList = new ArrayList<String>();
        stringList.add("sters");
        Mockito.when(multiMap.getAll("key")).thenReturn(stringList);
        Assert.assertNotNull(instance.getParameterValues("param"));
    } catch (Exception e) {
        Assert.assertNotNull(e);
        validAssert = false;
    } catch (Error e) {
        Assert.assertNotNull(e);
        validAssert = false;
    }
    Assert.assertTrue(validAssert);
}
Also used : MultiMap(io.vertx.core.MultiMap) HttpServerRequest(io.vertx.core.http.HttpServerRequest) ArrayList(java.util.ArrayList) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 29 with HttpServerRequest

use of io.vertx.core.http.HttpServerRequest in project java-chassis by ServiceComb.

the class TestVertxToServletMockRequest method testGetParameterMap.

@Test
public void testGetParameterMap() {
    boolean validAssert = true;
    try {
        init();
        @SuppressWarnings("unused") Map<String, String[]> paramMap = new HashMap<>();
        HttpServerRequest httpServerRequest = Mockito.mock(HttpServerRequest.class);
        Deencapsulation.setField(instance, "vertxRequest", httpServerRequest);
        MultiMap multiMap = Mockito.mock(MultiMap.class);
        Mockito.when(httpServerRequest.params()).thenReturn(multiMap);
        Set<String> stringSet = new HashSet<String>();
        stringSet.add("sters");
        Mockito.when(multiMap.names()).thenReturn(stringSet);
        Assert.assertNotNull(instance.getParameterMap());
    } catch (Exception e) {
        Assert.assertNotNull(e);
        validAssert = false;
    } catch (Error e) {
        Assert.assertNotNull(e);
        validAssert = false;
    }
    Assert.assertTrue(validAssert);
}
Also used : MultiMap(io.vertx.core.MultiMap) HashMap(java.util.HashMap) HttpServerRequest(io.vertx.core.http.HttpServerRequest) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 30 with HttpServerRequest

use of io.vertx.core.http.HttpServerRequest in project java-chassis by ServiceComb.

the class TestGrpcCodec method testEncodeResponse.

@Test
public void testEncodeResponse() {
    boolean status = false;
    try {
        OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
        WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
        Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
        HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
        Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
        Invocation invocation = Mockito.mock(Invocation.class);
        Response response = Mockito.mock(Response.class);
        Mockito.when(response.getResult()).thenReturn("test");
        Mockito.when(operationProtobuf.getResponseSchema()).thenReturn(Mockito.mock(WrapSchema.class));
        GrpcCodec.encodeResponse(invocation, response, operationProtobuf);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : HttpClientResponse(io.vertx.core.http.HttpClientResponse) Response(io.servicecomb.core.Response) Invocation(io.servicecomb.core.Invocation) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) HttpServerRequest(io.vertx.core.http.HttpServerRequest) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) Test(org.junit.Test)

Aggregations

HttpServerRequest (io.vertx.core.http.HttpServerRequest)31 Test (org.junit.Test)27 MultiMap (io.vertx.core.MultiMap)16 IOException (java.io.IOException)16 Buffer (io.vertx.core.buffer.Buffer)14 ArrayList (java.util.ArrayList)14 HttpServerOptions (io.vertx.core.http.HttpServerOptions)13 HashSet (java.util.HashSet)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 Bootstrap (io.netty.bootstrap.Bootstrap)10 ByteBuf (io.netty.buffer.ByteBuf)10 Unpooled (io.netty.buffer.Unpooled)10 Channel (io.netty.channel.Channel)10 ChannelDuplexHandler (io.netty.channel.ChannelDuplexHandler)10 ChannelFuture (io.netty.channel.ChannelFuture)10 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)10 ChannelInitializer (io.netty.channel.ChannelInitializer)10 ChannelPipeline (io.netty.channel.ChannelPipeline)10 EventLoopGroup (io.netty.channel.EventLoopGroup)10 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)10