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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations