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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations