mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
fix tests
This commit is contained in:
parent
7323880c01
commit
a5905307f0
@ -39,58 +39,59 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
*/
|
*/
|
||||||
public class NacosConfigAutoConfigurationTests {
|
public class NacosConfigAutoConfigurationTests {
|
||||||
|
|
||||||
private ConfigurableApplicationContext context;
|
private ConfigurableApplicationContext context;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
this.context = new SpringApplicationBuilder(
|
this.context = new SpringApplicationBuilder(
|
||||||
NacosConfigBootstrapConfiguration.class,
|
NacosConfigBootstrapConfiguration.class,
|
||||||
NacosConfigAutoConfiguration.class,
|
NacosConfigAutoConfiguration.class, TestConfiguration.class)
|
||||||
TestConfiguration.class)
|
.web(WebApplicationType.NONE)
|
||||||
.web(WebApplicationType.NONE).run(
|
.run("--spring.application.name=myapp",
|
||||||
"--spring.cloud.config.enabled=true",
|
"--spring.cloud.config.enabled=true",
|
||||||
"--spring.cloud.nacos.config.server-addr=127.0.0.1:8080",
|
"--spring.cloud.nacos.config.server-addr=127.0.0.1:8080",
|
||||||
"--spring.cloud.nacos.config.prefix=myapp");
|
"--spring.cloud.nacos.config.prefix=test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
if (this.context != null) {
|
if (this.context != null) {
|
||||||
this.context.close();
|
this.context.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNacosConfigProperties() {
|
public void testNacosConfigProperties() {
|
||||||
|
|
||||||
NacosConfigProperties nacosConfigProperties = this.context.getParent().getBean(NacosConfigProperties.class);
|
NacosConfigProperties nacosConfigProperties = this.context.getParent()
|
||||||
assertThat(nacosConfigProperties.getFileExtension()).isEqualTo("properties");
|
.getBean(NacosConfigProperties.class);
|
||||||
assertThat(nacosConfigProperties.getPrefix()).isEqualTo("myapp");
|
assertThat(nacosConfigProperties.getFileExtension()).isEqualTo("properties");
|
||||||
|
assertThat(nacosConfigProperties.getPrefix()).isEqualTo("test");
|
||||||
|
assertThat(nacosConfigProperties.getName()).isEqualTo("myapp");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNacosRefreshProperties() {
|
||||||
|
|
||||||
@Test
|
NacosRefreshProperties nacosRefreshProperties = this.context
|
||||||
public void testNacosRefreshProperties() {
|
.getBean(NacosRefreshProperties.class);
|
||||||
|
assertThat(nacosRefreshProperties.isEnabled()).isEqualTo(true);
|
||||||
|
|
||||||
NacosRefreshProperties nacosRefreshProperties = this.context.getBean(NacosRefreshProperties.class);
|
}
|
||||||
assertThat(nacosRefreshProperties.isEnabled()).isEqualTo(true);
|
|
||||||
|
|
||||||
}
|
@Configuration
|
||||||
|
@AutoConfigureBefore(NacosConfigAutoConfiguration.class)
|
||||||
|
static class TestConfiguration {
|
||||||
|
|
||||||
@Configuration
|
@Autowired
|
||||||
@AutoConfigureBefore(NacosConfigAutoConfiguration.class)
|
ConfigurableApplicationContext context;
|
||||||
static class TestConfiguration{
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
ContextRefresher contextRefresher() {
|
||||||
|
return new ContextRefresher(context, new RefreshScope());
|
||||||
|
}
|
||||||
|
|
||||||
@Autowired
|
}
|
||||||
ConfigurableApplicationContext context;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
ContextRefresher contextRefresher(){
|
|
||||||
return new ContextRefresher(context, new RefreshScope());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,9 +43,10 @@ public class NacosConfigBootstrapConfigurationTests {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
this.context = new SpringApplicationBuilder(
|
this.context = new SpringApplicationBuilder(
|
||||||
NacosConfigBootstrapConfiguration.class).web(WebApplicationType.NONE).run(
|
NacosConfigBootstrapConfiguration.class).web(WebApplicationType.NONE).run(
|
||||||
|
"--spring.application.name=myapp",
|
||||||
"--spring.cloud.config.enabled=true",
|
"--spring.cloud.config.enabled=true",
|
||||||
"--spring.cloud.nacos.config.server-addr=127.0.0.1:8080",
|
"--spring.cloud.nacos.config.server-addr=127.0.0.1:8080",
|
||||||
"--spring.cloud.nacos.config.prefix=myapp");
|
"--spring.cloud.nacos.config.prefix=test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
Loading…
x
Reference in New Issue
Block a user