Search in sources :

Example 6 with OperationProtobuf

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

the class TestGrpcCodec method testDecodeRequest.

@Test
public void testDecodeRequest() {
    boolean status = false;
    try {
        RoutingContext routingContext = Mockito.mock(RoutingContext.class);
        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);
        Buffer bodyBuffer = Mockito.mock(Buffer.class);
        Mockito.when(routingContext.getBody()).thenReturn(bodyBuffer);
        HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
        Mockito.when(routingContext.request()).thenReturn(request);
        SchemaMeta schemaMeta = Mockito.mock(SchemaMeta.class);
        Mockito.when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta);
        Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
        GrpcCodec.setGrpcTransport(new GrpcTransport());
        GrpcCodec.decodeRequest(routingContext, operationMeta);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) RoutingContext(io.vertx.ext.web.RoutingContext) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) HttpServerRequest(io.vertx.core.http.HttpServerRequest) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) Test(org.junit.Test)

Example 7 with OperationProtobuf

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

the class TestGrpcTransport method testSend.

@Test
public void testSend() {
    boolean status = false;
    Invocation invocation = Mockito.mock(Invocation.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
    Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
    OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
    Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
    Endpoint lEndpoint = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(lEndpoint);
    WrapSchema lWrapSchema = Mockito.mock(WrapSchema.class);
    Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(lWrapSchema);
    IpPort ipPort = Mockito.mock(IpPort.class);
    Mockito.when(lEndpoint.getAddress()).thenReturn(ipPort);
    Mockito.when(ipPort.getHostOrIp()).thenReturn("127.0.0.1");
    Mockito.when(ipPort.getPort()).thenReturn(80);
    new MockUp<ClientPoolManager<HttpClientWithContext>>() {

        @Mock
        public HttpClientWithContext findThreadBindClientPool() {
            return Mockito.mock(HttpClientWithContext.class);
        }
    };
    try {
        transport.send(invocation, asyncResp);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : Invocation(io.servicecomb.core.Invocation) Endpoint(io.servicecomb.core.Endpoint) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) HttpClientWithContext(io.servicecomb.foundation.vertx.client.http.HttpClientWithContext) IpPort(io.servicecomb.foundation.common.net.IpPort) MockUp(mockit.MockUp) OperationMeta(io.servicecomb.core.definition.OperationMeta) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 8 with OperationProtobuf

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

the class TestHighwayTransport method commonHighwayMock.

private void commonHighwayMock(Invocation invocation) {
    OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
    Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
    OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
    Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
    Endpoint lEndpoint = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(lEndpoint);
    WrapSchema lWrapSchema = Mockito.mock(WrapSchema.class);
    Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(lWrapSchema);
    URIEndpointObject ep = Mockito.mock(URIEndpointObject.class);
    Mockito.when(lEndpoint.getAddress()).thenReturn(ep);
    Mockito.when(ep.getHostOrIp()).thenReturn("127.0.0.1");
    Mockito.when(ep.getPort()).thenReturn(80);
}
Also used : Endpoint(io.servicecomb.core.Endpoint) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) OperationMeta(io.servicecomb.core.definition.OperationMeta) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject)

Example 9 with OperationProtobuf

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

the class TestGrpcServerInvoke method testSendSuccessResponseException.

@Test
public void testSendSuccessResponseException() {
    boolean status = false;
    try {
        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));
        try {
            Deencapsulation.invoke(lGrpcServerInvoke, "onProviderResponse", invocation, response);
        } catch (Exception e) {
        }
        OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
        Mockito.when(response.getResult()).thenReturn("test");
        Mockito.when(operationProtobuf.getResponseSchema()).thenReturn(Mockito.mock(WrapSchema.class));
        Deencapsulation.setField(lGrpcServerInvoke, "operationProtobuf", operationProtobuf);
        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) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) Test(org.junit.Test)

Example 10 with OperationProtobuf

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

the class TestGrpcServerInvoke method testSendSuccessResponseExptn.

@Test
public void testSendSuccessResponseExptn() {
    boolean status = false;
    try {
        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.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) 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