Search in sources :

Example 1 with URLPathBuilder

use of org.apache.servicecomb.common.rest.definition.path.URLPathBuilder in project incubator-servicecomb-java-chassis by apache.

the class TestPath method testUrlPathBuilder.

@Test
public void testUrlPathBuilder() throws Exception {
    Map<String, RestParam> paramMap = new HashMap<>();
    Parameter pathParameter = new PathParameter();
    pathParameter.setName("id");
    RestParam oRestParam = new RestParam(0, pathParameter, int.class);
    paramMap.put(oRestParam.getParamName(), oRestParam);
    Parameter queryParameter = new QueryParameter();
    queryParameter.setName("q");
    oRestParam = new RestParam(1, queryParameter, String.class);
    paramMap.put(oRestParam.getParamName(), oRestParam);
    URLPathBuilder oURLPathBuilder = new URLPathBuilder("/root/{id}", paramMap);
    Object[] args = new Object[] { 100, "query" };
    Assert.assertEquals("/root/100?q=query", oURLPathBuilder.createRequestPath(args));
    Assert.assertEquals("/root/100", oURLPathBuilder.createPathString(args));
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) HashMap(java.util.HashMap) PathParameter(io.swagger.models.parameters.PathParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) URLPathBuilder(org.apache.servicecomb.common.rest.definition.path.URLPathBuilder) PathParameter(io.swagger.models.parameters.PathParameter) Test(org.junit.Test)

Example 2 with URLPathBuilder

use of org.apache.servicecomb.common.rest.definition.path.URLPathBuilder in project incubator-servicecomb-java-chassis by apache.

the class TestVertxHttpMethod method testHandleResponse.

@Test
public void testHandleResponse() {
    boolean status = false;
    try {
        Invocation invocation = mock(Invocation.class);
        AsyncResponse asyncResp = mock(AsyncResponse.class);
        HttpClientResponse httpResponse = mock(HttpClientResponse.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);
        String contentType = httpResponse.getHeader("Content-Type");
        ProduceProcessor produceProcessor = mock(ProduceProcessor.class);
        when(swaggerRestOperation.findProduceProcessor(contentType)).thenReturn(produceProcessor);
        this.handleResponse(invocation, httpResponse, asyncResp);
    } catch (Exception ex) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : ProduceProcessor(org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor) Invocation(org.apache.servicecomb.core.Invocation) Endpoint(org.apache.servicecomb.core.Endpoint) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) HttpClientResponse(io.vertx.core.http.HttpClientResponse) URLPathBuilder(org.apache.servicecomb.common.rest.definition.path.URLPathBuilder) 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 3 with URLPathBuilder

use of org.apache.servicecomb.common.rest.definition.path.URLPathBuilder in project incubator-servicecomb-java-chassis by apache.

the class TestVertxHttpMethod method testSetCseContext.

@Test
public void testSetCseContext() {
    boolean status = false;
    try {
        Invocation invocation = mock(Invocation.class);
        HttpClientResponse httpResponse = mock(HttpClientResponse.class);
        OperationMeta operationMeta = mock(OperationMeta.class);
        RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
        HttpClientRequest request = mock(HttpClientRequest.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);
        String contentType = httpResponse.getHeader("Content-Type");
        ProduceProcessor produceProcessor = mock(ProduceProcessor.class);
        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(org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor) Invocation(org.apache.servicecomb.core.Invocation) Endpoint(org.apache.servicecomb.core.Endpoint) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) HttpClientResponse(io.vertx.core.http.HttpClientResponse) URLPathBuilder(org.apache.servicecomb.common.rest.definition.path.URLPathBuilder) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) RestOperationMeta(org.apache.servicecomb.common.rest.definition.RestOperationMeta) Test(org.junit.Test)

Example 4 with URLPathBuilder

use of org.apache.servicecomb.common.rest.definition.path.URLPathBuilder 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 5 with URLPathBuilder

use of org.apache.servicecomb.common.rest.definition.path.URLPathBuilder in project incubator-servicecomb-java-chassis by apache.

the class RestOperationMeta method setAbsolutePath.

public void setAbsolutePath(String absolutePath) {
    this.absolutePath = absolutePath;
    this.absolutePathRegExp = createPathRegExp(absolutePath);
    this.pathBuilder = new URLPathBuilder(absolutePath, paramMap);
}
Also used : URLPathBuilder(org.apache.servicecomb.common.rest.definition.path.URLPathBuilder)

Aggregations

URLPathBuilder (org.apache.servicecomb.common.rest.definition.path.URLPathBuilder)5 Test (org.junit.Test)4 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)3 Endpoint (org.apache.servicecomb.core.Endpoint)3 Invocation (org.apache.servicecomb.core.Invocation)3 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)3 HttpClientResponse (io.vertx.core.http.HttpClientResponse)2 HashMap (java.util.HashMap)2 ProduceProcessor (org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor)2 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)2 Parameter (io.swagger.models.parameters.Parameter)1 PathParameter (io.swagger.models.parameters.PathParameter)1 QueryParameter (io.swagger.models.parameters.QueryParameter)1 Context (io.vertx.core.Context)1 HttpClientRequest (io.vertx.core.http.HttpClientRequest)1 Mock (mockit.Mock)1 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)1 HttpClientWithContext (org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext)1