Search in sources :

Example 16 with OperationMeta

use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.

the class TestVertxHttpMethod method testHandleResponse.

@Test
public void testHandleResponse() {
    boolean status = false;
    try {
        Invocation invocation = mock(Invocation.class);
        AsyncResponse asyncResp = mock(AsyncResponse.class);
        HttpClientResponse httpResponse = mock(HttpClientResponse.class);
        OperationMeta operationMeta = mock(OperationMeta.class);
        RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
        Endpoint endpoint = mock(Endpoint.class);
        when(invocation.getOperationMeta()).thenReturn(operationMeta);
        URLPathBuilder urlPathBuilder = mock(URLPathBuilder.class);
        when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
        operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
        when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
        when(invocation.getEndpoint()).thenReturn(endpoint);
        String contentType = httpResponse.getHeader("Content-Type");
        ProduceProcessor produceProcessor = mock(ProduceProcessor.class);
        when(swaggerRestOperation.findProduceProcessor(contentType)).thenReturn(produceProcessor);
        this.handleResponse(invocation, httpResponse, asyncResp);
    } catch (Exception ex) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : ProduceProcessor(org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor) Invocation(org.apache.servicecomb.core.Invocation) Endpoint(org.apache.servicecomb.core.Endpoint) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) HttpClientResponse(io.vertx.core.http.HttpClientResponse) URLPathBuilder(org.apache.servicecomb.common.rest.definition.path.URLPathBuilder) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) Test(org.junit.Test)

Example 17 with OperationMeta

use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.

the class TestVertxHttpMethod method testCreateRequest.

@Test
public void testCreateRequest() {
    HttpClient client = mock(HttpClient.class);
    Invocation invocation = mock(Invocation.class);
    OperationMeta operationMeta = mock(OperationMeta.class);
    Endpoint endpoint = mock(Endpoint.class);
    URIEndpointObject address = mock(URIEndpointObject.class);
    when(invocation.getEndpoint()).thenReturn(endpoint);
    when(endpoint.getAddress()).thenReturn(address);
    when(address.isSslEnabled()).thenReturn(false);
    when(invocation.getOperationMeta()).thenReturn(operationMeta);
    RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
    when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
    IpPort ipPort = mock(IpPort.class);
    when(ipPort.getPort()).thenReturn(10);
    when(ipPort.getHostOrIp()).thenReturn("ever");
    AsyncResponse asyncResp = mock(AsyncResponse.class);
    List<HttpMethod> methods = new ArrayList<>(Arrays.asList(HttpMethod.GET, HttpMethod.PUT, HttpMethod.POST, HttpMethod.DELETE, HttpMethod.PATCH));
    for (HttpMethod method : methods) {
        when(swaggerRestOperation.getHttpMethod()).thenReturn(method.toString());
        HttpClientRequest obj = VertxHttpMethod.INSTANCE.createRequest(client, invocation, ipPort, "good", asyncResp);
        Assert.assertNull(obj);
    }
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) Invocation(org.apache.servicecomb.core.Invocation) Endpoint(org.apache.servicecomb.core.Endpoint) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) HttpClient(io.vertx.core.http.HttpClient) ArrayList(java.util.ArrayList) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) HttpMethod(io.vertx.core.http.HttpMethod) Test(org.junit.Test)

Example 18 with OperationMeta

use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.

the class TestVertxHttpMethod method testSetCseContext.

@Test
public void testSetCseContext() {
    boolean status = false;
    try {
        Invocation invocation = mock(Invocation.class);
        HttpClientResponse httpResponse = mock(HttpClientResponse.class);
        OperationMeta operationMeta = mock(OperationMeta.class);
        RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
        HttpClientRequest request = mock(HttpClientRequest.class);
        Endpoint endpoint = mock(Endpoint.class);
        when(invocation.getOperationMeta()).thenReturn(operationMeta);
        URLPathBuilder urlPathBuilder = mock(URLPathBuilder.class);
        when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
        operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
        when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
        when(invocation.getEndpoint()).thenReturn(endpoint);
        String contentType = httpResponse.getHeader("Content-Type");
        ProduceProcessor produceProcessor = mock(ProduceProcessor.class);
        when(swaggerRestOperation.findProduceProcessor(contentType)).thenReturn(produceProcessor);
        this.setCseContext(invocation, request);
    } catch (Exception ex) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) ProduceProcessor(org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor) Invocation(org.apache.servicecomb.core.Invocation) Endpoint(org.apache.servicecomb.core.Endpoint) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) HttpClientResponse(io.vertx.core.http.HttpClientResponse) URLPathBuilder(org.apache.servicecomb.common.rest.definition.path.URLPathBuilder) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) Test(org.junit.Test)

Example 19 with OperationMeta

use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.

the class TestVertxHttpMethod method testDoMethod.

@Test
public void testDoMethod(@Mocked HttpClient httpClient, @Injectable URIEndpointObject address) throws Exception {
    Context context = new MockUp<Context>() {

        @Mock
        public void runOnContext(Handler<Void> action) {
            action.handle(null);
        }
    }.getMockInstance();
    HttpClientWithContext httpClientWithContext = new HttpClientWithContext(httpClient, context);
    Invocation invocation = mock(Invocation.class);
    AsyncResponse asyncResp = mock(AsyncResponse.class);
    OperationMeta operationMeta = mock(OperationMeta.class);
    RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
    Endpoint endpoint = mock(Endpoint.class);
    when(invocation.getOperationMeta()).thenReturn(operationMeta);
    URLPathBuilder urlPathBuilder = mock(URLPathBuilder.class);
    when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
    operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
    when(invocation.getEndpoint()).thenReturn(endpoint);
    when(endpoint.getAddress()).thenReturn(address);
    when(request.exceptionHandler(Mockito.any())).then(answer -> null);
    Map<String, Object> map = new HashMap<>();
    when(invocation.getHandlerContext()).then(answer -> map);
    ;
    this.doMethod(httpClientWithContext, invocation, asyncResp);
    Assert.assertTrue(true);
}
Also used : Context(io.vertx.core.Context) HttpClientWithContext(org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext) Invocation(org.apache.servicecomb.core.Invocation) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) HashMap(java.util.HashMap) Mock(mockit.Mock) Endpoint(org.apache.servicecomb.core.Endpoint) HttpClientWithContext(org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext) URLPathBuilder(org.apache.servicecomb.common.rest.definition.path.URLPathBuilder) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) Test(org.junit.Test)

Example 20 with OperationMeta

use of org.apache.servicecomb.core.definition.OperationMeta in project incubator-servicecomb-java-chassis by apache.

the class TestHighwayClient method doTestSend.

private Object doTestSend(Vertx vertx, HighwayClientConnectionPool pool, HighwayClientConnection tcpClient, Object decodedResponse) throws Exception {
    new MockUp<VertxUtils>() {

        @Mock
        <VERTICLE extends AbstractVerticle> boolean blockDeploy(Vertx vertx, Class<VERTICLE> cls, DeploymentOptions options) throws InterruptedException {
            return true;
        }
    };
    new MockUp<ClientPoolManager<HighwayClientConnectionPool>>() {

        @Mock
        public HighwayClientConnectionPool findClientPool(boolean sync) {
            return pool;
        }
    };
    new MockUp<ProtobufManager>() {

        @Mock
        public OperationProtobuf getOrCreateOperation(OperationMeta operationMeta) throws Exception {
            return operationProtobuf;
        }
    };
    new MockUp<HighwayClientConnectionPool>() {

        @Mock
        HighwayClientConnection findOrCreateClient(String endpoint) {
            return tcpClient;
        }
    };
    new MockUp<HighwayCodec>() {

        @Mock
        public Buffer encodeRequest(Invocation invocation, OperationProtobuf operationProtobuf, long msgId) throws Exception {
            return null;
        }

        @Mock
        Response decodeResponse(Invocation invocation, OperationProtobuf operationProtobuf, TcpData tcpData, ProtobufFeature protobufFeature) throws Throwable {
            if (Response.class.isInstance(decodedResponse)) {
                return (Response) decodedResponse;
            }
            throw (Throwable) decodedResponse;
        }
    };
    client.init(vertx);
    Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
    Mockito.when(invocation.getEndpoint()).thenReturn(endpoint);
    Mockito.when(invocation.getEndpoint().getEndpoint()).thenReturn("endpoint");
    Mockito.when(invocation.getResponseExecutor()).thenReturn(new ReactiveExecutor());
    Holder<Object> result = new Holder<>();
    client.send(invocation, ar -> {
        result.value = ar.getResult();
    });
    return result.value;
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Holder(javax.xml.ws.Holder) ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) MockUp(mockit.MockUp) Vertx(io.vertx.core.Vertx) AbstractVerticle(io.vertx.core.AbstractVerticle) TcpData(org.apache.servicecomb.foundation.vertx.client.tcp.TcpData) ProtobufFeature(io.protostuff.runtime.ProtobufFeature) Response(org.apache.servicecomb.swagger.invocation.Response) DeploymentOptions(io.vertx.core.DeploymentOptions) OperationProtobuf(org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf) BeforeClass(org.junit.BeforeClass) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta)

Aggregations

OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)33 Test (org.junit.Test)14 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)12 Invocation (org.apache.servicecomb.core.Invocation)9 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)8 MockUp (mockit.MockUp)6 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)6 Endpoint (org.apache.servicecomb.core.Endpoint)5 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)5 OperationProtobuf (org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf)4 Response (org.apache.servicecomb.swagger.invocation.Response)4 HttpClientRequest (io.vertx.core.http.HttpClientRequest)3 Holder (javax.xml.ws.Holder)3 WrapSchema (org.apache.servicecomb.codec.protobuf.utils.WrapSchema)3 ProduceProcessor (org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor)3 URLPathBuilder (org.apache.servicecomb.common.rest.definition.path.URLPathBuilder)3 ReactiveExecutor (org.apache.servicecomb.core.executor.ReactiveExecutor)3 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)3 InvocationException (org.apache.servicecomb.swagger.invocation.exception.InvocationException)3 Buffer (io.vertx.core.buffer.Buffer)2