Search in sources :

Example 6 with Endpoint

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

the class TestVertxRestTransport method testSendException.

@Test
public void testSendException() {
    boolean validAssert;
    Invocation invocation = Mockito.mock(Invocation.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    URIEndpointObject endpoint = Mockito.mock(URIEndpointObject.class);
    Endpoint end = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(end);
    Mockito.when(invocation.getEndpoint().getAddress()).thenReturn(endpoint);
    try {
        validAssert = true;
        instance.send(invocation, asyncResp);
    } catch (Exception e) {
        validAssert = false;
    }
    Assert.assertFalse(validAssert);
}
Also used : Invocation(io.servicecomb.core.Invocation) Endpoint(io.servicecomb.core.Endpoint) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 7 with Endpoint

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

the class TestProducerSchemaFactory method testGetOrCreateProducer.

@Test
public void testGetOrCreateProducer() throws Exception {
    OperationMeta operationMeta = schemaMeta.ensureFindOperation("add");
    Assert.assertEquals("add", operationMeta.getOperationId());
    ProducerOperation producerOperation = operationMeta.getExtData(Const.PRODUCER_OPERATION);
    Object addBody = Class.forName("cse.gen.app.ms.schema.addBody").newInstance();
    ReflectUtils.setField(addBody, "x", 1);
    ReflectUtils.setField(addBody, "y", 2);
    Invocation invocation = new Invocation((Endpoint) null, operationMeta, new Object[] { addBody });
    Holder<Response> holder = new Holder<>();
    producerOperation.invoke(invocation, resp -> {
        holder.value = resp;
    });
    Assert.assertEquals(3, (int) holder.value.getResult());
    invocation = new Invocation((Endpoint) null, operationMeta, new Object[] { 1, 2 });
    producerOperation.invoke(invocation, resp -> {
        holder.value = resp;
    });
    Assert.assertEquals(true, holder.value.isFailed());
    InvocationException exception = (InvocationException) holder.value.getResult();
    CommonExceptionData data = (CommonExceptionData) exception.getErrorData();
    Assert.assertEquals("Cse Internal Server Error", data.getMessage());
}
Also used : Response(io.servicecomb.core.Response) Invocation(io.servicecomb.core.Invocation) Endpoint(io.servicecomb.core.Endpoint) ProducerOperation(io.servicecomb.core.provider.producer.ProducerOperation) InvocationException(io.servicecomb.core.exception.InvocationException) Holder(javax.xml.ws.Holder) CommonExceptionData(io.servicecomb.core.exception.CommonExceptionData) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 8 with Endpoint

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

the class TestHighwayVerticle method testHighwayVerticle.

@Test
public void testHighwayVerticle(@Mocked Transport transport, @Mocked Vertx vertx, @Mocked Context context, @Mocked JsonObject json) {
    URIEndpointObject endpiontObject = new URIEndpointObject("highway://127.0.0.1:9090");
    new Expectations() {

        {
            transport.parseAddress(anyString);
            result = endpiontObject;
        }
    };
    Endpoint endpoint = new Endpoint(transport, "highway://127.0.0.1:9090");
    new Expectations() {

        {
            context.config();
            result = json;
            json.getValue(anyString);
            result = endpoint;
        }
    };
    highwayVerticle.init(vertx, context);
    @SuppressWarnings("unchecked") Future<Void> startFuture = Mockito.mock(Future.class);
    highwayVerticle.startListen(startFuture);
    MockUtil.getInstance().mockHighwayConfig();
    try {
        highwayVerticle.startListen(startFuture);
        Assert.assertTrue(true);
    } catch (Exception e) {
        Assert.assertTrue(false);
    }
}
Also used : Expectations(mockit.Expectations) Endpoint(io.servicecomb.core.Endpoint) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject) Test(org.junit.Test)

Example 9 with Endpoint

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

the class TestVertxHttpMethod method testSetCseContext.

@Test
public void testSetCseContext() {
    boolean status = false;
    try {
        Invocation invocation = Mockito.mock(Invocation.class);
        HttpClientResponse httpResponse = Mockito.mock(HttpClientResponse.class);
        OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
        RestOperationMeta swaggerRestOperation = Mockito.mock(RestOperationMeta.class);
        HttpClientRequest request = Mockito.mock(HttpClientRequest.class);
        Endpoint endpoint = Mockito.mock(Endpoint.class);
        Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
        URLPathBuilder urlPathBuilder = Mockito.mock(URLPathBuilder.class);
        Mockito.when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
        operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
        Mockito.when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
        Mockito.when(invocation.getEndpoint()).thenReturn(endpoint);
        String contentType = httpResponse.getHeader("Content-Type");
        ProduceProcessor produceProcessor = Mockito.mock(ProduceProcessor.class);
        Mockito.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(io.servicecomb.common.rest.codec.produce.ProduceProcessor) Invocation(io.servicecomb.core.Invocation) Endpoint(io.servicecomb.core.Endpoint) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) HttpClientResponse(io.vertx.core.http.HttpClientResponse) URLPathBuilder(io.servicecomb.common.rest.definition.path.URLPathBuilder) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) Test(org.junit.Test)

Example 10 with Endpoint

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

the class TestVertxHttpMethod method testHandleResponse.

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

Aggregations

Endpoint (io.servicecomb.core.Endpoint)14 Test (org.junit.Test)10 Invocation (io.servicecomb.core.Invocation)7 OperationMeta (io.servicecomb.core.definition.OperationMeta)6 URIEndpointObject (io.servicecomb.foundation.common.net.URIEndpointObject)6 AsyncResponse (io.servicecomb.core.AsyncResponse)5 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)3 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)3 Expectations (mockit.Expectations)3 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)2 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)2 ProduceProcessor (io.servicecomb.common.rest.codec.produce.ProduceProcessor)2 HttpClientWithContext (io.servicecomb.foundation.vertx.client.http.HttpClientWithContext)2 HttpClientResponse (io.vertx.core.http.HttpClientResponse)2 Response (io.servicecomb.core.Response)1 Transport (io.servicecomb.core.Transport)1 EndpointsCache (io.servicecomb.core.endpoint.EndpointsCache)1 CommonExceptionData (io.servicecomb.core.exception.CommonExceptionData)1 InvocationException (io.servicecomb.core.exception.InvocationException)1 ProducerOperation (io.servicecomb.core.provider.producer.ProducerOperation)1