Search in sources :

Example 11 with HandlerResult

use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.

the class ViewResolutionResultHandlerTests method doesNotSupport.

@Test
public void doesNotSupport() throws Exception {
    MethodParameter returnType = on(TestController.class).resolveReturnType(Integer.class);
    ViewResolutionResultHandler resultHandler = resultHandler(mock(ViewResolver.class));
    HandlerResult handlerResult = new HandlerResult(new Object(), null, returnType, this.bindingContext);
    assertFalse(resultHandler.supports(handlerResult));
}
Also used : HandlerResult(org.springframework.web.reactive.HandlerResult) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 12 with HandlerResult

use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.

the class ResponseEntityResultHandlerTests method statusCode.

@Test
public void statusCode() throws Exception {
    ResponseEntity<Void> value = ResponseEntity.noContent().build();
    MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
    HandlerResult result = handlerResult(value, returnType);
    MockServerWebExchange exchange = get("/path").toExchange();
    this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
    assertEquals(HttpStatus.NO_CONTENT, exchange.getResponse().getStatusCode());
    assertEquals(0, exchange.getResponse().getHeaders().size());
    assertResponseBodyIsEmpty(exchange);
}
Also used : HandlerResult(org.springframework.web.reactive.HandlerResult) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 13 with HandlerResult

use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.

the class ResponseBodyResultHandlerTests method supports.

@Test
public void supports() throws NoSuchMethodException {
    Object controller = new TestController();
    Method method;
    method = on(TestController.class).annotPresent(ResponseBody.class).resolveMethod();
    testSupports(controller, method);
    method = on(TestController.class).annotNotPresent(ResponseBody.class).resolveMethod();
    HandlerResult handlerResult = getHandlerResult(controller, method);
    assertFalse(this.resultHandler.supports(handlerResult));
}
Also used : HandlerResult(org.springframework.web.reactive.HandlerResult) HandlerMethod(org.springframework.web.method.HandlerMethod) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 14 with HandlerResult

use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.

the class ResponseEntityResultHandlerTests method handleReturnValueETagAndLastModified.

@Test
public void handleReturnValueETagAndLastModified() throws Exception {
    String eTag = "\"deadb33f8badf00d\"";
    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(eTag).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.NOT_MODIFIED, null, eTag, oneMinAgo);
}
Also used : Instant(java.time.Instant) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) HandlerResult(org.springframework.web.reactive.HandlerResult) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 15 with HandlerResult

use of org.springframework.web.reactive.HandlerResult in project spring-framework by spring-projects.

the class ResponseEntityResultHandlerTests method handleReturnValueLastModified.

@Test
public void handleReturnValueLastModified() throws Exception {
    Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS);
    Instant oneMinAgo = currentTime.minusSeconds(60);
    MockServerWebExchange exchange = get("/path").ifModifiedSince(currentTime.toEpochMilli()).toExchange();
    ResponseEntity<String> entity = ok().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.NOT_MODIFIED, null, null, oneMinAgo);
}
Also used : Instant(java.time.Instant) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) HandlerResult(org.springframework.web.reactive.HandlerResult) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Aggregations

HandlerResult (org.springframework.web.reactive.HandlerResult)34 Test (org.junit.Test)24 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)22 MethodParameter (org.springframework.core.MethodParameter)16 Method (java.lang.reflect.Method)10 BindingContext (org.springframework.web.reactive.BindingContext)7 Mono (reactor.core.publisher.Mono)7 Arrays (java.util.Arrays)6 Optional (java.util.Optional)6 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)6 Matchers.is (org.hamcrest.Matchers.is)5 Assert.assertEquals (org.junit.Assert.assertEquals)5 Assert.assertThat (org.junit.Assert.assertThat)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 Assert.fail (org.junit.Assert.fail)5 Mockito.any (org.mockito.Mockito.any)5 Mockito.mock (org.mockito.Mockito.mock)5 Mockito.when (org.mockito.Mockito.when)5 Instant (java.time.Instant)4 HttpStatus (org.springframework.http.HttpStatus)4