Search in sources :

Example 11 with URIEndpointObject

use of io.servicecomb.foundation.common.net.URIEndpointObject 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 12 with URIEndpointObject

use of io.servicecomb.foundation.common.net.URIEndpointObject in project java-chassis by ServiceComb.

the class TestServletRestTransport method testSendException.

@Test
public void testSendException() {
    boolean status = true;
    Invocation invocation = Mockito.mock(Invocation.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    URIEndpointObject endpoint = Mockito.mock(URIEndpointObject.class);
    Endpoint endpoint1 = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(endpoint1);
    Mockito.when(invocation.getEndpoint().getAddress()).thenReturn(endpoint);
    try {
        transport.send(invocation, asyncResp);
    } catch (Exception exce) {
        Assert.assertNotNull(exce);
        status = false;
    }
    Assert.assertFalse(status);
}
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 13 with URIEndpointObject

use of io.servicecomb.foundation.common.net.URIEndpointObject in project java-chassis by ServiceComb.

the class TestRestServerVerticle method testRestServerVerticleWithRouterSSL.

@Test
public void testRestServerVerticleWithRouterSSL(@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?sslEnabled=true");
    new Expectations() {

        {
            transport.parseAddress("http://127.0.0.1:8080?sslEnabled=true");
            result = endpointObject;
        }
    };
    Endpoint endpiont = new Endpoint(transport, "http://127.0.0.1:8080?sslEnabled=true");
    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)

Example 14 with URIEndpointObject

use of io.servicecomb.foundation.common.net.URIEndpointObject in project java-chassis by ServiceComb.

the class TestTcpServer method testTcpServerNonSSL.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testTcpServerNonSSL(@Mocked Vertx vertx, @Mocked AsyncResultCallback<InetSocketAddress> callback, @Mocked NetServer netServer) {
    new Expectations() {

        {
            vertx.createNetServer();
            result = netServer;
            netServer.connectHandler((Handler) any);
            netServer.listen(anyInt, anyString, (Handler) any);
        }
    };
    URIEndpointObject endpointObject = new URIEndpointObject("highway://127.0.0.1:6663");
    TcpServer server = new TcpServerForTest(endpointObject);
    // assert done in Expectations 
    server.init(vertx, "", callback);
}
Also used : Expectations(mockit.Expectations) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject) Test(org.junit.Test)

Example 15 with URIEndpointObject

use of io.servicecomb.foundation.common.net.URIEndpointObject in project java-chassis by ServiceComb.

the class TestTcpServer method testTcpServerSSL.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testTcpServerSSL(@Mocked Vertx vertx, @Mocked AsyncResultCallback<InetSocketAddress> callback, @Mocked NetServer netServer) {
    new Expectations() {

        {
            vertx.createNetServer((NetServerOptions) any);
            result = netServer;
            netServer.connectHandler((Handler) any);
            netServer.listen(anyInt, anyString, (Handler) any);
        }
    };
    URIEndpointObject endpointObject = new URIEndpointObject("highway://127.0.0.1:6663?sslEnabled=true");
    TcpServer server = new TcpServerForTest(endpointObject);
    // assert done in Expectations 
    server.init(vertx, "", callback);
}
Also used : Expectations(mockit.Expectations) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject) Test(org.junit.Test)

Aggregations

URIEndpointObject (io.servicecomb.foundation.common.net.URIEndpointObject)15 Test (org.junit.Test)8 Endpoint (io.servicecomb.core.Endpoint)6 Expectations (mockit.Expectations)5 AsyncResponse (io.servicecomb.core.AsyncResponse)2 Invocation (io.servicecomb.core.Invocation)2 CacheEndpoint (io.servicecomb.serviceregistry.cache.CacheEndpoint)2 RestTransportClient (io.servicecomb.transport.rest.client.RestTransportClient)2 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)1 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)1 OperationMeta (io.servicecomb.core.definition.OperationMeta)1 TcpServer (io.servicecomb.foundation.vertx.server.TcpServer)1 MicroserviceInstance (io.servicecomb.serviceregistry.api.registry.MicroserviceInstance)1 ServiceRegistryClient (io.servicecomb.serviceregistry.client.ServiceRegistryClient)1 ArrayList (java.util.ArrayList)1 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)1 ServiceInstance (org.springframework.cloud.client.ServiceInstance)1