Search in sources :

Example 6 with ProduceProcessor

use of io.servicecomb.common.rest.codec.produce.ProduceProcessor in project java-chassis by ServiceComb.

the class TestVertxHttpMethod method testSetCseContext.

@Test
public void testSetCseContext() {
    boolean status = false;
    try {
        Invocation invocation = Mockito.mock(Invocation.class);
        HttpClientResponse httpResponse = Mockito.mock(HttpClientResponse.class);
        OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
        RestOperationMeta swaggerRestOperation = Mockito.mock(RestOperationMeta.class);
        HttpClientRequest request = Mockito.mock(HttpClientRequest.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.setCseContext(invocation, request);
    } catch (Exception ex) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) 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) Test(org.junit.Test)

Example 7 with ProduceProcessor

use of io.servicecomb.common.rest.codec.produce.ProduceProcessor 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 8 with ProduceProcessor

use of io.servicecomb.common.rest.codec.produce.ProduceProcessor in project java-chassis by ServiceComb.

the class TestServletRestServer method testDoSendResponse.

@Test
public void testDoSendResponse() {
    boolean status = true;
    HttpServletResponse httpServerResponse = Mockito.mock(HttpServletResponse.class);
    ProduceProcessor produceProcessor = Mockito.mock(ProduceProcessor.class);
    Object result = Mockito.mock(Object.class);
    Mockito.when(produceProcessor.getName()).thenReturn("testCall");
    assertEquals("testCall", produceProcessor.getName());
    try {
        Response response = Response.create(12, "gjhghjgk", result);
        servletRestServer.doSendResponse(httpServerResponse, produceProcessor, response);
    } catch (Exception exce) {
        Assert.assertNotNull(exce);
        status = false;
    }
    Assert.assertTrue(status);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(io.servicecomb.core.Response) ProduceProcessor(io.servicecomb.common.rest.codec.produce.ProduceProcessor) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test)

Aggregations

ProduceProcessor (io.servicecomb.common.rest.codec.produce.ProduceProcessor)8 Test (org.junit.Test)4 Invocation (io.servicecomb.core.Invocation)3 Response (io.servicecomb.core.Response)3 HttpClientResponse (io.vertx.core.http.HttpClientResponse)3 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)2 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)2 AsyncResponse (io.servicecomb.core.AsyncResponse)2 Endpoint (io.servicecomb.core.Endpoint)2 OperationMeta (io.servicecomb.core.definition.OperationMeta)2 CommonExceptionData (io.servicecomb.core.exception.CommonExceptionData)1 InvocationException (io.servicecomb.core.exception.InvocationException)1 ResponseMeta (io.servicecomb.swagger.invocation.response.ResponseMeta)1 HttpClientRequest (io.vertx.core.http.HttpClientRequest)1 HttpServerResponse (io.vertx.core.http.HttpServerResponse)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1