Add more tests for @ConditionalOnRefreshScope

This commit is contained in:
wenqi.huang
2019-04-11 18:28:09 +08:00
parent ffebfebe31
commit 7fd55be4b3

View File

@@ -20,6 +20,7 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;
import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration.ConditionalOnMissingRefreshScope;
import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration.ConditionalOnRefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -40,6 +41,7 @@ public class ConditionalOnRefreshScopeTests {
assertThat(c).hasSingleBean(
org.springframework.cloud.context.scope.refresh.RefreshScope.class);
assertThat(c.getBean("foo")).isEqualTo("foo");
assertThat(c).doesNotHaveBean("bar");
});
}
@@ -52,6 +54,7 @@ public class ConditionalOnRefreshScopeTests {
assertThat(c).hasSingleBean(
org.springframework.cloud.context.scope.refresh.RefreshScope.class);
assertThat(c).doesNotHaveBean("foo");
assertThat(c.getBean("bar")).isEqualTo("bar");
});
}
@@ -59,6 +62,14 @@ public class ConditionalOnRefreshScopeTests {
public void refreshScopeNotIncluded() {
new ApplicationContextRunner().withUserConfiguration(Beans.class).run(c -> {
assertThat(c).doesNotHaveBean("foo");
assertThat(c.getBean("bar")).isEqualTo("bar");
});
new ApplicationContextRunner().withUserConfiguration(Beans.class)
.withPropertyValues("eureka.client.refresh.enable=false")
.run(c -> {
assertThat(c).doesNotHaveBean("foo");
assertThat(c.getBean("bar")).isEqualTo("bar");
});
}
@@ -69,6 +80,12 @@ public class ConditionalOnRefreshScopeTests {
public String foo() {
return "foo";
}
@Bean
@ConditionalOnMissingRefreshScope
public String bar() {
return "bar";
}
}
}