Search in sources :

Example 11 with WrapSchema

use of io.servicecomb.codec.protobuf.utils.WrapSchema 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

WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)11 Test (org.junit.Test)7 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)6 OperationMeta (io.servicecomb.core.definition.OperationMeta)6 Invocation (io.servicecomb.core.Invocation)5 Buffer (io.vertx.core.buffer.Buffer)4 HttpServerRequest (io.vertx.core.http.HttpServerRequest)4 Response (io.servicecomb.core.Response)3 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)3 HttpClientResponse (io.vertx.core.http.HttpClientResponse)3 Endpoint (io.servicecomb.core.Endpoint)2 ResponseHeader (io.servicecomb.transport.highway.message.ResponseHeader)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 ArgsNotWrapSchema (io.servicecomb.codec.protobuf.utils.schema.ArgsNotWrapSchema)1 NormalWrapSchema (io.servicecomb.codec.protobuf.utils.schema.NormalWrapSchema)1 NotWrapSchema (io.servicecomb.codec.protobuf.utils.schema.NotWrapSchema)1 AsyncResponse (io.servicecomb.core.AsyncResponse)1 InvocationException (io.servicecomb.core.exception.InvocationException)1 UnitTestMeta (io.servicecomb.core.unittest.UnitTestMeta)1 IpPort (io.servicecomb.foundation.common.net.IpPort)1