mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge code from upstream
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 com.alibaba.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 aliCloudProperties = context
|
||||
.getBean(AliCloudProperties.class);
|
||||
assertThat(aliCloudProperties.getAccessKey()).isNull();
|
||||
assertThat(aliCloudProperties.getSecretKey()).isNull();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationValuesAreCorrectlyLoaded() {
|
||||
this.contextRunner.withPropertyValues("spring.cloud.alicloud.access-key=123",
|
||||
"spring.cloud.alicloud.secret-key=123456").run(context -> {
|
||||
AliCloudProperties aliCloudProperties = context
|
||||
.getBean(AliCloudProperties.class);
|
||||
assertThat(aliCloudProperties.getAccessKey()).isEqualTo("123");
|
||||
assertThat(aliCloudProperties.getSecretKey()).isEqualTo("123456");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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 com.alibaba.alicloud.context;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PowerMockRunnerDelegate(SpringRunner.class)
|
||||
@PowerMockIgnore("javax.management.*")
|
||||
@SpringBootTest(classes = BaseAliCloudSpringApplication.AliCloudApplication.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",
|
||||
"spring.cloud.alicloud.scx.group-id=1-2-3-4",
|
||||
"spring.cloud.alicloud.edas.namespace=cn-test",
|
||||
"spring.cloud.alicloud.ans.server-list=192.168.1.100",
|
||||
"spring.cloud.alicloud.ans.server-port=8888",
|
||||
"spring.cloud.alicloud.oss.enabled=false",
|
||||
"spring.cloud.alicloud.scx.enabled=false" })
|
||||
public abstract class BaseAliCloudSpringApplication {
|
||||
|
||||
@SpringBootApplication
|
||||
public static class AliCloudApplication {
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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 com.alibaba.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 com.alibaba.alicloud.context.AliCloudContextAutoConfiguration;
|
||||
import com.alibaba.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("spring.application.name=myapp")
|
||||
.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.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").run(context -> {
|
||||
AcmProperties acmProperties = context.getBean(AcmProperties.class);
|
||||
assertThat(acmProperties.getServerMode())
|
||||
.isEqualTo(AliCloudServerMode.EDAS);
|
||||
assertThat(acmProperties.getServerList()).isEqualTo("10.10.10.10");
|
||||
assertThat(acmProperties.getServerPort()).isEqualTo("11111");
|
||||
assertThat(acmProperties.getEndpoint()).isEqualTo("testDomain");
|
||||
assertThat(acmProperties.getGroup()).isEqualTo("testGroup");
|
||||
assertThat(acmProperties.getFileExtension()).isEqualTo("yaml");
|
||||
assertThat(acmProperties.getNamespace()).isEqualTo("testNamespace");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcmIntegrationConfigurationValuesAreCorrectlyLoaded() {
|
||||
this.contextRunner.withPropertyValues("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").run(context -> {
|
||||
AcmIntegrationProperties acmIntegrationProperties = context
|
||||
.getBean(AcmIntegrationProperties.class);
|
||||
assertThat(acmIntegrationProperties.getGroupConfigurationDataIds()
|
||||
.size()).isEqualTo(2);
|
||||
assertThat(acmIntegrationProperties
|
||||
.getApplicationConfigurationDataIds().size()).isEqualTo(2);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAcmIntegrationConfigurationValuesAreCorrectlyLoaded2() {
|
||||
this.contextRunner.withPropertyValues("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").run(context -> {
|
||||
AcmIntegrationProperties acmIntegrationProperties = context
|
||||
.getBean(AcmIntegrationProperties.class);
|
||||
assertThat(acmIntegrationProperties.getGroupConfigurationDataIds()
|
||||
.size()).isEqualTo(2);
|
||||
assertThat(acmIntegrationProperties
|
||||
.getApplicationConfigurationDataIds().size()).isEqualTo(6);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 com.alibaba.alicloud.context.ans;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.alicloud.context.BaseAliCloudSpringApplication;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
public class AnsContextApplicationListenerTests extends BaseAliCloudSpringApplication {
|
||||
|
||||
@Test
|
||||
public void testAnsContextApplicationListenerDefault() {
|
||||
assertThat(System
|
||||
.getProperty("com.alibaba.ans.shaded.com.taobao.vipserver.serverlist"))
|
||||
.isEqualTo("192.168.1.100");
|
||||
assertThat(System.getProperty("vipserver.server.port")).isEqualTo("8888");
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* 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 com.alibaba.alicloud.context.ans;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
|
||||
import com.alibaba.alicloud.context.AliCloudContextAutoConfiguration;
|
||||
import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration;
|
||||
import com.alibaba.cloud.context.AliCloudServerMode;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ NetworkInterface.class, AnsProperties.class })
|
||||
public class AnsPropertiesTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(AnsContextAutoConfiguration.class,
|
||||
EdasContextAutoConfiguration.class,
|
||||
AliCloudContextAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void testConfigurationValueDefaultsAreAsExpected() {
|
||||
this.contextRunner.withPropertyValues().run(context -> {
|
||||
AnsProperties ansProperties = context.getBean(AnsProperties.class);
|
||||
assertThat(ansProperties.getServerMode()).isEqualTo(AliCloudServerMode.LOCAL);
|
||||
assertThat(ansProperties.getServerList()).isEqualTo("127.0.0.1");
|
||||
assertThat(ansProperties.getServerPort()).isEqualTo("8080");
|
||||
assertThat(ansProperties.getClientDomains()).isEqualTo("");
|
||||
assertThat(ansProperties.getClientWeight()).isEqualTo(1.0F);
|
||||
assertThat(ansProperties.getClientWeights().size()).isEqualTo(0);
|
||||
assertThat(ansProperties.getClientTokens().size()).isEqualTo(0);
|
||||
assertThat(ansProperties.getClientMetadata().size()).isEqualTo(0);
|
||||
assertThat(ansProperties.getClientToken()).isNull();
|
||||
assertThat(ansProperties.getClientCluster()).isEqualTo("DEFAULT");
|
||||
assertThat(ansProperties.isRegisterEnabled()).isTrue();
|
||||
assertThat(ansProperties.getClientInterfaceName()).isNull();
|
||||
assertThat(ansProperties.getClientPort()).isEqualTo(-1);
|
||||
assertThat(ansProperties.getEnv()).isEqualTo("DEFAULT");
|
||||
assertThat(ansProperties.isSecure()).isFalse();
|
||||
assertThat(ansProperties.getTags().size()).isEqualTo(1);
|
||||
assertThat(ansProperties.getTags().keySet().iterator().next())
|
||||
.isEqualTo("ANS_SERVICE_TYPE");
|
||||
assertThat(ansProperties.getTags().get("ANS_SERVICE_TYPE"))
|
||||
.isEqualTo("SPRING_CLOUD");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationValuesAreCorrectlyLoaded1() {
|
||||
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 ansProperties = context.getBean(AnsProperties.class);
|
||||
assertThat(ansProperties.getServerMode())
|
||||
.isEqualTo(AliCloudServerMode.EDAS);
|
||||
assertThat(ansProperties.getServerList()).isEqualTo("10.10.10.10");
|
||||
assertThat(ansProperties.getServerPort()).isEqualTo("11111");
|
||||
assertThat(ansProperties.getClientDomains()).isEqualTo("testDomain");
|
||||
assertThat(ansProperties.getClientWeight()).isEqualTo(0.9F);
|
||||
assertThat(ansProperties.getClientWeights().size()).isEqualTo(1);
|
||||
assertThat(ansProperties.getClientTokens().size()).isEqualTo(0);
|
||||
assertThat(ansProperties.getClientMetadata().size()).isEqualTo(0);
|
||||
assertThat(ansProperties.getClientToken()).isNull();
|
||||
assertThat(ansProperties.getClientCluster()).isEqualTo("DEFAULT");
|
||||
assertThat(ansProperties.isRegisterEnabled()).isTrue();
|
||||
assertThat(ansProperties.getClientInterfaceName()).isNull();
|
||||
assertThat(ansProperties.getClientPort()).isEqualTo(-1);
|
||||
assertThat(ansProperties.getEnv()).isEqualTo("DEFAULT");
|
||||
assertThat(ansProperties.isSecure()).isFalse();
|
||||
assertThat(ansProperties.getTags().size()).isEqualTo(1);
|
||||
assertThat(ansProperties.getTags().keySet().iterator().next())
|
||||
.isEqualTo("ANS_SERVICE_TYPE");
|
||||
assertThat(ansProperties.getTags().get("ANS_SERVICE_TYPE"))
|
||||
.isEqualTo("SPRING_CLOUD");
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void testConfigurationValuesAreCorrectlyLoaded2() {
|
||||
this.contextRunner.withPropertyValues(
|
||||
"spring.cloud.alicloud.ans.client-interface-name=noneinterfacename")
|
||||
.run(context -> {
|
||||
AnsProperties ansProperties = context.getBean(AnsProperties.class);
|
||||
assertThat(ansProperties.getClientInterfaceName())
|
||||
.isEqualTo("noneinterfacename");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationValuesAreCorrectlyLoaded3() throws SocketException {
|
||||
NetworkInterface networkInterface = PowerMockito.mock(NetworkInterface.class);
|
||||
Vector<InetAddress> inetAddressList = new Vector<>();
|
||||
Inet4Address inetAddress = PowerMockito.mock(Inet4Address.class);
|
||||
PowerMockito.when(inetAddress.getHostAddress()).thenReturn("192.168.1.100");
|
||||
inetAddressList.add(inetAddress);
|
||||
PowerMockito.when(networkInterface.getInetAddresses())
|
||||
.thenReturn(inetAddressList.elements());
|
||||
PowerMockito.mockStatic(NetworkInterface.class);
|
||||
PowerMockito.when(NetworkInterface.getByName("eth0"))
|
||||
.thenReturn(networkInterface);
|
||||
this.contextRunner
|
||||
.withPropertyValues(
|
||||
"spring.cloud.alicloud.ans.client-interface-name=eth0")
|
||||
.run(context -> {
|
||||
AnsProperties ansProperties = context.getBean(AnsProperties.class);
|
||||
assertThat(ansProperties.getClientInterfaceName()).isEqualTo("eth0");
|
||||
assertThat(ansProperties.getClientIp()).isEqualTo("192.168.1.100");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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 com.alibaba.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 com.alibaba.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 edasProperties = context.getBean(EdasProperties.class);
|
||||
assertThat(edasProperties.getNamespace()).isNull();
|
||||
assertThat(edasProperties.isApplicationNameValid()).isFalse();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationValuesAreCorrectlyLoaded1() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.cloud.alicloud.edas.namespace=testns",
|
||||
"spring.application.name=myapps")
|
||||
.run(context -> {
|
||||
EdasProperties edasProperties = context.getBean(EdasProperties.class);
|
||||
assertThat(edasProperties.getNamespace()).isEqualTo("testns");
|
||||
assertThat(edasProperties.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 edasProperties = context.getBean(EdasProperties.class);
|
||||
assertThat(edasProperties.getNamespace()).isEqualTo("testns");
|
||||
assertThat(edasProperties.getApplicationName()).isEqualTo("myapps");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -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 com.alibaba.alicloud.context.nacos;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
|
||||
import com.alibaba.alicloud.context.BaseAliCloudSpringApplication;
|
||||
import com.alibaba.alicloud.utils.ChangeOrderUtils;
|
||||
import com.alibaba.cloud.context.ans.AliCloudAnsInitializer;
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@PrepareForTest({ EdasChangeOrderConfigurationFactory.class,
|
||||
NacosConfigParameterInitListener.class, AliCloudAnsInitializer.class })
|
||||
public class NacosConfigParameterInitListenerTests extends BaseAliCloudSpringApplication {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
ChangeOrderUtils.mockChangeOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNacosParameterInitListener() {
|
||||
assertThat(System.getProperty("spring.cloud.nacos.config.server-mode"))
|
||||
.isEqualTo("EDAS");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.config.server-addr"))
|
||||
.isEqualTo("");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.config.endpoint"))
|
||||
.isEqualTo("testDomain");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.config.namespace"))
|
||||
.isEqualTo("testTenantId");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.config.access-key"))
|
||||
.isEqualTo("testAK");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.config.secret-key"))
|
||||
.isEqualTo("testSK");
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 com.alibaba.alicloud.context.nacos;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
|
||||
import com.alibaba.alicloud.context.BaseAliCloudSpringApplication;
|
||||
import com.alibaba.alicloud.utils.ChangeOrderUtils;
|
||||
import com.alibaba.cloud.context.ans.AliCloudAnsInitializer;
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@PrepareForTest({ EdasChangeOrderConfigurationFactory.class,
|
||||
NacosDiscoveryParameterInitListener.class, AliCloudAnsInitializer.class })
|
||||
public class NacosDiscoveryParameterInitListenerTests
|
||||
extends BaseAliCloudSpringApplication {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
ChangeOrderUtils.mockChangeOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNacosParameterInitListener() {
|
||||
assertThat(System.getProperty("spring.cloud.nacos.discovery.server-mode"))
|
||||
.isEqualTo("EDAS");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.discovery.server-addr"))
|
||||
.isEqualTo("");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.discovery.endpoint"))
|
||||
.isEqualTo("testDomain");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.discovery.namespace"))
|
||||
.isEqualTo("testTenantId");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.discovery.access-key"))
|
||||
.isEqualTo("testAK");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.discovery.secret-key"))
|
||||
.isEqualTo("testSK");
|
||||
assertThat(System.getProperties().getProperty("nacos.naming.web.context"))
|
||||
.isEqualTo("/vipserver");
|
||||
assertThat(System.getProperties().getProperty("nacos.naming.exposed.port"))
|
||||
.isEqualTo("80");
|
||||
}
|
||||
}
|
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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 com.alibaba.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 com.alibaba.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",
|
||||
"spring.cloud.alicloud.secretKey=your-sk",
|
||||
"spring.cloud.alicloud.oss.endpoint=http://oss-cn-beijing.aliyuncs.com",
|
||||
"spring.cloud.alicloud.oss.config.userAgent=alibaba",
|
||||
"spring.cloud.alicloud.oss.sts.access-key=your-sts-ak",
|
||||
"spring.cloud.alicloud.oss.sts.secret-key=your-sts-sk",
|
||||
"spring.cloud.alicloud.oss.sts.security-token=your-sts-token");
|
||||
|
||||
@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");
|
||||
assertThat(ossProperties.getSts().getAccessKey()).isEqualTo("your-sts-ak");
|
||||
assertThat(ossProperties.getSts().getSecretKey()).isEqualTo("your-sts-sk");
|
||||
assertThat(ossProperties.getSts().getSecurityToken())
|
||||
.isEqualTo("your-sts-token");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOSSClient1() {
|
||||
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");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOSSClient2() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.cloud.alicloud.oss.authorization-mode=STS")
|
||||
.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-sts-ak");
|
||||
assertThat(ossClient.getCredentialsProvider().getCredentials()
|
||||
.getSecretAccessKey()).isEqualTo("your-sts-sk");
|
||||
assertThat(ossClient.getCredentialsProvider().getCredentials()
|
||||
.getSecurityToken()).isEqualTo("your-sts-token");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 com.alibaba.alicloud.context.scx;
|
||||
|
||||
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 com.alibaba.alicloud.context.edas.EdasProperties;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
public class ScxAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(ScxContextAutoConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.alicloud.scx.group-id=1-2-3-4")
|
||||
.withPropertyValues("spring.cloud.alicloud.edas.namespace=cn-test");
|
||||
|
||||
@Test
|
||||
public void testSxcProperties() {
|
||||
this.contextRunner.run(context -> {
|
||||
assertThat(context.getBeansOfType(ScxProperties.class).size() == 1).isTrue();
|
||||
EdasProperties edasProperties = context.getBean(EdasProperties.class);
|
||||
ScxProperties scxProperties = context.getBean(ScxProperties.class);
|
||||
assertThat(scxProperties.getGroupId()).isEqualTo("1-2-3-4");
|
||||
assertThat(edasProperties.getNamespace()).isEqualTo("cn-test");
|
||||
assertThat(scxProperties.getDomainName()).isNull();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 com.alibaba.alicloud.context.sentinel;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
|
||||
import com.alibaba.alicloud.context.BaseAliCloudSpringApplication;
|
||||
import com.alibaba.alicloud.context.Constants;
|
||||
import com.alibaba.alicloud.utils.ChangeOrderUtils;
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@PrepareForTest({ EdasChangeOrderConfigurationFactory.class,
|
||||
SentinelAliCloudListener.class })
|
||||
public class SentinelAliCloudListenerTests extends BaseAliCloudSpringApplication {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
ChangeOrderUtils.mockChangeOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNacosParameterInitListener() {
|
||||
assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_ENDPOINT))
|
||||
.isEqualTo("testDomain");
|
||||
assertThat(System.getProperty(Constants.Sentinel.PROJECT_NAME))
|
||||
.isEqualTo("testProjectName");
|
||||
assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_NAMESPACE))
|
||||
.isEqualTo("testTenantId");
|
||||
assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_AK))
|
||||
.isEqualTo("testAK");
|
||||
assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_SK))
|
||||
.isEqualTo("testSK");
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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 com.alibaba.alicloud.context.sms;
|
||||
|
||||
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 com.alibaba.alicloud.context.AliCloudContextAutoConfiguration;
|
||||
import com.alibaba.alicloud.context.edas.EdasContextAutoConfiguration;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
public class SmsPropertiesTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(SmsContextAutoConfiguration.class,
|
||||
EdasContextAutoConfiguration.class,
|
||||
AliCloudContextAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void testConfigurationValueDefaultsAreAsExpected() {
|
||||
this.contextRunner.run(context -> {
|
||||
SmsProperties config = context.getBean(SmsProperties.class);
|
||||
assertThat(config.getReportQueueName()).isNull();
|
||||
assertThat(config.getUpQueueName()).isNull();
|
||||
assertThat(config.getConnectTimeout()).isEqualTo("10000");
|
||||
assertThat(config.getReadTimeout()).isEqualTo("10000");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationValuesAreCorrectlyLoaded() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.cloud.alicloud.sms.reportQueueName=q1",
|
||||
"spring.cloud.alicloud.sms.upQueueName=q2",
|
||||
"spring.cloud.alicloud.sms.connect-timeout=20",
|
||||
"spring.cloud.alicloud.sms.read-timeout=30")
|
||||
.run(context -> {
|
||||
SmsProperties config = context.getBean(SmsProperties.class);
|
||||
assertThat(config.getReportQueueName()).isEqualTo("q1");
|
||||
assertThat(config.getUpQueueName()).isEqualTo("q2");
|
||||
assertThat(config.getConnectTimeout()).isEqualTo("20");
|
||||
assertThat(config.getReadTimeout()).isEqualTo("30");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user