use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse 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();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse 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();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse 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();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.
the class ServerWebExchangeContextFilterTests method extractServerWebExchangeFromContext.
@Test
void extractServerWebExchangeFromContext() {
MyService service = new MyService();
HttpHandler httpHandler = WebHttpHandlerBuilder.webHandler(exchange -> service.service().then()).filter(new ServerWebExchangeContextFilter()).build();
httpHandler.handle(MockServerHttpRequest.get("/path").build(), new MockServerHttpResponse()).block(Duration.ofSeconds(5));
assertThat(service.getExchange()).isNotNull();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.
the class JRubyScriptTemplateTests method renderTemplate.
@Test
public void renderTemplate() throws Exception {
Map<String, Object> model = new HashMap<>();
model.put("title", "Layout example");
model.put("body", "This is the body");
String url = "org/springframework/web/reactive/result/view/script/jruby/template.erb";
MockServerHttpResponse response = renderViewWithModel(url, model);
assertThat(response.getBodyAsString().block()).isEqualTo("<html><head><title>Layout example</title></head><body><p>This is the body</p></body></html>");
}
Aggregations