|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
18 | 18 |
|
19 | 19 | import java.lang.annotation.Retention;
|
20 | 20 | import java.lang.annotation.RetentionPolicy;
|
| 21 | +import java.util.Arrays; |
21 | 22 | import java.util.Locale;
|
22 | 23 |
|
23 | 24 | import org.junit.jupiter.api.BeforeEach;
|
|
28 | 29 | import org.springframework.context.i18n.LocaleContextHolder;
|
29 | 30 | import org.springframework.context.support.StaticMessageSource;
|
30 | 31 | import org.springframework.core.annotation.AliasFor;
|
| 32 | +import org.springframework.http.HttpHeaders; |
| 33 | +import org.springframework.http.HttpMethod; |
31 | 34 | import org.springframework.http.HttpStatus;
|
32 | 35 | import org.springframework.web.bind.annotation.ResponseStatus;
|
| 36 | +import org.springframework.web.server.MethodNotAllowedException; |
33 | 37 | import org.springframework.web.server.ResponseStatusException;
|
34 | 38 | import org.springframework.web.servlet.ModelAndView;
|
35 | 39 | import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
|
@@ -128,6 +132,16 @@ public void responseStatusExceptionWithReason() throws Exception {
|
128 | 132 | assertResolved(mav, 400, "The reason");
|
129 | 133 | }
|
130 | 134 |
|
| 135 | + @Test |
| 136 | + void responseStatusExceptionWithHeaders() { |
| 137 | + Exception ex = new MethodNotAllowedException( |
| 138 | + HttpMethod.GET, Arrays.asList(HttpMethod.POST, HttpMethod.PUT)); |
| 139 | + |
| 140 | + ModelAndView mav = exceptionResolver.resolveException(request, response, null, ex); |
| 141 | + |
| 142 | + assertResolved(mav, 405, "Request method 'GET' not supported"); |
| 143 | + assertThat(response.getHeader(HttpHeaders.ALLOW)).isEqualTo("POST,PUT"); |
| 144 | + } |
131 | 145 |
|
132 | 146 | private void assertResolved(ModelAndView mav, int status, String reason) {
|
133 | 147 | assertThat(mav != null && mav.isEmpty()).as("No Empty ModelAndView returned").isTrue();
|
|
0 commit comments