use of io.servicecomb.core.AsyncResponse 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.core.AsyncResponse 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.core.AsyncResponse in project java-chassis by ServiceComb.
the class TestGrpcTransport method testSend.
@Test
public void testSend() {
boolean status = false;
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
Endpoint lEndpoint = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getEndpoint()).thenReturn(lEndpoint);
WrapSchema lWrapSchema = Mockito.mock(WrapSchema.class);
Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(lWrapSchema);
IpPort ipPort = Mockito.mock(IpPort.class);
Mockito.when(lEndpoint.getAddress()).thenReturn(ipPort);
Mockito.when(ipPort.getHostOrIp()).thenReturn("127.0.0.1");
Mockito.when(ipPort.getPort()).thenReturn(80);
new MockUp<ClientPoolManager<HttpClientWithContext>>() {
@Mock
public HttpClientWithContext findThreadBindClientPool() {
return Mockito.mock(HttpClientWithContext.class);
}
};
try {
transport.send(invocation, asyncResp);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
use of io.servicecomb.core.AsyncResponse 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);
}
use of io.servicecomb.core.AsyncResponse in project java-chassis by ServiceComb.
the class ProducerOperation method invoke.
public void invoke(Invocation invocation, AsyncResponse asyncResp) {
InvocationContext context = new InvocationContext(invocation.getContext());
ContextUtils.setInvocationContext(context);
Response response = null;
try {
Object[] args = argsMapper.toProducerArgs(invocation);
Object result = method.invoke(instance, args);
response = responseMapper.mapResponse(context.getStatus(), result);
} catch (Throwable e) {
response = processException(e);
}
ContextUtils.removeInvocationContext();
asyncResp.handle(response);
}
Aggregations