Search in sources :

Example 1 with APPLICATION_JSON

use of org.springframework.http.MediaType.APPLICATION_JSON in project spring-framework by spring-projects.

the class DispatcherHandlerErrorTests method responseBodyMessageConversionError.

@Test
public void responseBodyMessageConversionError() {
    ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/request-body").accept(APPLICATION_JSON).body("body"));
    Mono<Void> publisher = this.dispatcherHandler.handle(exchange);
    StepVerifier.create(publisher).consumeErrorWith(error -> assertThat(error).isInstanceOf(NotAcceptableStatusException.class)).verify();
}
Also used : CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) BeforeEach(org.junit.jupiter.api.BeforeEach) RequestMappingHandlerMapping(org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping) StepVerifier(reactor.test.StepVerifier) RequestMappingHandlerAdapter(org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) Controller(org.springframework.stereotype.Controller) WebHandler(org.springframework.web.server.WebHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) ServerWebExchange(org.springframework.web.server.ServerWebExchange) RequestBody(org.springframework.web.bind.annotation.RequestBody) ResponseBodyResultHandler(org.springframework.web.reactive.result.method.annotation.ResponseBodyResultHandler) EncoderHttpMessageWriter(org.springframework.http.codec.EncoderHttpMessageWriter) Duration(java.time.Duration) HeaderContentTypeResolver(org.springframework.web.reactive.accept.HeaderContentTypeResolver) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) ResponseStatusException(org.springframework.web.server.ResponseStatusException) ExceptionHandlingWebHandler(org.springframework.web.server.handler.ExceptionHandlingWebHandler) WebExceptionHandler(org.springframework.web.server.WebExceptionHandler) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) NotAcceptableStatusException(org.springframework.web.server.NotAcceptableStatusException) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) HttpStatus(org.springframework.http.HttpStatus) MockServerHttpRequest(org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest) List(java.util.List) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) MockServerWebExchange(org.springframework.web.testfixture.server.MockServerWebExchange) ServerWebExchange(org.springframework.web.server.ServerWebExchange) Test(org.junit.jupiter.api.Test)

Aggregations

Duration (java.time.Duration)1 Collections (java.util.Collections)1 List (java.util.List)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 Publisher (org.reactivestreams.Publisher)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 Configuration (org.springframework.context.annotation.Configuration)1 CharSequenceEncoder (org.springframework.core.codec.CharSequenceEncoder)1 HttpStatus (org.springframework.http.HttpStatus)1 APPLICATION_JSON (org.springframework.http.MediaType.APPLICATION_JSON)1 EncoderHttpMessageWriter (org.springframework.http.codec.EncoderHttpMessageWriter)1 Controller (org.springframework.stereotype.Controller)1 RequestBody (org.springframework.web.bind.annotation.RequestBody)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 HeaderContentTypeResolver (org.springframework.web.reactive.accept.HeaderContentTypeResolver)1