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

update nacos-config test case

This commit is contained in:
fangjian0423 2019-04-16 17:38:55 +08:00
parent 7ca6123fb0
commit 10da0cc19f

View File

@ -83,22 +83,23 @@ public class NacosConfigurationTests {
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.nacos-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 {
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.nacos-age=1"; 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.nacos-name=dev"; return "user.name=dev";
} }
if ("ext-config-common01.properties".equals(args[0]) if ("ext-config-common01.properties".equals(args[0])
@ -144,7 +145,7 @@ public class NacosConfigurationTests {
private NacosRefreshHistory refreshHistory; private NacosRefreshHistory refreshHistory;
@Test @Test
public void contextLoads() { 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);
@ -232,11 +233,11 @@ public class NacosConfigurationTests {
private void checkoutDataLoad() { private void checkoutDataLoad() {
Assert.assertEquals("dev", environment.getProperty("user.nacos-name")); Assert.assertEquals(environment.getProperty("user.name"), "dev");
Assert.assertEquals("1", environment.getProperty("user.nacos-age")); Assert.assertEquals(environment.getProperty("user.age"), "12");
} }
private void checkoutEndpoint() { 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();