优化
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
||||
package com.baiyue.common.web;
|
||||
|
||||
import feign.RequestInterceptor;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class FeignTracePropagationAutoConfigurationTest {
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(FeignTracePropagationAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
void registersTraceInterceptorWhenFeignIsPresent() {
|
||||
contextRunner.run(context -> {
|
||||
assertThat(context).hasSingleBean(FeignTraceRequestInterceptor.class);
|
||||
assertThat(context.getBeansOfType(RequestInterceptor.class)).hasSize(1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotLoadFeignConfigurationWhenFeignIsAbsent() {
|
||||
contextRunner.withClassLoader(new FilteredClassLoader(RequestInterceptor.class))
|
||||
.run(context -> {
|
||||
assertThat(context).hasNotFailed();
|
||||
assertThat(context).doesNotHaveBean("feignTraceRequestInterceptor");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void backsOffOnlyForAnApplicationProvidedTraceInterceptor() {
|
||||
contextRunner.withBean(FeignTraceRequestInterceptor.class, FeignTraceRequestInterceptor::new)
|
||||
.run(context -> assertThat(context).hasSingleBean(FeignTraceRequestInterceptor.class));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user