Search in sources :

Example 11 with ReactiveHttpOutputMessage

use of cn.taketoday.http.ReactiveHttpOutputMessage in project today-framework by TAKETODAY.

the class BodyInsertersTests method ofProducerWithMono.

@Test
public void ofProducerWithMono() {
    Mono<User> body = Mono.just(new User("foo", "bar"));
    BodyInserter<?, ReactiveHttpOutputMessage> inserter = BodyInserters.fromProducer(body, User.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\",\"password\":\"bar\"}").expectComplete().verify();
}
Also used : ReactiveHttpOutputMessage(cn.taketoday.http.ReactiveHttpOutputMessage) MockServerHttpResponse(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 12 with ReactiveHttpOutputMessage

use of cn.taketoday.http.ReactiveHttpOutputMessage in project today-framework by TAKETODAY.

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(cn.taketoday.http.ReactiveHttpOutputMessage) MockServerHttpResponse(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 13 with ReactiveHttpOutputMessage

use of cn.taketoday.http.ReactiveHttpOutputMessage in project today-framework by TAKETODAY.

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(cn.taketoday.http.ReactiveHttpOutputMessage) MockServerHttpResponse(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 14 with ReactiveHttpOutputMessage

use of cn.taketoday.http.ReactiveHttpOutputMessage in project today-framework by TAKETODAY.

the class BodyInsertersTests method ofObject.

@Test
public void ofObject() {
    User body = new User("foo", "bar");
    BodyInserter<User, 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.getBodyAsString()).expectNext("{\"username\":\"foo\",\"password\":\"bar\"}").expectComplete().verify();
}
Also used : ReactiveHttpOutputMessage(cn.taketoday.http.ReactiveHttpOutputMessage) MockServerHttpResponse(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse) Test(org.junit.jupiter.api.Test)

Example 15 with ReactiveHttpOutputMessage

use of cn.taketoday.http.ReactiveHttpOutputMessage in project today-framework by TAKETODAY.

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(cn.taketoday.core.io.buffer.DefaultDataBuffer) ReactiveHttpOutputMessage(cn.taketoday.http.ReactiveHttpOutputMessage) Flux(reactor.core.publisher.Flux) MockServerHttpResponse(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

ReactiveHttpOutputMessage (cn.taketoday.http.ReactiveHttpOutputMessage)30 MockServerHttpResponse (cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse)18 Test (org.junit.jupiter.api.Test)18 Resource (cn.taketoday.core.io.Resource)12 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)12 MediaType (cn.taketoday.http.MediaType)12 List (java.util.List)12 MultiValueMap (cn.taketoday.core.MultiValueMap)10 ResolvableType (cn.taketoday.core.ResolvableType)10 Nullable (cn.taketoday.lang.Nullable)10 Publisher (org.reactivestreams.Publisher)10 Flux (reactor.core.publisher.Flux)10 Mono (reactor.core.publisher.Mono)10 LinkedMultiValueMap (cn.taketoday.core.LinkedMultiValueMap)8 HttpEntity (cn.taketoday.http.HttpEntity)8 HttpMessageWriter (cn.taketoday.http.codec.HttpMessageWriter)8 ServerHttpResponse (cn.taketoday.http.server.reactive.ServerHttpResponse)8 Assert (cn.taketoday.lang.Assert)8 Map (java.util.Map)8 ReactiveAdapter (cn.taketoday.core.ReactiveAdapter)6