From a95a323bc860d1f4b5eb6364fb30d28762a8ed81 Mon Sep 17 00:00:00 2001 From: xiaolongzuo <150349407@qq.com> Date: Tue, 30 Oct 2018 14:53:29 +0800 Subject: [PATCH] optimize spring-cloud-alicloud-context tests. --- .../context/AliCloudPropertiesTests.java | 14 ++-- ...tiesTests.java => AcmPropertiesTests.java} | 23 +++--- .../context/ans/AnsPropertiesTests.java | 77 ++++++++++--------- .../context/edas/EdasPropertiesTests.java | 18 ++--- 4 files changed, 66 insertions(+), 66 deletions(-) rename spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/{AnsPropertiesTests.java => AcmPropertiesTests.java} (86%) diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudPropertiesTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudPropertiesTests.java index 3253a756f..1094b928f 100644 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudPropertiesTests.java +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudPropertiesTests.java @@ -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"); }); } diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AnsPropertiesTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmPropertiesTests.java similarity index 86% rename from spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AnsPropertiesTests.java rename to spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmPropertiesTests.java index 8a1f473ab..d129d64e9 100644 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AnsPropertiesTests.java +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmPropertiesTests.java @@ -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()); }); } diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/ans/AnsPropertiesTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/ans/AnsPropertiesTests.java index 11762c1b3..a81f0ab5b 100644 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/ans/AnsPropertiesTests.java +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/ans/AnsPropertiesTests.java @@ -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"); }); } diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesTests.java index 5f5f08ae0..ed59a46c2 100644 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesTests.java +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesTests.java @@ -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"); }); }