org.springframework.mock.web.server

## Class MockServerWebExchange

- java.lang.Object
- - org.springframework.web.server.adapter.DefaultServerWebExchange
  - - org.springframework.mock.web.server.MockServerWebExchange

- All Implemented Interfaces:
    ServerWebExchange

      public final class MockServerWebExchange
      extends DefaultServerWebExchange

  Extension of `DefaultServerWebExchange` for use in tests, along with `MockServerHttpRequest` and `MockServerHttpResponse`.

  See static factory methods to create an instance.

  Since:
    5.0
  Author:
    Rossen Stoyanchev

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `MockServerWebExchange.Builder` Builder for a `MockServerWebExchange`.

  - ### Field Summary

    - ### Fields inherited from interface org.springframework.web.server.ServerWebExchange

      `LOG_ID_ATTRIBUTE`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static MockServerWebExchange.Builder` | `builder(MockServerHttpRequest.BaseBuilder<?> requestBuilder)` Variant of `builder(MockServerHttpRequest)` with a mock request builder.
    `static MockServerWebExchange.Builder` | `builder(MockServerHttpRequest request)` Create a `MockServerWebExchange.Builder` starting with the given mock request.
    `static MockServerWebExchange` | `from(MockServerHttpRequest.BaseBuilder<?> requestBuilder)` Variant of `from(MockServerHttpRequest)` with a mock request builder.
    `static MockServerWebExchange` | `from(MockServerHttpRequest request)` Create a `MockServerWebExchange` from the given mock request.
    `MockServerHttpResponse` | `getResponse()` Return the current HTTP response.

    - ### Methods inherited from class org.springframework.web.server.adapter.DefaultServerWebExchange

      `addUrlTransformer, checkNotModified, checkNotModified, checkNotModified, getApplicationContext, getAttributes, getFormData, getLocaleContext, getLogPrefix, getMultipartData, getPrincipal, getRequest, getSession, isNotModified, transformUrl`

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

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

    - ### Methods inherited from interface org.springframework.web.server.ServerWebExchange

      `getAttribute, getAttributeOrDefault, getRequiredAttribute, mutate`

- - ### Method Detail

    - #### getResponse

          public MockServerHttpResponse getResponse()

      Description copied from interface: `ServerWebExchange`
      Return the current HTTP response.
      Specified by:
        `getResponse` in interface `ServerWebExchange`
      Overrides:
        `getResponse` in class `DefaultServerWebExchange`

    - #### from

          public static MockServerWebExchange from(MockServerHttpRequest request)

      Create a `MockServerWebExchange` from the given mock request.
      Parameters:
        `request` - the request to use.
      Returns:
        the exchange

    - #### from

          public static MockServerWebExchange from(MockServerHttpRequest.BaseBuilder<?> requestBuilder)

      Variant of `from(MockServerHttpRequest)` with a mock request builder.
      Parameters:
        `requestBuilder` - the builder for the mock request.
      Returns:
        the exchange

    - #### builder

          public static MockServerWebExchange.Builder builder(MockServerHttpRequest request)

      Create a `MockServerWebExchange.Builder` starting with the given mock request.
      Parameters:
        `request` - the request to use.
      Returns:
        the exchange builder
      Since:
        5.1

    - #### builder

          public static MockServerWebExchange.Builder builder(MockServerHttpRequest.BaseBuilder<?> requestBuilder)

      Variant of `builder(MockServerHttpRequest)` with a mock request builder.
      Parameters:
        `requestBuilder` - the builder for the mock request.
      Returns:
        the exchange builder
      Since:
        5.1