Search in sources :

Example 6 with HttpMediaTypeNotSupportedException

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

the class DefaultHandlerExceptionResolverTests method handleHttpMediaTypeNotSupported.

@Test
public void handleHttpMediaTypeNotSupported() {
    HttpMediaTypeNotSupportedException ex = new HttpMediaTypeNotSupportedException(new MediaType("text", "plain"), Collections.singletonList(new MediaType("application", "pdf")));
    ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex);
    assertNotNull("No ModelAndView returned", mav);
    assertTrue("No Empty ModelAndView returned", mav.isEmpty());
    assertEquals("Invalid status code", 415, response.getStatus());
    assertEquals("Invalid Accept header", "application/pdf", response.getHeader("Accept"));
}
Also used : HttpMediaTypeNotSupportedException(org.springframework.web.HttpMediaTypeNotSupportedException) ModelAndView(org.springframework.web.servlet.ModelAndView) MediaType(org.springframework.http.MediaType) Test(org.junit.Test)

Aggregations

HttpMediaTypeNotSupportedException (org.springframework.web.HttpMediaTypeNotSupportedException)6 MediaType (org.springframework.http.MediaType)5 Test (org.junit.Test)3 InvalidMediaTypeException (org.springframework.http.InvalidMediaTypeException)2 HttpMessageNotReadableException (org.springframework.http.converter.HttpMessageNotReadableException)2 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)2 HttpMediaTypeNotAcceptableException (org.springframework.web.HttpMediaTypeNotAcceptableException)2 HttpRequestMethodNotSupportedException (org.springframework.web.HttpRequestMethodNotSupportedException)2 IOException (java.io.IOException)1 ConversionNotSupportedException (org.springframework.beans.ConversionNotSupportedException)1 TypeMismatchException (org.springframework.beans.TypeMismatchException)1 ResolvableType (org.springframework.core.ResolvableType)1 HttpMethod (org.springframework.http.HttpMethod)1 HttpRequest (org.springframework.http.HttpRequest)1 GenericHttpMessageConverter (org.springframework.http.converter.GenericHttpMessageConverter)1 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)1 HttpMessageNotWritableException (org.springframework.http.converter.HttpMessageNotWritableException)1 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)1 BindException (org.springframework.validation.BindException)1 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)1