Search in sources :

Example 11 with URIEndpointObject

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

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject 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 13 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.

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(org.apache.servicecomb.core.Endpoint) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) Test(org.junit.Test)

Example 14 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.

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(org.apache.servicecomb.core.Endpoint) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) Test(org.junit.Test)

Example 15 with URIEndpointObject

use of org.apache.servicecomb.foundation.common.net.URIEndpointObject in project incubator-servicecomb-java-chassis by apache.

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(org.apache.servicecomb.core.Endpoint) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) Test(org.junit.Test)

Aggregations

URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)16 Endpoint (org.apache.servicecomb.core.Endpoint)8 Test (org.junit.Test)8 Expectations (mockit.Expectations)5 ArrayList (java.util.ArrayList)3 Invocation (org.apache.servicecomb.core.Invocation)3 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)3 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)3 HttpClientRequest (io.vertx.core.http.HttpClientRequest)2 HttpMethod (io.vertx.core.http.HttpMethod)2 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)2 VersionedCache (org.apache.servicecomb.foundation.common.cache.VersionedCache)2 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)2 DiscoveryContext (org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext)2 Server (com.netflix.loadbalancer.Server)1 Context (io.vertx.core.Context)1 HttpClient (io.vertx.core.http.HttpClient)1 RequestOptions (io.vertx.core.http.RequestOptions)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1