From b91f4a975875e1461528b1116497893c902c0348 Mon Sep 17 00:00:00 2001 From: xiaolongzuo <150349407@qq.com> Date: Tue, 30 Oct 2018 14:47:46 +0800 Subject: [PATCH] Add spring-cloud-alicloud-context tests. --- .../ans/AnsContextAutoConfiguration.java | 8 ++- .../alicloud/acm/AcmAutoConfiguration.java | 23 ++++++ .../alicloud/ans/AnsAutoConfiguration.java | 23 ++++++ .../AliCloudPropertiesDefaultTests.java | 45 ++++++++++++ .../context/AliCloudPropertiesLoadTests.java | 47 ++++++++++++ .../AliCloudSpringApplicationTests.java | 50 +++++++++++++ .../AcmIntegrationPropertiesLoad2Tests.java | 54 ++++++++++++++ .../AcmIntegrationPropertiesLoadTests.java | 53 ++++++++++++++ .../acm/AcmPropertiesDefaultTests.java | 52 ++++++++++++++ .../context/acm/AcmPropertiesLoadTests.java | 58 +++++++++++++++ .../ans/AnsPropertiesDefaultTests.java | 64 +++++++++++++++++ .../context/ans/AnsPropertiesLoadTests.java | 68 ++++++++++++++++++ .../edas/EdasPropertiesDefaultTests.java | 42 +++++++++++ .../edas/EdasPropertiesLoad2Tests.java | 44 ++++++++++++ .../context/edas/EdasPropertiesLoadTests.java | 43 +++++++++++ .../alicloud/context/oss/OssLoadTests.java | 71 +++++++++++++++++++ .../alicloud/oss/OssAutoConfiguration.java | 23 ++++++ 17 files changed, 767 insertions(+), 1 deletion(-) create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/acm/AcmAutoConfiguration.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/ans/AnsAutoConfiguration.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudPropertiesDefaultTests.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudPropertiesLoadTests.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudSpringApplicationTests.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmIntegrationPropertiesLoad2Tests.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmIntegrationPropertiesLoadTests.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmPropertiesDefaultTests.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmPropertiesLoadTests.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/ans/AnsPropertiesDefaultTests.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/ans/AnsPropertiesLoadTests.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesDefaultTests.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesLoad2Tests.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesLoadTests.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/oss/OssLoadTests.java create mode 100644 spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/oss/OssAutoConfiguration.java diff --git a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/ans/AnsContextAutoConfiguration.java b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/ans/AnsContextAutoConfiguration.java index fc58b69e9..f70407051 100644 --- a/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/ans/AnsContextAutoConfiguration.java +++ b/spring-cloud-alicloud-context/src/main/java/org/springframework/cloud/alicloud/context/ans/AnsContextAutoConfiguration.java @@ -31,10 +31,16 @@ import org.springframework.context.annotation.Configuration; */ @Configuration @ConditionalOnClass(name = "org.springframework.cloud.alicloud.ans.AnsAutoConfiguration") -@EnableConfigurationProperties({ AnsProperties.class, InetUtilsProperties.class }) +@EnableConfigurationProperties({ AnsProperties.class }) @ImportAutoConfiguration(EdasContextAutoConfiguration.class) public class AnsContextAutoConfiguration { + @Bean + @ConditionalOnMissingBean + public InetUtilsProperties inetUtilsProperties() { + return new InetUtilsProperties(); + } + @Bean @ConditionalOnMissingBean public InetUtils inetUtils(InetUtilsProperties inetUtilsProperties) { 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 new file mode 100644 index 000000000..1ecff17f8 --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/acm/AcmAutoConfiguration.java @@ -0,0 +1,23 @@ +/* + * 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 new file mode 100644 index 000000000..1f15f8827 --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/ans/AnsAutoConfiguration.java @@ -0,0 +1,23 @@ +/* + * 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/AliCloudPropertiesDefaultTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudPropertiesDefaultTests.java new file mode 100644 index 000000000..cca39c8b8 --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudPropertiesDefaultTests.java @@ -0,0 +1,45 @@ +/* + * 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.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.alicloud.context.AliCloudContextAutoConfiguration; +import org.springframework.cloud.alicloud.context.AliCloudProperties; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author xiaolongzuo + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = AliCloudContextAutoConfiguration.class) +public class AliCloudPropertiesDefaultTests { + + @Autowired + private AliCloudProperties aliCloudProperties; + + @Test + public void test() { + assertThat(aliCloudProperties.getAccessKey()).isNull(); + assertThat(aliCloudProperties.getSecretKey()).isNull(); + } + +} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudPropertiesLoadTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudPropertiesLoadTests.java new file mode 100644 index 000000000..e9901b9de --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudPropertiesLoadTests.java @@ -0,0 +1,47 @@ +/* + * 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.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.alicloud.context.AliCloudContextAutoConfiguration; +import org.springframework.cloud.alicloud.context.AliCloudProperties; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author xiaolongzuo + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = AliCloudContextAutoConfiguration.class, properties = { + "spring.cloud.alicloud.access-key=123", + "spring.cloud.alicloud.secret-key=123456" }) +public class AliCloudPropertiesLoadTests { + + @Autowired + private AliCloudProperties aliCloudProperties; + + @Test + public void test() { + 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/AliCloudSpringApplicationTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudSpringApplicationTests.java new file mode 100644 index 000000000..636adf64e --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/AliCloudSpringApplicationTests.java @@ -0,0 +1,50 @@ +/* + * 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.AliCloudDisabledApp.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 AliCloudDisabledApp { + + } + +} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmIntegrationPropertiesLoad2Tests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmIntegrationPropertiesLoad2Tests.java new file mode 100644 index 000000000..b8a1065db --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmIntegrationPropertiesLoad2Tests.java @@ -0,0 +1,54 @@ +/* + * 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.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author xiaolongzuo + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { AcmContextBootstrapConfiguration.class }, properties = { + "spring.application.name=myapp", "spring.application.group=com.alicloud.test", + "spring.profiles.active=profile1,profile2", "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" }) +public class AcmIntegrationPropertiesLoad2Tests { + + @Autowired + private AcmIntegrationProperties acmIntegrationProperties; + + @Test + public void test() { + assertThat(acmIntegrationProperties.getGroupConfigurationDataIds().size()) + .isEqualTo(2); + assertThat(acmIntegrationProperties.getApplicationConfigurationDataIds().size()) + .isEqualTo(6); + } +} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmIntegrationPropertiesLoadTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmIntegrationPropertiesLoadTests.java new file mode 100644 index 000000000..b8b2b251f --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmIntegrationPropertiesLoadTests.java @@ -0,0 +1,53 @@ +/* + * 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.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author xiaolongzuo + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { AcmContextBootstrapConfiguration.class }, properties = { + "spring.application.name=myapp", "spring.application.group=com.alicloud.test", + "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" }) +public class AcmIntegrationPropertiesLoadTests { + + @Autowired + private AcmIntegrationProperties acmIntegrationProperties; + + @Test + public void test() { + assertThat(acmIntegrationProperties.getGroupConfigurationDataIds().size()) + .isEqualTo(2); + assertThat(acmIntegrationProperties.getApplicationConfigurationDataIds().size()) + .isEqualTo(2); + } +} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmPropertiesDefaultTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmPropertiesDefaultTests.java new file mode 100644 index 000000000..ba117dae2 --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmPropertiesDefaultTests.java @@ -0,0 +1,52 @@ +/* + * 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.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.alibaba.cloud.context.AliCloudServerMode; + +/** + * @author xiaolongzuo + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { AcmContextBootstrapConfiguration.class }, properties = { + "spring.application.name=myapp" }) +public class AcmPropertiesDefaultTests { + + @Autowired + private AcmProperties acmProperties; + + @Test + public void test() { + assertThat(acmProperties.getServerMode()).isEqualTo(AliCloudServerMode.LOCAL); + assertThat(acmProperties.getServerList()).isEqualTo("127.0.0.1"); + assertThat(acmProperties.getServerPort()).isEqualTo("8080"); + assertThat(acmProperties.getEndpoint()).isNull(); + assertThat(acmProperties.getFileExtension()).isEqualTo("properties"); + assertThat(acmProperties.getGroup()).isEqualTo("DEFAULT_GROUP"); + assertThat(acmProperties.getNamespace()).isNull(); + assertThat(acmProperties.getRamRoleName()).isNull(); + assertThat(acmProperties.getTimeout()).isEqualTo(3000); + } +} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmPropertiesLoadTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmPropertiesLoadTests.java new file mode 100644 index 000000000..31adc474a --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/acm/AcmPropertiesLoadTests.java @@ -0,0 +1,58 @@ +/* + * 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.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.alibaba.cloud.context.AliCloudServerMode; + +/** + * @author xiaolongzuo + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { AcmContextBootstrapConfiguration.class }, properties = { + "spring.application.name=myapp", "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" }) +public class AcmPropertiesLoadTests { + + @Autowired + private AcmProperties acmProperties; + + @Test + public void test() { + 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"); + } +} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/ans/AnsPropertiesDefaultTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/ans/AnsPropertiesDefaultTests.java new file mode 100644 index 000000000..7022c1132 --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/ans/AnsPropertiesDefaultTests.java @@ -0,0 +1,64 @@ +/* + * 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.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.alicloud.context.ans.AnsContextAutoConfiguration; +import org.springframework.cloud.alicloud.context.ans.AnsProperties; +import org.springframework.test.context.junit4.SpringRunner; + +import com.alibaba.cloud.context.AliCloudServerMode; + +/** + * @author xiaolongzuo + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { AnsContextAutoConfiguration.class }) +public class AnsPropertiesDefaultTests { + + @Autowired + private AnsProperties ansProperties; + + @Test + public void test() { + 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(ansProperties.getTags().get("ANS_SERVICE_TYPE")) + .isEqualTo("SPRING_CLOUD"); + } +} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/ans/AnsPropertiesLoadTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/ans/AnsPropertiesLoadTests.java new file mode 100644 index 000000000..8ba17957e --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/ans/AnsPropertiesLoadTests.java @@ -0,0 +1,68 @@ +/* + * 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.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.alibaba.cloud.context.AliCloudServerMode; + +/** + * @author xiaolongzuo + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { AnsContextAutoConfiguration.class }, properties = { + "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" }) +public class AnsPropertiesLoadTests { + + @Autowired + private AnsProperties ansProperties; + + @Test + public void test() { + 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(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/EdasPropertiesDefaultTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesDefaultTests.java new file mode 100644 index 000000000..99b58efb8 --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesDefaultTests.java @@ -0,0 +1,42 @@ +/* + * 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.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author xiaolongzuo + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { EdasContextAutoConfiguration.class }) +public class EdasPropertiesDefaultTests { + + @Autowired + private EdasProperties edasProperties; + + @Test + public void test() { + assertThat(edasProperties.getNamespace()).isNull(); + assertThat(edasProperties.isApplicationNameValid()).isFalse(); + } +} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesLoad2Tests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesLoad2Tests.java new file mode 100644 index 000000000..7a7911597 --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesLoad2Tests.java @@ -0,0 +1,44 @@ +/* + * 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.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author xiaolongzuo + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { EdasContextAutoConfiguration.class }, properties = { + "spring.cloud.alicloud.edas.namespace=testns", + "spring.cloud.alicloud.edas.application.name=myapps" }) +public class EdasPropertiesLoad2Tests { + + @Autowired + private EdasProperties edasProperties; + + @Test + public void test() { + assertThat(edasProperties.getNamespace()).isEqualTo("testns"); + assertThat(edasProperties.getApplicationName()).isEqualTo("myapps"); + } +} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesLoadTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesLoadTests.java new file mode 100644 index 000000000..5cf934640 --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/edas/EdasPropertiesLoadTests.java @@ -0,0 +1,43 @@ +/* + * 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.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author xiaolongzuo + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { EdasContextAutoConfiguration.class }, properties = { + "spring.cloud.alicloud.edas.namespace=testns", "spring.application.name=myapps" }) +public class EdasPropertiesLoadTests { + + @Autowired + private EdasProperties edasProperties; + + @Test + public void test() { + assertThat(edasProperties.getNamespace()).isEqualTo("testns"); + assertThat(edasProperties.getApplicationName()).isEqualTo("myapps"); + } +} diff --git a/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/oss/OssLoadTests.java b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/oss/OssLoadTests.java new file mode 100644 index 000000000..86e874c2c --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/context/oss/OssLoadTests.java @@ -0,0 +1,71 @@ +/* + * 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.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.alicloud.context.AliCloudProperties; +import org.springframework.test.context.junit4.SpringRunner; + +import com.aliyun.oss.OSSClient; + +/** + * @author xiaolongzuo + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = OssContextAutoConfiguration.class, properties = { + "spring.cloud.alicloud.accessKey=your-ak", + "spring.cloud.alicloud.secretKey=your-sk", + "spring.cloud.alicloud.oss.endpoint=http://oss-cn-beijing.aliyuncs.com", + "spring.cloud.alicloud.oss.config.userAgent=alibaba" }) +public class OssLoadTests { + + @Autowired + private OssProperties ossProperties; + + @Autowired + private AliCloudProperties aliCloudProperties; + + @Autowired + private OSSClient ossClient; + + @Test + public void testProperties() { + 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 testClient() { + 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 new file mode 100644 index 000000000..2f6961c6d --- /dev/null +++ b/spring-cloud-alicloud-context/src/test/java/org/springframework/cloud/alicloud/oss/OssAutoConfiguration.java @@ -0,0 +1,23 @@ +/* + * 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 { +}