use of org.apache.servicecomb.swagger.invocation.AsyncResponse 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.swagger.invocation.AsyncResponse in project incubator-servicecomb-java-chassis by apache.
the class TestInvoker method completableFutureInvoke_normal.
@Test
public void completableFutureInvoke_normal(@Mocked Invocation invocation, @Mocked SwaggerConsumerOperation consumerOperation, @Mocked ConsumerResponseMapper mapper) {
Response response = Response.ok("1");
new MockUp<InvokerUtils>() {
@Mock
void reactiveInvoke(Invocation invocation, AsyncResponse asyncResp) {
asyncResp.handle(response);
;
}
};
new Expectations() {
{
consumerOperation.getResponseMapper();
result = mapper;
mapper.mapResponse(response);
result = 1;
}
};
Invoker invoker = new Invoker("test", null, IPerson.class);
CompletableFuture<Object> future = invoker.completableFutureInvoke(invocation, consumerOperation);
future.whenComplete((result, ex) -> {
Assert.assertEquals(1, result);
Assert.assertEquals(null, ex);
});
}
Aggregations