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