use of com.linkedin.parseq.promise.PromiseListener in project rest.li by linkedin.
the class TestParseqTraceDebugRequestHandler method executeRequestThroughParseqDebugHandler.
private void executeRequestThroughParseqDebugHandler(URI uri, Callback<RestResponse> callback) {
ParseqTraceDebugRequestHandler requestHandler = new ParseqTraceDebugRequestHandler();
RestRequestBuilder requestBuilder = new RestRequestBuilder(uri);
RestRequest request = requestBuilder.build();
RequestContext requestContext = new RequestContext();
requestHandler.handleRequest(request, requestContext, new RestLiDebugRequestHandler.ResourceDebugRequestHandler() {
@Override
@SuppressWarnings("unchecked")
public void handleRequest(RestRequest request, RequestContext requestContext, Callback<RestResponse> callback) {
RestResponse response = EasyMock.createMock(RestResponse.class);
JsonTraceCodec jsonTraceCodec = new JsonTraceCodec();
Trace t = null;
try {
t = jsonTraceCodec.decode(TEST_TRACE);
} catch (IOException exc) {
// test will fail later
}
Task<Object> task = EasyMock.createMock(Task.class);
EasyMock.expect(task.getTrace()).andReturn(t);
EasyMock.replay(task);
PromiseListener<Object> promiseListener = (PromiseListener<Object>) requestContext.getLocalAttr(RestLiMethodInvoker.ATTRIBUTE_PROMISE_LISTENER);
promiseListener.onResolved(task);
callback.onSuccess(response);
}
}, callback);
}
Aggregations