Search in sources :

Example 11 with OperationProtobuf

use of io.servicecomb.codec.protobuf.definition.OperationProtobuf in project java-chassis by ServiceComb.

the class TestGrpcServerInvoke method testSendSuccessResponse.

@Test
public void testSendSuccessResponse() {
    boolean status = false;
    try {
        new MockUp<GrpcCodec>() {

            @Mock
            public Buffer encodeResponse(Invocation invocation, Response response, OperationProtobuf operationProtobuf) throws Exception {
                return Mockito.mock(Buffer.class);
            }
        };
        MockUtil.getInstance().mockMicroserviceMetaManager();
        Invocation invocation = Mockito.mock(Invocation.class);
        Response response = Mockito.mock(Response.class);
        Mockito.when(response.getResult()).thenReturn("test");
        Mockito.when(routingContext.response()).thenReturn(Mockito.mock(HttpServerResponse.class));
        OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
        Mockito.when(response.getResult()).thenReturn("test");
        Mockito.when(operationProtobuf.getResponseSchema()).thenReturn(Mockito.mock(WrapSchema.class));
        Deencapsulation.setField(lGrpcServerInvoke, "routingContext", routingContext);
        Deencapsulation.invoke(lGrpcServerInvoke, "sendSuccessResponse", invocation, response);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertTrue(status);
}
Also used : HttpServerResponse(io.vertx.core.http.HttpServerResponse) Response(io.servicecomb.core.Response) Invocation(io.servicecomb.core.Invocation) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) HttpServerResponse(io.vertx.core.http.HttpServerResponse) MockUp(mockit.MockUp) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) Test(org.junit.Test)

Example 12 with OperationProtobuf

use of io.servicecomb.codec.protobuf.definition.OperationProtobuf 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)

Example 13 with OperationProtobuf

use of io.servicecomb.codec.protobuf.definition.OperationProtobuf 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

OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)13 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)9 Invocation (io.servicecomb.core.Invocation)9 OperationMeta (io.servicecomb.core.definition.OperationMeta)8 Test (org.junit.Test)8 Response (io.servicecomb.core.Response)7 Buffer (io.vertx.core.buffer.Buffer)5 HttpClientResponse (io.vertx.core.http.HttpClientResponse)4 HttpServerRequest (io.vertx.core.http.HttpServerRequest)4 AsyncResponse (io.servicecomb.core.AsyncResponse)3 SchemaMeta (io.servicecomb.core.definition.SchemaMeta)3 HttpServerResponse (io.vertx.core.http.HttpServerResponse)3 MockUp (mockit.MockUp)3 Endpoint (io.servicecomb.core.Endpoint)2 IpPort (io.servicecomb.foundation.common.net.IpPort)2 HttpClientWithContext (io.servicecomb.foundation.vertx.client.http.HttpClientWithContext)2 RoutingContext (io.vertx.ext.web.RoutingContext)2 LinkedBuffer (io.protostuff.LinkedBuffer)1 ProtobufManager (io.servicecomb.codec.protobuf.definition.ProtobufManager)1 Const (io.servicecomb.core.Const)1