Search in sources :

Example 96 with Mono

use of reactor.core.publisher.Mono in project spring-framework by spring-projects.

the class InvocableHandlerMethodTests method cannotResolveArg.

@Test
public void cannotResolveArg() {
    Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
    Mono<HandlerResult> mono = invoke(new TestController(), method);
    assertThatIllegalStateException().isThrownBy(mono::block).withMessage("Could not resolve parameter [0] in " + method.toGenericString() + ": No suitable resolver");
}
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 97 with Mono

use of reactor.core.publisher.Mono in project spring-framework by spring-projects.

the class InvocableHandlerMethodTests method illegalArgumentException.

@Test
public void illegalArgumentException() {
    this.resolvers.add(stubResolver(1));
    Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
    Mono<HandlerResult> mono = invoke(new TestController(), method);
    assertThatIllegalStateException().isThrownBy(mono::block).withCauseInstanceOf(IllegalArgumentException.class).withMessageContaining("Controller [").withMessageContaining("Method [").withMessageContaining("with argument values:").withMessageContaining("[0] [type=java.lang.Integer] [value=1]");
}
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 98 with Mono

use of reactor.core.publisher.Mono in project spring-framework by spring-projects.

the class InvocableHandlerMethodTests method resolveProvidedArg.

@Test
public void resolveProvidedArg() {
    Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
    Mono<HandlerResult> mono = invoke(new TestController(), method, "value1");
    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 99 with Mono

use of reactor.core.publisher.Mono in project spring-framework by spring-projects.

the class InvocableHandlerMethodTests method exceptionInResolvingArg.

@Test
public void exceptionInResolvingArg() {
    this.resolvers.add(stubResolver(Mono.error(new UnsupportedMediaTypeStatusException("boo"))));
    Method method = ResolvableMethod.on(TestController.class).mockCall(o -> o.singleArg(null)).method();
    Mono<HandlerResult> mono = invoke(new TestController(), method);
    assertThatExceptionOfType(UnsupportedMediaTypeStatusException.class).isThrownBy(mono::block).withMessage("415 UNSUPPORTED_MEDIA_TYPE \"boo\"");
}
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) UnsupportedMediaTypeStatusException(org.springframework.web.server.UnsupportedMediaTypeStatusException) 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 100 with Mono

use of reactor.core.publisher.Mono in project spring-framework by spring-projects.

the class ModelAttributeMethodArgumentResolverTests method validationErrorForMono.

@Test
void validationErrorForMono() throws Exception {
    MethodParameter parameter = this.testMethod.annotNotPresent(ModelAttribute.class).arg(Mono.class, Pojo.class);
    testValidationError(parameter, resolvedArgumentMono -> {
        Object value = resolvedArgumentMono.block(Duration.ofSeconds(5));
        assertThat(value).isInstanceOf(Mono.class);
        return (Mono<?>) value;
    });
}
Also used : Mono(reactor.core.publisher.Mono) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.jupiter.api.Test)

Aggregations

Mono (reactor.core.publisher.Mono)308 Test (org.junit.jupiter.api.Test)143 StepVerifier (reactor.test.StepVerifier)117 List (java.util.List)116 Flux (reactor.core.publisher.Flux)110 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)102 Collections (java.util.Collections)85 Map (java.util.Map)75 HttpStatus (org.springframework.http.HttpStatus)66 ServerWebExchange (org.springframework.web.server.ServerWebExchange)65 Duration (java.time.Duration)60 ArrayList (java.util.ArrayList)58 Test (org.junit.Test)53 MockServerHttpRequest (org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest)52 DataBuffer (org.springframework.core.io.buffer.DataBuffer)51 Assert (org.springframework.util.Assert)49 Mockito.mock (org.mockito.Mockito.mock)48 MockServerWebExchange (org.springframework.web.testfixture.server.MockServerWebExchange)46 Optional (java.util.Optional)44 StandardCharsets (java.nio.charset.StandardCharsets)43