use of cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse in project today-infrastructure 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.web.testfixture.http.server.reactive.MockServerHttpResponse in project today-infrastructure 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.web.testfixture.http.server.reactive.MockServerHttpResponse in project today-infrastructure by TAKETODAY.
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();
}
use of cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpResponse in project today-infrastructure 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.web.testfixture.http.server.reactive.MockServerHttpResponse in project today-infrastructure by TAKETODAY.
the class BodyInsertersTests method ofServerSentEventFlux.
@Test
public void ofServerSentEventFlux() {
ServerSentEvent<String> event = ServerSentEvent.builder("foo").build();
Flux<ServerSentEvent<String>> body = Flux.just(event);
BodyInserter<Flux<ServerSentEvent<String>>, ServerHttpResponse> inserter = BodyInserters.fromServerSentEvents(body);
MockServerHttpResponse response = new MockServerHttpResponse();
Mono<Void> result = inserter.insert(response, this.context);
StepVerifier.create(result).expectNextCount(0).expectComplete().verify();
}
Aggregations