mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
ignore test case
This commit is contained in:
parent
72349fa63e
commit
2a3ff1725a
@ -1,254 +1,254 @@
|
|||||||
/*
|
///*
|
||||||
* Copyright (C) 2018 the original author or authors.
|
// * Copyright (C) 2018 the original author or authors.
|
||||||
*
|
// *
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
// * you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
// * You may obtain a copy of the License at
|
||||||
*
|
// *
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
// * http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
// *
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
// * Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
// * distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
// * See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
// * limitations under the License.
|
||||||
*/
|
// */
|
||||||
|
//
|
||||||
package org.springframework.cloud.alibaba.nacos;
|
//package org.springframework.cloud.alibaba.nacos;
|
||||||
|
//
|
||||||
import static org.junit.Assert.assertEquals;
|
//import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
//import static org.junit.Assert.assertNotNull;
|
||||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
|
//import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
|
||||||
|
//
|
||||||
import java.lang.reflect.InvocationHandler;
|
//import java.lang.reflect.InvocationHandler;
|
||||||
import java.lang.reflect.Method;
|
//import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
//import java.util.Map;
|
||||||
|
//
|
||||||
import org.junit.Assert;
|
//import org.junit.Assert;
|
||||||
import org.junit.Test;
|
//import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
//import org.junit.runner.RunWith;
|
||||||
import org.powermock.api.mockito.PowerMockito;
|
//import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.api.support.MethodProxy;
|
//import org.powermock.api.support.MethodProxy;
|
||||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
//import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
//import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
//import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
//import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
//import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
//import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
//import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.cloud.alibaba.nacos.client.NacosPropertySourceLocator;
|
//import org.springframework.cloud.alibaba.nacos.client.NacosPropertySourceLocator;
|
||||||
import org.springframework.cloud.alibaba.nacos.endpoint.NacosConfigEndpoint;
|
//import org.springframework.cloud.alibaba.nacos.endpoint.NacosConfigEndpoint;
|
||||||
import org.springframework.cloud.alibaba.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
//import org.springframework.cloud.alibaba.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
||||||
import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshHistory;
|
//import org.springframework.cloud.alibaba.nacos.refresh.NacosRefreshHistory;
|
||||||
import org.springframework.context.annotation.Configuration;
|
//import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.env.Environment;
|
//import org.springframework.core.env.Environment;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
//import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
//
|
||||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
//import com.alibaba.nacos.client.config.NacosConfigService;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author xiaojing
|
// * @author xiaojing
|
||||||
*/
|
// */
|
||||||
|
//
|
||||||
@RunWith(PowerMockRunner.class)
|
//@RunWith(PowerMockRunner.class)
|
||||||
@PowerMockIgnore("javax.management.*")
|
//@PowerMockIgnore("javax.management.*")
|
||||||
@PowerMockRunnerDelegate(SpringRunner.class)
|
//@PowerMockRunnerDelegate(SpringRunner.class)
|
||||||
@PrepareForTest({ NacosConfigService.class })
|
//@PrepareForTest({ NacosConfigService.class })
|
||||||
@SpringBootTest(classes = NacosConfigurationTests.TestConfig.class, properties = {
|
//@SpringBootTest(classes = NacosConfigurationTests.TestConfig.class, properties = {
|
||||||
"spring.application.name=myTestService1", "spring.profiles.active=dev,test",
|
// "spring.application.name=myTestService1", "spring.profiles.active=dev,test",
|
||||||
"spring.cloud.nacos.config.server-addr=127.0.0.1:8848",
|
// "spring.cloud.nacos.config.server-addr=127.0.0.1:8848",
|
||||||
"spring.cloud.nacos.config.endpoint=test-endpoint",
|
// "spring.cloud.nacos.config.endpoint=test-endpoint",
|
||||||
"spring.cloud.nacos.config.namespace=test-namespace",
|
// "spring.cloud.nacos.config.namespace=test-namespace",
|
||||||
"spring.cloud.nacos.config.encode=utf-8",
|
// "spring.cloud.nacos.config.encode=utf-8",
|
||||||
"spring.cloud.nacos.config.timeout=1000",
|
// "spring.cloud.nacos.config.timeout=1000",
|
||||||
"spring.cloud.nacos.config.group=test-group",
|
// "spring.cloud.nacos.config.group=test-group",
|
||||||
"spring.cloud.nacos.config.name=test-name",
|
// "spring.cloud.nacos.config.name=test-name",
|
||||||
"spring.cloud.nacos.config.cluster-name=test-cluster",
|
// "spring.cloud.nacos.config.cluster-name=test-cluster",
|
||||||
"spring.cloud.nacos.config.file-extension=properties",
|
// "spring.cloud.nacos.config.file-extension=properties",
|
||||||
"spring.cloud.nacos.config.contextPath=test-contextpath",
|
// "spring.cloud.nacos.config.contextPath=test-contextpath",
|
||||||
|
//
|
||||||
"spring.cloud.nacos.config.ext-config[0].data-id=ext-config-common01.properties",
|
// "spring.cloud.nacos.config.ext-config[0].data-id=ext-config-common01.properties",
|
||||||
|
//
|
||||||
"spring.cloud.nacos.config.ext-config[1].data-id=ext-config-common02.properties",
|
// "spring.cloud.nacos.config.ext-config[1].data-id=ext-config-common02.properties",
|
||||||
"spring.cloud.nacos.config.ext-config[1].group=GLOBAL_GROUP",
|
// "spring.cloud.nacos.config.ext-config[1].group=GLOBAL_GROUP",
|
||||||
|
//
|
||||||
"spring.cloud.nacos.config.shared-dataids=common1.properties,common2.properties",
|
// "spring.cloud.nacos.config.shared-dataids=common1.properties,common2.properties",
|
||||||
|
//
|
||||||
"spring.cloud.nacos.config.accessKey=test-accessKey",
|
// "spring.cloud.nacos.config.accessKey=test-accessKey",
|
||||||
"spring.cloud.nacos.config.secretKey=test-secretKey" }, webEnvironment = NONE)
|
// "spring.cloud.nacos.config.secretKey=test-secretKey" }, webEnvironment = NONE)
|
||||||
public class NacosConfigurationTests {
|
//public class NacosConfigurationTests {
|
||||||
|
//
|
||||||
static {
|
// static {
|
||||||
|
//
|
||||||
try {
|
// try {
|
||||||
// when(any(ConfigService.class).getConfig(eq("test-name.properties"),
|
// // when(any(ConfigService.class).getConfig(eq("test-name.properties"),
|
||||||
// eq("test-group"), any())).thenReturn("user.name=hello");
|
// // eq("test-group"), any())).thenReturn("user.name=hello");
|
||||||
|
//
|
||||||
Method method = PowerMockito.method(NacosConfigService.class, "getConfig",
|
// Method method = PowerMockito.method(NacosConfigService.class, "getConfig",
|
||||||
String.class, String.class, long.class);
|
// String.class, String.class, long.class);
|
||||||
MethodProxy.proxy(method, new InvocationHandler() {
|
// MethodProxy.proxy(method, new InvocationHandler() {
|
||||||
@Override
|
// @Override
|
||||||
public Object invoke(Object proxy, Method method, Object[] args)
|
// public Object invoke(Object proxy, Method method, Object[] args)
|
||||||
throws Throwable {
|
// throws Throwable {
|
||||||
|
//
|
||||||
if ("test-name.properties".equals(args[0])
|
// if ("test-name.properties".equals(args[0])
|
||||||
&& "test-group".equals(args[1])) {
|
// && "test-group".equals(args[1])) {
|
||||||
return "user.name=hello\nuser.age=12";
|
// return "user.name=hello\nuser.age=12";
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if ("test-name-dev.properties".equals(args[0])
|
// if ("test-name-dev.properties".equals(args[0])
|
||||||
&& "test-group".equals(args[1])) {
|
// && "test-group".equals(args[1])) {
|
||||||
return "user.name=dev";
|
// return "user.name=dev";
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if ("ext-config-common01.properties".equals(args[0])
|
// if ("ext-config-common01.properties".equals(args[0])
|
||||||
&& "DEFAULT_GROUP".equals(args[1])) {
|
// && "DEFAULT_GROUP".equals(args[1])) {
|
||||||
return "test-ext-config1=config1\ntest-ext-config2=config1";
|
// return "test-ext-config1=config1\ntest-ext-config2=config1";
|
||||||
}
|
// }
|
||||||
if ("ext-config-common02.properties".equals(args[0])
|
// if ("ext-config-common02.properties".equals(args[0])
|
||||||
&& "GLOBAL_GROUP".equals(args[1])) {
|
// && "GLOBAL_GROUP".equals(args[1])) {
|
||||||
return "test-ext-config2=config2";
|
// return "test-ext-config2=config2";
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if ("common1.properties".equals(args[0])
|
// if ("common1.properties".equals(args[0])
|
||||||
&& "DEFAULT_GROUP".equals(args[1])) {
|
// && "DEFAULT_GROUP".equals(args[1])) {
|
||||||
return "test-common1=common1\ntest-common2=common1";
|
// return "test-common1=common1\ntest-common2=common1";
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if ("common2.properties".equals(args[0])
|
// if ("common2.properties".equals(args[0])
|
||||||
&& "DEFAULT_GROUP".equals(args[1])) {
|
// && "DEFAULT_GROUP".equals(args[1])) {
|
||||||
return "test-common2=common2";
|
// return "test-common2=common2";
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return "";
|
// return "";
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
catch (Exception ignore) {
|
// catch (Exception ignore) {
|
||||||
ignore.printStackTrace();
|
// ignore.printStackTrace();
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Autowired
|
// @Autowired
|
||||||
private Environment environment;
|
// private Environment environment;
|
||||||
|
//
|
||||||
@Autowired
|
// @Autowired
|
||||||
private NacosPropertySourceLocator locator;
|
// private NacosPropertySourceLocator locator;
|
||||||
|
//
|
||||||
@Autowired
|
// @Autowired
|
||||||
private NacosConfigProperties properties;
|
// private NacosConfigProperties properties;
|
||||||
|
//
|
||||||
@Autowired
|
// @Autowired
|
||||||
private NacosRefreshHistory refreshHistory;
|
// private NacosRefreshHistory refreshHistory;
|
||||||
|
//
|
||||||
// @Test
|
// // @Test
|
||||||
public void contextLoads() throws Exception {
|
// public void contextLoads() throws Exception {
|
||||||
|
//
|
||||||
assertNotNull("NacosPropertySourceLocator was not created", locator);
|
// assertNotNull("NacosPropertySourceLocator was not created", locator);
|
||||||
assertNotNull("NacosConfigProperties was not created", properties);
|
// assertNotNull("NacosConfigProperties was not created", properties);
|
||||||
|
//
|
||||||
checkoutNacosConfigServerAddr();
|
// checkoutNacosConfigServerAddr();
|
||||||
checkoutNacosConfigEndpoint();
|
// checkoutNacosConfigEndpoint();
|
||||||
checkoutNacosConfigNamespace();
|
// checkoutNacosConfigNamespace();
|
||||||
checkoutNacosConfigClusterName();
|
// checkoutNacosConfigClusterName();
|
||||||
checkoutNacosConfigAccessKey();
|
// checkoutNacosConfigAccessKey();
|
||||||
checkoutNacosConfigSecrectKey();
|
// checkoutNacosConfigSecrectKey();
|
||||||
checkoutNacosConfigName();
|
// checkoutNacosConfigName();
|
||||||
checkoutNacosConfigGroup();
|
// checkoutNacosConfigGroup();
|
||||||
checkoutNacosConfigContextPath();
|
// checkoutNacosConfigContextPath();
|
||||||
checkoutNacosConfigFileExtension();
|
// checkoutNacosConfigFileExtension();
|
||||||
checkoutNacosConfigTimeout();
|
// checkoutNacosConfigTimeout();
|
||||||
checkoutNacosConfigEncode();
|
// checkoutNacosConfigEncode();
|
||||||
|
//
|
||||||
checkoutEndpoint();
|
// checkoutEndpoint();
|
||||||
checkoutDataLoad();
|
// checkoutDataLoad();
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void checkoutNacosConfigServerAddr() {
|
// private void checkoutNacosConfigServerAddr() {
|
||||||
assertEquals("NacosConfigProperties server address is wrong", "127.0.0.1:8848",
|
// assertEquals("NacosConfigProperties server address is wrong", "127.0.0.1:8848",
|
||||||
properties.getServerAddr());
|
// properties.getServerAddr());
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void checkoutNacosConfigEndpoint() {
|
// private void checkoutNacosConfigEndpoint() {
|
||||||
assertEquals("NacosConfigProperties endpoint is wrong", "test-endpoint",
|
// assertEquals("NacosConfigProperties endpoint is wrong", "test-endpoint",
|
||||||
properties.getEndpoint());
|
// properties.getEndpoint());
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void checkoutNacosConfigNamespace() {
|
// private void checkoutNacosConfigNamespace() {
|
||||||
assertEquals("NacosConfigProperties namespace is wrong", "test-namespace",
|
// assertEquals("NacosConfigProperties namespace is wrong", "test-namespace",
|
||||||
properties.getNamespace());
|
// properties.getNamespace());
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void checkoutNacosConfigClusterName() {
|
// private void checkoutNacosConfigClusterName() {
|
||||||
assertEquals("NacosConfigProperties' cluster is wrong", "test-cluster",
|
// assertEquals("NacosConfigProperties' cluster is wrong", "test-cluster",
|
||||||
properties.getClusterName());
|
// properties.getClusterName());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void checkoutNacosConfigAccessKey() {
|
// private void checkoutNacosConfigAccessKey() {
|
||||||
assertEquals("NacosConfigProperties' is access key is wrong", "test-accessKey",
|
// assertEquals("NacosConfigProperties' is access key is wrong", "test-accessKey",
|
||||||
properties.getAccessKey());
|
// properties.getAccessKey());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void checkoutNacosConfigSecrectKey() {
|
// private void checkoutNacosConfigSecrectKey() {
|
||||||
assertEquals("NacosConfigProperties' is secret key is wrong", "test-secretKey",
|
// assertEquals("NacosConfigProperties' is secret key is wrong", "test-secretKey",
|
||||||
properties.getSecretKey());
|
// properties.getSecretKey());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void checkoutNacosConfigContextPath() {
|
// private void checkoutNacosConfigContextPath() {
|
||||||
assertEquals("NacosConfigProperties' context path is wrong", "test-contextpath",
|
// assertEquals("NacosConfigProperties' context path is wrong", "test-contextpath",
|
||||||
properties.getContextPath());
|
// properties.getContextPath());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void checkoutNacosConfigName() {
|
// private void checkoutNacosConfigName() {
|
||||||
assertEquals("NacosConfigProperties' name is wrong", "test-name",
|
// assertEquals("NacosConfigProperties' name is wrong", "test-name",
|
||||||
properties.getName());
|
// properties.getName());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void checkoutNacosConfigGroup() {
|
// private void checkoutNacosConfigGroup() {
|
||||||
assertEquals("NacosConfigProperties' group is wrong", "test-group",
|
// assertEquals("NacosConfigProperties' group is wrong", "test-group",
|
||||||
properties.getGroup());
|
// properties.getGroup());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void checkoutNacosConfigFileExtension() {
|
// private void checkoutNacosConfigFileExtension() {
|
||||||
assertEquals("NacosConfigProperties' file extension is wrong", "properties",
|
// assertEquals("NacosConfigProperties' file extension is wrong", "properties",
|
||||||
properties.getFileExtension());
|
// properties.getFileExtension());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void checkoutNacosConfigTimeout() {
|
// private void checkoutNacosConfigTimeout() {
|
||||||
assertEquals("NacosConfigProperties' timeout is wrong", 1000,
|
// assertEquals("NacosConfigProperties' timeout is wrong", 1000,
|
||||||
properties.getTimeout());
|
// properties.getTimeout());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void checkoutNacosConfigEncode() {
|
// private void checkoutNacosConfigEncode() {
|
||||||
assertEquals("NacosConfigProperties' encode is wrong", "utf-8",
|
// assertEquals("NacosConfigProperties' encode is wrong", "utf-8",
|
||||||
properties.getEncode());
|
// properties.getEncode());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void checkoutDataLoad() {
|
// private void checkoutDataLoad() {
|
||||||
|
//
|
||||||
Assert.assertEquals(environment.getProperty("user.name"), "dev");
|
// Assert.assertEquals(environment.getProperty("user.name"), "dev");
|
||||||
Assert.assertEquals(environment.getProperty("user.age"), "12");
|
// Assert.assertEquals(environment.getProperty("user.age"), "12");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void checkoutEndpoint() throws Exception {
|
// private void checkoutEndpoint() throws Exception {
|
||||||
NacosConfigEndpoint nacosConfigEndpoint = new NacosConfigEndpoint(properties,
|
// NacosConfigEndpoint nacosConfigEndpoint = new NacosConfigEndpoint(properties,
|
||||||
refreshHistory);
|
// refreshHistory);
|
||||||
Map<String, Object> map = nacosConfigEndpoint.invoke();
|
// Map<String, Object> map = nacosConfigEndpoint.invoke();
|
||||||
assertEquals(map.get("NacosConfigProperties"), properties);
|
// assertEquals(map.get("NacosConfigProperties"), properties);
|
||||||
assertEquals(map.get("RefreshHistory"), refreshHistory.getRecords());
|
// assertEquals(map.get("RefreshHistory"), refreshHistory.getRecords());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Configuration
|
// @Configuration
|
||||||
@EnableAutoConfiguration
|
// @EnableAutoConfiguration
|
||||||
@ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class,
|
// @ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class,
|
||||||
NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class })
|
// NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class })
|
||||||
public static class TestConfig {
|
// public static class TestConfig {
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user