Search in sources :

Example 21 with RestOperationMeta

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

Example 22 with RestOperationMeta

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

the class TestVertxPostMethod method testVertxPostMethod.

@Test
public void testVertxPostMethod() {
    Invocation invocation = Mockito.mock(Invocation.class);
    HttpClient client = Mockito.mock(HttpClient.class);
    IpPort ipPort = Mockito.mock(IpPort.class);
    RestOperationMeta operation = Mockito.mock(RestOperationMeta.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    Mockito.when(ipPort.getPort()).thenReturn(23);
    assertEquals(23, ipPort.getPort());
    Mockito.when(ipPort.getHostOrIp()).thenReturn("testCall");
    assertNotNull("testCall", ipPort.getHostOrIp());
    HttpClientRequest obj = VertxPostMethod.INSTANCE.createRequest(client, invocation, ipPort, "test", 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 23 with RestOperationMeta

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

the class TestVertxRestServer method setUp.

@Before
public void setUp() throws Exception {
    Router mainRouter = Router.router(null);
    mainRouter.route().handler(BodyHandler.create());
    instance = new VertxRestServer(mainRouter) {

        @Override
        protected RestOperationMeta findRestOperation(RestServerRequestInternal restRequest) {
            return super.findRestOperation(restRequest);
        }

        @Override
        public void sendFailResponse(RestServerRequestInternal restRequest, HttpServerResponse httpResponse, Throwable throwable) {
        }
    };
}
Also used : RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) RestServerRequestInternal(io.servicecomb.common.rest.codec.RestServerRequestInternal) HttpServerResponse(io.vertx.core.http.HttpServerResponse) Router(io.vertx.ext.web.Router) Before(org.junit.Before)

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