|
|
@ -18,12 +18,14 @@ package org.springframework.boot.actuate.autoconfigure;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.actuate.trace.TraceProperties;
|
|
|
|
import org.springframework.boot.actuate.trace.TraceProperties;
|
|
|
|
import org.springframework.boot.actuate.trace.TraceRepository;
|
|
|
|
import org.springframework.boot.actuate.trace.TraceRepository;
|
|
|
|
import org.springframework.boot.actuate.trace.WebRequestTraceFilter;
|
|
|
|
import org.springframework.boot.actuate.trace.WebRequestTraceFilter;
|
|
|
|
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
|
|
|
|
|
|
|
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
@ -34,28 +36,54 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
* Tests for {@link TraceWebFilterAutoConfiguration}.
|
|
|
|
* Tests for {@link TraceWebFilterAutoConfiguration}.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Phillip Webb
|
|
|
|
* @author Phillip Webb
|
|
|
|
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class TraceWebFilterAutoConfigurationTests {
|
|
|
|
public class TraceWebFilterAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private AnnotationConfigApplicationContext context;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
|
|
|
|
public void close() {
|
|
|
|
|
|
|
|
if (this.context != null) {
|
|
|
|
|
|
|
|
this.context.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void configureFilter() {
|
|
|
|
public void configureFilter() {
|
|
|
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
|
|
|
load();
|
|
|
|
PropertyPlaceholderAutoConfiguration.class,
|
|
|
|
assertThat(this.context.getBean(WebRequestTraceFilter.class)).isNotNull();
|
|
|
|
TraceRepositoryAutoConfiguration.class,
|
|
|
|
|
|
|
|
TraceWebFilterAutoConfiguration.class);
|
|
|
|
|
|
|
|
assertThat(context.getBean(WebRequestTraceFilter.class)).isNotNull();
|
|
|
|
|
|
|
|
context.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void overrideTraceFilter() throws Exception {
|
|
|
|
public void overrideTraceFilter() throws Exception {
|
|
|
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
|
|
|
load(CustomTraceFilterConfig.class);
|
|
|
|
CustomTraceFilterConfig.class, PropertyPlaceholderAutoConfiguration.class,
|
|
|
|
WebRequestTraceFilter filter = this.context.getBean(WebRequestTraceFilter.class);
|
|
|
|
|
|
|
|
assertThat(filter).isInstanceOf(TestWebRequestTraceFilter.class);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void skipsFilterIfPropertyDisabled() throws Exception {
|
|
|
|
|
|
|
|
load("endpoints.trace.filter.enabled:false");
|
|
|
|
|
|
|
|
assertThat(this.context.getBeansOfType(WebRequestTraceFilter.class).size())
|
|
|
|
|
|
|
|
.isEqualTo(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void load(String... environment) {
|
|
|
|
|
|
|
|
load(null, environment);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void load(Class<?> config, String... environment) {
|
|
|
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
|
|
|
|
|
|
|
EnvironmentTestUtils.addEnvironment(ctx, environment);
|
|
|
|
|
|
|
|
if (config != null) {
|
|
|
|
|
|
|
|
ctx.register(config);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.register(PropertyPlaceholderAutoConfiguration.class,
|
|
|
|
TraceRepositoryAutoConfiguration.class,
|
|
|
|
TraceRepositoryAutoConfiguration.class,
|
|
|
|
TraceWebFilterAutoConfiguration.class);
|
|
|
|
TraceWebFilterAutoConfiguration.class);
|
|
|
|
WebRequestTraceFilter filter = context.getBean(WebRequestTraceFilter.class);
|
|
|
|
ctx.refresh();
|
|
|
|
assertThat(filter).isInstanceOf(TestWebRequestTraceFilter.class);
|
|
|
|
this.context = ctx;
|
|
|
|
context.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|