Package org.springframework.mock.http.client.reactive

# Class MockClientHttpRequest

java.lang.Object
org.springframework.http.client.reactive.AbstractClientHttpRequest
org.springframework.mock.http.client.reactive.MockClientHttpRequest

All Implemented Interfaces:
  `org.springframework.http.client.reactive.ClientHttpRequest`, `org.springframework.http.HttpMessage`, `org.springframework.http.ReactiveHttpOutputMessage`

public class MockClientHttpRequest extends org.springframework.http.client.reactive.AbstractClientHttpRequest
Mock implementation of `ClientHttpRequest`.

Since:
  5.0
Author:
  Brian Clozel, Rossen Stoyanchev

## Constructor Summary

Constructors
Constructor
Description
`MockClientHttpRequest(org.springframework.http.HttpMethod httpMethod, String urlTemplate, Object... vars)`
`MockClientHttpRequest(org.springframework.http.HttpMethod httpMethod, URI url)`

## Method Summary

Modifier and Type
Method
Description
`protected void`
`applyAttributes()`
`protected void`
`applyCookies()`
`protected void`
`applyHeaders()`
`org.springframework.core.io.buffer.DataBufferFactory`
`bufferFactory()`
`reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>`
`getBody()`
Return the request body, or an error stream if the body was never set or when `setWriteHandler(java.util.function.Function<reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>, reactor.core.publisher.Mono<java.lang.Void>>)` is configured.
`reactor.core.publisher.Mono<String>`
`getBodyAsString()`
Aggregate response data and convert to a String using the "Content-Type" charset or "UTF-8" by default.
`org.springframework.http.HttpMethod`
`getMethod()`
`<T> T`
`getNativeRequest()`
`URI`
`getURI()`
`reactor.core.publisher.Mono<Void>`
`setComplete()`
`void`
`setWriteHandler(Function<reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>,reactor.core.publisher.Mono<Void>> writeHandler)`
Configure a custom handler for writing the request body.
`reactor.core.publisher.Mono<Void>`
`writeAndFlushWith(Publisher<? extends Publisher<? extends org.springframework.core.io.buffer.DataBuffer>> body)`
`reactor.core.publisher.Mono<Void>`
`writeWith(Publisher<? extends org.springframework.core.io.buffer.DataBuffer> body)`

### Methods inherited from class org.springframework.http.client.reactive.AbstractClientHttpRequest

`beforeCommit, doCommit, doCommit, getAttributes, getCookies, getHeaders, initReadOnlyHeaders, isCommitted`

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

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

## Constructor Details

### MockClientHttpRequest

public MockClientHttpRequest(org.springframework.http.HttpMethod httpMethod, String urlTemplate, Object... vars)

### MockClientHttpRequest

public MockClientHttpRequest(org.springframework.http.HttpMethod httpMethod, URI url)

## Method Details

### setWriteHandler

public void setWriteHandler(Function<reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>,reactor.core.publisher.Mono<Void>> writeHandler)
Configure a custom handler for writing the request body.

The default write handler consumes and caches the request body so it may be accessed subsequently, for example, in test assertions. Use this property when the request body is an infinite stream.

Parameters:
  `writeHandler` - the write handler to use returning `Mono<Void>` when the body has been "written" (i.e. consumed).

### getMethod

public org.springframework.http.HttpMethod getMethod()

### getURI

public URI getURI()

### bufferFactory

public org.springframework.core.io.buffer.DataBufferFactory bufferFactory()

### getNativeRequest

public <T> T getNativeRequest()

### applyHeaders

protected void applyHeaders()

Specified by:
  `applyHeaders` in class `org.springframework.http.client.reactive.AbstractClientHttpRequest`

### applyCookies

protected void applyCookies()

Specified by:
  `applyCookies` in class `org.springframework.http.client.reactive.AbstractClientHttpRequest`

### applyAttributes

protected void applyAttributes()

Overrides:
  `applyAttributes` in class `org.springframework.http.client.reactive.AbstractClientHttpRequest`

### writeWith

public reactor.core.publisher.Mono<Void> writeWith(Publisher<? extends org.springframework.core.io.buffer.DataBuffer> body)

### writeAndFlushWith

public reactor.core.publisher.Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends org.springframework.core.io.buffer.DataBuffer>> body)

### setComplete

public reactor.core.publisher.Mono<Void> setComplete()

### getBody

public reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer> getBody()
Return the request body, or an error stream if the body was never set or when `setWriteHandler(java.util.function.Function<reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>, reactor.core.publisher.Mono<java.lang.Void>>)` is configured.

### getBodyAsString

public reactor.core.publisher.Mono<String> getBodyAsString()
Aggregate response data and convert to a String using the "Content-Type" charset or "UTF-8" by default.