Search in sources :

Example 56 with HandlerResult

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

the class InvocableHandlerMethodTests method resolveNoArgValue.

@Test
public void resolveNoArgValue() {
    this.resolvers.add(stubResolver(Mono.empty()));
    Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
    Mono<HandlerResult> mono = invoke(new TestController(), method);
    assertHandlerResultValue(mono, "success:null");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StepVerifier(reactor.test.StepVerifier) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) BindingContext(org.springframework.web.reactive.BindingContext) ArrayList(java.util.ArrayList) ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerHttpRequest.get(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest.get) UnsupportedMediaTypeStatusException(org.springframework.web.server.UnsupportedMediaTypeStatusException) BDDMockito.given(org.mockito.BDDMockito.given) Duration(java.time.Duration) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Nullable(org.springframework.lang.Nullable) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) Method(java.lang.reflect.Method) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) Mono(reactor.core.publisher.Mono) Instant(java.time.Instant) DataBuffer(org.springframework.core.io.buffer.DataBuffer) HandlerResult(org.springframework.web.reactive.HandlerResult) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) HttpStatus(org.springframework.http.HttpStatus) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) List(java.util.List) ResolvableMethod(org.springframework.web.testfixture.method.ResolvableMethod) Mockito.mock(org.mockito.Mockito.mock) HandlerResult(org.springframework.web.reactive.HandlerResult) Method(java.lang.reflect.Method) ResolvableMethod(org.springframework.web.testfixture.method.ResolvableMethod) Test(org.junit.jupiter.api.Test)

Example 57 with HandlerResult

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

the class InvocableHandlerMethodTests method voidMethodWithExchangeArg.

@Test
public void voidMethodWithExchangeArg() {
    this.resolvers.add(stubResolver(this.exchange));
    Method method = ResolvableMethod.on(TestController.class).mockCall(c -> c.exchange(exchange)).method();
    HandlerResult result = invokeForResult(new TestController(), method);
    assertThat(result).as("Expected no result (i.e. fully handled)").isNull();
    assertThat(this.exchange.getResponse().getHeaders().getFirst("foo")).isEqualTo("bar");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StepVerifier(reactor.test.StepVerifier) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) BindingContext(org.springframework.web.reactive.BindingContext) ArrayList(java.util.ArrayList) ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerHttpRequest.get(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest.get) UnsupportedMediaTypeStatusException(org.springframework.web.server.UnsupportedMediaTypeStatusException) BDDMockito.given(org.mockito.BDDMockito.given) Duration(java.time.Duration) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Nullable(org.springframework.lang.Nullable) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) Method(java.lang.reflect.Method) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) Mono(reactor.core.publisher.Mono) Instant(java.time.Instant) DataBuffer(org.springframework.core.io.buffer.DataBuffer) HandlerResult(org.springframework.web.reactive.HandlerResult) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) HttpStatus(org.springframework.http.HttpStatus) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) List(java.util.List) ResolvableMethod(org.springframework.web.testfixture.method.ResolvableMethod) Mockito.mock(org.mockito.Mockito.mock) HandlerResult(org.springframework.web.reactive.HandlerResult) Method(java.lang.reflect.Method) ResolvableMethod(org.springframework.web.testfixture.method.ResolvableMethod) Test(org.junit.jupiter.api.Test)

Example 58 with HandlerResult

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

the class InvocableHandlerMethodTests method invocationTargetException.

@Test
public void invocationTargetException() {
    Method method = ResolvableMethod.on(TestController.class).mockCall(TestController::exceptionMethod).method();
    Mono<HandlerResult> mono = invoke(new TestController(), method);
    assertThatIllegalStateException().isThrownBy(mono::block).withMessage("boo");
}
Also used : HandlerResult(org.springframework.web.reactive.HandlerResult) Method(java.lang.reflect.Method) ResolvableMethod(org.springframework.web.testfixture.method.ResolvableMethod) Test(org.junit.jupiter.api.Test)

Example 59 with HandlerResult

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

the class InvocableHandlerMethodTests method resolveArg.

@Test
public void resolveArg() {
    this.resolvers.add(stubResolver("value1"));
    Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
    Mono<HandlerResult> mono = invoke(new TestController(), method);
    assertHandlerResultValue(mono, "success:value1");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StepVerifier(reactor.test.StepVerifier) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) BindingContext(org.springframework.web.reactive.BindingContext) ArrayList(java.util.ArrayList) ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerHttpRequest.get(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest.get) UnsupportedMediaTypeStatusException(org.springframework.web.server.UnsupportedMediaTypeStatusException) BDDMockito.given(org.mockito.BDDMockito.given) Duration(java.time.Duration) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Nullable(org.springframework.lang.Nullable) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) Method(java.lang.reflect.Method) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) Mono(reactor.core.publisher.Mono) Instant(java.time.Instant) DataBuffer(org.springframework.core.io.buffer.DataBuffer) HandlerResult(org.springframework.web.reactive.HandlerResult) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) HttpStatus(org.springframework.http.HttpStatus) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) List(java.util.List) ResolvableMethod(org.springframework.web.testfixture.method.ResolvableMethod) Mockito.mock(org.mockito.Mockito.mock) HandlerResult(org.springframework.web.reactive.HandlerResult) Method(java.lang.reflect.Method) ResolvableMethod(org.springframework.web.testfixture.method.ResolvableMethod) Test(org.junit.jupiter.api.Test)

Example 60 with HandlerResult

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

the class InvocableHandlerMethodTests method resolveProvidedArgFirst.

@Test
public void resolveProvidedArgFirst() {
    this.resolvers.add(stubResolver("value1"));
    Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
    Mono<HandlerResult> mono = invoke(new TestController(), method, "value2");
    assertHandlerResultValue(mono, "success:value2");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StepVerifier(reactor.test.StepVerifier) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) ServerHttpResponse(org.springframework.http.server.reactive.ServerHttpResponse) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) BindingContext(org.springframework.web.reactive.BindingContext) ArrayList(java.util.ArrayList) ServerWebExchange(org.springframework.web.server.ServerWebExchange) MockServerHttpRequest.get(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest.get) UnsupportedMediaTypeStatusException(org.springframework.web.server.UnsupportedMediaTypeStatusException) BDDMockito.given(org.mockito.BDDMockito.given) Duration(java.time.Duration) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Nullable(org.springframework.lang.Nullable) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) Method(java.lang.reflect.Method) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) Mono(reactor.core.publisher.Mono) Instant(java.time.Instant) DataBuffer(org.springframework.core.io.buffer.DataBuffer) HandlerResult(org.springframework.web.reactive.HandlerResult) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) HttpStatus(org.springframework.http.HttpStatus) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) List(java.util.List) ResolvableMethod(org.springframework.web.testfixture.method.ResolvableMethod) Mockito.mock(org.mockito.Mockito.mock) HandlerResult(org.springframework.web.reactive.HandlerResult) Method(java.lang.reflect.Method) ResolvableMethod(org.springframework.web.testfixture.method.ResolvableMethod) Test(org.junit.jupiter.api.Test)

Aggregations

HandlerResult (org.springframework.web.reactive.HandlerResult)60 Test (org.junit.jupiter.api.Test)36 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)36 Method (java.lang.reflect.Method)24 MethodParameter (org.springframework.core.MethodParameter)23 BindingContext (org.springframework.web.reactive.BindingContext)20 Mono (reactor.core.publisher.Mono)20 HttpStatus (org.springframework.http.HttpStatus)19 StepVerifier (reactor.test.StepVerifier)19 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)18 Instant (java.time.Instant)17 Mockito.mock (org.mockito.Mockito.mock)17 UnsupportedMediaTypeStatusException (org.springframework.web.server.UnsupportedMediaTypeStatusException)17 List (java.util.List)15 ServerWebExchange (org.springframework.web.server.ServerWebExchange)15 ResolvableMethod (org.springframework.web.testfixture.method.ResolvableMethod)15 Duration (java.time.Duration)14 ArrayList (java.util.ArrayList)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 Nullable (org.springframework.lang.Nullable)14