Search in sources :

Example 26 with Invocation

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

the class TestGrpcServerInvoke method testOnProviderResponseSuccess.

@Test
public void testOnProviderResponseSuccess() {
    //boolean status = false;
    try {
        MockUtil.getInstance().mockMicroserviceMetaManager();
        mockForExecutorManager();
        mockForOperationMeta();
        new MockUp<GrpcServerInvoke>() {

            @Mock
            private void sendFailResponse(Throwable throwable) {
            // Nothing to do Just For mock  
            }
        };
        Invocation invocation = Mockito.mock(Invocation.class);
        Response response = Mockito.mock(Response.class);
        Mockito.when(response.isSuccessed()).thenReturn(true);
        Mockito.when(response.getResult()).thenReturn("test");
        Mockito.when(routingContext.response()).thenReturn(Mockito.mock(HttpServerResponse.class));
        Deencapsulation.setField(lGrpcServerInvoke, "routingContext", routingContext);
        Deencapsulation.invoke(lGrpcServerInvoke, "onProviderResponse", 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) HttpServerResponse(io.vertx.core.http.HttpServerResponse) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 27 with Invocation

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

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

the class TestVertxDeleteMethod method testCreateRequest.

@Test
public void testCreateRequest() {
    HttpClient client = Mockito.mock(HttpClient.class);
    IpPort ipPort = Mockito.mock(IpPort.class);
    Mockito.when(ipPort.getPort()).thenReturn(23);
    Mockito.when(ipPort.getHostOrIp()).thenReturn("test");
    Invocation invocation = Mockito.mock(Invocation.class);
    RestOperationMeta operation = Mockito.mock(RestOperationMeta.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    HttpClientRequest obj = (HttpClientRequest) VertxDeleteMethod.INSTANCE.createRequest(client, invocation, ipPort, "testCall", operation, asyncResp);
    Assert.assertNull(obj);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) Invocation(io.servicecomb.core.Invocation) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) HttpClient(io.vertx.core.http.HttpClient) IpPort(io.servicecomb.foundation.common.net.IpPort) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 29 with Invocation

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

the class InvocationFactory method forConsumer.

public static Invocation forConsumer(ReferenceConfig referenceConfig, OperationMeta operationMeta, Object[] swaggerArguments) {
    Invocation invocation = new Invocation(referenceConfig, operationMeta, swaggerArguments);
    invocation.addContext(Const.SRC_MICROSERVICE, microserviceName);
    return invocation;
}
Also used : Invocation(io.servicecomb.core.Invocation)

Example 30 with Invocation

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

the class InvocationFactory method forConsumer.

public static Invocation forConsumer(ReferenceConfig referenceConfig, SchemaMeta schemaMeta, String operationName, Object[] swaggerArguments) {
    OperationMeta operationMeta = schemaMeta.ensureFindOperation(operationName);
    Invocation invocation = new Invocation(referenceConfig, operationMeta, swaggerArguments);
    invocation.addContext(Const.SRC_MICROSERVICE, microserviceName);
    return invocation;
}
Also used : Invocation(io.servicecomb.core.Invocation) OperationMeta(io.servicecomb.core.definition.OperationMeta)

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