Search in sources :

Example 36 with HandlerResult

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

the class InvocableHandlerMethodTests method illegalArgumentExceptionIsWrappedWithInvocationDetails.

@Test
public void illegalArgumentExceptionIsWrappedWithInvocationDetails() throws Exception {
    Mono<Object> resolvedValue = Mono.just(1);
    Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
    Mono<HandlerResult> mono = invoke(new TestController(), method, resolverFor(resolvedValue));
    try {
        mono.block();
        fail("Expected IllegalStateException");
    } catch (IllegalStateException ex) {
        assertThat(ex.getMessage(), is("Failed to invoke handler method with resolved arguments: " + "[0][type=java.lang.Integer][value=1] " + "on " + method.toGenericString()));
    }
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ResolvableMethod.on(org.springframework.web.method.ResolvableMethod.on) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) BindingContext(org.springframework.web.reactive.BindingContext) Mockito.when(org.mockito.Mockito.when) HandlerResult(org.springframework.web.reactive.HandlerResult) Assert.assertThat(org.junit.Assert.assertThat) HttpStatus(org.springframework.http.HttpStatus) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) UnsupportedMediaTypeStatusException(org.springframework.web.server.UnsupportedMediaTypeStatusException) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Assert.fail(org.junit.Assert.fail) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) Mockito.any(org.mockito.Mockito.any) Method(java.lang.reflect.Method) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) HandlerResult(org.springframework.web.reactive.HandlerResult) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 37 with HandlerResult

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

the class InvocableHandlerMethodTests method resolverThrowsException.

@Test
public void resolverThrowsException() throws Exception {
    Mono<Object> resolvedValue = Mono.error(new UnsupportedMediaTypeStatusException("boo"));
    Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
    Mono<HandlerResult> mono = invoke(new TestController(), method, resolverFor(resolvedValue));
    try {
        mono.block();
        fail("Expected UnsupportedMediaTypeStatusException");
    } catch (UnsupportedMediaTypeStatusException ex) {
        assertThat(ex.getMessage(), is("Request failure [status: 415, reason: \"boo\"]"));
    }
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ResolvableMethod.on(org.springframework.web.method.ResolvableMethod.on) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) BindingContext(org.springframework.web.reactive.BindingContext) Mockito.when(org.mockito.Mockito.when) HandlerResult(org.springframework.web.reactive.HandlerResult) Assert.assertThat(org.junit.Assert.assertThat) HttpStatus(org.springframework.http.HttpStatus) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) UnsupportedMediaTypeStatusException(org.springframework.web.server.UnsupportedMediaTypeStatusException) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Assert.fail(org.junit.Assert.fail) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) Mockito.any(org.mockito.Mockito.any) Method(java.lang.reflect.Method) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) UnsupportedMediaTypeStatusException(org.springframework.web.server.UnsupportedMediaTypeStatusException) HandlerResult(org.springframework.web.reactive.HandlerResult) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 38 with HandlerResult

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

the class InvocableHandlerMethodTests method noMatchingResolver.

@Test
public void noMatchingResolver() throws Exception {
    Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
    Mono<HandlerResult> mono = invoke(new TestController(), method);
    try {
        mono.block();
        fail("Expected IllegalStateException");
    } catch (IllegalStateException ex) {
        assertThat(ex.getMessage(), is("No suitable resolver for argument 0 of type 'java.lang.String' " + "on " + method.toGenericString()));
    }
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ResolvableMethod.on(org.springframework.web.method.ResolvableMethod.on) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) BindingContext(org.springframework.web.reactive.BindingContext) Mockito.when(org.mockito.Mockito.when) HandlerResult(org.springframework.web.reactive.HandlerResult) Assert.assertThat(org.junit.Assert.assertThat) HttpStatus(org.springframework.http.HttpStatus) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) UnsupportedMediaTypeStatusException(org.springframework.web.server.UnsupportedMediaTypeStatusException) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Assert.fail(org.junit.Assert.fail) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) Mockito.any(org.mockito.Mockito.any) Method(java.lang.reflect.Method) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) HandlerResult(org.springframework.web.reactive.HandlerResult) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 39 with HandlerResult

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

the class InvocableHandlerMethodTests method invokeMethodWithNoValue.

@Test
public void invokeMethodWithNoValue() throws Exception {
    Mono<Object> resolvedValue = Mono.empty();
    Method method = on(TestController.class).mockCall(o -> o.singleArg(null)).method();
    Mono<HandlerResult> mono = invoke(new TestController(), method, resolverFor(resolvedValue));
    assertHandlerResultValue(mono, "success:null");
}
Also used : Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ResolvableMethod.on(org.springframework.web.method.ResolvableMethod.on) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) BindingContext(org.springframework.web.reactive.BindingContext) Mockito.when(org.mockito.Mockito.when) HandlerResult(org.springframework.web.reactive.HandlerResult) Assert.assertThat(org.junit.Assert.assertThat) HttpStatus(org.springframework.http.HttpStatus) MockServerWebExchange(org.springframework.mock.http.server.reactive.test.MockServerWebExchange) MockServerHttpRequest(org.springframework.mock.http.server.reactive.test.MockServerHttpRequest) UnsupportedMediaTypeStatusException(org.springframework.web.server.UnsupportedMediaTypeStatusException) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Assert.fail(org.junit.Assert.fail) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) Mockito.any(org.mockito.Mockito.any) Method(java.lang.reflect.Method) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) HandlerResult(org.springframework.web.reactive.HandlerResult) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 40 with HandlerResult

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

the class ViewResolutionResultHandlerTests method testSupports.

private void testSupports(MethodParameter returnType) {
    ViewResolutionResultHandler resultHandler = resultHandler(mock(ViewResolver.class));
    HandlerResult handlerResult = new HandlerResult(new Object(), null, returnType, this.bindingContext);
    assertTrue(resultHandler.supports(handlerResult));
}
Also used : HandlerResult(org.springframework.web.reactive.HandlerResult)

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