Package org.springframework.mock.web

# Class MockAsyncContext

java.lang.Object
org.springframework.mock.web.MockAsyncContext

All Implemented Interfaces:
  `AsyncContext`

public class MockAsyncContext extends Object implements AsyncContext
Mock implementation of the `AsyncContext` interface.

Since:
  3.2
Author:
  Rossen Stoyanchev

## Field Summary

### Fields inherited from interface jakarta.servlet.AsyncContext

`ASYNC_CONTEXT_PATH, ASYNC_MAPPING, ASYNC_PATH_INFO, ASYNC_QUERY_STRING, ASYNC_REQUEST_URI, ASYNC_SERVLET_PATH`

## Constructor Summary

Constructors
Constructor
Description
`MockAsyncContext(ServletRequest request, ServletResponse response)`

## Method Summary

Modifier and Type
Method
Description
`void`
`addDispatchHandler(Runnable handler)`
`void`
`addListener(AsyncListener listener)`
`void`
`addListener(AsyncListener listener, ServletRequest request, ServletResponse response)`
`void`
`complete()`
`<T extends AsyncListener>
T`
`createListener(Class<T> clazz)`
`void`
`dispatch()`
`void`
`dispatch(ServletContext context, String path)`
`void`
`dispatch(String path)`
`String`
`getDispatchedPath()`
`List<AsyncListener>`
`getListeners()`
`ServletRequest`
`getRequest()`
`ServletResponse`
`getResponse()`
`long`
`getTimeout()`
`boolean`
`hasOriginalRequestAndResponse()`
`void`
`setTimeout(long timeout)`
By default this is set to 10000 (10 seconds) even though the Servlet API specifies a default async request timeout of 30 seconds.
`void`
`start(Runnable runnable)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### MockAsyncContext

public MockAsyncContext(ServletRequest request, @Nullable ServletResponse response)

## Method Details

### addDispatchHandler

public void addDispatchHandler(Runnable handler)

### getRequest

public ServletRequest getRequest()

Specified by:
  `getRequest` in interface `AsyncContext`

### getResponse

@Nullable public ServletResponse getResponse()

Specified by:
  `getResponse` in interface `AsyncContext`

### hasOriginalRequestAndResponse

public boolean hasOriginalRequestAndResponse()

Specified by:
  `hasOriginalRequestAndResponse` in interface `AsyncContext`

### dispatch

public void dispatch()

Specified by:
  `dispatch` in interface `AsyncContext`

### dispatch

public void dispatch(String path)

Specified by:
  `dispatch` in interface `AsyncContext`

### dispatch

public void dispatch(@Nullable ServletContext context, String path)

Specified by:
  `dispatch` in interface `AsyncContext`

### getDispatchedPath

@Nullable public String getDispatchedPath()

### complete

public void complete()

Specified by:
  `complete` in interface `AsyncContext`

### start

public void start(Runnable runnable)

Specified by:
  `start` in interface `AsyncContext`

### addListener

public void addListener(AsyncListener listener)

Specified by:
  `addListener` in interface `AsyncContext`

### addListener

public void addListener(AsyncListener listener, ServletRequest request, ServletResponse response)

Specified by:
  `addListener` in interface `AsyncContext`

### getListeners

public List<AsyncListener> getListeners()

### createListener

public <T extends AsyncListener> T createListener(Class<T> clazz) throws ServletException

Specified by:
  `createListener` in interface `AsyncContext`
Throws:
  `ServletException`

### setTimeout

public void setTimeout(long timeout)
By default this is set to 10000 (10 seconds) even though the Servlet API specifies a default async request timeout of 30 seconds. Keep in mind the timeout could further be impacted by global configuration through the MVC Java config or the XML namespace, as well as be overridden per request on `DeferredResult` or on `SseEmitter`.

Specified by:
  `setTimeout` in interface `AsyncContext`
Parameters:
  `timeout` - the timeout value to use.
See Also:
  - `AsyncContext.setTimeout(long)`

### getTimeout

public long getTimeout()

Specified by:
  `getTimeout` in interface `AsyncContext`