Package 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:
  `org.springframework.web.server.ServerWebExchange`

public final class MockServerWebExchange extends org.springframework.web.server.adapter.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
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

Modifier and Type
Method
Description
`static MockServerWebExchange.Builder`
`builder(MockServerHttpRequest request)`
Create a `MockServerWebExchange.Builder` starting with the given mock request.
`static MockServerWebExchange.Builder`
`builder(MockServerHttpRequest.BaseBuilder<?> requestBuilder)`
Variant of `builder(MockServerHttpRequest)` with a mock request builder.
`static MockServerWebExchange`
`from(MockServerHttpRequest request)`
Create a `MockServerWebExchange` from the given mock request.
`static MockServerWebExchange`
`from(MockServerHttpRequest.BaseBuilder<?> requestBuilder)`
Variant of `from(MockServerHttpRequest)` with a mock request builder.
`<T extends Principal>
reactor.core.publisher.Mono<T>`
`getPrincipal()`
Return the user set via `MockServerWebExchange.Builder.principal(Principal)`.
`MockServerHttpResponse`
`getResponse()`

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

`addUrlTransformer, checkNotModified, checkNotModified, checkNotModified, cleanupMultipart, getApplicationContext, getAttributes, getFormData, getLocaleContext, getLogPrefix, getMultipartData, 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 Details

### getResponse

public MockServerHttpResponse getResponse()

Specified by:
  `getResponse` in interface `org.springframework.web.server.ServerWebExchange`
Overrides:
  `getResponse` in class `org.springframework.web.server.adapter.DefaultServerWebExchange`

### getPrincipal

public <T extends Principal> reactor.core.publisher.Mono<T> getPrincipal()
Return the user set via `MockServerWebExchange.Builder.principal(Principal)`.

Specified by:
  `getPrincipal` in interface `org.springframework.web.server.ServerWebExchange`
Overrides:
  `getPrincipal` in class `org.springframework.web.server.adapter.DefaultServerWebExchange`
Since:
  6.2.7

### 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