Search in sources :

Example 1 with RestOperationMeta

use of io.servicecomb.common.rest.definition.RestOperationMeta 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 RestOperationMeta

use of io.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.

the class TestVertxHttpMethod method testCreateRequestPath.

@Test
public void testCreateRequestPath() throws Exception {
    Invocation invocation = Mockito.mock(Invocation.class);
    RestOperationMeta restOperationMeta = Mockito.mock(RestOperationMeta.class);
    URLPathBuilder urlPathBuilder = Mockito.mock(URLPathBuilder.class);
    Mockito.when(restOperationMeta.getPathBuilder()).thenReturn(urlPathBuilder);
    String pathUrl = this.createRequestPath(invocation, restOperationMeta);
    Assert.assertNull(pathUrl);
}
Also used : Invocation(io.servicecomb.core.Invocation) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) URLPathBuilder(io.servicecomb.common.rest.definition.path.URLPathBuilder) Test(org.junit.Test)

Example 3 with RestOperationMeta

use of io.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.

the class TestVertxPutMethod method testVertxPutMethod.

@Test
public void testVertxPutMethod() {
    HttpClient client = Mockito.mock(HttpClient.class);
    Invocation invocation = Mockito.mock(Invocation.class);
    IpPort ipPort = Mockito.mock(IpPort.class);
    RestOperationMeta operation = Mockito.mock(RestOperationMeta.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    Mockito.when(ipPort.getHostOrIp()).thenReturn("test");
    assertNotNull("test", ipPort.getHostOrIp());
    Mockito.when(ipPort.getPort()).thenReturn(13);
    assertEquals(13, ipPort.getPort());
    HttpClientRequest obj = VertxPutMethod.INSTANCE.createRequest(client, invocation, ipPort, "testCall", operation, asyncResp);
    Assert.assertNull(obj);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) Invocation(io.servicecomb.core.Invocation) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) HttpClient(io.vertx.core.http.HttpClient) IpPort(io.servicecomb.foundation.common.net.IpPort) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 4 with RestOperationMeta

use of io.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.

the class VertxHttpMethod method doMethod.

public void doMethod(HttpClientWithContext httpClientWithContext, Invocation invocation, AsyncResponse asyncResp) throws Exception {
    OperationMeta operationMeta = invocation.getOperationMeta();
    RestOperationMeta swaggerRestOperation = operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
    String path = this.createRequestPath(invocation, swaggerRestOperation);
    IpPort ipPort = (IpPort) invocation.getEndpoint().getAddress();
    HttpClientRequest clientRequest = this.createRequest(httpClientWithContext.getHttpClient(), invocation, ipPort, path, swaggerRestOperation, asyncResp);
    RestClientRequestImpl restClientRequest = new RestClientRequestImpl(clientRequest);
    RestCodec.argsToRest(invocation.getArgs(), swaggerRestOperation, restClientRequest);
    clientRequest.exceptionHandler(e -> {
        LOGGER.error(e.toString());
        asyncResp.fail(invocation.getInvocationType(), e);
    });
    // 从业务线程转移到网络线程中去发送
    httpClientWithContext.runOnContext(httpClient -> {
        this.setCseContext(invocation, clientRequest);
        clientRequest.setTimeout(AbstractTransport.getRequestTimeout());
        try {
            restClientRequest.end();
        } catch (Exception e) {
            LOGGER.error("send http reqeust failed,", e);
            asyncResp.fail(invocation.getInvocationType(), e);
        }
    });
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) RestClientRequestImpl(io.servicecomb.common.rest.codec.param.RestClientRequestImpl) IpPort(io.servicecomb.foundation.common.net.IpPort) OperationMeta(io.servicecomb.core.definition.OperationMeta) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta)

Example 5 with RestOperationMeta

use of io.servicecomb.common.rest.definition.RestOperationMeta in project java-chassis by ServiceComb.

the class TestVertxDeleteMethod method testCreateRequest.

@Test
public void testCreateRequest() {
    HttpClient client = Mockito.mock(HttpClient.class);
    IpPort ipPort = Mockito.mock(IpPort.class);
    Mockito.when(ipPort.getPort()).thenReturn(23);
    Mockito.when(ipPort.getHostOrIp()).thenReturn("test");
    Invocation invocation = Mockito.mock(Invocation.class);
    RestOperationMeta operation = Mockito.mock(RestOperationMeta.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    HttpClientRequest obj = (HttpClientRequest) VertxDeleteMethod.INSTANCE.createRequest(client, invocation, ipPort, "testCall", operation, asyncResp);
    Assert.assertNull(obj);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) Invocation(io.servicecomb.core.Invocation) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) HttpClient(io.vertx.core.http.HttpClient) IpPort(io.servicecomb.foundation.common.net.IpPort) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Aggregations

RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)23 Test (org.junit.Test)14 OperationMeta (io.servicecomb.core.definition.OperationMeta)12 Invocation (io.servicecomb.core.Invocation)10 AsyncResponse (io.servicecomb.core.AsyncResponse)6 HttpClientRequest (io.vertx.core.http.HttpClientRequest)6 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)5 MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)5 IpPort (io.servicecomb.foundation.common.net.IpPort)5 HttpClient (io.vertx.core.http.HttpClient)4 Endpoint (io.servicecomb.core.Endpoint)3 InvocationException (io.servicecomb.core.exception.InvocationException)3 RestServerRequestInternal (io.servicecomb.common.rest.codec.RestServerRequestInternal)2 ProduceProcessor (io.servicecomb.common.rest.codec.produce.ProduceProcessor)2 ServicePathManager (io.servicecomb.common.rest.locator.ServicePathManager)2 CommonExceptionData (io.servicecomb.core.exception.CommonExceptionData)2 HttpClientWithContext (io.servicecomb.foundation.vertx.client.http.HttpClientWithContext)2 HttpClientResponse (io.vertx.core.http.HttpClientResponse)2 HashMap (java.util.HashMap)2 MockUp (mockit.MockUp)2