Search in sources :

Example 6 with ErrorAttributes

use of org.springframework.boot.web.servlet.error.ErrorAttributes in project spring-boot by spring-projects.

the class ManagementErrorEndpointTests method errorResponseWithDefaultErrorAttributesSubclassWithoutDelegation.

@Test
void errorResponseWithDefaultErrorAttributesSubclassWithoutDelegation() {
    ErrorAttributes attributes = new DefaultErrorAttributes() {

        @Override
        public Map<String, Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) {
            return Collections.singletonMap("error", "custom error");
        }
    };
    ManagementErrorEndpoint endpoint = new ManagementErrorEndpoint(attributes, this.errorProperties);
    Map<String, Object> response = endpoint.invoke(new ServletWebRequest(new MockHttpServletRequest()));
    assertThat(response).containsExactly(entry("error", "custom error"));
}
Also used : ErrorAttributes(org.springframework.boot.web.servlet.error.ErrorAttributes) DefaultErrorAttributes(org.springframework.boot.web.servlet.error.DefaultErrorAttributes) WebRequest(org.springframework.web.context.request.WebRequest) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ErrorAttributeOptions(org.springframework.boot.web.error.ErrorAttributeOptions) DefaultErrorAttributes(org.springframework.boot.web.servlet.error.DefaultErrorAttributes) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)6 ErrorAttributes (org.springframework.boot.web.servlet.error.ErrorAttributes)6 ErrorAttributeOptions (org.springframework.boot.web.error.ErrorAttributeOptions)3 DefaultErrorAttributes (org.springframework.boot.web.servlet.error.DefaultErrorAttributes)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)3 WebRequest (org.springframework.web.context.request.WebRequest)3 View (org.springframework.web.servlet.View)3 DispatcherServletWebRequest (org.springframework.web.servlet.handler.DispatcherServletWebRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2