diff --git a/spring-cloud-alibaba-dependencies/pom.xml b/spring-cloud-alibaba-dependencies/pom.xml index b05bf85ef..bf95c0654 100644 --- a/spring-cloud-alibaba-dependencies/pom.xml +++ b/spring-cloud-alibaba-dependencies/pom.xml @@ -19,11 +19,47 @@ 0.2.0 3.1.0 0.3.0-RC1 + 1.0.8 + 0.1.1 + 4.0.1 + 1.0.0 + 2.16.0 - + + + com.alibaba.cloud + alicloud-context + ${alicloud.context.version} + + + com.aliyun + aliyun-java-sdk-edas + ${aliyun.sdk.edas.version} + + + com.aliyun + aliyun-java-sdk-core + + + + + com.aliyun + aliyun-java-sdk-core + ${aliyun.sdk.version} + + + com.alibaba.ans + ans-sdk + ${ans.version} + + + com.alibaba.edas.acm + acm-sdk + ${acm.version} + com.alibaba.nacos nacos-client @@ -81,7 +117,6 @@ - com.aliyun.oss @@ -142,8 +177,6 @@ - - diff --git a/spring-cloud-alicloud-context/pom.xml b/spring-cloud-alicloud-context/pom.xml index 2341776cf..316c63fb3 100644 --- a/spring-cloud-alicloud-context/pom.xml +++ b/spring-cloud-alicloud-context/pom.xml @@ -5,7 +5,7 @@ org.springframework.cloud spring-cloud-alibaba - 0.2.0.BUILD-SNAPSHOT + 0.1.0.BUILD-SNAPSHOT 4.0.0 diff --git a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/acm/AcmContextBootstrapConfiguration.java b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/acm/AcmContextBootstrapConfiguration.java index 772724420..13f038aa9 100644 --- a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/acm/AcmContextBootstrapConfiguration.java +++ b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/acm/AcmContextBootstrapConfiguration.java @@ -25,7 +25,11 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.cloud.alicloud.context.AliCloudProperties; import org.springframework.cloud.alicloud.context.edas.EdasContextAutoConfiguration; import org.springframework.cloud.alicloud.context.edas.EdasProperties; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; import com.alibaba.cloud.context.acm.AliCloudAcmInitializer; @@ -47,10 +51,27 @@ public class AcmContextBootstrapConfiguration { @Autowired private AliCloudProperties aliCloudProperties; + @Autowired + private Environment environment; + @PostConstruct public void initAcmProperties() { AliCloudAcmInitializer.initialize(aliCloudProperties, edasProperties, acmProperties); } + @Bean + public AcmIntegrationProperties acmIntegrationProperties() { + AcmIntegrationProperties acmIntegrationProperties = new AcmIntegrationProperties(); + String applicationName = environment.getProperty("spring.application.name"); + String applicationGroup = environment.getProperty("spring.application.group"); + Assert.isTrue(!StringUtils.isEmpty(applicationName), + "'spring.application.name' must be configured in bootstrap.properties or bootstrap.yml/yaml..."); + acmIntegrationProperties.setApplicationName(applicationName); + acmIntegrationProperties.setApplicationGroup(applicationGroup); + acmIntegrationProperties.setActiveProfiles(environment.getActiveProfiles()); + acmIntegrationProperties.setAcmProperties(acmProperties); + return acmIntegrationProperties; + } + } diff --git a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/acm/AcmIntegrationProperties.java b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/acm/AcmIntegrationProperties.java new file mode 100644 index 000000000..0ad6a6b4c --- /dev/null +++ b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/acm/AcmIntegrationProperties.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.alicloud.context.acm; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.util.StringUtils; + +/** + * @author xiaolongzuo + */ +public class AcmIntegrationProperties { + + private String applicationName; + + private String applicationGroup; + + private String[] activeProfiles = new String[0]; + + private AcmProperties acmProperties; + + public List getGroupConfigurationDataIds() { + List groupConfigurationDataIds = new ArrayList<>(); + if (StringUtils.isEmpty(applicationGroup)) { + return groupConfigurationDataIds; + } + String[] parts = applicationGroup.split("\\."); + for (int i = 1; i < parts.length; i++) { + StringBuilder subGroup = new StringBuilder(parts[0]); + for (int j = 1; j <= i; j++) { + subGroup.append(".").append(parts[j]); + } + groupConfigurationDataIds + .add(subGroup + ":application." + acmProperties.getFileExtension()); + } + return groupConfigurationDataIds; + } + + public List getApplicationConfigurationDataIds() { + List applicationConfigurationDataIds = new ArrayList<>(); + if (!StringUtils.isEmpty(applicationGroup)) { + applicationConfigurationDataIds.add(applicationGroup + ":" + applicationName + + "." + acmProperties.getFileExtension()); + for (String profile : activeProfiles) { + applicationConfigurationDataIds + .add(applicationGroup + ":" + applicationName + "-" + profile + + "." + acmProperties.getFileExtension()); + } + + } + applicationConfigurationDataIds + .add(applicationName + "." + acmProperties.getFileExtension()); + for (String profile : activeProfiles) { + applicationConfigurationDataIds.add(applicationName + "-" + profile + "." + + acmProperties.getFileExtension()); + } + return applicationConfigurationDataIds; + } + + public void setApplicationName(String applicationName) { + this.applicationName = applicationName; + } + + public void setApplicationGroup(String applicationGroup) { + this.applicationGroup = applicationGroup; + } + + public void setActiveProfiles(String[] activeProfiles) { + this.activeProfiles = activeProfiles; + } + + public void setAcmProperties(AcmProperties acmProperties) { + this.acmProperties = acmProperties; + } + +} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/acm/AcmAutoConfiguration.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/acm/AcmAutoConfiguration.java deleted file mode 100644 index 1ecff17f8..000000000 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/acm/AcmAutoConfiguration.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.alicloud.acm; - -/** - * @author xiaolongzuo - */ -public class AcmAutoConfiguration { -} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/ans/AnsAutoConfiguration.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/ans/AnsAutoConfiguration.java deleted file mode 100644 index 1f15f8827..000000000 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/ans/AnsAutoConfiguration.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.alicloud.ans; - -/** - * @author xiaolongzuo - */ -public class AnsAutoConfiguration { -} 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 deleted file mode 100644 index 3253a756f..000000000 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudPropertiesTests.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.alicloud.context; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -import org.junit.Test; -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; - -/** - * @author xiaolongzuo - */ -public class AliCloudPropertiesTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration( - AutoConfigurations.of(AliCloudContextAutoConfiguration.class)); - - @Test - public void testConfigurationValueDefaultsAreAsExpected() { - this.contextRunner.run(context -> { - AliCloudProperties config = context.getBean(AliCloudProperties.class); - assertThat(config.getAccessKey()).isNull(); - assertThat(config.getSecretKey()).isNull(); - }); - } - - @Test - 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"); - }); - } - -} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudSpringApplicationTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudSpringApplicationTests.java deleted file mode 100644 index b40edd268..000000000 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudSpringApplicationTests.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.alicloud.context; - -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * @author xiaolongzuo - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = AliCloudSpringApplicationTests.EurekaClientDisabledApp.class, properties = { - "spring.application.name=myapp", - "spring.cloud.alicloud.edas.application.name=myapp", - "spring.cloud.alicloud.access-key=ak", "spring.cloud.alicloud.secret-key=sk", - "spring.cloud.alicloud.oss.endpoint=test" }, webEnvironment = RANDOM_PORT) -@DirtiesContext -public class AliCloudSpringApplicationTests { - - @Test - public void contextLoads() { - System.out.println("Context load..."); - } - - @SpringBootApplication - public static class EurekaClientDisabledApp { - - } - -} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmPropertiesTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmPropertiesTests.java deleted file mode 100644 index 1a51309df..000000000 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmPropertiesTests.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.alicloud.context.acm; - -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - -import org.junit.Test; -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.cloud.alicloud.context.AliCloudContextAutoConfiguration; -import org.springframework.cloud.alicloud.context.edas.EdasContextAutoConfiguration; - -import com.alibaba.cloud.context.AliCloudServerMode; - -/** - * @author xiaolongzuo - */ -public class AcmPropertiesTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration( - AutoConfigurations.of(AcmContextBootstrapConfiguration.class, - EdasContextAutoConfiguration.class, - AliCloudContextAutoConfiguration.class)); - - @Test - public void testConfigurationValueDefaultsAreAsExpected() { - this.contextRunner.withPropertyValues().run(context -> { - AcmProperties config = context.getBean(AcmProperties.class); - assertThat(config.getServerMode()).isEqualTo(AliCloudServerMode.LOCAL); - assertThat(config.getServerList()).isEqualTo("127.0.0.1"); - assertThat(config.getServerPort()).isEqualTo("8080"); - assertThat(config.getEndpoint()).isNull(); - assertThat(config.getFileExtension()).isEqualTo("properties"); - assertThat(config.getGroup()).isEqualTo("DEFAULT_GROUP"); - assertThat(config.getNamespace()).isNull(); - assertThat(config.getRamRoleName()).isNull(); - assertThat(config.getTimeout()).isEqualTo(3000); - }); - } - - @Test - public void testConfigurationValuesAreCorrectlyLoaded() { - this.contextRunner.withPropertyValues("spring.cloud.alicloud.access-key=ak", - "spring.cloud.alicloud.secret-key=sk", - "spring.cloud.alicloud.acm.server-mode=EDAS", - "spring.cloud.alicloud.acm.server-port=11111", - "spring.cloud.alicloud.acm.server-list=10.10.10.10", - "spring.cloud.alicloud.acm.namespace=testNamespace", - "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"); - }); - } - -} 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 deleted file mode 100644 index 11762c1b3..000000000 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/ans/AnsPropertiesTests.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.alicloud.context.ans; - -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - -import org.junit.Test; -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.cloud.alicloud.context.AliCloudContextAutoConfiguration; -import org.springframework.cloud.alicloud.context.edas.EdasContextAutoConfiguration; - -import com.alibaba.cloud.context.AliCloudServerMode; - -/** - * @author xiaolongzuo - */ -public class AnsPropertiesTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(AnsContextAutoConfiguration.class, - EdasContextAutoConfiguration.class, - AliCloudContextAutoConfiguration.class)); - - @Test - 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()) - .isEqualTo("ANS_SERVICE_TYPE"); - assertThat(config.getTags().get("ANS_SERVICE_TYPE")) - .isEqualTo("SPRING_CLOUD"); - }); - } - - @Test - public void testConfigurationValuesAreCorrectlyLoaded() { - this.contextRunner - .withPropertyValues("spring.cloud.alicloud.ans.server-mode=EDAS", - "spring.cloud.alicloud.ans.server-port=11111", - "spring.cloud.alicloud.ans.server-list=10.10.10.10", - "spring.cloud.alicloud.ans.client-domains=testDomain", - "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()) - .isEqualTo("ANS_SERVICE_TYPE"); - assertThat(config.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 deleted file mode 100644 index 5f5f08ae0..000000000 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesTests.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.alicloud.context.edas; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -import org.junit.Test; -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.cloud.alicloud.context.AliCloudContextAutoConfiguration; - -/** - * @author xiaolongzuo - */ -public class EdasPropertiesTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(EdasContextAutoConfiguration.class, - AliCloudContextAutoConfiguration.class)); - - @Test - public void testConfigurationValueDefaultsAreAsExpected() { - this.contextRunner.withPropertyValues().run(context -> { - EdasProperties config = context.getBean(EdasProperties.class); - assertThat(config.getNamespace()).isNull(); - assertThat(config.isApplicationNameValid()).isFalse(); - }); - } - - @Test - public void testConfigurationValuesAreCorrectlyLoaded1() { - this.contextRunner - .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"); - }); - } - - @Test - public void testConfigurationValuesAreCorrectlyLoaded2() { - this.contextRunner - .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"); - }); - } - -} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/oss/OssAutoConfigurationTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/oss/OssAutoConfigurationTests.java deleted file mode 100644 index 042ec0873..000000000 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/oss/OssAutoConfigurationTests.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.alicloud.context.oss; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.Test; -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.cloud.alicloud.context.AliCloudProperties; - -import com.aliyun.oss.OSS; -import com.aliyun.oss.OSSClient; - -/** - * {@link OSS} {@link OssProperties} Test - * - * @author Jim - */ -public class OssAutoConfigurationTests { - - private ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(OssContextAutoConfiguration.class)) - .withPropertyValues("spring.cloud.alicloud.accessKey=your-ak") - .withPropertyValues("spring.cloud.alicloud.secretKey=your-sk") - .withPropertyValues( - "spring.cloud.alicloud.oss.endpoint=http://oss-cn-beijing.aliyuncs.com") - .withPropertyValues("spring.cloud.alicloud.oss.config.userAgent=alibaba"); - - @Test - public void testOSSProperties() { - this.contextRunner.run(context -> { - assertThat(context.getBeansOfType(OssProperties.class).size() == 1).isTrue(); - AliCloudProperties aliCloudProperties = context - .getBean(AliCloudProperties.class); - OssProperties ossProperties = context.getBean(OssProperties.class); - assertThat(aliCloudProperties.getAccessKey()).isEqualTo("your-ak"); - assertThat(aliCloudProperties.getSecretKey()).isEqualTo("your-sk"); - assertThat(ossProperties.getEndpoint()) - .isEqualTo("http://oss-cn-beijing.aliyuncs.com"); - assertThat(ossProperties.getConfig().getUserAgent()).isEqualTo("alibaba"); - }); - } - - @Test - public void testOSSClient() { - this.contextRunner.run(context -> { - assertThat(context.getBeansOfType(OSS.class).size() == 1).isTrue(); - assertThat(context.getBeanNamesForType(OSS.class)[0]).isEqualTo("ossClient"); - OSSClient ossClient = (OSSClient) context.getBean(OSS.class); - assertThat(ossClient.getEndpoint().toString()) - .isEqualTo("http://oss-cn-beijing.aliyuncs.com"); - assertThat(ossClient.getClientConfiguration().getUserAgent()) - .isEqualTo("alibaba"); - assertThat( - ossClient.getCredentialsProvider().getCredentials().getAccessKeyId()) - .isEqualTo("your-ak"); - assertThat(ossClient.getCredentialsProvider().getCredentials() - .getSecretAccessKey()).isEqualTo("your-sk"); - }); - } - -} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/oss/OssAutoConfiguration.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/oss/OssAutoConfiguration.java deleted file mode 100644 index 2f6961c6d..000000000 --- a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/oss/OssAutoConfiguration.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.alicloud.oss; - -/** - * @author xiaolongzuo - */ -public class OssAutoConfiguration { -}