mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
format code with maven plugins
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -16,16 +16,16 @@
|
||||
|
||||
package com.alibaba.cloud.nacos;
|
||||
|
||||
import com.alibaba.cloud.nacos.refresh.NacosContextRefresher;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosRefreshProperties;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.alibaba.cloud.nacos.refresh.NacosContextRefresher;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosRefreshProperties;
|
||||
|
||||
/**
|
||||
* @author juven.xuxb
|
||||
*/
|
||||
@@ -67,4 +67,5 @@ public class NacosConfigAutoConfiguration {
|
||||
return new NacosContextRefresher(nacosRefreshProperties, refreshHistory,
|
||||
nacosConfigManager.getConfigService());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package com.alibaba.cloud.nacos;
|
||||
|
||||
import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* 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
|
||||
*
|
||||
* https://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,
|
||||
@@ -14,16 +13,18 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.nacos;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:liaochunyhm@live.com">liaochuntao</a>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -16,38 +16,37 @@
|
||||
|
||||
package com.alibaba.cloud.nacos;
|
||||
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.MAX_RETRY;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_RETRY_TIME;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_RETRY_TIME;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.MAX_RETRY;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
|
||||
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
|
||||
|
||||
/**
|
||||
* nacos properties
|
||||
* Nacos properties.
|
||||
*
|
||||
* @author leijuan
|
||||
* @author xiaojing
|
||||
@@ -57,6 +56,9 @@ import com.alibaba.nacos.api.config.ConfigService;
|
||||
@ConfigurationProperties(NacosConfigProperties.PREFIX)
|
||||
public class NacosConfigProperties {
|
||||
|
||||
/**
|
||||
* Prefix of {@link NacosConfigProperties}.
|
||||
*/
|
||||
public static final String PREFIX = "spring.cloud.nacos.config";
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
@@ -101,6 +103,7 @@ public class NacosConfigProperties {
|
||||
* nacos config dataId prefix.
|
||||
*/
|
||||
private String prefix;
|
||||
|
||||
/**
|
||||
* the suffix of nacos config dataId, also the file extension of config content.
|
||||
*/
|
||||
@@ -351,60 +354,9 @@ public class NacosConfigProperties {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static class Config {
|
||||
/**
|
||||
* the data id of extended configuration
|
||||
*/
|
||||
private String dataId;
|
||||
/**
|
||||
* the group of extended configuration, the default value is DEFAULT_GROUP
|
||||
*/
|
||||
private String group = "DEFAULT_GROUP";
|
||||
/**
|
||||
* whether to support dynamic refresh, the default does not support .
|
||||
*/
|
||||
private boolean refresh = false;
|
||||
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public boolean isRefresh() {
|
||||
return refresh;
|
||||
}
|
||||
|
||||
public void setRefresh(boolean refresh) {
|
||||
this.refresh = refresh;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NacosConfigProperties{" + "serverAddr='" + serverAddr + '\''
|
||||
+ ", encode='" + encode + '\'' + ", group='" + group + '\'' + ", prefix='"
|
||||
+ prefix + '\'' + ", fileExtension='" + fileExtension + '\''
|
||||
+ ", timeout=" + timeout + ", endpoint='" + endpoint + '\''
|
||||
+ ", namespace='" + namespace + '\'' + ", accessKey='" + accessKey + '\''
|
||||
+ ", secretKey='" + secretKey + '\'' + ", contextPath='" + contextPath
|
||||
+ '\'' + ", clusterName='" + clusterName + '\'' + ", name='" + name + '\''
|
||||
+ ", sharedDataids='" + sharedDataids + '\'' + ", refreshableDataids='"
|
||||
+ refreshableDataids + '\'' + ", extConfig=" + extConfig + '}';
|
||||
}
|
||||
|
||||
/**
|
||||
* @see NacosConfigManager#getConfigService()
|
||||
* @see NacosConfigManager#getConfigService() .
|
||||
* @return ConfigService
|
||||
*/
|
||||
@Deprecated
|
||||
public ConfigService configServiceInstance() {
|
||||
@@ -442,4 +394,60 @@ public class NacosConfigProperties {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NacosConfigProperties{" + "serverAddr='" + serverAddr + '\''
|
||||
+ ", encode='" + encode + '\'' + ", group='" + group + '\'' + ", prefix='"
|
||||
+ prefix + '\'' + ", fileExtension='" + fileExtension + '\''
|
||||
+ ", timeout=" + timeout + ", endpoint='" + endpoint + '\''
|
||||
+ ", namespace='" + namespace + '\'' + ", accessKey='" + accessKey + '\''
|
||||
+ ", secretKey='" + secretKey + '\'' + ", contextPath='" + contextPath
|
||||
+ '\'' + ", clusterName='" + clusterName + '\'' + ", name='" + name + '\''
|
||||
+ ", sharedDataids='" + sharedDataids + '\'' + ", refreshableDataids='"
|
||||
+ refreshableDataids + '\'' + ", extConfig=" + extConfig + '}';
|
||||
}
|
||||
|
||||
public static class Config {
|
||||
|
||||
/**
|
||||
* the data id of extended configuration.
|
||||
*/
|
||||
private String dataId;
|
||||
|
||||
/**
|
||||
* the group of extended configuration, the default value is DEFAULT_GROUP.
|
||||
*/
|
||||
private String group = "DEFAULT_GROUP";
|
||||
|
||||
/**
|
||||
* whether to support dynamic refresh, the default does not support .
|
||||
*/
|
||||
private boolean refresh = false;
|
||||
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public boolean isRefresh() {
|
||||
return refresh;
|
||||
}
|
||||
|
||||
public void setRefresh(boolean refresh) {
|
||||
this.refresh = refresh;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -16,25 +16,29 @@
|
||||
|
||||
package com.alibaba.cloud.nacos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.alibaba.cloud.nacos.client.NacosPropertySource;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
* @author pbting
|
||||
*/
|
||||
public class NacosPropertySourceRepository {
|
||||
public final class NacosPropertySourceRepository {
|
||||
|
||||
private final static ConcurrentHashMap<String, NacosPropertySource> NACOS_PROPERTY_SOURCE_REPOSITORY = new ConcurrentHashMap<>();
|
||||
|
||||
private NacosPropertySourceRepository() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all nacos properties from application context
|
||||
* @return all nacos properties from application context.
|
||||
*/
|
||||
public static List<NacosPropertySource> getAll() {
|
||||
return Lists.newArrayList(NACOS_PROPERTY_SOURCE_REPOSITORY.values());
|
||||
return new ArrayList<>(NACOS_PROPERTY_SOURCE_REPOSITORY.values());
|
||||
}
|
||||
|
||||
public static void collectNacosPropertySources(
|
||||
@@ -44,7 +48,7 @@ public class NacosPropertySourceRepository {
|
||||
}
|
||||
|
||||
public static NacosPropertySource getNacosPropertySource(String dataId) {
|
||||
|
||||
return NACOS_PROPERTY_SOURCE_REPOSITORY.get(dataId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -28,22 +28,22 @@ import org.springframework.core.env.MapPropertySource;
|
||||
public class NacosPropertySource extends MapPropertySource {
|
||||
|
||||
/**
|
||||
* Nacos Group
|
||||
* Nacos Group.
|
||||
*/
|
||||
private final String group;
|
||||
|
||||
/**
|
||||
* Nacos dataID
|
||||
* Nacos dataID.
|
||||
*/
|
||||
private final String dataId;
|
||||
|
||||
/**
|
||||
* timestamp the property get
|
||||
* timestamp the property get.
|
||||
*/
|
||||
private final Date timestamp;
|
||||
|
||||
/**
|
||||
* Whether to support dynamic refresh for this Property Source
|
||||
* Whether to support dynamic refresh for this Property Source.
|
||||
*/
|
||||
private final boolean isRefreshable;
|
||||
|
||||
@@ -71,4 +71,5 @@ public class NacosPropertySource extends MapPropertySource {
|
||||
public boolean isRefreshable() {
|
||||
return isRefreshable;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -22,25 +22,28 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosPropertySourceRepository;
|
||||
import com.alibaba.cloud.nacos.parser.NacosDataParserHandler;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
* @author pbting
|
||||
*/
|
||||
public class NacosPropertySourceBuilder {
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(NacosPropertySourceBuilder.class);
|
||||
|
||||
private static final Properties EMPTY_PROPERTIES = new Properties();
|
||||
|
||||
private ConfigService configService;
|
||||
|
||||
private long timeout;
|
||||
|
||||
public NacosPropertySourceBuilder(ConfigService configService, long timeout) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -19,8 +19,14 @@ package com.alibaba.cloud.nacos.client;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosConfigManager;
|
||||
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
||||
import com.alibaba.cloud.nacos.NacosPropertySourceRepository;
|
||||
import com.alibaba.cloud.nacos.parser.NacosDataParserHandler;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosContextRefresher;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.core.env.CompositePropertySource;
|
||||
@@ -29,12 +35,6 @@ import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
||||
import com.alibaba.cloud.nacos.NacosPropertySourceRepository;
|
||||
import com.alibaba.cloud.nacos.parser.NacosDataParserHandler;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosContextRefresher;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
* @author pbting
|
||||
@@ -44,9 +44,13 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(NacosPropertySourceLocator.class);
|
||||
|
||||
private static final String NACOS_PROPERTY_SOURCE_NAME = "NACOS";
|
||||
|
||||
private static final String SEP1 = "-";
|
||||
|
||||
private static final String DOT = ".";
|
||||
|
||||
private static final String SHARED_CONFIG_SEPARATOR_CHAR = "[,]";
|
||||
|
||||
private NacosPropertySourceBuilder nacosPropertySourceBuilder;
|
||||
@@ -197,7 +201,7 @@ public class NacosPropertySourceLocator implements PropertySourceLocator {
|
||||
|
||||
/**
|
||||
* Add the nacos configuration to the first place and maybe ignore the empty
|
||||
* configuration
|
||||
* configuration.
|
||||
*/
|
||||
private void addFirstPropertySource(final CompositePropertySource composite,
|
||||
NacosPropertySource nacosPropertySource, boolean ignoreEmpty) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -34,4 +34,5 @@ public class NacosConnectionFailureAnalyzer
|
||||
return new FailureAnalysis("Application failed to connect to Nacos server",
|
||||
"check your Nacos server config", cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -23,16 +23,17 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
||||
import com.alibaba.cloud.nacos.NacosPropertySourceRepository;
|
||||
import com.alibaba.cloud.nacos.client.NacosPropertySource;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||
|
||||
/**
|
||||
* Endpoint for Nacos, contains config data and refresh history
|
||||
* Endpoint for Nacos, contains config data and refresh history.
|
||||
*
|
||||
* @author xiaojing
|
||||
*/
|
||||
@Endpoint(id = "nacos-config")
|
||||
@@ -70,4 +71,5 @@ public class NacosConfigEndpoint {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -17,6 +17,9 @@
|
||||
package com.alibaba.cloud.nacos.endpoint;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosConfigManager;
|
||||
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
@@ -26,14 +29,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
*/
|
||||
@ConditionalOnWebApplication
|
||||
@ConditionalOnClass(value = Endpoint.class)
|
||||
@ConditionalOnClass(Endpoint.class)
|
||||
@ConditionalOnProperty(name = "spring.cloud.nacos.config.enabled", matchIfMissing = true)
|
||||
public class NacosConfigEndpointAutoConfiguration {
|
||||
|
||||
@@ -57,4 +57,5 @@ public class NacosConfigEndpointAutoConfiguration {
|
||||
public NacosConfigHealthIndicator nacosConfigHealthIndicator() {
|
||||
return new NacosConfigHealthIndicator(nacosConfigManager.getConfigService());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package com.alibaba.cloud.nacos.endpoint;
|
||||
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
|
||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
*/
|
||||
@@ -39,4 +39,5 @@ public class NacosConfigHealthIndicator extends AbstractHealthIndicator {
|
||||
String status = configService.getServerStatus();
|
||||
builder.status(status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -29,9 +29,11 @@ import com.alibaba.nacos.client.utils.StringUtils;
|
||||
public abstract class AbstractNacosDataParser {
|
||||
|
||||
protected static final String DOT = ".";
|
||||
|
||||
protected static final String VALUE = "value";
|
||||
|
||||
private String extension;
|
||||
|
||||
private AbstractNacosDataParser nextParser;
|
||||
|
||||
protected AbstractNacosDataParser(String extension) {
|
||||
@@ -41,7 +43,11 @@ public abstract class AbstractNacosDataParser {
|
||||
this.extension = extension.toLowerCase();
|
||||
}
|
||||
|
||||
/** Verify file extensions */
|
||||
/**
|
||||
* Verify dataId extensions.
|
||||
* @param extension file extension. json or xml or yml or yaml or properties
|
||||
* @return valid or not
|
||||
*/
|
||||
public final boolean checkFileExtension(String extension) {
|
||||
if (this.isLegal(extension.toLowerCase())) {
|
||||
return true;
|
||||
@@ -53,7 +59,13 @@ public abstract class AbstractNacosDataParser {
|
||||
|
||||
}
|
||||
|
||||
/** Parsing nacos configuration content */
|
||||
/**
|
||||
* Parsing nacos configuration content.
|
||||
* @param data config data from Nacos
|
||||
* @param extension file extension. json or xml or yml or yaml or properties
|
||||
* @return result of Properties
|
||||
* @throws IOException thrown if there is a problem parsing config.
|
||||
*/
|
||||
public final Properties parseNacosData(String data, String extension)
|
||||
throws IOException {
|
||||
if (extension == null || extension.length() < 1) {
|
||||
@@ -68,7 +80,12 @@ public abstract class AbstractNacosDataParser {
|
||||
return this.nextParser.parseNacosData(data, extension);
|
||||
}
|
||||
|
||||
/** Core logic for parsing */
|
||||
/**
|
||||
* Core logic for parsing.
|
||||
* @param data config from Nacos
|
||||
* @return result of Properties
|
||||
* @throws IOException thrown if there is a problem parsing config.
|
||||
*/
|
||||
protected abstract Properties doParse(String data) throws IOException;
|
||||
|
||||
protected AbstractNacosDataParser setNextParser(AbstractNacosDataParser nextParser) {
|
||||
@@ -76,7 +93,6 @@ public abstract class AbstractNacosDataParser {
|
||||
return this;
|
||||
}
|
||||
|
||||
/** add the next parser */
|
||||
public AbstractNacosDataParser addNextParser(AbstractNacosDataParser nextParser) {
|
||||
if (this.nextParser == null) {
|
||||
this.nextParser = nextParser;
|
||||
@@ -93,7 +109,7 @@ public abstract class AbstractNacosDataParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate key-value pairs from the map
|
||||
* Generate key-value pairs from the map.
|
||||
*/
|
||||
protected Properties generateProperties(Map<String, String> map) {
|
||||
if (null == map || map.isEmpty()) {
|
||||
@@ -112,7 +128,7 @@ public abstract class AbstractNacosDataParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the key ending in `value`,if you need
|
||||
* Reload the key ending in `value` if need.
|
||||
*/
|
||||
protected Map<String, String> reloadMap(Map<String, String> map) {
|
||||
if (map == null || map.isEmpty()) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -30,6 +30,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
* @author zkz
|
||||
*/
|
||||
public class NacosDataJsonParser extends AbstractNacosDataParser {
|
||||
|
||||
protected NacosDataJsonParser() {
|
||||
super("json");
|
||||
}
|
||||
@@ -44,7 +45,10 @@ public class NacosDataJsonParser extends AbstractNacosDataParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON to Map
|
||||
* JSON to Map.
|
||||
* @param json json data
|
||||
* @return the map convert by json string
|
||||
* @throws IOException thrown if there is a problem parsing config.
|
||||
*/
|
||||
public static Map<String, String> parseJSON2Map(String json) throws IOException {
|
||||
Map<String, String> map = new HashMap<>(32);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -22,7 +22,7 @@ import java.util.Properties;
|
||||
/**
|
||||
* @author zkz
|
||||
*/
|
||||
public class NacosDataParserHandler {
|
||||
public final class NacosDataParserHandler {
|
||||
|
||||
private AbstractNacosDataParser parser;
|
||||
|
||||
@@ -30,7 +30,13 @@ public class NacosDataParserHandler {
|
||||
parser = this.createParser();
|
||||
}
|
||||
|
||||
/** Parsing nacos configuration content */
|
||||
/**
|
||||
* Parsing nacos configuration content.
|
||||
* @param data config from Nacos
|
||||
* @param extension file extension. json or xml or yml or yaml or properties
|
||||
* @return result of properties
|
||||
* @throws IOException thrown if there is a problem parsing config.
|
||||
*/
|
||||
public Properties parseNacosData(String data, String extension) throws IOException {
|
||||
if (null == parser) {
|
||||
parser = this.createParser();
|
||||
@@ -38,7 +44,11 @@ public class NacosDataParserHandler {
|
||||
return parser.parseNacosData(data, extension);
|
||||
}
|
||||
|
||||
/** check the validity of file extensions in dataid */
|
||||
/**
|
||||
* check the validity of file extensions in dataid.
|
||||
* @param dataIdAry array of dataId
|
||||
* @return dataId handle success or not
|
||||
*/
|
||||
public boolean checkDataId(String... dataIdAry) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (String dataId : dataIdAry) {
|
||||
@@ -70,6 +80,9 @@ public class NacosDataParserHandler {
|
||||
}
|
||||
|
||||
private static class ParserHandler {
|
||||
|
||||
private static final NacosDataParserHandler HANDLER = new NacosDataParserHandler();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -35,4 +35,5 @@ public class NacosDataPropertiesParser extends AbstractNacosDataParser {
|
||||
properties.load(new StringReader(data));
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -25,17 +25,16 @@ import java.util.Properties;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* With relatively few usage scenarios, only simple parsing is performed to reduce jar
|
||||
* dependencies
|
||||
* dependencies.
|
||||
*
|
||||
* @author zkz
|
||||
*/
|
||||
@@ -55,9 +54,7 @@ public class NacosDataXmlParser extends AbstractNacosDataParser {
|
||||
}
|
||||
|
||||
private Map<String, String> parseXml2Map(String xml) throws IOException {
|
||||
xml = xml.replaceAll("\\r", "")
|
||||
.replaceAll("\\n", "")
|
||||
.replaceAll("\\t", "");
|
||||
xml = xml.replaceAll("\\r", "").replaceAll("\\n", "").replaceAll("\\t", "");
|
||||
Map<String, String> map = new HashMap<>(32);
|
||||
try {
|
||||
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance()
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -36,4 +36,5 @@ public class NacosDataYamlParser extends AbstractNacosDataParser {
|
||||
yamlFactory.setResources(new ByteArrayResource(data.getBytes()));
|
||||
return yamlFactory.getObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -26,8 +26,14 @@ import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosPropertySourceRepository;
|
||||
import com.alibaba.cloud.nacos.client.NacosPropertySource;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.config.listener.Listener;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.cloud.endpoint.event.RefreshEvent;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -35,12 +41,6 @@ import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosPropertySourceRepository;
|
||||
import com.alibaba.cloud.nacos.client.NacosPropertySource;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.config.listener.Listener;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
|
||||
/**
|
||||
* On application start up, NacosContextRefresher add nacos listeners to all application
|
||||
* level dataIds, when there is a change in the data, listeners will refresh
|
||||
@@ -150,4 +150,5 @@ public class NacosContextRefresher
|
||||
public static void refreshCountIncrement() {
|
||||
REFRESH_COUNT.incrementAndGet();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -44,6 +44,7 @@ public class NacosRefreshHistory {
|
||||
public LinkedList<Record> getRecords() {
|
||||
return records;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Record {
|
||||
@@ -54,7 +55,7 @@ class Record {
|
||||
|
||||
private final String md5;
|
||||
|
||||
public Record(String timestamp, String dataId, String md5) {
|
||||
Record(String timestamp, String dataId, String md5) {
|
||||
this.timestamp = timestamp;
|
||||
this.dataId = dataId;
|
||||
this.md5 = md5;
|
||||
@@ -71,4 +72,5 @@ class Record {
|
||||
public String getMd5() {
|
||||
return md5;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -35,4 +35,5 @@ public class NacosRefreshProperties {
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
/*
|
||||
* Copyright 2013-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
|
||||
*
|
||||
* https://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.cloud.nacos;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
@@ -12,15 +27,18 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:lyuzb@lyuzb.com">lyuzb</a>
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = NacosConfigPropertiesServerAddressBothLevelTests.TestConfig.class, properties = {
|
||||
"spring.cloud.nacos.config.server-addr=321,321,321,321:8848",
|
||||
"spring.cloud.nacos.server-addr=123.123.123.123:8848" }, webEnvironment = RANDOM_PORT)
|
||||
@SpringBootTest(
|
||||
classes = NacosConfigPropertiesServerAddressBothLevelTests.TestConfig.class,
|
||||
properties = { "spring.cloud.nacos.config.server-addr=321,321,321,321:8848",
|
||||
"spring.cloud.nacos.server-addr=123.123.123.123:8848" },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class NacosConfigPropertiesServerAddressBothLevelTests {
|
||||
|
||||
@Autowired
|
||||
@@ -28,8 +46,7 @@ public class NacosConfigPropertiesServerAddressBothLevelTests {
|
||||
|
||||
@Test
|
||||
public void testGetServerAddr() {
|
||||
assertEquals("NacosConfigProperties server address was wrong",
|
||||
"321,321,321,321:8848", properties.getServerAddr());
|
||||
assertThat(properties.getServerAddr()).isEqualTo("321,321,321,321:8848");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -37,5 +54,7 @@ public class NacosConfigPropertiesServerAddressBothLevelTests {
|
||||
@ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class,
|
||||
NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class })
|
||||
public static class TestConfig {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
/*
|
||||
* Copyright 2013-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
|
||||
*
|
||||
* https://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.cloud.nacos;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
@@ -12,14 +27,17 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:lyuzb@lyuzb.com">lyuzb</a>
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = NacosConfigPropertiesServerAddressTopLevelTests.TestConfig.class, properties = {
|
||||
"spring.cloud.nacos.server-addr=123.123.123.123:8848" }, webEnvironment = RANDOM_PORT)
|
||||
@SpringBootTest(
|
||||
classes = NacosConfigPropertiesServerAddressTopLevelTests.TestConfig.class,
|
||||
properties = { "spring.cloud.nacos.server-addr=123.123.123.123:8848" },
|
||||
webEnvironment = RANDOM_PORT)
|
||||
public class NacosConfigPropertiesServerAddressTopLevelTests {
|
||||
|
||||
@Autowired
|
||||
@@ -27,8 +45,7 @@ public class NacosConfigPropertiesServerAddressTopLevelTests {
|
||||
|
||||
@Test
|
||||
public void testGetServerAddr() {
|
||||
assertEquals("NacosConfigProperties server address was wrong",
|
||||
"123.123.123.123:8848", properties.getServerAddr());
|
||||
assertThat(properties.getServerAddr()).isEqualTo("123.123.123.123:8848");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -36,5 +53,7 @@ public class NacosConfigPropertiesServerAddressTopLevelTests {
|
||||
@ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class,
|
||||
NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class })
|
||||
public static class TestConfig {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -16,13 +16,12 @@
|
||||
|
||||
package com.alibaba.cloud.nacos;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.Assert;
|
||||
import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator;
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
@@ -31,6 +30,7 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
@@ -39,9 +39,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator;
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
@@ -51,18 +50,20 @@ import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
@PowerMockIgnore("javax.management.*")
|
||||
@PowerMockRunnerDelegate(SpringRunner.class)
|
||||
@PrepareForTest({ NacosConfigService.class })
|
||||
@SpringBootTest(classes = NacosConfigurationExtConfigTests.TestConfig.class, properties = {
|
||||
"spring.application.name=myTestService1", "spring.profiles.active=dev,test",
|
||||
"spring.cloud.nacos.config.server-addr=127.0.0.1:8848",
|
||||
"spring.cloud.nacos.config.encode=utf-8",
|
||||
"spring.cloud.nacos.config.timeout=1000",
|
||||
"spring.cloud.nacos.config.file-extension=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].group=GLOBAL_GROUP",
|
||||
"spring.cloud.nacos.config.shared-dataids=common1.properties,common2.properties",
|
||||
"spring.cloud.nacos.config.accessKey=test-accessKey",
|
||||
"spring.cloud.nacos.config.secretKey=test-secretKey" }, webEnvironment = NONE)
|
||||
@SpringBootTest(classes = NacosConfigurationExtConfigTests.TestConfig.class,
|
||||
properties = { "spring.application.name=myTestService1",
|
||||
"spring.profiles.active=dev,test",
|
||||
"spring.cloud.nacos.config.server-addr=127.0.0.1:8848",
|
||||
"spring.cloud.nacos.config.encode=utf-8",
|
||||
"spring.cloud.nacos.config.timeout=1000",
|
||||
"spring.cloud.nacos.config.file-extension=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].group=GLOBAL_GROUP",
|
||||
"spring.cloud.nacos.config.shared-dataids=common1.properties,common2.properties",
|
||||
"spring.cloud.nacos.config.accessKey=test-accessKey",
|
||||
"spring.cloud.nacos.config.secretKey=test-secretKey" },
|
||||
webEnvironment = NONE)
|
||||
public class NacosConfigurationExtConfigTests {
|
||||
|
||||
static {
|
||||
@@ -130,14 +131,13 @@ public class NacosConfigurationExtConfigTests {
|
||||
@Test
|
||||
public void contextLoads() throws Exception {
|
||||
|
||||
assertNotNull("NacosPropertySourceLocator was not created", locator);
|
||||
assertNotNull("NacosConfigProperties was not created", properties);
|
||||
|
||||
Assert.assertEquals(environment.getProperty("test-ext-config1"), "config1");
|
||||
Assert.assertEquals(environment.getProperty("test-ext-config2"), "config2");
|
||||
Assert.assertEquals(environment.getProperty("test-common1"), "common1");
|
||||
Assert.assertEquals(environment.getProperty("test-common2"), "common2");
|
||||
assertThat(locator).isNotNull();
|
||||
assertThat(properties).isNotNull();
|
||||
|
||||
assertThat("config1").isEqualTo(environment.getProperty("test-ext-config1"));
|
||||
assertThat("config2").isEqualTo(environment.getProperty("test-ext-config2"));
|
||||
assertThat("common1").isEqualTo(environment.getProperty("test-common1"));
|
||||
assertThat("common2").isEqualTo(environment.getProperty("test-common2"));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -145,5 +145,7 @@ public class NacosConfigurationExtConfigTests {
|
||||
@ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class,
|
||||
NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class })
|
||||
public static class TestConfig {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -16,15 +16,15 @@
|
||||
|
||||
package com.alibaba.cloud.nacos;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator;
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpoint;
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;
|
||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
@@ -33,21 +33,17 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.CompositePropertySource;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator;
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpoint;
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;
|
||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
|
||||
|
||||
/**
|
||||
* @author zkz
|
||||
@@ -163,14 +159,15 @@ public class NacosConfigurationNoSuffixTest {
|
||||
|
||||
@Autowired
|
||||
private NacosRefreshHistory refreshHistory;
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
@Test
|
||||
public void contextLoads() throws Exception {
|
||||
|
||||
assertNotNull("NacosPropertySourceLocator was not created", locator);
|
||||
assertNotNull("NacosConfigProperties was not created", properties);
|
||||
assertThat(locator).isNotNull();
|
||||
assertThat(properties).isNotNull();
|
||||
|
||||
checkoutNacosConfigServerAddr();
|
||||
checkoutNacosConfigNamespace();
|
||||
@@ -189,77 +186,61 @@ public class NacosConfigurationNoSuffixTest {
|
||||
}
|
||||
|
||||
private void checkEnvironmentProperties() {
|
||||
assertNull(
|
||||
"The configuration of `spring.cloud.nacos.config.name` must be used first",
|
||||
environment.getProperty("test-no-suffix"));
|
||||
assertEquals(
|
||||
"Priority of configuration is wrong , should be in this order : `profile->hasSuffix->noSuffix`",
|
||||
"assign-dev-value-no-suffix-333",
|
||||
environment.getProperty("test-no-suffix-assign"));
|
||||
|
||||
assertThat(environment.getProperty("test-no-suffix")).isNull();
|
||||
assertThat(environment.getProperty("test-no-suffix-assign"))
|
||||
.isEqualTo("assign-dev-value-no-suffix-333");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigServerAddr() {
|
||||
assertEquals("NacosConfigProperties server address is wrong", "127.0.0.1:8848",
|
||||
properties.getServerAddr());
|
||||
assertThat(properties.getServerAddr()).isEqualTo("127.0.0.1:8848");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigNamespace() {
|
||||
assertEquals("NacosConfigProperties namespace is wrong", "test-namespace",
|
||||
properties.getNamespace());
|
||||
assertThat(properties.getNamespace()).isEqualTo("test-namespace");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigClusterName() {
|
||||
assertEquals("NacosConfigProperties' cluster is wrong", "test-cluster",
|
||||
properties.getClusterName());
|
||||
assertThat(properties.getClusterName()).isEqualTo("test-cluster");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigAccessKey() {
|
||||
assertEquals("NacosConfigProperties' is access key is wrong", "test-accessKey",
|
||||
properties.getAccessKey());
|
||||
assertThat(properties.getAccessKey()).isEqualTo("test-accessKey");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigSecrectKey() {
|
||||
assertEquals("NacosConfigProperties' is secret key is wrong", "test-secretKey",
|
||||
properties.getSecretKey());
|
||||
assertThat(properties.getSecretKey()).isEqualTo("test-secretKey");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigContextPath() {
|
||||
assertEquals("NacosConfigProperties' context path is wrong", "test-contextpath",
|
||||
properties.getContextPath());
|
||||
assertThat(properties.getContextPath()).isEqualTo("test-contextpath");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigName() {
|
||||
assertEquals("NacosConfigProperties' name is wrong", "test-no-suffix-name",
|
||||
properties.getName());
|
||||
assertThat(properties.getName()).isEqualTo("test-no-suffix-name");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigGroup() {
|
||||
assertEquals("NacosConfigProperties' group is wrong", "test-group",
|
||||
properties.getGroup());
|
||||
assertThat(properties.getGroup()).isEqualTo("test-group");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigFileExtension() {
|
||||
assertEquals("NacosConfigProperties' file extension is wrong", "properties",
|
||||
properties.getFileExtension());
|
||||
assertThat(properties.getFileExtension()).isEqualTo("properties");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigTimeout() {
|
||||
assertEquals("NacosConfigProperties' timeout is wrong", 1000,
|
||||
properties.getTimeout());
|
||||
assertThat(properties.getTimeout()).isEqualTo(1000);
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigEncode() {
|
||||
assertEquals("NacosConfigProperties' encode is wrong", "utf-8",
|
||||
properties.getEncode());
|
||||
assertThat(properties.getEncode()).isEqualTo("utf-8");
|
||||
}
|
||||
|
||||
private void checkoutEndpoint() throws Exception {
|
||||
NacosConfigEndpoint nacosConfigEndpoint = new NacosConfigEndpoint(properties,
|
||||
refreshHistory);
|
||||
Map<String, Object> map = nacosConfigEndpoint.invoke();
|
||||
assertEquals(map.get("NacosConfigProperties"), properties);
|
||||
assertEquals(map.get("RefreshHistory"), refreshHistory.getRecords());
|
||||
assertThat(properties).isEqualTo(map.get("NacosConfigProperties"));
|
||||
assertThat(refreshHistory.getRecords()).isEqualTo(map.get("RefreshHistory"));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -267,5 +248,7 @@ public class NacosConfigurationNoSuffixTest {
|
||||
@ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class,
|
||||
NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class })
|
||||
public static class TestConfig {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -16,15 +16,15 @@
|
||||
|
||||
package com.alibaba.cloud.nacos;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator;
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpoint;
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;
|
||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
@@ -33,6 +33,7 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
@@ -41,16 +42,12 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator;
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpoint;
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;
|
||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PowerMockIgnore("javax.management.*")
|
||||
@PowerMockRunnerDelegate(SpringRunner.class)
|
||||
@@ -140,8 +137,8 @@ public class NacosConfigurationTests {
|
||||
@Test
|
||||
public void contextLoads() throws Exception {
|
||||
|
||||
assertNotNull("NacosPropertySourceLocator was not created", locator);
|
||||
assertNotNull("NacosConfigProperties was not created", properties);
|
||||
assertThat(locator).isNotNull();
|
||||
assertThat(properties).isNotNull();
|
||||
|
||||
checkoutNacosConfigServerAddr();
|
||||
checkoutNacosConfigNamespace();
|
||||
@@ -161,72 +158,60 @@ public class NacosConfigurationTests {
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigServerAddr() {
|
||||
assertEquals("NacosConfigProperties server address is wrong", "127.0.0.1:8848",
|
||||
properties.getServerAddr());
|
||||
assertThat(properties.getServerAddr()).isEqualTo("127.0.0.1:8848");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigNamespace() {
|
||||
assertEquals("NacosConfigProperties namespace is wrong", "test-namespace",
|
||||
properties.getNamespace());
|
||||
assertThat(properties.getNamespace()).isEqualTo("test-namespace");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigClusterName() {
|
||||
assertEquals("NacosConfigProperties' cluster is wrong", "test-cluster",
|
||||
properties.getClusterName());
|
||||
assertThat(properties.getClusterName()).isEqualTo("test-cluster");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigAccessKey() {
|
||||
assertEquals("NacosConfigProperties' is access key is wrong", "test-accessKey",
|
||||
properties.getAccessKey());
|
||||
assertThat(properties.getAccessKey()).isEqualTo("test-accessKey");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigSecrectKey() {
|
||||
assertEquals("NacosConfigProperties' is secret key is wrong", "test-secretKey",
|
||||
properties.getSecretKey());
|
||||
assertThat(properties.getSecretKey()).isEqualTo("test-secretKey");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigContextPath() {
|
||||
assertEquals("NacosConfigProperties' context path is wrong", "test-contextpath",
|
||||
properties.getContextPath());
|
||||
assertThat(properties.getContextPath()).isEqualTo("test-contextpath");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigName() {
|
||||
assertEquals("NacosConfigProperties' name is wrong", "test-name",
|
||||
properties.getName());
|
||||
assertThat(properties.getName()).isEqualTo("test-name");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigGroup() {
|
||||
assertEquals("NacosConfigProperties' group is wrong", "test-group",
|
||||
properties.getGroup());
|
||||
assertThat(properties.getGroup()).isEqualTo("test-group");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigFileExtension() {
|
||||
assertEquals("NacosConfigProperties' file extension is wrong", "properties",
|
||||
properties.getFileExtension());
|
||||
assertThat(properties.getFileExtension()).isEqualTo("properties");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigTimeout() {
|
||||
assertEquals("NacosConfigProperties' timeout is wrong", 1000,
|
||||
properties.getTimeout());
|
||||
assertThat(properties.getTimeout()).isEqualTo(1000);
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigEncode() {
|
||||
assertEquals("NacosConfigProperties' encode is wrong", "utf-8",
|
||||
properties.getEncode());
|
||||
assertThat(properties.getEncode()).isEqualTo("utf-8");
|
||||
}
|
||||
|
||||
private void checkoutDataLoad() {
|
||||
|
||||
Assert.assertEquals("dev", environment.getProperty("user.name"));
|
||||
Assert.assertEquals("12", environment.getProperty("user.age"));
|
||||
assertThat(environment.getProperty("user.name")).isEqualTo("dev");
|
||||
assertThat(environment.getProperty("user.age")).isEqualTo("12");
|
||||
}
|
||||
|
||||
private void checkoutEndpoint() throws Exception {
|
||||
NacosConfigEndpoint nacosConfigEndpoint = new NacosConfigEndpoint(properties,
|
||||
refreshHistory);
|
||||
Map<String, Object> map = nacosConfigEndpoint.invoke();
|
||||
assertEquals(map.get("NacosConfigProperties"), properties);
|
||||
assertEquals(map.get("RefreshHistory"), refreshHistory.getRecords());
|
||||
assertThat(map.get("NacosConfigProperties")).isEqualTo(properties);
|
||||
assertThat(map.get("RefreshHistory")).isEqualTo(refreshHistory.getRecords());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -234,5 +219,7 @@ public class NacosConfigurationTests {
|
||||
@ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class,
|
||||
NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class })
|
||||
public static class TestConfig {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -16,12 +16,15 @@
|
||||
|
||||
package com.alibaba.cloud.nacos;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.cloud.nacos.client.NacosPropertySourceLocator;
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpoint;
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;
|
||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
@@ -30,48 +33,42 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
|
||||
|
||||
/**
|
||||
* @author zkz
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PowerMockIgnore("javax.management.*")
|
||||
@PowerMockRunnerDelegate(SpringRunner.class)
|
||||
@PrepareForTest({ NacosConfigService.class })
|
||||
@SpringBootTest(classes = NacosConfigurationXmlJsonTest.TestConfig.class, properties = {
|
||||
"spring.application.name=xmlApp", "spring.profiles.active=dev"
|
||||
,"spring.cloud.nacos.config.server-addr=127.0.0.1:8848"
|
||||
,"spring.cloud.nacos.config.namespace=test-namespace"
|
||||
,"spring.cloud.nacos.config.encode=utf-8"
|
||||
,"spring.cloud.nacos.config.timeout=1000"
|
||||
,"spring.cloud.nacos.config.group=test-group"
|
||||
,"spring.cloud.nacos.config.name=test-name"
|
||||
,"spring.cloud.nacos.config.cluster-name=test-cluster"
|
||||
,"spring.cloud.nacos.config.file-extension=xml"
|
||||
,"spring.cloud.nacos.config.contextPath=test-contextpath"
|
||||
,"spring.cloud.nacos.config.ext-config[0].data-id=ext-json-test.json"
|
||||
,"spring.cloud.nacos.config.ext-config[1].data-id=ext-common02.properties"
|
||||
,"spring.cloud.nacos.config.ext-config[1].group=GLOBAL_GROUP"
|
||||
,"spring.cloud.nacos.config.shared-dataids=shared-data1.properties"
|
||||
,"spring.cloud.nacos.config.accessKey=test-accessKey"
|
||||
,"spring.cloud.nacos.config.secretKey=test-secretKey"
|
||||
}, webEnvironment = NONE)
|
||||
@SpringBootTest(classes = NacosConfigurationXmlJsonTest.TestConfig.class,
|
||||
properties = { "spring.application.name=xmlApp", "spring.profiles.active=dev",
|
||||
"spring.cloud.nacos.config.server-addr=127.0.0.1:8848",
|
||||
"spring.cloud.nacos.config.namespace=test-namespace",
|
||||
"spring.cloud.nacos.config.encode=utf-8",
|
||||
"spring.cloud.nacos.config.timeout=1000",
|
||||
"spring.cloud.nacos.config.group=test-group",
|
||||
"spring.cloud.nacos.config.name=test-name",
|
||||
"spring.cloud.nacos.config.cluster-name=test-cluster",
|
||||
"spring.cloud.nacos.config.file-extension=xml",
|
||||
"spring.cloud.nacos.config.contextPath=test-contextpath",
|
||||
"spring.cloud.nacos.config.ext-config[0].data-id=ext-json-test.json",
|
||||
"spring.cloud.nacos.config.ext-config[1].data-id=ext-common02.properties",
|
||||
"spring.cloud.nacos.config.ext-config[1].group=GLOBAL_GROUP",
|
||||
"spring.cloud.nacos.config.shared-dataids=shared-data1.properties",
|
||||
"spring.cloud.nacos.config.accessKey=test-accessKey",
|
||||
"spring.cloud.nacos.config.secretKey=test-secretKey" },
|
||||
webEnvironment = NONE)
|
||||
public class NacosConfigurationXmlJsonTest {
|
||||
|
||||
static {
|
||||
@@ -82,64 +79,60 @@ public class NacosConfigurationXmlJsonTest {
|
||||
String.class, String.class, long.class);
|
||||
MethodProxy.proxy(method, new InvocationHandler() {
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
public Object invoke(Object proxy, Method method, Object[] args)
|
||||
throws Throwable {
|
||||
|
||||
if ("xmlApp.xml".equals(args[0]) && "test-group".equals(args[1])) {
|
||||
return "<top>\n" +
|
||||
" <first>one</first>\n" +
|
||||
" <sencond value=\"two\">\n" +
|
||||
" <third>three</third>\n" +
|
||||
" </sencond>\n" +
|
||||
"</top>";
|
||||
return "<top>\n" + " <first>one</first>\n"
|
||||
+ " <sencond value=\"two\">\n"
|
||||
+ " <third>three</third>\n" + " </sencond>\n"
|
||||
+ "</top>";
|
||||
}
|
||||
if ("test-name.xml".equals(args[0]) && "test-group".equals(args[1])) {
|
||||
return "<Server port=\"8005\" shutdown=\"SHUTDOWN\"> \n" +
|
||||
" <Service name=\"Catalina\"> \n" +
|
||||
" <Connector value=\"第二个连接器\"> \n" +
|
||||
" <open>开启服务</open> \n" +
|
||||
" <init>初始化一下</init> \n" +
|
||||
" <process>\n" +
|
||||
" <top>\n" +
|
||||
" <first>one</first>\n" +
|
||||
" <sencond value=\"two\">\n" +
|
||||
" <third>three</third>\n" +
|
||||
" </sencond>\n" +
|
||||
" </top>\n" +
|
||||
" </process> \n" +
|
||||
" <destory>销毁一下</destory> \n" +
|
||||
" <close>关闭服务</close> \n" +
|
||||
" </Connector> \n" +
|
||||
" </Service> \n" +
|
||||
"</Server> ";
|
||||
return "<Server port=\"8005\" shutdown=\"SHUTDOWN\"> \n"
|
||||
+ " <Service name=\"Catalina\"> \n"
|
||||
+ " <Connector value=\"第二个连接器\"> \n"
|
||||
+ " <open>开启服务</open> \n"
|
||||
+ " <init>初始化一下</init> \n"
|
||||
+ " <process>\n" + " <top>\n"
|
||||
+ " <first>one</first>\n"
|
||||
+ " <sencond value=\"two\">\n"
|
||||
+ " <third>three</third>\n"
|
||||
+ " </sencond>\n"
|
||||
+ " </top>\n" + " </process> \n"
|
||||
+ " <destory>销毁一下</destory> \n"
|
||||
+ " <close>关闭服务</close> \n"
|
||||
+ " </Connector> \n" + " </Service> \n"
|
||||
+ "</Server> ";
|
||||
}
|
||||
|
||||
if ("test-name-dev.xml".equals(args[0]) && "test-group".equals(args[1])) {
|
||||
return "<application android:label=\"@string/app_name\" android:icon=\"@drawable/osg\">\n" +
|
||||
" <activity android:name=\".osgViewer\"\n" +
|
||||
" android:label=\"@string/app_name\" android:screenOrientation=\"landscape\">\n" +
|
||||
" <intent-filter>\n" +
|
||||
" <action android:name=\"android.intent.action.MAIN\" />\n" +
|
||||
" <category android:name=\"android.intent.category.LAUNCHER\" />\n" +
|
||||
" </intent-filter>\n" +
|
||||
" </activity>\n" +
|
||||
"</application>";
|
||||
if ("test-name-dev.xml".equals(args[0])
|
||||
&& "test-group".equals(args[1])) {
|
||||
return "<application android:label=\"@string/app_name\" android:icon=\"@drawable/osg\">\n"
|
||||
+ " <activity android:name=\".osgViewer\"\n"
|
||||
+ " android:label=\"@string/app_name\" android:screenOrientation=\"landscape\">\n"
|
||||
+ " <intent-filter>\n"
|
||||
+ " <action android:name=\"android.intent.action.MAIN\" />\n"
|
||||
+ " <category android:name=\"android.intent.category.LAUNCHER\" />\n"
|
||||
+ " </intent-filter>\n" + " </activity>\n"
|
||||
+ "</application>";
|
||||
}
|
||||
|
||||
if ("ext-json-test.json".equals(args[0]) && "DEFAULT_GROUP".equals(args[1])) {
|
||||
return "{\n" +
|
||||
" \"people\":{\n" +
|
||||
" \"firstName\":\"Brett\",\n" +
|
||||
" \"lastName\":\"McLaughlin\"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
if ("ext-json-test.json".equals(args[0])
|
||||
&& "DEFAULT_GROUP".equals(args[1])) {
|
||||
return "{\n" + " \"people\":{\n"
|
||||
+ " \"firstName\":\"Brett\",\n"
|
||||
+ " \"lastName\":\"McLaughlin\"\n" + " }\n"
|
||||
+ "}";
|
||||
}
|
||||
|
||||
if ("ext-config-common02.properties".equals(args[0]) && "GLOBAL_GROUP".equals(args[1])) {
|
||||
if ("ext-config-common02.properties".equals(args[0])
|
||||
&& "GLOBAL_GROUP".equals(args[1])) {
|
||||
return "global-ext-config=global-config-value-2";
|
||||
}
|
||||
|
||||
|
||||
if ("shared-data1.properties".equals(args[0]) && "DEFAULT_GROUP".equals(args[1])) {
|
||||
if ("shared-data1.properties".equals(args[0])
|
||||
&& "DEFAULT_GROUP".equals(args[1])) {
|
||||
return "shared-name=shared-value-1";
|
||||
}
|
||||
|
||||
@@ -166,8 +159,8 @@ public class NacosConfigurationXmlJsonTest {
|
||||
@Test
|
||||
public void contextLoads() throws Exception {
|
||||
|
||||
assertNotNull("NacosPropertySourceLocator was not created", locator);
|
||||
assertNotNull("NacosConfigProperties was not created", properties);
|
||||
assertThat(locator).isNotNull();
|
||||
assertThat(properties).isNotNull();
|
||||
|
||||
checkoutNacosConfigServerAddr();
|
||||
checkoutNacosConfigNamespace();
|
||||
@@ -186,67 +179,55 @@ public class NacosConfigurationXmlJsonTest {
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigServerAddr() {
|
||||
assertEquals("NacosConfigProperties server address is wrong", "127.0.0.1:8848",
|
||||
properties.getServerAddr());
|
||||
assertThat(properties.getServerAddr()).isEqualTo("127.0.0.1:8848");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigNamespace() {
|
||||
assertEquals("NacosConfigProperties namespace is wrong", "test-namespace",
|
||||
properties.getNamespace());
|
||||
assertThat(properties.getNamespace()).isEqualTo("test-namespace");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigClusterName() {
|
||||
assertEquals("NacosConfigProperties' cluster is wrong", "test-cluster",
|
||||
properties.getClusterName());
|
||||
assertThat(properties.getClusterName()).isEqualTo("test-cluster");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigAccessKey() {
|
||||
assertEquals("NacosConfigProperties' is access key is wrong", "test-accessKey",
|
||||
properties.getAccessKey());
|
||||
assertThat(properties.getAccessKey()).isEqualTo("test-accessKey");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigSecrectKey() {
|
||||
assertEquals("NacosConfigProperties' is secret key is wrong", "test-secretKey",
|
||||
properties.getSecretKey());
|
||||
assertThat(properties.getSecretKey()).isEqualTo("test-secretKey");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigContextPath() {
|
||||
assertEquals("NacosConfigProperties' context path is wrong", "test-contextpath",
|
||||
properties.getContextPath());
|
||||
assertThat(properties.getContextPath()).isEqualTo("test-contextpath");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigName() {
|
||||
assertEquals("NacosConfigProperties' name is wrong", "test-name",
|
||||
properties.getName());
|
||||
assertThat(properties.getName()).isEqualTo("test-name");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigGroup() {
|
||||
assertEquals("NacosConfigProperties' group is wrong", "test-group",
|
||||
properties.getGroup());
|
||||
assertThat(properties.getGroup()).isEqualTo("test-group");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigFileExtension() {
|
||||
assertEquals("NacosConfigProperties' file extension is wrong", "xml",
|
||||
properties.getFileExtension());
|
||||
assertThat(properties.getFileExtension()).isEqualTo("xml");
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigTimeout() {
|
||||
assertEquals("NacosConfigProperties' timeout is wrong", 1000,
|
||||
properties.getTimeout());
|
||||
assertThat(properties.getTimeout()).isEqualTo(1000);
|
||||
}
|
||||
|
||||
private void checkoutNacosConfigEncode() {
|
||||
assertEquals("NacosConfigProperties' encode is wrong", "utf-8",
|
||||
properties.getEncode());
|
||||
assertThat(properties.getEncode()).isEqualTo("utf-8");
|
||||
}
|
||||
|
||||
|
||||
private void checkoutEndpoint() throws Exception {
|
||||
NacosConfigEndpoint nacosConfigEndpoint = new NacosConfigEndpoint(properties,
|
||||
refreshHistory);
|
||||
Map<String, Object> map = nacosConfigEndpoint.invoke();
|
||||
assertEquals(map.get("NacosConfigProperties"), properties);
|
||||
assertEquals(map.get("RefreshHistory"), refreshHistory.getRecords());
|
||||
assertThat(properties).isEqualTo(map.get("NacosConfigProperties"));
|
||||
assertThat(refreshHistory.getRecords()).isEqualTo(map.get("RefreshHistory"));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -254,5 +235,7 @@ public class NacosConfigurationXmlJsonTest {
|
||||
@ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class,
|
||||
NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class })
|
||||
public static class TestConfig {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2019 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package com.alibaba.cloud.nacos;
|
||||
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -30,6 +30,7 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
@@ -38,8 +39,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration;
|
||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
@@ -49,10 +49,11 @@ import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
@PowerMockIgnore("javax.management.*")
|
||||
@PowerMockRunnerDelegate(SpringRunner.class)
|
||||
@PrepareForTest({ NacosConfigService.class })
|
||||
@SpringBootTest(classes = NacosFileExtensionTest.TestConfig.class, properties = {
|
||||
"spring.application.name=test-name",
|
||||
"spring.cloud.nacos.config.server-addr=127.0.0.1:8848",
|
||||
"spring.cloud.nacos.config.file-extension=yaml" }, webEnvironment = NONE)
|
||||
@SpringBootTest(classes = NacosFileExtensionTest.TestConfig.class,
|
||||
properties = { "spring.application.name=test-name",
|
||||
"spring.cloud.nacos.config.server-addr=127.0.0.1:8848",
|
||||
"spring.cloud.nacos.config.file-extension=yaml" },
|
||||
webEnvironment = NONE)
|
||||
public class NacosFileExtensionTest {
|
||||
|
||||
static {
|
||||
@@ -94,5 +95,7 @@ public class NacosFileExtensionTest {
|
||||
@ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class,
|
||||
NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class })
|
||||
public static class TestConfig {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-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
|
||||
* https://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,
|
||||
@@ -16,13 +16,15 @@
|
||||
|
||||
package com.alibaba.cloud.nacos.endpoint;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosConfigAutoConfiguration;
|
||||
import com.alibaba.cloud.nacos.NacosConfigBootstrapConfiguration;
|
||||
import com.alibaba.cloud.nacos.NacosConfigManager;
|
||||
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;
|
||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
@@ -31,6 +33,7 @@ import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.health.Health.Builder;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -39,31 +42,29 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosConfigAutoConfiguration;
|
||||
import com.alibaba.cloud.nacos.NacosConfigBootstrapConfiguration;
|
||||
import com.alibaba.cloud.nacos.NacosConfigProperties;
|
||||
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;
|
||||
import com.alibaba.nacos.client.config.NacosConfigService;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
|
||||
|
||||
/**
|
||||
* @author xiaojing
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PowerMockIgnore("javax.management.*")
|
||||
@PowerMockRunnerDelegate(SpringRunner.class)
|
||||
@PrepareForTest({ NacosConfigService.class })
|
||||
@SpringBootTest(classes = NacosConfigEndpointTests.TestConfig.class, properties = {
|
||||
"spring.application.name=test-name",
|
||||
"spring.cloud.nacos.config.server-addr=127.0.0.1:8848",
|
||||
"spring.cloud.nacos.config.file-extension=properties" }, webEnvironment = NONE)
|
||||
@SpringBootTest(classes = NacosConfigEndpointTests.TestConfig.class,
|
||||
properties = { "spring.application.name=test-name",
|
||||
"spring.cloud.nacos.config.server-addr=127.0.0.1:8848",
|
||||
"spring.cloud.nacos.config.file-extension=properties" },
|
||||
webEnvironment = NONE)
|
||||
public class NacosConfigEndpointTests {
|
||||
|
||||
static {
|
||||
|
||||
try {
|
||||
|
||||
Method method = PowerMockito.method(NacosConfigService.class, "getServerStatus");
|
||||
Method method = PowerMockito.method(NacosConfigService.class,
|
||||
"getServerStatus");
|
||||
MethodProxy.proxy(method, (proxy, method1, args) -> "UP");
|
||||
|
||||
}
|
||||
@@ -101,8 +102,7 @@ public class NacosConfigEndpointTests {
|
||||
Builder builder1 = new Builder();
|
||||
builder1.up();
|
||||
|
||||
assertEquals(builder1.build(), builder.build());
|
||||
|
||||
assertThat(builder.build()).isEqualTo(builder1.build());
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
|
||||
@@ -114,8 +114,9 @@ public class NacosConfigEndpointTests {
|
||||
NacosConfigEndpoint endpoint = new NacosConfigEndpoint(properties,
|
||||
refreshHistory);
|
||||
Map<String, Object> map = endpoint.invoke();
|
||||
assertEquals(map.get("NacosConfigProperties"), properties);
|
||||
assertEquals(map.get("RefreshHistory"), refreshHistory.getRecords());
|
||||
|
||||
assertThat(properties).isEqualTo(map.get("NacosConfigProperties"));
|
||||
assertThat(refreshHistory.getRecords()).isEqualTo(map.get("RefreshHistory"));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -123,5 +124,7 @@ public class NacosConfigEndpointTests {
|
||||
@ImportAutoConfiguration({ NacosConfigEndpointAutoConfiguration.class,
|
||||
NacosConfigAutoConfiguration.class, NacosConfigBootstrapConfiguration.class })
|
||||
public static class TestConfig {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user