Merge pull request #73 from xiaolongzuo/1.x
Optimize spring-cloud-alicloud-context module for branch 1.xpull/74/head
commit
b702d891d6
@ -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<String> getGroupConfigurationDataIds() {
|
||||
List<String> 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<String> getApplicationConfigurationDataIds() {
|
||||
List<String> 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;
|
||||
}
|
||||
|
||||
}
|
@ -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 {
|
||||
}
|
@ -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 {
|
||||
}
|
@ -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");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -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 {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -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");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -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");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -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 <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");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -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 {
|
||||
}
|
Loading…
Reference in New Issue