optimize spring-cloud-alicloud-context tests.

pull/77/head
xiaolongzuo 6 years ago
parent f0e2e0732e
commit a95a323bc8

@ -34,9 +34,10 @@ public class AliCloudPropertiesTests {
@Test
public void testConfigurationValueDefaultsAreAsExpected() {
this.contextRunner.run(context -> {
AliCloudProperties config = context.getBean(AliCloudProperties.class);
assertThat(config.getAccessKey()).isNull();
assertThat(config.getSecretKey()).isNull();
AliCloudProperties aliCloudProperties = context
.getBean(AliCloudProperties.class);
assertThat(aliCloudProperties.getAccessKey()).isNull();
assertThat(aliCloudProperties.getSecretKey()).isNull();
});
}
@ -44,9 +45,10 @@ public class AliCloudPropertiesTests {
public void testConfigurationValuesAreCorrectlyLoaded() {
this.contextRunner.withPropertyValues("spring.cloud.alicloud.access-key=123",
"spring.cloud.alicloud.secret-key=123456").run(context -> {
AliCloudProperties config = context.getBean(AliCloudProperties.class);
assertThat(config.getAccessKey()).isEqualTo("123");
assertThat(config.getSecretKey()).isEqualTo("123456");
AliCloudProperties aliCloudProperties = context
.getBean(AliCloudProperties.class);
assertThat(aliCloudProperties.getAccessKey()).isEqualTo("123");
assertThat(aliCloudProperties.getSecretKey()).isEqualTo("123456");
});
}

@ -29,7 +29,7 @@ import com.alibaba.cloud.context.AliCloudServerMode;
/**
* @author xiaolongzuo
*/
public class AnsPropertiesTests {
public class AcmPropertiesTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(
@ -67,14 +67,15 @@ public class AnsPropertiesTests {
"spring.cloud.alicloud.acm.endpoint=testDomain",
"spring.cloud.alicloud.acm.group=testGroup",
"spring.cloud.alicloud.acm.file-extension=yaml").run(context -> {
AcmProperties config = context.getBean(AcmProperties.class);
assertThat(config.getServerMode()).isEqualTo(AliCloudServerMode.EDAS);
assertThat(config.getServerList()).isEqualTo("10.10.10.10");
assertThat(config.getServerPort()).isEqualTo("11111");
assertThat(config.getEndpoint()).isEqualTo("testDomain");
assertThat(config.getGroup()).isEqualTo("testGroup");
assertThat(config.getFileExtension()).isEqualTo("yaml");
assertThat(config.getNamespace()).isEqualTo("testNamespace");
AcmProperties acmProperties = context.getBean(AcmProperties.class);
assertThat(acmProperties.getServerMode())
.isEqualTo(AliCloudServerMode.EDAS);
assertThat(acmProperties.getServerList()).isEqualTo("10.10.10.10");
assertThat(acmProperties.getServerPort()).isEqualTo("11111");
assertThat(acmProperties.getEndpoint()).isEqualTo("testDomain");
assertThat(acmProperties.getGroup()).isEqualTo("testGroup");
assertThat(acmProperties.getFileExtension()).isEqualTo("yaml");
assertThat(acmProperties.getNamespace()).isEqualTo("testNamespace");
});
}
@ -97,10 +98,6 @@ public class AnsPropertiesTests {
.size()).isEqualTo(2);
assertThat(acmIntegrationProperties
.getApplicationConfigurationDataIds().size()).isEqualTo(2);
System.out.println("-----"
+ acmIntegrationProperties.getGroupConfigurationDataIds());
System.out.println(acmIntegrationProperties
.getApplicationConfigurationDataIds());
});
}

@ -40,26 +40,26 @@ public class AnsPropertiesTests {
public void testConfigurationValueDefaultsAreAsExpected()
throws ClassNotFoundException {
this.contextRunner.withPropertyValues().run(context -> {
AnsProperties config = context.getBean(AnsProperties.class);
assertThat(config.getServerMode()).isEqualTo(AliCloudServerMode.LOCAL);
assertThat(config.getServerList()).isEqualTo("127.0.0.1");
assertThat(config.getServerPort()).isEqualTo("8080");
assertThat(config.getClientDomains()).isEqualTo("");
assertThat(config.getClientWeight()).isEqualTo(1.0F);
assertThat(config.getClientWeights().size()).isEqualTo(0);
assertThat(config.getClientTokens().size()).isEqualTo(0);
assertThat(config.getClientMetadata().size()).isEqualTo(0);
assertThat(config.getClientToken()).isNull();
assertThat(config.getClientCluster()).isEqualTo("DEFAULT");
assertThat(config.isRegisterEnabled()).isTrue();
assertThat(config.getClientInterfaceName()).isNull();
assertThat(config.getClientPort()).isEqualTo(-1);
assertThat(config.getEnv()).isEqualTo("DEFAULT");
assertThat(config.isSecure()).isFalse();
assertThat(config.getTags().size()).isEqualTo(1);
assertThat(config.getTags().keySet().iterator().next())
AnsProperties ansProperties = context.getBean(AnsProperties.class);
assertThat(ansProperties.getServerMode()).isEqualTo(AliCloudServerMode.LOCAL);
assertThat(ansProperties.getServerList()).isEqualTo("127.0.0.1");
assertThat(ansProperties.getServerPort()).isEqualTo("8080");
assertThat(ansProperties.getClientDomains()).isEqualTo("");
assertThat(ansProperties.getClientWeight()).isEqualTo(1.0F);
assertThat(ansProperties.getClientWeights().size()).isEqualTo(0);
assertThat(ansProperties.getClientTokens().size()).isEqualTo(0);
assertThat(ansProperties.getClientMetadata().size()).isEqualTo(0);
assertThat(ansProperties.getClientToken()).isNull();
assertThat(ansProperties.getClientCluster()).isEqualTo("DEFAULT");
assertThat(ansProperties.isRegisterEnabled()).isTrue();
assertThat(ansProperties.getClientInterfaceName()).isNull();
assertThat(ansProperties.getClientPort()).isEqualTo(-1);
assertThat(ansProperties.getEnv()).isEqualTo("DEFAULT");
assertThat(ansProperties.isSecure()).isFalse();
assertThat(ansProperties.getTags().size()).isEqualTo(1);
assertThat(ansProperties.getTags().keySet().iterator().next())
.isEqualTo("ANS_SERVICE_TYPE");
assertThat(config.getTags().get("ANS_SERVICE_TYPE"))
assertThat(ansProperties.getTags().get("ANS_SERVICE_TYPE"))
.isEqualTo("SPRING_CLOUD");
});
}
@ -74,26 +74,27 @@ public class AnsPropertiesTests {
"spring.cloud.alicloud.ans.client-weight=0.9",
"spring.cloud.alicloud.ans.client-weights.testDomain=0.9")
.run(context -> {
AnsProperties config = context.getBean(AnsProperties.class);
assertThat(config.getServerMode()).isEqualTo(AliCloudServerMode.EDAS);
assertThat(config.getServerList()).isEqualTo("10.10.10.10");
assertThat(config.getServerPort()).isEqualTo("11111");
assertThat(config.getClientDomains()).isEqualTo("testDomain");
assertThat(config.getClientWeight()).isEqualTo(0.9F);
assertThat(config.getClientWeights().size()).isEqualTo(1);
assertThat(config.getClientTokens().size()).isEqualTo(0);
assertThat(config.getClientMetadata().size()).isEqualTo(0);
assertThat(config.getClientToken()).isNull();
assertThat(config.getClientCluster()).isEqualTo("DEFAULT");
assertThat(config.isRegisterEnabled()).isTrue();
assertThat(config.getClientInterfaceName()).isNull();
assertThat(config.getClientPort()).isEqualTo(-1);
assertThat(config.getEnv()).isEqualTo("DEFAULT");
assertThat(config.isSecure()).isFalse();
assertThat(config.getTags().size()).isEqualTo(1);
assertThat(config.getTags().keySet().iterator().next())
AnsProperties ansProperties = context.getBean(AnsProperties.class);
assertThat(ansProperties.getServerMode())
.isEqualTo(AliCloudServerMode.EDAS);
assertThat(ansProperties.getServerList()).isEqualTo("10.10.10.10");
assertThat(ansProperties.getServerPort()).isEqualTo("11111");
assertThat(ansProperties.getClientDomains()).isEqualTo("testDomain");
assertThat(ansProperties.getClientWeight()).isEqualTo(0.9F);
assertThat(ansProperties.getClientWeights().size()).isEqualTo(1);
assertThat(ansProperties.getClientTokens().size()).isEqualTo(0);
assertThat(ansProperties.getClientMetadata().size()).isEqualTo(0);
assertThat(ansProperties.getClientToken()).isNull();
assertThat(ansProperties.getClientCluster()).isEqualTo("DEFAULT");
assertThat(ansProperties.isRegisterEnabled()).isTrue();
assertThat(ansProperties.getClientInterfaceName()).isNull();
assertThat(ansProperties.getClientPort()).isEqualTo(-1);
assertThat(ansProperties.getEnv()).isEqualTo("DEFAULT");
assertThat(ansProperties.isSecure()).isFalse();
assertThat(ansProperties.getTags().size()).isEqualTo(1);
assertThat(ansProperties.getTags().keySet().iterator().next())
.isEqualTo("ANS_SERVICE_TYPE");
assertThat(config.getTags().get("ANS_SERVICE_TYPE"))
assertThat(ansProperties.getTags().get("ANS_SERVICE_TYPE"))
.isEqualTo("SPRING_CLOUD");
});
}

@ -35,9 +35,9 @@ public class EdasPropertiesTests {
@Test
public void testConfigurationValueDefaultsAreAsExpected() {
this.contextRunner.withPropertyValues().run(context -> {
EdasProperties config = context.getBean(EdasProperties.class);
assertThat(config.getNamespace()).isNull();
assertThat(config.isApplicationNameValid()).isFalse();
EdasProperties edasProperties = context.getBean(EdasProperties.class);
assertThat(edasProperties.getNamespace()).isNull();
assertThat(edasProperties.isApplicationNameValid()).isFalse();
});
}
@ -47,9 +47,9 @@ public class EdasPropertiesTests {
.withPropertyValues("spring.cloud.alicloud.edas.namespace=testns",
"spring.application.name=myapps")
.run(context -> {
EdasProperties config = context.getBean(EdasProperties.class);
assertThat(config.getNamespace()).isEqualTo("testns");
assertThat(config.getApplicationName()).isEqualTo("myapps");
EdasProperties edasProperties = context.getBean(EdasProperties.class);
assertThat(edasProperties.getNamespace()).isEqualTo("testns");
assertThat(edasProperties.getApplicationName()).isEqualTo("myapps");
});
}
@ -59,9 +59,9 @@ public class EdasPropertiesTests {
.withPropertyValues("spring.cloud.alicloud.edas.namespace=testns",
"spring.cloud.alicloud.edas.application.name=myapps")
.run(context -> {
EdasProperties config = context.getBean(EdasProperties.class);
assertThat(config.getNamespace()).isEqualTo("testns");
assertThat(config.getApplicationName()).isEqualTo("myapps");
EdasProperties edasProperties = context.getBean(EdasProperties.class);
assertThat(edasProperties.getNamespace()).isEqualTo("testns");
assertThat(edasProperties.getApplicationName()).isEqualTo("myapps");
});
}

Loading…
Cancel
Save