1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

closes #63, closes #64, closes #65, closes #66.

This commit is contained in:
chenzhu.zxl
2018-10-26 19:08:12 +08:00
parent 591350d7e0
commit 7126a8ce33
97 changed files with 4732 additions and 463 deletions

View File

@@ -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 {
}

View File

@@ -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 {
}

View File

@@ -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;
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");
});
}
}

View File

@@ -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.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 {
}
}

View File

@@ -0,0 +1,78 @@
/*
* 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 AnsPropertiesTests {
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");
});
}
}

View File

@@ -0,0 +1,101 @@
/*
* 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");
});
}
}

View File

@@ -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.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");
});
}
}

View File

@@ -0,0 +1,77 @@
/*
* 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 <a href="mailto:fangjian0423@gmail.com">Jim</a>
*/
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");
});
}
}

View File

@@ -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 {
}