use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ResponseEntityResultHandlerTests method testHandle.
private void testHandle(Object returnValue, MethodParameter returnType) {
MockServerWebExchange exchange = get("/path").toExchange();
HandlerResult result = handlerResult(returnValue, returnType);
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
assertEquals(HttpStatus.OK, exchange.getResponse().getStatusCode());
assertEquals("text/plain;charset=UTF-8", exchange.getResponse().getHeaders().getFirst("Content-Type"));
assertResponseBody(exchange, "abc");
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ResponseEntityResultHandlerTests method handleReturnValueChangedETagAndLastModified.
@Test
public void handleReturnValueChangedETagAndLastModified() throws Exception {
String etag = "\"deadb33f8badf00d\"";
String newEtag = "\"changed-etag-value\"";
Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS);
Instant oneMinAgo = currentTime.minusSeconds(60);
MockServerWebExchange exchange = get("/path").ifNoneMatch(etag).ifModifiedSince(currentTime.toEpochMilli()).toExchange();
ResponseEntity<String> entity = ok().eTag(newEtag).lastModified(oneMinAgo.toEpochMilli()).body("body");
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
HandlerResult result = handlerResult(entity, returnType);
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
assertConditionalResponse(exchange, HttpStatus.OK, "body", newEtag, oneMinAgo);
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ResponseEntityResultHandlerTests method handleResponseEntityWithNullBody.
@Test
public void handleResponseEntityWithNullBody() throws Exception {
Object returnValue = Mono.just(notFound().build());
MethodParameter type = on(TestController.class).resolveReturnType(Mono.class, entity(String.class));
HandlerResult result = handlerResult(returnValue, type);
MockServerWebExchange exchange = get("/path").toExchange();
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
assertEquals(HttpStatus.NOT_FOUND, exchange.getResponse().getStatusCode());
assertResponseBodyIsEmpty(exchange);
}
use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.
the class ResponseEntityResultHandlerTests method handleReturnValueEtag.
@Test
public void handleReturnValueEtag() throws Exception {
String etagValue = "\"deadb33f8badf00d\"";
MockServerWebExchange exchange = get("/path").ifNoneMatch(etagValue).toExchange();
ResponseEntity<String> entity = ok().eTag(etagValue).body("body");
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
HandlerResult result = handlerResult(entity, returnType);
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
assertConditionalResponse(exchange, HttpStatus.NOT_MODIFIED, null, etagValue, Instant.MIN);
}
Aggregations