use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.
the class DefaultServerResponseBuilderTests method build.
@Test
public void build() {
ResponseCookie cookie = ResponseCookie.from("name", "value").build();
Mono<ServerResponse> result = ServerResponse.status(HttpStatus.CREATED).header("MyKey", "MyValue").cookie(cookie).build();
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.com").build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
result.flatMap(res -> res.writeTo(exchange, EMPTY_CONTEXT)).block();
MockServerHttpResponse response = exchange.getResponse();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
assertThat(response.getHeaders().getFirst("MyKey")).isEqualTo("MyValue");
assertThat(response.getCookies().getFirst("name").getValue()).isEqualTo("value");
StepVerifier.create(response.getBody()).expectComplete().verify();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.
the class DefaultEntityResponseBuilderTests method notModifiedEtag.
@Test
public void notModifiedEtag() {
String etag = "\"foo\"";
EntityResponse<String> responseMono = EntityResponse.fromObject("bar").eTag(etag).build().block();
MockServerHttpRequest request = MockServerHttpRequest.get("https://example.com").header(HttpHeaders.IF_NONE_MATCH, etag).build();
MockServerWebExchange exchange = MockServerWebExchange.from(request);
responseMono.writeTo(exchange, DefaultServerResponseBuilderTests.EMPTY_CONTEXT);
MockServerHttpResponse response = exchange.getResponse();
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
StepVerifier.create(response.getBody()).expectError(IllegalStateException.class).verify();
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.
the class WebHttpHandlerBuilderTests method configWithoutFilters.
@Test
void configWithoutFilters() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(NoFilterConfig.class);
context.refresh();
HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(context).build();
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
MockServerHttpResponse response = new MockServerHttpResponse();
httpHandler.handle(request, response).block(ofMillis(5000));
assertThat(response.getBodyAsString().block(ofMillis(5000))).isEqualTo("handled");
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.
the class WebHttpHandlerBuilderTests method orderedWebExceptionHandlerBeans.
// SPR-15074
@Test
void orderedWebExceptionHandlerBeans() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(OrderedExceptionHandlerBeanConfig.class);
context.refresh();
HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(context).build();
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
MockServerHttpResponse response = new MockServerHttpResponse();
httpHandler.handle(request, response).block(ofMillis(5000));
assertThat(response.getBodyAsString().block(ofMillis(5000))).isEqualTo("ExceptionHandlerB");
}
use of org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse in project spring-framework by spring-projects.
the class WebHttpHandlerBuilderTests method httpHandlerDecoratorFactoryBeans.
@Test
void httpHandlerDecoratorFactoryBeans() {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(new AnnotationConfigApplicationContext(HttpHandlerDecoratorFactoryBeansConfig.class)).build();
MockServerHttpResponse response = new MockServerHttpResponse();
handler.handle(MockServerHttpRequest.get("/").build(), response).block();
Function<String, Long> headerValue = name -> Long.valueOf(response.getHeaders().getFirst(name));
assertThat(headerValue.apply("decoratorA")).isLessThan(headerValue.apply("decoratorB"));
assertThat(headerValue.apply("decoratorC")).isLessThan(headerValue.apply("decoratorB"));
}
Aggregations