Search in sources :

Example 31 with HttpServerRequest

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

the class TestGrpcCodec method testDecodeResponseEx.

@Test
public void testDecodeResponseEx() {
    boolean status = false;
    OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
    OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
    WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
    Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
    Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
    HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
    SchemaMeta schemaMeta = Mockito.mock(SchemaMeta.class);
    Mockito.when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta);
    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));
    HttpClientResponse httpResponse = Mockito.mock(HttpClientResponse.class);
    Buffer buffer = Mockito.mock(Buffer.class);
    Mockito.when(httpResponse.statusCode()).thenReturn(200);
    try {
        GrpcCodec.decodeResponse(invocation, operationProtobuf, httpResponse, buffer);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : HttpClientResponse(io.vertx.core.http.HttpClientResponse) Response(io.servicecomb.core.Response) Buffer(io.vertx.core.buffer.Buffer) Invocation(io.servicecomb.core.Invocation) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) HttpServerRequest(io.vertx.core.http.HttpServerRequest) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) HttpClientResponse(io.vertx.core.http.HttpClientResponse) OperationMeta(io.servicecomb.core.definition.OperationMeta) 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