use of org.springframework.mock.web.MockAsyncContext in project spring-framework by spring-projects.
the class TestDispatcherServlet method service.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
registerAsyncResultInterceptors(request);
super.service(request, response);
if (request.getAsyncContext() != null) {
MockAsyncContext asyncContext;
if (request.getAsyncContext() instanceof MockAsyncContext) {
asyncContext = (MockAsyncContext) request.getAsyncContext();
} else {
MockHttpServletRequest mockRequest = WebUtils.getNativeRequest(request, MockHttpServletRequest.class);
Assert.notNull(mockRequest, "Expected MockHttpServletRequest");
asyncContext = (MockAsyncContext) mockRequest.getAsyncContext();
String requestClassName = request.getClass().getName();
Assert.notNull(asyncContext, () -> "Outer request wrapper " + requestClassName + " has an AsyncContext," + "but it is not a MockAsyncContext, while the nested " + mockRequest.getClass().getName() + " does not have an AsyncContext at all.");
}
CountDownLatch dispatchLatch = new CountDownLatch(1);
asyncContext.addDispatchHandler(dispatchLatch::countDown);
getMvcResult(request).setAsyncDispatchLatch(dispatchLatch);
}
}
use of org.springframework.mock.web.MockAsyncContext in project cxf by apache.
the class SseEventSinkContextProviderTest method setUp.
@Before
public void setUp() {
provider = new SseEventSinkContextProvider();
final Exchange exchange = mock(Exchange.class);
final Endpoint endpoint = mock(Endpoint.class);
final ContinuationProvider continuationProvider = mock(ContinuationProvider.class);
final MockHttpServletResponse response = new MockHttpServletResponse();
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockAsyncContext ctx = new MockAsyncContext(request, response) {
@Override
public void start(Runnable runnable) {
/* do nothing */
}
};
request.setAsyncContext(ctx);
message = new MessageImpl();
message.setExchange(exchange);
message.put(ContinuationProvider.class.getName(), continuationProvider);
message.put(AbstractHTTPDestination.HTTP_REQUEST, request);
when(exchange.getEndpoint()).thenReturn(endpoint);
}
use of org.springframework.mock.web.MockAsyncContext in project cxf by apache.
the class SseBroadcasterImplTest method setUp.
@SuppressWarnings("unchecked")
@Before
public void setUp() {
broadcaster = new SseBroadcasterImpl();
response = new MockHttpServletResponse();
writer = mock(MessageBodyWriter.class);
ctx = new MockAsyncContext(new MockHttpServletRequest(), response);
}
Aggregations