Search in sources :

Example 6 with ReactiveHttpOutputMessage

use of org.springframework.http.ReactiveHttpOutputMessage in project spring-framework by spring-projects.

the class BodyInsertersTests method ofPublisher.

@Test
public void ofPublisher() {
    Flux<String> body = Flux.just("foo");
    BodyInserter<Flux<String>, ReactiveHttpOutputMessage> inserter = BodyInserters.fromPublisher(body, String.class);
    MockServerHttpResponse response = new MockServerHttpResponse();
    Mono<Void> result = inserter.insert(response, this.context);
    StepVerifier.create(result).expectComplete().verify();
    StepVerifier.create(response.getBody()).consumeNextWith(buf -> {
        String actual = buf.toString(UTF_8);
        assertThat(actual).isEqualTo("foo");
    }).expectComplete().verify();
}
Also used : ReactiveHttpOutputMessage(org.springframework.http.ReactiveHttpOutputMessage) Flux(reactor.core.publisher.Flux) MockServerHttpResponse(org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 7 with ReactiveHttpOutputMessage

use of org.springframework.http.ReactiveHttpOutputMessage in project spring-framework by spring-projects.

the class BodyInsertersTests method ofProducerWithFlux.

@Test
public void ofProducerWithFlux() {
    Flux<String> body = Flux.just("foo");
    BodyInserter<?, ReactiveHttpOutputMessage> inserter = BodyInserters.fromProducer(body, String.class);
    MockServerHttpResponse response = new MockServerHttpResponse();
    Mono<Void> result = inserter.insert(response, this.context);
    StepVerifier.create(result).expectComplete().verify();
    StepVerifier.create(response.getBody()).consumeNextWith(buf -> {
        String actual = buf.toString(UTF_8);
        assertThat(actual).isEqualTo("foo");
    }).expectComplete().verify();
}
Also used : ReactiveHttpOutputMessage(org.springframework.http.ReactiveHttpOutputMessage) MockServerHttpResponse(org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 8 with ReactiveHttpOutputMessage

use of org.springframework.http.ReactiveHttpOutputMessage in project spring-framework by spring-projects.

the class BodyInsertersTests method ofString.

@Test
public void ofString() {
    String body = "foo";
    BodyInserter<String, ReactiveHttpOutputMessage> inserter = BodyInserters.fromValue(body);
    MockServerHttpResponse response = new MockServerHttpResponse();
    Mono<Void> result = inserter.insert(response, this.context);
    StepVerifier.create(result).expectComplete().verify();
    StepVerifier.create(response.getBody()).consumeNextWith(buf -> {
        String actual = buf.toString(UTF_8);
        assertThat(actual).isEqualTo("foo");
    }).expectComplete().verify();
}
Also used : ReactiveHttpOutputMessage(org.springframework.http.ReactiveHttpOutputMessage) MockServerHttpResponse(org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 9 with ReactiveHttpOutputMessage

use of org.springframework.http.ReactiveHttpOutputMessage in project spring-framework by spring-projects.

the class BodyInsertersTests method ofObjectWithHints.

@Test
public void ofObjectWithHints() {
    User body = new User("foo", "bar");
    BodyInserter<User, ReactiveHttpOutputMessage> inserter = BodyInserters.fromValue(body);
    this.hints.put(JSON_VIEW_HINT, SafeToSerialize.class);
    MockServerHttpResponse response = new MockServerHttpResponse();
    Mono<Void> result = inserter.insert(response, this.context);
    StepVerifier.create(result).expectComplete().verify();
    StepVerifier.create(response.getBodyAsString()).expectNext("{\"username\":\"foo\"}").expectComplete().verify();
}
Also used : ReactiveHttpOutputMessage(org.springframework.http.ReactiveHttpOutputMessage) MockServerHttpResponse(org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 10 with ReactiveHttpOutputMessage

use of org.springframework.http.ReactiveHttpOutputMessage in project spring-framework by spring-projects.

the class BodyInsertersTests method ofDataBuffers.

@Test
public void ofDataBuffers() {
    byte[] bytes = "foo".getBytes(UTF_8);
    DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
    Flux<DataBuffer> body = Flux.just(dataBuffer);
    BodyInserter<Flux<DataBuffer>, ReactiveHttpOutputMessage> inserter = BodyInserters.fromDataBuffers(body);
    MockServerHttpResponse response = new MockServerHttpResponse();
    Mono<Void> result = inserter.insert(response, this.context);
    StepVerifier.create(result).expectComplete().verify();
    StepVerifier.create(response.getBody()).expectNext(dataBuffer).expectComplete().verify();
}
Also used : DefaultDataBuffer(org.springframework.core.io.buffer.DefaultDataBuffer) ReactiveHttpOutputMessage(org.springframework.http.ReactiveHttpOutputMessage) Flux(reactor.core.publisher.Flux) MockServerHttpResponse(org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse) DefaultDataBuffer(org.springframework.core.io.buffer.DefaultDataBuffer) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

ReactiveHttpOutputMessage (org.springframework.http.ReactiveHttpOutputMessage)15 Test (org.junit.jupiter.api.Test)9 MockServerHttpResponse (org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse)9 List (java.util.List)7 DataBuffer (org.springframework.core.io.buffer.DataBuffer)7 Publisher (org.reactivestreams.Publisher)6 ResolvableType (org.springframework.core.ResolvableType)6 Resource (org.springframework.core.io.Resource)6 MediaType (org.springframework.http.MediaType)6 Nullable (org.springframework.lang.Nullable)6 Mono (reactor.core.publisher.Mono)6 ServerHttpResponse (org.springframework.http.server.reactive.ServerHttpResponse)5 Assert (org.springframework.util.Assert)5 MultiValueMap (org.springframework.util.MultiValueMap)5 Flux (reactor.core.publisher.Flux)5 Map (java.util.Map)4 HttpEntity (org.springframework.http.HttpEntity)4 HttpMessageWriter (org.springframework.http.codec.HttpMessageWriter)4 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)4 Optional (java.util.Optional)3