Search in sources :

Example 66 with Invocation

use of io.servicecomb.core.Invocation 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 67 with Invocation

use of io.servicecomb.core.Invocation 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)

Example 68 with Invocation

use of io.servicecomb.core.Invocation 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 69 with Invocation

use of io.servicecomb.core.Invocation 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 70 with Invocation

use of io.servicecomb.core.Invocation 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

Invocation (io.servicecomb.core.Invocation)70 Test (org.junit.Test)55 OperationMeta (io.servicecomb.core.definition.OperationMeta)29 Response (io.servicecomb.core.Response)20 AsyncResponse (io.servicecomb.core.AsyncResponse)19 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)10 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)9 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)9 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)9 MockUp (mockit.MockUp)9 InvocationException (io.servicecomb.core.exception.InvocationException)8 Endpoint (io.servicecomb.core.Endpoint)7 IpPort (io.servicecomb.foundation.common.net.IpPort)6 HttpClientRequest (io.vertx.core.http.HttpClientRequest)6 HttpClientResponse (io.vertx.core.http.HttpClientResponse)6 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)5 Buffer (io.vertx.core.buffer.Buffer)5 HttpClient (io.vertx.core.http.HttpClient)4 ArrayList (java.util.ArrayList)4 ProduceProcessor (io.servicecomb.common.rest.codec.produce.ProduceProcessor)3