[bs-22] Add loads of actuator tests
Discovered a few issues along the way and refactored accordingly. [#48127729] [bs-22] Add missing unit tests
This commit is contained in:
parent
19d8315639
commit
b7c0e3279e
|
@ -32,7 +32,7 @@ import org.springframework.context.annotation.Import;
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ ActuatorWebConfiguration.class, ManagementConfiguration.class,
|
@Import({ ActuatorWebConfiguration.class, ManagementConfiguration.class,
|
||||||
MetricRepositoryConfiguration.class, ServerConfiguration.class,
|
MetricRepositoryConfiguration.class, ErrorConfiguration.class,
|
||||||
SecurityConfiguration.class, TraceFilterConfiguration.class,
|
SecurityConfiguration.class, TraceFilterConfiguration.class,
|
||||||
MetricFilterConfiguration.class, AuditConfiguration.class })
|
MetricFilterConfiguration.class, AuditConfiguration.class })
|
||||||
public class ActuatorAutoConfiguration {
|
public class ActuatorAutoConfiguration {
|
||||||
|
|
|
@ -36,7 +36,7 @@ import org.springframework.context.annotation.Import;
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass({ Servlet.class })
|
@ConditionalOnClass({ Servlet.class })
|
||||||
@Import(InfoConfiguration.class)
|
@Import(InfoConfiguration.class)
|
||||||
public class ServerConfiguration implements EmbeddedServletContainerCustomizer {
|
public class ErrorConfiguration implements EmbeddedServletContainerCustomizer {
|
||||||
|
|
||||||
@Value("${endpoints.error.path:/error}")
|
@Value("${endpoints.error.path:/error}")
|
||||||
private String errorPath = "/error";
|
private String errorPath = "/error";
|
|
@ -16,16 +16,14 @@
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
package org.springframework.bootstrap.actuate.autoconfigure;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.servlet.Servlet;
|
import javax.servlet.Servlet;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.actuate.endpoint.info.InfoEndpoint;
|
||||||
import org.springframework.bootstrap.bind.PropertiesConfigurationFactory;
|
import org.springframework.bootstrap.bind.PropertiesConfigurationFactory;
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
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.context.annotation.Configuration;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
import org.springframework.core.env.StandardEnvironment;
|
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.core.io.support.PropertiesLoaderUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,55 +48,52 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||||
@ConditionalOnMissingBean({ InfoEndpoint.class })
|
@ConditionalOnMissingBean({ InfoEndpoint.class })
|
||||||
public class InfoConfiguration {
|
public class InfoConfiguration {
|
||||||
|
|
||||||
@Resource(name = "infoMap")
|
|
||||||
private Map<String, Object> infoMap;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("gitInfo")
|
private InfoPropertiesConfiguration properties;
|
||||||
private GitInfo gitInfo;
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Map<String, Object> applicationInfo() {
|
protected Map<String, Object> applicationInfo() throws Exception {
|
||||||
LinkedHashMap<String, Object> info = new LinkedHashMap<String, Object>();
|
LinkedHashMap<String, Object> info = new LinkedHashMap<String, Object>();
|
||||||
info.putAll(this.infoMap);
|
info.putAll(this.properties.infoMap());
|
||||||
if (this.gitInfo.getBranch() != null) {
|
GitInfo gitInfo = this.properties.gitInfo();
|
||||||
info.put("git", this.gitInfo);
|
if (gitInfo.getBranch() != null) {
|
||||||
|
info.put("git", gitInfo);
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public InfoEndpoint infoEndpoint() {
|
public InfoEndpoint infoEndpoint() throws Exception {
|
||||||
return new InfoEndpoint(applicationInfo());
|
return new InfoEndpoint(applicationInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Component
|
||||||
public static class InfoPropertiesConfiguration {
|
protected static class InfoPropertiesConfiguration {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ConfigurableEnvironment environment = new StandardEnvironment();
|
private ConfigurableEnvironment environment = new StandardEnvironment();
|
||||||
|
|
||||||
@Bean
|
@Value("${spring.git.properties:classpath:git.properties}")
|
||||||
public PropertiesConfigurationFactory<GitInfo> gitInfo() throws IOException {
|
private Resource gitProperties;
|
||||||
|
|
||||||
|
public GitInfo gitInfo() throws Exception {
|
||||||
PropertiesConfigurationFactory<GitInfo> factory = new PropertiesConfigurationFactory<GitInfo>(
|
PropertiesConfigurationFactory<GitInfo> factory = new PropertiesConfigurationFactory<GitInfo>(
|
||||||
new GitInfo());
|
new GitInfo());
|
||||||
factory.setTargetName("git");
|
factory.setTargetName("git");
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
if (new ClassPathResource("git.properties").exists()) {
|
if (this.gitProperties.exists()) {
|
||||||
properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource(
|
properties = PropertiesLoaderUtils.loadProperties(this.gitProperties);
|
||||||
"git.properties"));
|
|
||||||
}
|
}
|
||||||
factory.setProperties(properties);
|
factory.setProperties(properties);
|
||||||
return factory;
|
return factory.getObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
public Map<String, Object> infoMap() throws Exception {
|
||||||
public PropertiesConfigurationFactory<Map<String, Object>> infoMap() {
|
|
||||||
PropertiesConfigurationFactory<Map<String, Object>> factory = new PropertiesConfigurationFactory<Map<String, Object>>(
|
PropertiesConfigurationFactory<Map<String, Object>> factory = new PropertiesConfigurationFactory<Map<String, Object>>(
|
||||||
new LinkedHashMap<String, Object>());
|
new LinkedHashMap<String, Object>());
|
||||||
factory.setTargetName("info");
|
factory.setTargetName("info");
|
||||||
factory.setPropertySources(this.environment.getPropertySources());
|
factory.setPropertySources(this.environment.getPropertySources());
|
||||||
return factory;
|
return factory.getObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
package org.springframework.bootstrap.actuate.autoconfigure;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.DisposableBean;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.bootstrap.actuate.properties.ManagementServerProperties;
|
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.annotation.ConditionalOnExpression;
|
||||||
import org.springframework.bootstrap.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
|
import org.springframework.bootstrap.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
|
||||||
import org.springframework.bootstrap.properties.ServerProperties;
|
import org.springframework.bootstrap.properties.ServerProperties;
|
||||||
|
@ -26,8 +26,10 @@ import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.context.event.ContextClosedEvent;
|
||||||
import org.springframework.context.event.ContextRefreshedEvent;
|
import org.springframework.context.event.ContextRefreshedEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,8 +38,7 @@ import org.springframework.context.event.ContextRefreshedEvent;
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnExpression("${management.port:${server.port:8080}}>0")
|
@ConditionalOnExpression("${management.port:${server.port:8080}}>0")
|
||||||
public class ManagementConfiguration implements ApplicationContextAware, DisposableBean,
|
public class ManagementConfiguration implements ApplicationContextAware {
|
||||||
ApplicationListener<ContextRefreshedEvent> {
|
|
||||||
|
|
||||||
private ApplicationContext parent;
|
private ApplicationContext parent;
|
||||||
private ConfigurableApplicationContext context;
|
private ConfigurableApplicationContext context;
|
||||||
|
@ -61,27 +62,42 @@ public class ManagementConfiguration implements ApplicationContextAware, Disposa
|
||||||
this.parent = applicationContext;
|
this.parent = applicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ApplicationListener<ContextClosedEvent> managementContextClosedListener() {
|
||||||
|
return new ApplicationListener<ContextClosedEvent>() {
|
||||||
@Override
|
@Override
|
||||||
public void destroy() throws Exception {
|
public void onApplicationEvent(ContextClosedEvent event) {
|
||||||
if (this.context != null) {
|
if (event.getSource() != ManagementConfiguration.this.parent) {
|
||||||
this.context.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
|
||||||
if (event.getSource() != this.parent) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.configuration.getPort() != this.management.getPort()) {
|
if (ManagementConfiguration.this.context != null) {
|
||||||
|
ManagementConfiguration.this.context.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public ApplicationListener<ContextRefreshedEvent> managementContextRefeshedListener() {
|
||||||
|
return new ApplicationListener<ContextRefreshedEvent>() {
|
||||||
|
@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();
|
AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext();
|
||||||
context.setParent(this.parent);
|
context.setParent(ManagementConfiguration.this.parent);
|
||||||
context.register(ManagementServerConfiguration.class,
|
context.register(EmbeddedContainerCustomizerConfiguration.class,
|
||||||
|
ManagementServerConfiguration.class,
|
||||||
MetricsConfiguration.class, HealthConfiguration.class,
|
MetricsConfiguration.class, HealthConfiguration.class,
|
||||||
ShutdownConfiguration.class, TraceConfiguration.class);
|
ShutdownConfiguration.class, TraceConfiguration.class);
|
||||||
context.refresh();
|
context.refresh();
|
||||||
this.context = context;
|
ManagementConfiguration.this.context = context;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,16 +16,14 @@
|
||||||
|
|
||||||
package org.springframework.bootstrap.actuate.autoconfigure;
|
package org.springframework.bootstrap.actuate.autoconfigure;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
|
||||||
import org.springframework.beans.factory.HierarchicalBeanFactory;
|
import org.springframework.beans.factory.HierarchicalBeanFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
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.endpoint.error.ErrorEndpoint;
|
||||||
import org.springframework.bootstrap.actuate.properties.ManagementServerProperties;
|
import org.springframework.bootstrap.actuate.properties.ManagementServerProperties;
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnBean;
|
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.ConfigurableEmbeddedServletContainerFactory;
|
||||||
|
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerCustomizer;
|
||||||
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerFactory;
|
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerFactory;
|
||||||
import org.springframework.bootstrap.context.embedded.ErrorPage;
|
import org.springframework.bootstrap.context.embedded.ErrorPage;
|
||||||
import org.springframework.bootstrap.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
|
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.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
|
||||||
|
@ -44,15 +43,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebMvc
|
@EnableWebMvc
|
||||||
public class ManagementServerConfiguration implements BeanPostProcessor {
|
public class ManagementServerConfiguration {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ManagementServerProperties configuration = new ManagementServerProperties();
|
|
||||||
|
|
||||||
private boolean initialized = false;
|
|
||||||
|
|
||||||
@Value("${endpoints.error.path:/error}")
|
|
||||||
private String errorPath = "/error";
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public DispatcherServlet dispatcherServlet() {
|
public DispatcherServlet dispatcherServlet() {
|
||||||
|
@ -86,35 +77,26 @@ public class ManagementServerConfiguration implements BeanPostProcessor {
|
||||||
return new JettyEmbeddedServletContainerFactory();
|
return new JettyEmbeddedServletContainerFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Component
|
||||||
public Object postProcessBeforeInitialization(Object bean, String beanName)
|
protected static class ServerCustomizationConfiguration implements
|
||||||
throws BeansException {
|
EmbeddedServletContainerCustomizer {
|
||||||
return bean;
|
|
||||||
}
|
@Value("${endpoints.error.path:/error}")
|
||||||
|
private String errorPath = "/error";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationContext beanFactory;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
public void customize(ConfigurableEmbeddedServletContainerFactory factory) {
|
||||||
throws BeansException {
|
ManagementServerProperties configuration = this.beanFactory
|
||||||
|
.getBean(ManagementServerProperties.class);
|
||||||
if (bean instanceof EmbeddedServletContainerFactory) {
|
factory.setPort(configuration.getPort());
|
||||||
|
factory.setAddress(configuration.getAddress());
|
||||||
if (bean instanceof AbstractEmbeddedServletContainerFactory
|
factory.setContextPath(configuration.getContextPath());
|
||||||
&& !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));
|
factory.addErrorPages(new ErrorPage(this.errorPath));
|
||||||
this.initialized = true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bean;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import javax.servlet.Servlet;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.bootstrap.actuate.endpoint.metrics.PublicMetrics;
|
import org.springframework.bootstrap.actuate.endpoint.metrics.PublicMetrics;
|
||||||
import org.springframework.bootstrap.actuate.endpoint.metrics.VanillaPublicMetrics;
|
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.actuate.metrics.MetricRepository;
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean;
|
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean;
|
||||||
|
@ -37,7 +37,7 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
||||||
@ConditionalOnMissingBean({ VarzEndpoint.class })
|
@ConditionalOnMissingBean({ MetricsEndpoint.class })
|
||||||
public class MetricsConfiguration {
|
public class MetricsConfiguration {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -47,11 +47,11 @@ public class MetricsConfiguration {
|
||||||
private PublicMetrics metrics;
|
private PublicMetrics metrics;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public VarzEndpoint varzEndpoint() {
|
public MetricsEndpoint metricsEndpoint() {
|
||||||
if (this.metrics == null) {
|
if (this.metrics == null) {
|
||||||
this.metrics = new VanillaPublicMetrics(this.repository);
|
this.metrics = new VanillaPublicMetrics(this.repository);
|
||||||
}
|
}
|
||||||
return new VarzEndpoint(this.metrics);
|
return new MetricsEndpoint(this.metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,14 +28,14 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
@Controller
|
@Controller
|
||||||
public class VarzEndpoint {
|
public class MetricsEndpoint {
|
||||||
|
|
||||||
private PublicMetrics metrics;
|
private PublicMetrics metrics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param metrics
|
* @param metrics
|
||||||
*/
|
*/
|
||||||
public VarzEndpoint(PublicMetrics metrics) {
|
public MetricsEndpoint(PublicMetrics metrics) {
|
||||||
this.metrics = metrics;
|
this.metrics = metrics;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<String, Object> map = new HashMap<String, Object>();
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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 {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
|
@ -35,7 +35,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class VarzAddressServiceBootstrapApplicationTests {
|
public class ManagementAddressServiceBootstrapApplicationTests {
|
||||||
|
|
||||||
private static ConfigurableApplicationContext context;
|
private static ConfigurableApplicationContext context;
|
||||||
|
|
|
@ -26,7 +26,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class VarzContextServiceBootstrapApplicationTests {
|
public class ManagementServiceBootstrapApplicationTests {
|
||||||
|
|
||||||
private static ConfigurableApplicationContext context;
|
private static ConfigurableApplicationContext context;
|
||||||
|
|
|
@ -35,7 +35,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class NoVarzContextServiceBootstrapApplicationTests {
|
public class NoManagementServiceBootstrapApplicationTests {
|
||||||
|
|
||||||
private static ConfigurableApplicationContext context;
|
private static ConfigurableApplicationContext context;
|
||||||
|
|
|
@ -17,28 +17,26 @@
|
||||||
package org.springframework.bootstrap.autoconfigure.web;
|
package org.springframework.bootstrap.autoconfigure.web;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.servlet.Servlet;
|
import javax.servlet.Servlet;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
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.beans.factory.config.BeanPostProcessor;
|
||||||
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
import org.springframework.bootstrap.context.annotation.ConditionalOnClass;
|
||||||
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
|
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration;
|
||||||
import org.springframework.bootstrap.context.embedded.ConfigurableEmbeddedServletContainerFactory;
|
import org.springframework.bootstrap.context.embedded.ConfigurableEmbeddedServletContainerFactory;
|
||||||
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerCustomizer;
|
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.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link EnableAutoConfiguration Auto-configuration} for
|
* {@link EnableAutoConfiguration Auto-configuration} for
|
||||||
* {@link JettyEmbeddedServletContainerFactory}.
|
* {@link EmbeddedServletContainerCustomizer}.
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
|
@ -46,12 +44,14 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||||
@ConditionalOnClass({ Servlet.class, EmbeddedServletContainerCustomizer.class })
|
@ConditionalOnClass({ Servlet.class, EmbeddedServletContainerCustomizer.class })
|
||||||
public class EmbeddedContainerCustomizerConfiguration {
|
public class EmbeddedContainerCustomizerConfiguration {
|
||||||
|
|
||||||
@Autowired(required = false)
|
|
||||||
private Set<EmbeddedServletContainerCustomizer> customizers = new HashSet<EmbeddedServletContainerCustomizer>();
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public BeanPostProcessor embeddedContainerCustomizerBeanPostProcessor() {
|
public BeanPostProcessor embeddedContainerCustomizerBeanPostProcessor(
|
||||||
return new EmbeddedContainerCustomizerBeanPostProcessor(this.customizers);
|
ListableBeanFactory beanFactory) {
|
||||||
|
// Look these up, not autowired because we don't want the ones from the parent
|
||||||
|
// context
|
||||||
|
Collection<EmbeddedServletContainerCustomizer> customizers = beanFactory
|
||||||
|
.getBeansOfType(EmbeddedServletContainerCustomizer.class).values();
|
||||||
|
return new EmbeddedContainerCustomizerBeanPostProcessor(customizers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class EmbeddedContainerCustomizerBeanPostProcessor implements
|
private static final class EmbeddedContainerCustomizerBeanPostProcessor implements
|
||||||
|
@ -60,7 +60,7 @@ public class EmbeddedContainerCustomizerConfiguration {
|
||||||
private List<EmbeddedServletContainerCustomizer> customizers;
|
private List<EmbeddedServletContainerCustomizer> customizers;
|
||||||
|
|
||||||
public EmbeddedContainerCustomizerBeanPostProcessor(
|
public EmbeddedContainerCustomizerBeanPostProcessor(
|
||||||
Set<EmbeddedServletContainerCustomizer> customizers) {
|
Collection<EmbeddedServletContainerCustomizer> customizers) {
|
||||||
final List<EmbeddedServletContainerCustomizer> list = new ArrayList<EmbeddedServletContainerCustomizer>(
|
final List<EmbeddedServletContainerCustomizer> list = new ArrayList<EmbeddedServletContainerCustomizer>(
|
||||||
customizers);
|
customizers);
|
||||||
Collections.sort(list, new AnnotationAwareOrderComparator());
|
Collections.sort(list, new AnnotationAwareOrderComparator());
|
||||||
|
|
Loading…
Reference in New Issue