Search in sources :

Example 26 with Response

use of io.servicecomb.core.Response 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 27 with Response

use of io.servicecomb.core.Response 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 28 with Response

use of io.servicecomb.core.Response 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 29 with Response

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

Example 30 with Response

use of io.servicecomb.core.Response in project java-chassis by ServiceComb.

the class TestConsumerResponseMapper method test.

@Test
public void test() {
    ConsumerResponseMapperFactory factory = new ConsumerResponseMapperFactory();
    ConsumerResponseMapper m1 = new ConsumerResponseCseSame();
    ConsumerResponseMapper m2 = new ConsumerResponseSame();
    factory.setMapperList(Arrays.asList(m1, m2));
    Assert.assertEquals(m1, factory.createResponseMapper(Response.class));
    Assert.assertEquals(m2, factory.createResponseMapper(String.class));
    Response r = Response.ok(1);
    Response r1 = (Response) m1.mapResponse(r);
    Assert.assertEquals(r, r1);
    Object result = m2.mapResponse(r);
    Assert.assertEquals(1, (int) result);
}
Also used : Response(io.servicecomb.core.Response) Test(org.junit.Test)

Aggregations

Response (io.servicecomb.core.Response)37 Test (org.junit.Test)21 Invocation (io.servicecomb.core.Invocation)20 OperationMeta (io.servicecomb.core.definition.OperationMeta)11 AsyncResponse (io.servicecomb.core.AsyncResponse)8 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)7 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)7 HystrixCommandProperties (com.netflix.hystrix.HystrixCommandProperties)6 HttpServerResponse (io.vertx.core.http.HttpServerResponse)5 InvocationException (io.servicecomb.core.exception.InvocationException)4 MockUp (mockit.MockUp)4 ProduceProcessor (io.servicecomb.common.rest.codec.produce.ProduceProcessor)3 SyncResponseExecutor (io.servicecomb.core.provider.consumer.SyncResponseExecutor)3 User (io.servicecomb.demo.server.User)3 HttpClientResponse (io.vertx.core.http.HttpClientResponse)3 List (java.util.List)3 ExecutionListener (com.netflix.loadbalancer.reactive.ExecutionListener)2 CommonExceptionData (io.servicecomb.core.exception.CommonExceptionData)2 ResponseHeaders (io.servicecomb.swagger.extend.annotations.ResponseHeaders)2 ApiResponse (io.swagger.annotations.ApiResponse)2