Search in sources :

Example 6 with ErrorAttributeOptions

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

the class ErrorAttributesOptionsTests method includingFromEmptyAttributesReturnAddedEntry.

@Test
void includingFromEmptyAttributesReturnAddedEntry() {
    ErrorAttributeOptions options = ErrorAttributeOptions.of(EnumSet.noneOf(Include.class));
    assertThat(options.including(Include.EXCEPTION).getIncludes()).containsOnly(Include.EXCEPTION);
}
Also used : Include(org.springframework.boot.web.error.ErrorAttributeOptions.Include) ErrorAttributeOptions(org.springframework.boot.web.error.ErrorAttributeOptions) Test(org.junit.jupiter.api.Test)

Example 7 with ErrorAttributeOptions

use of org.springframework.boot.web.error.ErrorAttributeOptions 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)7 ErrorAttributeOptions (org.springframework.boot.web.error.ErrorAttributeOptions)7 DefaultErrorAttributes (org.springframework.boot.web.servlet.error.DefaultErrorAttributes)3 ErrorAttributes (org.springframework.boot.web.servlet.error.ErrorAttributes)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)3 WebRequest (org.springframework.web.context.request.WebRequest)3 Include (org.springframework.boot.web.error.ErrorAttributeOptions.Include)2