Search in sources :

Example 1 with Endpoint

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

the class TestVertxHttpMethod method testDoMethod.

@Test
public void testDoMethod(@Mocked HttpClient httpClient) 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 = Mockito.mock(Invocation.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.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);
    Mockito.when(request.exceptionHandler(Mockito.any())).then(answer -> null);
    this.doMethod(httpClientWithContext, invocation, asyncResp);
    Assert.assertTrue(true);
}
Also used : HttpClientWithContext(io.servicecomb.foundation.vertx.client.http.HttpClientWithContext) Context(io.vertx.core.Context) Invocation(io.servicecomb.core.Invocation) Endpoint(io.servicecomb.core.Endpoint) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) HttpClientWithContext(io.servicecomb.foundation.vertx.client.http.HttpClientWithContext) 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) Mock(mockit.Mock) Test(org.junit.Test)

Example 2 with Endpoint

use of io.servicecomb.core.Endpoint 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 3 with Endpoint

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

the class TestHighwayTransport method commonHighwayMock.

private void commonHighwayMock(Invocation invocation) {
    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);
    URIEndpointObject ep = Mockito.mock(URIEndpointObject.class);
    Mockito.when(lEndpoint.getAddress()).thenReturn(ep);
    Mockito.when(ep.getHostOrIp()).thenReturn("127.0.0.1");
    Mockito.when(ep.getPort()).thenReturn(80);
}
Also used : Endpoint(io.servicecomb.core.Endpoint) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) OperationMeta(io.servicecomb.core.definition.OperationMeta) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject)

Example 4 with Endpoint

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

the class AbstractTransport method setListenAddressWithoutSchema.

protected void setListenAddressWithoutSchema(String addressWithoutSchema, Map<String, String> pairs) {
    if (addressWithoutSchema != null && pairs != null && !pairs.isEmpty()) {
        int idx = addressWithoutSchema.indexOf('?');
        if (idx == -1) {
            addressWithoutSchema += "?";
        } else {
            addressWithoutSchema += "&";
        }
        StringBuilder sb = new StringBuilder();
        for (Entry<String, String> entry : pairs.entrySet()) {
            sb.append(entry.getKey()).append('=').append(entry.getValue()).append('&');
        }
        sb.setLength(sb.length() - 1);
        addressWithoutSchema += sb.toString();
    }
    this.endpoint = new Endpoint(this, NetUtils.getRealListenAddress(getName(), addressWithoutSchema));
    if (this.endpoint.getEndpoint() != null) {
        this.publishEndpoint = new Endpoint(this, RegistryUtils.getPublishAddress(getName(), addressWithoutSchema));
    } else {
        this.publishEndpoint = null;
    }
}
Also used : Endpoint(io.servicecomb.core.Endpoint) Endpoint(io.servicecomb.core.Endpoint)

Example 5 with Endpoint

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

the class TestRestServerVerticle method testRestServerVerticleWithRouter.

@Test
public void testRestServerVerticleWithRouter(@Mocked Transport transport, @Mocked Vertx vertx, @Mocked Context context, @Mocked JsonObject jsonObject, @Mocked Future<Void> startFuture) throws Exception {
    URIEndpointObject endpointObject = new URIEndpointObject("http://127.0.0.1:8080");
    new Expectations() {

        {
            transport.parseAddress("http://127.0.0.1:8080");
            result = endpointObject;
        }
    };
    Endpoint endpiont = new Endpoint(transport, "http://127.0.0.1:8080");
    new Expectations() {

        {
            context.config();
            result = jsonObject;
            jsonObject.getValue(AbstractTransport.ENDPOINT_KEY);
            result = endpiont;
        }
    };
    RestServerVerticle server = new RestServerVerticle();
    // process stuff done by Expectations
    server.init(vertx, context);
    server.start(startFuture);
}
Also used : Expectations(mockit.Expectations) Endpoint(io.servicecomb.core.Endpoint) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject) 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