Merge branch '1.2.x'
This commit is contained in:
commit
17fde264e2
|
|
@ -115,12 +115,13 @@ public class EndpointWebMvcChildContextConfiguration {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The error controller is present but not mapped as an endpoint in this context
|
* The error controller is present but not mapped as an endpoint in this context
|
||||||
* because of the DispatcherServlet having had it's HandlerMapping explicitly
|
* because of the DispatcherServlet having had its HandlerMapping explicitly disabled.
|
||||||
* disabled. So we expose the same feature but only for machine endpoints.
|
* So we expose the same feature but only for machine endpoints.
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
|
@ConditionalOnBean(ErrorAttributes.class)
|
||||||
public ManagementErrorEndpoint errorEndpoint(ServerProperties serverProperties,
|
public ManagementErrorEndpoint errorEndpoint(ServerProperties serverProperties,
|
||||||
final ErrorAttributes errorAttributes) {
|
ErrorAttributes errorAttributes) {
|
||||||
return new ManagementErrorEndpoint(serverProperties.getError().getPath(),
|
return new ManagementErrorEndpoint(serverProperties.getError().getPath(),
|
||||||
errorAttributes);
|
errorAttributes);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.hamcrest.Matcher;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
@ -77,6 +78,7 @@ import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
import static org.hamcrest.Matchers.startsWith;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
@ -145,6 +147,7 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||||
assertContent("/endpoint", ports.get().server, null);
|
assertContent("/endpoint", ports.get().server, null);
|
||||||
assertContent("/controller", ports.get().management, null);
|
assertContent("/controller", ports.get().management, null);
|
||||||
assertContent("/endpoint", ports.get().management, "endpointoutput");
|
assertContent("/endpoint", ports.get().management, "endpointoutput");
|
||||||
|
assertContent("/error", ports.get().management, startsWith("{"));
|
||||||
ApplicationContext managementContext = this.applicationContext
|
ApplicationContext managementContext = this.applicationContext
|
||||||
.getBean(ManagementContextResolver.class).getApplicationContext();
|
.getBean(ManagementContextResolver.class).getApplicationContext();
|
||||||
List<?> interceptors = (List<?>) ReflectionTestUtils.getField(
|
List<?> interceptors = (List<?>) ReflectionTestUtils.getField(
|
||||||
|
|
@ -154,6 +157,17 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||||
assertAllClosed();
|
assertAllClosed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onDifferentPortWithoutErrorMvcAutoConfiguration() throws Exception {
|
||||||
|
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
|
||||||
|
DifferentPortConfig.class, BaseConfiguration.class,
|
||||||
|
EndpointWebMvcAutoConfiguration.class);
|
||||||
|
this.applicationContext.refresh();
|
||||||
|
assertContent("/error", ports.get().management, null);
|
||||||
|
this.applicationContext.close();
|
||||||
|
assertAllClosed();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onDifferentPortInServletContainer() throws Exception {
|
public void onDifferentPortInServletContainer() throws Exception {
|
||||||
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
|
this.applicationContext.register(RootConfig.class, EndpointConfig.class,
|
||||||
|
|
@ -378,6 +392,7 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||||
assertContent("/endpoint", ports.get().management, null);
|
assertContent("/endpoint", ports.get().management, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void assertContent(String url, int port, Object expected) throws Exception {
|
public void assertContent(String url, int port, Object expected) throws Exception {
|
||||||
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
|
SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
|
||||||
ClientHttpRequest request = clientHttpRequestFactory
|
ClientHttpRequest request = clientHttpRequestFactory
|
||||||
|
|
@ -387,7 +402,12 @@ public class EndpointWebMvcAutoConfigurationTests {
|
||||||
try {
|
try {
|
||||||
String actual = StreamUtils.copyToString(response.getBody(),
|
String actual = StreamUtils.copyToString(response.getBody(),
|
||||||
Charset.forName("UTF-8"));
|
Charset.forName("UTF-8"));
|
||||||
assertThat(actual, equalTo(expected));
|
if (expected instanceof Matcher) {
|
||||||
|
assertThat(actual, is((Matcher<String>) expected));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assertThat(actual, equalTo(expected));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
response.close();
|
response.close();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue