From b7c0e3279e8f6cf539601a18f9b86b2a72db8cdc Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 23 May 2013 18:36:23 +0100 Subject: [PATCH] [bs-22] Add loads of actuator tests Discovered a few issues along the way and refactored accordingly. [#48127729] [bs-22] Add missing unit tests --- .../ActuatorAutoConfiguration.java | 2 +- ...iguration.java => ErrorConfiguration.java} | 2 +- .../autoconfigure/InfoConfiguration.java | 46 ++++--- .../ManagementConfiguration.java | 60 +++++---- .../ManagementServerConfiguration.java | 54 +++----- .../autoconfigure/MetricsConfiguration.java | 8 +- ...VarzEndpoint.java => MetricsEndpoint.java} | 4 +- .../bootstrap/actuate/TestUtils.java | 43 +++++++ .../ActuatorWebConfigurationTests.java | 42 +++++++ .../ErrorConfigurationTests.java | 51 ++++++++ .../HealthConfigurationTests.java | 39 ++++++ .../autoconfigure/InfoConfigurationTests.java | 59 +++++++++ .../ManagementConfigurationTests.java | 119 ++++++++++++++++++ .../ManagementServerConfigurationTests.java | 57 +++++++++ .../MetricFilterConfigurationTests.java | 51 ++++++++ .../MetricRepositoryConfigurationTests.java | 40 ++++++ .../MetricsConfigurationTests.java | 41 ++++++ .../SecurityConfigurationTests.java | 44 +++++++ .../ShutdownConfigurationTests.java | 43 +++++++ .../TraceConfigurationTests.java | 41 ++++++ .../src/test/resources/git.properties | 13 ++ ...ressServiceBootstrapApplicationTests.java} | 2 +- ...mentServiceBootstrapApplicationTests.java} | 2 +- ...mentServiceBootstrapApplicationTests.java} | 2 +- ...eddedContainerCustomizerConfiguration.java | 22 ++-- 25 files changed, 782 insertions(+), 105 deletions(-) rename spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/{ServerConfiguration.java => ErrorConfiguration.java} (95%) rename spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/endpoint/metrics/{VarzEndpoint.java => MetricsEndpoint.java} (94%) create mode 100644 spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/TestUtils.java create mode 100644 spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ActuatorWebConfigurationTests.java create mode 100644 spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ErrorConfigurationTests.java create mode 100644 spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/HealthConfigurationTests.java create mode 100644 spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/InfoConfigurationTests.java create mode 100644 spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementConfigurationTests.java create mode 100644 spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementServerConfigurationTests.java create mode 100644 spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/MetricFilterConfigurationTests.java create mode 100644 spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/MetricRepositoryConfigurationTests.java create mode 100644 spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/MetricsConfigurationTests.java create mode 100644 spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/SecurityConfigurationTests.java create mode 100644 spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ShutdownConfigurationTests.java create mode 100644 spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/TraceConfigurationTests.java create mode 100644 spring-bootstrap-actuator/src/test/resources/git.properties rename spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/{VarzAddressServiceBootstrapApplicationTests.java => ManagementAddressServiceBootstrapApplicationTests.java} (98%) rename spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/{VarzContextServiceBootstrapApplicationTests.java => ManagementServiceBootstrapApplicationTests.java} (97%) rename spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/{NoVarzContextServiceBootstrapApplicationTests.java => NoManagementServiceBootstrapApplicationTests.java} (98%) diff --git a/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ActuatorAutoConfiguration.java b/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ActuatorAutoConfiguration.java index 1783b858e2..e56be46871 100644 --- a/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ActuatorAutoConfiguration.java +++ b/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ActuatorAutoConfiguration.java @@ -32,7 +32,7 @@ import org.springframework.context.annotation.Import; */ @Configuration @Import({ ActuatorWebConfiguration.class, ManagementConfiguration.class, - MetricRepositoryConfiguration.class, ServerConfiguration.class, + MetricRepositoryConfiguration.class, ErrorConfiguration.class, SecurityConfiguration.class, TraceFilterConfiguration.class, MetricFilterConfiguration.class, AuditConfiguration.class }) public class ActuatorAutoConfiguration { diff --git a/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ServerConfiguration.java b/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ErrorConfiguration.java similarity index 95% rename from spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ServerConfiguration.java rename to spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ErrorConfiguration.java index e6062267bb..cfce145beb 100644 --- a/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ServerConfiguration.java +++ b/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ErrorConfiguration.java @@ -36,7 +36,7 @@ import org.springframework.context.annotation.Import; @Configuration @ConditionalOnClass({ Servlet.class }) @Import(InfoConfiguration.class) -public class ServerConfiguration implements EmbeddedServletContainerCustomizer { +public class ErrorConfiguration implements EmbeddedServletContainerCustomizer { @Value("${endpoints.error.path:/error}") private String errorPath = "/error"; diff --git a/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/InfoConfiguration.java b/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/InfoConfiguration.java index 92819bc944..f6ca2eb8f2 100644 --- a/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/InfoConfiguration.java +++ b/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/InfoConfiguration.java @@ -16,16 +16,14 @@ package org.springframework.bootstrap.actuate.autoconfigure; -import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; import java.util.Properties; -import javax.annotation.Resource; import javax.servlet.Servlet; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.bootstrap.actuate.endpoint.info.InfoEndpoint; import org.springframework.bootstrap.bind.PropertiesConfigurationFactory; import org.springframework.bootstrap.context.annotation.ConditionalOnClass; @@ -35,8 +33,9 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.StandardEnvironment; -import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; import org.springframework.core.io.support.PropertiesLoaderUtils; +import org.springframework.stereotype.Component; import org.springframework.web.servlet.DispatcherServlet; /** @@ -49,55 +48,52 @@ import org.springframework.web.servlet.DispatcherServlet; @ConditionalOnMissingBean({ InfoEndpoint.class }) public class InfoConfiguration { - @Resource(name = "infoMap") - private Map infoMap; - @Autowired - @Qualifier("gitInfo") - private GitInfo gitInfo; + private InfoPropertiesConfiguration properties; @Bean - public Map applicationInfo() { + protected Map applicationInfo() throws Exception { LinkedHashMap info = new LinkedHashMap(); - info.putAll(this.infoMap); - if (this.gitInfo.getBranch() != null) { - info.put("git", this.gitInfo); + info.putAll(this.properties.infoMap()); + GitInfo gitInfo = this.properties.gitInfo(); + if (gitInfo.getBranch() != null) { + info.put("git", gitInfo); } return info; } @Bean - public InfoEndpoint infoEndpoint() { + public InfoEndpoint infoEndpoint() throws Exception { return new InfoEndpoint(applicationInfo()); } - @Configuration - public static class InfoPropertiesConfiguration { + @Component + protected static class InfoPropertiesConfiguration { @Autowired private ConfigurableEnvironment environment = new StandardEnvironment(); - @Bean - public PropertiesConfigurationFactory gitInfo() throws IOException { + @Value("${spring.git.properties:classpath:git.properties}") + private Resource gitProperties; + + public GitInfo gitInfo() throws Exception { PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory( new GitInfo()); factory.setTargetName("git"); Properties properties = new Properties(); - if (new ClassPathResource("git.properties").exists()) { - properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource( - "git.properties")); + if (this.gitProperties.exists()) { + properties = PropertiesLoaderUtils.loadProperties(this.gitProperties); } factory.setProperties(properties); - return factory; + return factory.getObject(); } - @Bean - public PropertiesConfigurationFactory> infoMap() { + public Map infoMap() throws Exception { PropertiesConfigurationFactory> factory = new PropertiesConfigurationFactory>( new LinkedHashMap()); factory.setTargetName("info"); factory.setPropertySources(this.environment.getPropertySources()); - return factory; + return factory.getObject(); } } diff --git a/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementConfiguration.java b/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementConfiguration.java index 3312845b7c..62792296ff 100644 --- a/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementConfiguration.java +++ b/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementConfiguration.java @@ -16,9 +16,9 @@ package org.springframework.bootstrap.actuate.autoconfigure; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.bootstrap.actuate.properties.ManagementServerProperties; +import org.springframework.bootstrap.autoconfigure.web.EmbeddedContainerCustomizerConfiguration; import org.springframework.bootstrap.context.annotation.ConditionalOnExpression; import org.springframework.bootstrap.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; import org.springframework.bootstrap.properties.ServerProperties; @@ -26,8 +26,10 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import org.springframework.context.event.ContextClosedEvent; import org.springframework.context.event.ContextRefreshedEvent; /** @@ -36,8 +38,7 @@ import org.springframework.context.event.ContextRefreshedEvent; */ @Configuration @ConditionalOnExpression("${management.port:${server.port:8080}}>0") -public class ManagementConfiguration implements ApplicationContextAware, DisposableBean, - ApplicationListener { +public class ManagementConfiguration implements ApplicationContextAware { private ApplicationContext parent; private ConfigurableApplicationContext context; @@ -61,27 +62,42 @@ public class ManagementConfiguration implements ApplicationContextAware, Disposa this.parent = applicationContext; } - @Override - public void destroy() throws Exception { - if (this.context != null) { - this.context.close(); - } + @Bean + public ApplicationListener managementContextClosedListener() { + return new ApplicationListener() { + @Override + public void onApplicationEvent(ContextClosedEvent event) { + if (event.getSource() != ManagementConfiguration.this.parent) { + return; + } + if (ManagementConfiguration.this.context != null) { + ManagementConfiguration.this.context.close(); + } + } + }; } - @Override - public void onApplicationEvent(ContextRefreshedEvent event) { - if (event.getSource() != this.parent) { - return; - } - if (this.configuration.getPort() != this.management.getPort()) { - AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext(); - context.setParent(this.parent); - context.register(ManagementServerConfiguration.class, - MetricsConfiguration.class, HealthConfiguration.class, - ShutdownConfiguration.class, TraceConfiguration.class); - context.refresh(); - this.context = context; - } + @Bean + public ApplicationListener managementContextRefeshedListener() { + return new ApplicationListener() { + @Override + public void onApplicationEvent(ContextRefreshedEvent event) { + if (event.getSource() != ManagementConfiguration.this.parent) { + return; + } + if (ManagementConfiguration.this.configuration.getPort() != ManagementConfiguration.this.management + .getPort()) { + AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext(); + context.setParent(ManagementConfiguration.this.parent); + context.register(EmbeddedContainerCustomizerConfiguration.class, + ManagementServerConfiguration.class, + MetricsConfiguration.class, HealthConfiguration.class, + ShutdownConfiguration.class, TraceConfiguration.class); + context.refresh(); + ManagementConfiguration.this.context = context; + } + } + }; } } diff --git a/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementServerConfiguration.java b/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementServerConfiguration.java index b7a95ba223..f5e2b3f9fb 100644 --- a/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementServerConfiguration.java +++ b/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementServerConfiguration.java @@ -16,16 +16,14 @@ package org.springframework.bootstrap.actuate.autoconfigure; -import org.springframework.beans.BeansException; import org.springframework.beans.factory.HierarchicalBeanFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.bootstrap.actuate.endpoint.error.ErrorEndpoint; import org.springframework.bootstrap.actuate.properties.ManagementServerProperties; import org.springframework.bootstrap.context.annotation.ConditionalOnBean; -import org.springframework.bootstrap.context.embedded.AbstractEmbeddedServletContainerFactory; import org.springframework.bootstrap.context.embedded.ConfigurableEmbeddedServletContainerFactory; +import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerCustomizer; import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerFactory; import org.springframework.bootstrap.context.embedded.ErrorPage; import org.springframework.bootstrap.context.embedded.jetty.JettyEmbeddedServletContainerFactory; @@ -34,6 +32,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.stereotype.Component; import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @@ -44,15 +43,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; */ @Configuration @EnableWebMvc -public class ManagementServerConfiguration implements BeanPostProcessor { - - @Autowired - private ManagementServerProperties configuration = new ManagementServerProperties(); - - private boolean initialized = false; - - @Value("${endpoints.error.path:/error}") - private String errorPath = "/error"; +public class ManagementServerConfiguration { @Bean public DispatcherServlet dispatcherServlet() { @@ -86,35 +77,26 @@ public class ManagementServerConfiguration implements BeanPostProcessor { return new JettyEmbeddedServletContainerFactory(); } - @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) - throws BeansException { - return bean; - } + @Component + protected static class ServerCustomizationConfiguration implements + EmbeddedServletContainerCustomizer { - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) - throws BeansException { + @Value("${endpoints.error.path:/error}") + private String errorPath = "/error"; - if (bean instanceof EmbeddedServletContainerFactory) { - - if (bean instanceof AbstractEmbeddedServletContainerFactory - && !this.initialized) { - - ConfigurableEmbeddedServletContainerFactory factory = (ConfigurableEmbeddedServletContainerFactory) bean; - factory.setPort(this.configuration.getPort()); - factory.setAddress(this.configuration.getAddress()); - factory.setContextPath(this.configuration.getContextPath()); - - factory.addErrorPages(new ErrorPage(this.errorPath)); - this.initialized = true; - - } + @Autowired + private ApplicationContext beanFactory; + @Override + public void customize(ConfigurableEmbeddedServletContainerFactory factory) { + ManagementServerProperties configuration = this.beanFactory + .getBean(ManagementServerProperties.class); + factory.setPort(configuration.getPort()); + factory.setAddress(configuration.getAddress()); + factory.setContextPath(configuration.getContextPath()); + factory.addErrorPages(new ErrorPage(this.errorPath)); } - return bean; - } } diff --git a/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/MetricsConfiguration.java b/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/MetricsConfiguration.java index 388c878a27..48ac70a5a9 100644 --- a/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/MetricsConfiguration.java +++ b/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/autoconfigure/MetricsConfiguration.java @@ -21,7 +21,7 @@ import javax.servlet.Servlet; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.bootstrap.actuate.endpoint.metrics.PublicMetrics; import org.springframework.bootstrap.actuate.endpoint.metrics.VanillaPublicMetrics; -import org.springframework.bootstrap.actuate.endpoint.metrics.VarzEndpoint; +import org.springframework.bootstrap.actuate.endpoint.metrics.MetricsEndpoint; import org.springframework.bootstrap.actuate.metrics.MetricRepository; import org.springframework.bootstrap.context.annotation.ConditionalOnClass; import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean; @@ -37,7 +37,7 @@ import org.springframework.web.servlet.DispatcherServlet; */ @Configuration @ConditionalOnClass({ Servlet.class, DispatcherServlet.class }) -@ConditionalOnMissingBean({ VarzEndpoint.class }) +@ConditionalOnMissingBean({ MetricsEndpoint.class }) public class MetricsConfiguration { @Autowired @@ -47,11 +47,11 @@ public class MetricsConfiguration { private PublicMetrics metrics; @Bean - public VarzEndpoint varzEndpoint() { + public MetricsEndpoint metricsEndpoint() { if (this.metrics == null) { this.metrics = new VanillaPublicMetrics(this.repository); } - return new VarzEndpoint(this.metrics); + return new MetricsEndpoint(this.metrics); } } diff --git a/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/endpoint/metrics/VarzEndpoint.java b/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/endpoint/metrics/MetricsEndpoint.java similarity index 94% rename from spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/endpoint/metrics/VarzEndpoint.java rename to spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/endpoint/metrics/MetricsEndpoint.java index 477e581e2f..f1ef14cd5e 100644 --- a/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/endpoint/metrics/VarzEndpoint.java +++ b/spring-bootstrap-actuator/src/main/java/org/springframework/bootstrap/actuate/endpoint/metrics/MetricsEndpoint.java @@ -28,14 +28,14 @@ import org.springframework.web.bind.annotation.ResponseBody; * @author Dave Syer */ @Controller -public class VarzEndpoint { +public class MetricsEndpoint { private PublicMetrics metrics; /** * @param metrics */ - public VarzEndpoint(PublicMetrics metrics) { + public MetricsEndpoint(PublicMetrics metrics) { this.metrics = metrics; } diff --git a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/TestUtils.java b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/TestUtils.java new file mode 100644 index 0000000000..ade84630fc --- /dev/null +++ b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/TestUtils.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.bootstrap.actuate; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.MapPropertySource; + +/** + * @author Dave Syer + * + */ +public class TestUtils { + + public static void addEnviroment(ConfigurableApplicationContext context, + String... pairs) { + Map map = new HashMap(); + for (String pair : pairs) { + int index = pair.indexOf(":"); + String key = pair.substring(0, index > 0 ? index : pair.length()); + String value = index > 0 ? pair.substring(index + 1) : ""; + map.put(key, value); + } + context.getEnvironment().getPropertySources() + .addFirst(new MapPropertySource("test", map)); + } + +} diff --git a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ActuatorWebConfigurationTests.java b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ActuatorWebConfigurationTests.java new file mode 100644 index 0000000000..8f4e035422 --- /dev/null +++ b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ActuatorWebConfigurationTests.java @@ -0,0 +1,42 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.actuate.autoconfigure; + +import org.junit.Test; +import org.springframework.mock.web.MockServletContext; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; + +import static org.junit.Assert.assertNotNull; + +/** + * @author Dave Syer + */ +public class ActuatorWebConfigurationTests { + + private AnnotationConfigWebApplicationContext context; + + @Test + public void testWebConfiguration() throws Exception { + this.context = new AnnotationConfigWebApplicationContext(); + this.context.setServletContext(new MockServletContext()); + this.context.register(ActuatorWebConfiguration.class); + this.context.refresh(); + assertNotNull(this.context.getBean(WebMvcConfigurationSupport.class)); + } + +} diff --git a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ErrorConfigurationTests.java b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ErrorConfigurationTests.java new file mode 100644 index 0000000000..54eb37fd38 --- /dev/null +++ b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ErrorConfigurationTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.actuate.autoconfigure; + +import org.junit.Test; +import org.mockito.Mockito; +import org.springframework.bootstrap.actuate.autoconfigure.ActuatorAutoConfiguration.ServerPropertiesConfiguration; +import org.springframework.bootstrap.actuate.endpoint.error.ErrorEndpoint; +import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.bootstrap.context.embedded.ConfigurableEmbeddedServletContainerFactory; +import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerCustomizer; +import org.springframework.bootstrap.context.embedded.ErrorPage; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +import static org.junit.Assert.assertNotNull; + +/** + * @author Dave Syer + */ +public class ErrorConfigurationTests { + + private AnnotationConfigApplicationContext context; + + @Test + public void testErrorEndpointConfiguration() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(ErrorConfiguration.class, + ServerPropertiesConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + assertNotNull(this.context.getBean(ErrorEndpoint.class)); + ConfigurableEmbeddedServletContainerFactory factory = Mockito + .mock(ConfigurableEmbeddedServletContainerFactory.class); + this.context.getBean(EmbeddedServletContainerCustomizer.class).customize(factory); + Mockito.verify(factory).addErrorPages(Mockito.any(ErrorPage.class)); + } +} diff --git a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/HealthConfigurationTests.java b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/HealthConfigurationTests.java new file mode 100644 index 0000000000..121757bd29 --- /dev/null +++ b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/HealthConfigurationTests.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.actuate.autoconfigure; + +import org.junit.Test; +import org.springframework.bootstrap.actuate.endpoint.health.HealthEndpoint; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +import static org.junit.Assert.assertNotNull; + +/** + * @author Dave Syer + */ +public class HealthConfigurationTests { + + private AnnotationConfigApplicationContext context; + + @Test + public void testTraceConfiguration() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(HealthConfiguration.class); + this.context.refresh(); + assertNotNull(this.context.getBean(HealthEndpoint.class)); + } +} diff --git a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/InfoConfigurationTests.java b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/InfoConfigurationTests.java new file mode 100644 index 0000000000..6f7d349485 --- /dev/null +++ b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/InfoConfigurationTests.java @@ -0,0 +1,59 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.actuate.autoconfigure; + +import org.junit.Test; +import org.springframework.bootstrap.actuate.TestUtils; +import org.springframework.bootstrap.actuate.endpoint.info.InfoEndpoint; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +/** + * @author Dave Syer + */ +public class InfoConfigurationTests { + + private AnnotationConfigApplicationContext context; + + @Test + public void testInfoEndpointConfiguration() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + TestUtils.addEnviroment(this.context, "info.foo:bar"); + this.context.register(InfoConfiguration.class); + this.context.refresh(); + InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class); + assertNotNull(endpoint); + assertNotNull(endpoint.info().get("git")); + assertEquals("bar", endpoint.info().get("foo")); + } + + @Test + public void testNoGitProperties() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + TestUtils.addEnviroment(this.context, + "spring.git.properties:classpath:nonexistent"); + this.context.register(InfoConfiguration.class); + this.context.refresh(); + InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class); + assertNotNull(endpoint); + assertNull(endpoint.info().get("git")); + } + +} diff --git a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementConfigurationTests.java b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementConfigurationTests.java new file mode 100644 index 0000000000..552e374f20 --- /dev/null +++ b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementConfigurationTests.java @@ -0,0 +1,119 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.actuate.autoconfigure; + +import javax.servlet.Servlet; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration.Dynamic; + +import org.junit.After; +import org.junit.Test; +import org.mockito.Mockito; +import org.springframework.bootstrap.actuate.TestUtils; +import org.springframework.bootstrap.actuate.endpoint.health.HealthEndpoint; +import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.bootstrap.autoconfigure.web.ServerPropertiesConfiguration; +import org.springframework.bootstrap.context.embedded.EmbeddedServletContainer; +import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerException; +import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerFactory; +import org.springframework.bootstrap.context.embedded.ServletContextInitializer; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.mock.web.MockServletContext; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * @author Dave Syer + */ +public class ManagementConfigurationTests { + + private AnnotationConfigApplicationContext context; + + @After + public void close() { + if (this.context != null) { + this.context.close(); + } + } + + @Test + public void testManagementConfiguration() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + this.context + .register(MetricRepositoryConfiguration.class, + TraceFilterConfiguration.class, + ServerPropertiesConfiguration.class, + ActuatorAutoConfiguration.ServerPropertiesConfiguration.class, + ManagementConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + assertNotNull(this.context.getBean(HealthEndpoint.class)); + } + + @Test + public void testChildContextCreated() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + TestUtils.addEnviroment(this.context, "server.port:7000", "management.port:7001"); + this.context + .register(ParentContext.class, MetricRepositoryConfiguration.class, + TraceFilterConfiguration.class, + ServerPropertiesConfiguration.class, + ActuatorAutoConfiguration.ServerPropertiesConfiguration.class, + ManagementConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + assertEquals(0, this.context.getBeanNamesForType(HealthEndpoint.class).length); + } + + @Configuration + protected static class ParentContext { + + @Bean + public EmbeddedServletContainerFactory factory() { + return new EmbeddedServletContainerFactory() { + + @Override + public EmbeddedServletContainer getEmbdeddedServletContainer( + ServletContextInitializer... initializers) { + ServletContext servletContext = new MockServletContext() { + @Override + public Dynamic addServlet(String servletName, Servlet servlet) { + return Mockito.mock(Dynamic.class); + } + }; + for (ServletContextInitializer initializer : initializers) { + try { + initializer.onStartup(servletContext); + } catch (ServletException ex) { + throw new IllegalStateException(ex); + } + } + return new EmbeddedServletContainer() { + @Override + public void stop() throws EmbeddedServletContainerException { + } + }; + } + }; + } + } + +} diff --git a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementServerConfigurationTests.java b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementServerConfigurationTests.java new file mode 100644 index 0000000000..fb89850213 --- /dev/null +++ b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ManagementServerConfigurationTests.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.actuate.autoconfigure; + +import org.junit.Test; +import org.mockito.Mockito; +import org.springframework.bootstrap.actuate.autoconfigure.ActuatorAutoConfiguration.ServerPropertiesConfiguration; +import org.springframework.bootstrap.actuate.endpoint.error.ErrorEndpoint; +import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.bootstrap.context.embedded.ConfigurableEmbeddedServletContainerFactory; +import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerCustomizer; +import org.springframework.bootstrap.context.embedded.ErrorPage; +import org.springframework.mock.web.MockServletContext; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; + +import static org.junit.Assert.assertNotNull; + +/** + * @author Dave Syer + */ +public class ManagementServerConfigurationTests { + + private AnnotationConfigWebApplicationContext context; + + @Test + public void testWebConfiguration() throws Exception { + this.context = new AnnotationConfigWebApplicationContext(); + this.context.setServletContext(new MockServletContext()); + this.context.register(ManagementServerConfiguration.class, + ServerPropertiesConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + assertNotNull(this.context.getBean(WebMvcConfigurationSupport.class)); + assertNotNull(this.context.getBean(ErrorEndpoint.class)); + ConfigurableEmbeddedServletContainerFactory factory = Mockito + .mock(ConfigurableEmbeddedServletContainerFactory.class); + this.context.getBean(EmbeddedServletContainerCustomizer.class).customize(factory); + Mockito.verify(factory).addErrorPages(Mockito.any(ErrorPage.class)); + Mockito.verify(factory).setPort(8080); + } + +} diff --git a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/MetricFilterConfigurationTests.java b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/MetricFilterConfigurationTests.java new file mode 100644 index 0000000000..cc5eefa3de --- /dev/null +++ b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/MetricFilterConfigurationTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.actuate.autoconfigure; + +import javax.servlet.Filter; + +import org.junit.Test; +import org.springframework.mock.web.MockFilterChain; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.mock.web.MockServletContext; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; + +import static org.junit.Assert.assertNotNull; + +/** + * @author Dave Syer + */ +public class MetricFilterConfigurationTests { + + private AnnotationConfigWebApplicationContext context; + + @Test + public void testMetricFilterConfiguration() throws Exception { + this.context = new AnnotationConfigWebApplicationContext(); + this.context.setServletContext(new MockServletContext()); + // Order is important + this.context.register(MetricRepositoryConfiguration.class, + MetricFilterConfiguration.class); + this.context.refresh(); + Filter filter = this.context.getBean(Filter.class); + assertNotNull(filter); + filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), + new MockFilterChain()); + } + +} diff --git a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/MetricRepositoryConfigurationTests.java b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/MetricRepositoryConfigurationTests.java new file mode 100644 index 0000000000..ad5231e555 --- /dev/null +++ b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/MetricRepositoryConfigurationTests.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.actuate.autoconfigure; + +import org.junit.Test; +import org.springframework.bootstrap.actuate.metrics.MetricRepository; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +import static org.junit.Assert.assertNotNull; + +/** + * @author Dave Syer + */ +public class MetricRepositoryConfigurationTests { + + private AnnotationConfigApplicationContext context; + + @Test + public void testTraceConfiguration() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(MetricRepositoryConfiguration.class); + this.context.refresh(); + assertNotNull(this.context.getBean(MetricRepository.class)); + } + +} diff --git a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/MetricsConfigurationTests.java b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/MetricsConfigurationTests.java new file mode 100644 index 0000000000..b02e994bb0 --- /dev/null +++ b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/MetricsConfigurationTests.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.actuate.autoconfigure; + +import org.junit.Test; +import org.springframework.bootstrap.actuate.endpoint.metrics.MetricsEndpoint; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +import static org.junit.Assert.assertNotNull; + +/** + * @author Dave Syer + */ +public class MetricsConfigurationTests { + + private AnnotationConfigApplicationContext context; + + @Test + public void testTraceConfiguration() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(MetricRepositoryConfiguration.class, + MetricsConfiguration.class); + this.context.refresh(); + assertNotNull(this.context.getBean(MetricsEndpoint.class)); + } + +} diff --git a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/SecurityConfigurationTests.java b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/SecurityConfigurationTests.java new file mode 100644 index 0000000000..79d8af54a3 --- /dev/null +++ b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/SecurityConfigurationTests.java @@ -0,0 +1,44 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.actuate.autoconfigure; + +import org.junit.Test; +import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.mock.web.MockServletContext; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; + +import static org.junit.Assert.assertNotNull; + +/** + * @author Dave Syer + */ +public class SecurityConfigurationTests { + + private AnnotationConfigWebApplicationContext context; + + @Test + public void testWebConfiguration() throws Exception { + this.context = new AnnotationConfigWebApplicationContext(); + this.context.setServletContext(new MockServletContext()); + this.context.register(SecurityConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + assertNotNull(this.context.getBean(AuthenticationManager.class)); + } + +} diff --git a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ShutdownConfigurationTests.java b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ShutdownConfigurationTests.java new file mode 100644 index 0000000000..4a703bd863 --- /dev/null +++ b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/ShutdownConfigurationTests.java @@ -0,0 +1,43 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.actuate.autoconfigure; + +import org.junit.Test; +import org.springframework.bootstrap.actuate.autoconfigure.ActuatorAutoConfiguration.ServerPropertiesConfiguration; +import org.springframework.bootstrap.actuate.endpoint.shutdown.ShutdownEndpoint; +import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +import static org.junit.Assert.assertNotNull; + +/** + * @author Dave Syer + */ +public class ShutdownConfigurationTests { + + private AnnotationConfigApplicationContext context; + + @Test + public void testEndpointConfiguration() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(ShutdownConfiguration.class, + ServerPropertiesConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + assertNotNull(this.context.getBean(ShutdownEndpoint.class)); + } +} diff --git a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/TraceConfigurationTests.java b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/TraceConfigurationTests.java new file mode 100644 index 0000000000..1374f4c34d --- /dev/null +++ b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/TraceConfigurationTests.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.bootstrap.actuate.autoconfigure; + +import org.junit.Test; +import org.springframework.bootstrap.actuate.endpoint.trace.TraceEndpoints; +import org.springframework.bootstrap.autoconfigure.PropertyPlaceholderAutoConfiguration; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +import static org.junit.Assert.assertNotNull; + +/** + * @author Dave Syer + */ +public class TraceConfigurationTests { + + private AnnotationConfigApplicationContext context; + + @Test + public void testEndpointConfiguration() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(TraceFilterConfiguration.class, TraceConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + assertNotNull(this.context.getBean(TraceEndpoints.class)); + } +} diff --git a/spring-bootstrap-actuator/src/test/resources/git.properties b/spring-bootstrap-actuator/src/test/resources/git.properties new file mode 100644 index 0000000000..d88056068a --- /dev/null +++ b/spring-bootstrap-actuator/src/test/resources/git.properties @@ -0,0 +1,13 @@ +#Generated by Git-Commit-Id-Plugin +#Thu May 23 09:26:42 BST 2013 +git.commit.id.abbrev=e02a4f3 +git.commit.user.email=dsyer@vmware.com +git.commit.message.full=Update Spring +git.commit.id=e02a4f3b6f452cdbf6dd311f1362679eb4c31ced +git.commit.message.short=Update Spring +git.commit.user.name=Dave Syer +git.build.user.name=Dave Syer +git.build.user.email=dsyer@vmware.com +git.branch=develop +git.commit.time=2013-04-24T08\:42\:13+0100 +git.build.time=2013-05-23T09\:26\:42+0100 diff --git a/spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/VarzAddressServiceBootstrapApplicationTests.java b/spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/ManagementAddressServiceBootstrapApplicationTests.java similarity index 98% rename from spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/VarzAddressServiceBootstrapApplicationTests.java rename to spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/ManagementAddressServiceBootstrapApplicationTests.java index 55241be7e3..0a8506dbfa 100644 --- a/spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/VarzAddressServiceBootstrapApplicationTests.java +++ b/spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/ManagementAddressServiceBootstrapApplicationTests.java @@ -35,7 +35,7 @@ import static org.junit.Assert.assertTrue; * @author Dave Syer * */ -public class VarzAddressServiceBootstrapApplicationTests { +public class ManagementAddressServiceBootstrapApplicationTests { private static ConfigurableApplicationContext context; diff --git a/spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/VarzContextServiceBootstrapApplicationTests.java b/spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/ManagementServiceBootstrapApplicationTests.java similarity index 97% rename from spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/VarzContextServiceBootstrapApplicationTests.java rename to spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/ManagementServiceBootstrapApplicationTests.java index baec04765d..e84a419b40 100644 --- a/spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/VarzContextServiceBootstrapApplicationTests.java +++ b/spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/ManagementServiceBootstrapApplicationTests.java @@ -26,7 +26,7 @@ import static org.junit.Assert.assertEquals; * @author Dave Syer * */ -public class VarzContextServiceBootstrapApplicationTests { +public class ManagementServiceBootstrapApplicationTests { private static ConfigurableApplicationContext context; diff --git a/spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/NoVarzContextServiceBootstrapApplicationTests.java b/spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/NoManagementServiceBootstrapApplicationTests.java similarity index 98% rename from spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/NoVarzContextServiceBootstrapApplicationTests.java rename to spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/NoManagementServiceBootstrapApplicationTests.java index f7fcc35f9e..5be515bcc4 100644 --- a/spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/NoVarzContextServiceBootstrapApplicationTests.java +++ b/spring-bootstrap-samples/spring-bootstrap-actuator-sample/src/test/java/org/springframework/bootstrap/sample/service/NoManagementServiceBootstrapApplicationTests.java @@ -35,7 +35,7 @@ import static org.junit.Assert.assertEquals; * @author Dave Syer * */ -public class NoVarzContextServiceBootstrapApplicationTests { +public class NoManagementServiceBootstrapApplicationTests { private static ConfigurableApplicationContext context; diff --git a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/web/EmbeddedContainerCustomizerConfiguration.java b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/web/EmbeddedContainerCustomizerConfiguration.java index b75a99f0cf..4069b46372 100644 --- a/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/web/EmbeddedContainerCustomizerConfiguration.java +++ b/spring-bootstrap/src/main/java/org/springframework/bootstrap/autoconfigure/web/EmbeddedContainerCustomizerConfiguration.java @@ -17,28 +17,26 @@ package org.springframework.bootstrap.autoconfigure.web; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Set; import javax.servlet.Servlet; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.bootstrap.context.annotation.ConditionalOnClass; import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration; import org.springframework.bootstrap.context.embedded.ConfigurableEmbeddedServletContainerFactory; import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerCustomizer; -import org.springframework.bootstrap.context.embedded.jetty.JettyEmbeddedServletContainerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.AnnotationAwareOrderComparator; /** * {@link EnableAutoConfiguration Auto-configuration} for - * {@link JettyEmbeddedServletContainerFactory}. + * {@link EmbeddedServletContainerCustomizer}. * * @author Dave Syer */ @@ -46,12 +44,14 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator; @ConditionalOnClass({ Servlet.class, EmbeddedServletContainerCustomizer.class }) public class EmbeddedContainerCustomizerConfiguration { - @Autowired(required = false) - private Set customizers = new HashSet(); - @Bean - public BeanPostProcessor embeddedContainerCustomizerBeanPostProcessor() { - return new EmbeddedContainerCustomizerBeanPostProcessor(this.customizers); + public BeanPostProcessor embeddedContainerCustomizerBeanPostProcessor( + ListableBeanFactory beanFactory) { + // Look these up, not autowired because we don't want the ones from the parent + // context + Collection customizers = beanFactory + .getBeansOfType(EmbeddedServletContainerCustomizer.class).values(); + return new EmbeddedContainerCustomizerBeanPostProcessor(customizers); } private static final class EmbeddedContainerCustomizerBeanPostProcessor implements @@ -60,7 +60,7 @@ public class EmbeddedContainerCustomizerConfiguration { private List customizers; public EmbeddedContainerCustomizerBeanPostProcessor( - Set customizers) { + Collection customizers) { final List list = new ArrayList( customizers); Collections.sort(list, new AnnotationAwareOrderComparator());