use of org.springframework.boot.web.error.ErrorAttributeOptions in project spring-boot by spring-projects.
the class ManagementErrorEndpointTests method errorResponseWithDefaultErrorAttributesSubclassUsingDelegation.
@Test
void errorResponseWithDefaultErrorAttributesSubclassUsingDelegation() {
ErrorAttributes attributes = new DefaultErrorAttributes() {
@Override
public Map<String, Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) {
Map<String, Object> response = super.getErrorAttributes(webRequest, options);
response.put("error", "custom error");
response.put("custom", "value");
response.remove("path");
return response;
}
};
ManagementErrorEndpoint endpoint = new ManagementErrorEndpoint(attributes, this.errorProperties);
Map<String, Object> response = endpoint.invoke(new ServletWebRequest(new MockHttpServletRequest()));
assertThat(response).containsEntry("error", "custom error");
assertThat(response).containsEntry("custom", "value");
assertThat(response).doesNotContainKey("path");
assertThat(response).containsKey("timestamp");
}
use of org.springframework.boot.web.error.ErrorAttributeOptions in project spring-boot by spring-projects.
the class ManagementErrorEndpointTests method errorResponseWithCustomErrorAttributesUsingDeprecatedApi.
@Test
void errorResponseWithCustomErrorAttributesUsingDeprecatedApi() {
ErrorAttributes attributes = new ErrorAttributes() {
@Override
public Map<String, Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) {
return Collections.singletonMap("message", "An error occurred");
}
@Override
public Throwable getError(WebRequest webRequest) {
return null;
}
};
ManagementErrorEndpoint endpoint = new ManagementErrorEndpoint(attributes, this.errorProperties);
Map<String, Object> response = endpoint.invoke(new ServletWebRequest(new MockHttpServletRequest()));
assertThat(response).containsExactly(entry("message", "An error occurred"));
}
use of org.springframework.boot.web.error.ErrorAttributeOptions in project spring-boot by spring-projects.
the class ErrorAttributesOptionsTests method excludingFromEmptyAttributesReturnEmptyList.
@Test
void excludingFromEmptyAttributesReturnEmptyList() {
ErrorAttributeOptions options = ErrorAttributeOptions.of(EnumSet.noneOf(Include.class));
assertThat(options.excluding(Include.EXCEPTION).getIncludes()).isEmpty();
}
use of org.springframework.boot.web.error.ErrorAttributeOptions in project spring-boot by spring-projects.
the class ErrorAttributesOptionsTests method excludingFromMatchingAttributesRemoveMatch.
@Test
void excludingFromMatchingAttributesRemoveMatch() {
ErrorAttributeOptions options = ErrorAttributeOptions.of(EnumSet.of(Include.EXCEPTION, Include.STACK_TRACE));
assertThat(options.excluding(Include.EXCEPTION).getIncludes()).containsOnly(Include.STACK_TRACE);
}
use of org.springframework.boot.web.error.ErrorAttributeOptions in project spring-boot by spring-projects.
the class ErrorAttributesOptionsTests method includingFromMatchingAttributesDoesNotModifyOptions.
@Test
void includingFromMatchingAttributesDoesNotModifyOptions() {
ErrorAttributeOptions options = ErrorAttributeOptions.of(EnumSet.of(Include.EXCEPTION, Include.STACK_TRACE));
assertThat(options.including(Include.EXCEPTION).getIncludes()).containsOnly(Include.EXCEPTION, Include.STACK_TRACE);
}
Aggregations