[IT]Adjust config module config integration tests to meet checkstyle requirements. (#12377)

This commit is contained in:
阿魁 2024-07-24 16:09:51 +08:00 committed by GitHub
parent 0f023a270f
commit c00d863242
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 404 additions and 348 deletions

View File

@ -64,7 +64,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
abstract class AbstractConfigAPI_CITCase {
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
abstract class AbstractConfigAPIConfigITCase {
public static final long TIME_OUT = 5000;
@ -72,9 +73,9 @@ abstract class AbstractConfigAPI_CITCase {
private static final String SPECIAL_CHARACTERS = "!@#$%^&*()_+-=_|/'?.";
static ConfigService iconfig = null;
private static ConfigService iconfig = null;
static HttpAgent agent = null;
private static HttpAgent agent = null;
private static String dataId = "yanlin";
@ -211,13 +212,13 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @TCDescription : nacos_正常获取数据
* @TestStep :
* @ExpectResult :
* Retrieve data successfully.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 3 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_getconfig_1() throws Exception {
public void getConfig() throws Exception {
final String content = "test";
boolean result = iconfig.publishConfig(dataId, group, content);
Thread.sleep(TIME_OUT);
@ -233,13 +234,13 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @TCDescription : nacos_正常推送&获取加密数据
* @TestStep :
* @ExpectResult :
* Publish and retrieve encrypted data successfully.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 3 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacosPublishAndGetConfig() throws Exception {
public void publishAndGetConfig() throws Exception {
String dataId = "cipher-aes-dataId";
final String content = "test";
boolean result = iconfig.publishConfig(dataId, group, content);
@ -255,23 +256,25 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @throws Exception
* @TCDescription : nacos_服务端无配置时获取配置
* Test retrieving configuration when server has no config.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_getconfig_2() throws Exception {
public void testGetConfigWhenServerHasNoConfig() throws Exception {
String content = iconfig.getConfig(dataId, "nacos", TIME_OUT);
assertNull(content);
}
/**
* @throws Exception
* @TCDescription : nacos_获取配置时dataId为null
* Test fetching config when dataId is null.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_getconfig_3() throws Exception {
public void testGetConfigWithNullDataId() throws Exception {
try {
String content = iconfig.getConfig(null, group, TIME_OUT);
} catch (Exception e) {
@ -282,12 +285,13 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @throws Exception
* @TCDescription : nacos_获取配置时group为null
* Test fetching config when group is null.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_getconfig_4() throws Exception {
public void testGetConfigWithNullGroup() throws Exception {
final String dataId = "nacos_getconfig_4";
final String content = "test";
boolean result = iconfig.publishConfig(dataId, null, content);
@ -303,12 +307,13 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @throws Exception
* @TCDescription : nacos_服务端无该配置项时正常创建配置
* Test publishing config to Nacos when the server does not have the config.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_publishConfig_1() throws Exception {
public void testPublishConfigWhenServerDoesNotExist() throws Exception {
final String content = "publishConfigTest";
boolean result = iconfig.publishConfig(dataId, group, content);
Thread.sleep(TIME_OUT);
@ -318,12 +323,13 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @throws Exception
* @TCDescription : nacos_服务端有该配置项时正常修改配置
* Test updating config in Nacos when the server already has the config.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_publishConfig_2() throws Exception {
public void testUpdateConfigWhenServerHasExistingConfig() throws Exception {
final String content = "publishConfigTest";
boolean result = iconfig.publishConfig(dataId, group, content);
Thread.sleep(TIME_OUT);
@ -337,12 +343,13 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @throws Exception
* @TCDescription : nacos_发布配置时包含特殊字符
* Test publishing config to Nacos with special characters.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_publishConfig_3() throws Exception {
public void testPublishConfigWithSpecialCharacters() throws Exception {
String content = "test" + SPECIAL_CHARACTERS;
boolean result = iconfig.publishConfig(dataId, group, content);
Thread.sleep(TIME_OUT);
@ -353,12 +360,13 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @throws Exception
* @TCDescription : nacos_发布配置时dataId为null
* Test publishing config to Nacos when dataId is null.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_publishConfig_4() throws Exception {
public void testPublishConfigWithNullDataId() throws Exception {
try {
String content = "test";
boolean result = iconfig.publishConfig(null, group, content);
@ -372,12 +380,13 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @throws Exception
* @TCDescription : nacos_发布配置时group为null
* Test publishing config to Nacos when group is null.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_publishConfig_5() throws Exception {
public void testPublishConfigWithNullGroup() throws Exception {
final String dataId = "nacos_publishConfig_5";
String content = "test";
boolean result = iconfig.publishConfig(dataId, null, content);
@ -390,12 +399,13 @@ abstract class AbstractConfigAPI_CITCase {
/**
* @throws Exception
* @TCDescription : nacos_发布配置时配置内容为null
* Test publishing config to Nacos when content is null.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_publishConfig_6() throws Exception {
public void testPublishConfigWithNullContent() throws Exception {
String content = null;
try {
boolean result = iconfig.publishConfig(dataId, group, content);
@ -408,12 +418,13 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @throws Exception
* @TCDescription : nacos_发布配置时配置内容包含中文字符
* Test publishing configuration to Nacos with content containing Chinese characters.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_publishConfig_7() throws Exception {
public void testPublishConfigWithChineseCharacters() throws Exception {
String content = "阿里abc";
boolean result = iconfig.publishConfig(dataId, group, content);
Thread.sleep(TIME_OUT);
@ -423,11 +434,12 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @throws Exception
* @TCDescription : nacos_服务端有该配置项时正常删除配置
* Test removing config from Nacos when the server has the config.
*
* @throws Exception if an error occurs during the test.
*/
@Test
public void nacos_removeConfig_1() throws Exception {
public void testRemoveConfigWhenServerHasConfig() throws Exception {
String content = "test";
boolean result = iconfig.publishConfig(dataId, group, content);
@ -442,24 +454,26 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @throws Exception
* @TCDescription : nacos_服务端无该配置项时配置删除失败
* Test removing config from Nacos when the server does not have the config.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_removeConfig_2() throws Exception {
public void testRemoveConfigWhenServerDoesNotHaveConfig() throws Exception {
group += "removeConfig2";
boolean result = iconfig.removeConfig(dataId, group);
assertTrue(result);
}
/**
* @throws Exception
* @TCDescription : nacos_删除配置时dataId为null
* Test removing configuration from Nacos when dataId is null.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_removeConfig_3() throws Exception {
public void testRemoveConfigWithNullDataId() throws Exception {
try {
boolean result = iconfig.removeConfig(null, group);
assertTrue(result);
@ -471,23 +485,25 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @throws Exception
* @TCDescription : nacos_删除配置时group为null
* Test removing configuration from Nacos when group is null.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_removeConfig_4() throws Exception {
public void testRemoveConfigWithNullGroup() throws Exception {
boolean result = iconfig.removeConfig(dataId, null);
assertTrue(result);
}
/**
* @throws Exception
* @TCDescription : nacos_添加对dataId的监听在服务端修改配置后获取监听后的修改的配置
* Test adding listener for dataId in Nacos, retrieving modified configuration after server-side modification.
*
* @throws Exception if an error occurs during the test.
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_addListener_1() throws Exception {
public void testAddListenerAndRetrieveModifiedConfig() throws Exception {
final AtomicInteger count = new AtomicInteger(0);
final String content = "test-abc";
boolean result = iconfig.publishConfig(dataId, group, content);
@ -515,15 +531,14 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @TCDescription : nacos_设置监听器为null抛出异常信息
* @TestStep :
* @ExpectResult :
* Verify that setting a listener to null throws an IllegalArgumentException.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_addListener_2() throws Exception {
public void testAddNullListenerThrowsException() throws Exception {
assertThrows(IllegalArgumentException.class, () -> {
iconfig.addListener(dataId, group, null);
});
@ -531,15 +546,15 @@ abstract class AbstractConfigAPI_CITCase {
/**
* @TCDescription : nacos_添加对dataId的监听修改服务端配置正常推送并只推送一次
* @TestStep : TODO Test steps
* @ExpectResult : TODO expect results
* Verify adding a listener for dataId, modifying the server configuration, and ensuring the listener is triggered
* exactly once.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = Constants.CONFIG_LONG_POLL_TIMEOUT << 2, unit = TimeUnit.MILLISECONDS)
public void nacos_addListener_3() throws InterruptedException, NacosException {
public void testAddListenerAndModifyConfig() throws InterruptedException, NacosException {
final AtomicInteger count = new AtomicInteger(0);
final String dataId = "nacos_addListener_3";
final String group = "nacos_addListener_3";
@ -570,15 +585,14 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @TCDescription : nacos_服务端无配置时添加对dataId的监听
* @TestStep : TODO Test steps
* @ExpectResult : TODO expect results
* Verify that setting a null listener in Nacos throws an IllegalArgumentException.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_addListener_4() throws Exception {
@Timeout(value = TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void testAddNullListener() throws Exception {
final AtomicInteger count = new AtomicInteger(0);
iconfig.removeConfig(dataId, group);
@ -604,14 +618,15 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @TCDescription : nacos_在主动拉取配置后并注册Listener在更新配置后才触发Listener监听事件(使用特定接口)
* @TestStep : TODO Test steps
* @ExpectResult : TODO expect results
* Subscribe to dataId in Nacos, update server-side configuration, and verify that the listener receives the update
* exactly once.
*
* @author chuntaojun
* @since 3.6.8
*/
@Test
public void nacos_addListener_5() throws InterruptedException, NacosException {
@Timeout(value = Constants.CONFIG_LONG_POLL_TIMEOUT << 2, unit = TimeUnit.MILLISECONDS)
public void testAddListenerAndUpdateConfig() throws InterruptedException, NacosException {
final AtomicInteger count = new AtomicInteger(0);
final String dataId = "nacos_addListener_5";
final String group = "nacos_addListener_5";
@ -644,14 +659,14 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @TCDescription : nacos_在主动拉取配置后并注册Listener在更新配置后才触发Listener监听事件(进行配置参数设置)
* @TestStep : TODO Test steps
* @ExpectResult : TODO expect results
* Verify that the listener is triggered only after the configuration is updated.
*
* @author chuntaojun
* @since 3.6.8
*/
@Test
public void nacos_addListener_6() throws InterruptedException, NacosException {
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void testListenerTriggeredAfterConfigUpdate() throws Exception {
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1" + ":" + port);
@ -698,15 +713,14 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @TCDescription : nacos_正常移除监听器
* @TestStep : TODO Test steps
* @ExpectResult : TODO expect results
* Verify normal removal of listener in Nacos.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_removeListener_1() throws Exception {
public void testRemoveListener() throws Exception {
iconfig.addListener(dataId, group, new AbstractListener() {
@Override
public void receiveConfigInfo(String configInfo) {
@ -722,20 +736,19 @@ abstract class AbstractConfigAPI_CITCase {
}
});
} catch (Exception e) {
// ignore
}
}
/**
* @TCDescription : nacos_移除无该项dataId的监听器
* @TestStep : TODO Test steps
* @ExpectResult : TODO expect results
* Verify removing listener for dataId that does not exist in Nacos.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_removeListener_2() {
public void testRemoveListenerForNonexistentDataId() {
group += "test.nacos";
Assertions.assertDoesNotThrow(() -> {
iconfig.removeListener(dataId, group, new AbstractListener() {
@ -748,15 +761,14 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @TCDescription : nacos_存在多个监听器时删除最后一个监听器
* @TestStep : TODO Test steps
* @ExpectResult : TODO expect results
* Verify removal of the last listener when multiple listeners exist in Nacos.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_removeListener_3() throws Exception {
public void testRemoveLastListener() throws Exception {
final String contentRemove = "test-abc-two";
final AtomicInteger count = new AtomicInteger(0);
@ -791,30 +803,28 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @TCDescription : nacos_监听器为null时
* @TestStep : TODO Test steps
* @ExpectResult : TODO expect results
* Verify exception thrown when listener is null during removal in Nacos.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_removeListener_4() {
public void testRemoveListenerNull() {
assertThrows(IllegalArgumentException.class, () -> {
iconfig.removeListener(dataId, group, null);
});
}
/**
* @TCDescription : nacos_openAPI_配置具体信息
* @TestStep :
* @ExpectResult :
* Verify detailed configuration retrieval using Nacos Open API.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = 3 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_openAPI_detailConfig_1() {
public void testOpenApiDetailConfig() {
Assertions.assertDoesNotThrow(() -> {
final String content = "test";
boolean ret = iconfig.publishConfig(dataId, group, content);
@ -824,7 +834,8 @@ abstract class AbstractConfigAPI_CITCase {
params.put("dataId", dataId);
params.put("group", group);
params.put("show", "all");
HttpRestResult<String> result = agent.httpGet(CONFIG_CONTROLLER_PATH, null, params, agent.getEncode(), TIME_OUT);
HttpRestResult<String> result = agent.httpGet(CONFIG_CONTROLLER_PATH, null, params, agent.getEncode(),
TIME_OUT);
assertEquals(HttpURLConnection.HTTP_OK, result.getCode());
assertEquals(content, JacksonUtils.toObj(result.getData()).get("content").textValue());
@ -832,15 +843,14 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @TCDescription : nacos_openAPI_catalog信息
* @TestStep :
* @ExpectResult :
* Verify catalog information retrieval using Nacos Open API.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = 3 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_openAPI_catalog() {
public void testOpenApiCatalog() {
Assertions.assertDoesNotThrow(() -> {
final String content = "test";
boolean ret = iconfig.publishConfig(dataId, group, content);
@ -849,7 +859,8 @@ abstract class AbstractConfigAPI_CITCase {
Map<String, String> params = new HashMap<>();
params.put("dataId", dataId);
params.put("group", group);
HttpRestResult<String> result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/catalog", null, params, agent.getEncode(), TIME_OUT);
HttpRestResult<String> result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/catalog", null, params,
agent.getEncode(), TIME_OUT);
assertEquals(HttpURLConnection.HTTP_OK, result.getCode());
System.out.println(result.getData());
@ -859,17 +870,15 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @TCDescription : nacos_openAPI_queryBeta信息
* @TestStep :
* @ExpectResult :
* Verify beta configuration query using Nacos Open API.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = 3 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_openAPI_queryBeta_1() {
public void testOpenApiQueryBeta() {
Assertions.assertDoesNotThrow(() -> {
HttpRestResult<String> result = null;
final String content = "test-beta";
Map<String, String> headers = new HashMap<>();
headers.put("betaIps", "127.0.0.1");
@ -877,7 +886,8 @@ abstract class AbstractConfigAPI_CITCase {
params.put("dataId", dataId);
params.put("group", group);
params.put("content", content);
result = agent.httpPost(CONFIG_CONTROLLER_PATH + "/", headers, params, agent.getEncode(), TIME_OUT);
HttpRestResult<String> result = agent.httpPost(CONFIG_CONTROLLER_PATH + "/", headers, params,
agent.getEncode(), TIME_OUT);
assertEquals(HttpURLConnection.HTTP_OK, result.getCode());
assertEquals("true", result.getData());
params.clear();
@ -894,15 +904,14 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @TCDescription : nacos_openAPI_queryBeta删除信息
* @TestStep : 1. 发布配置 2. 删除Beta配置信息
* @ExpectResult :
* Verify beta configuration deletion using Nacos Open API.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = 3 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_openAPI_queryBeta_delete() {
public void testOpenApiQueryBetaDelete() {
HttpRestResult<String> result = null;
try {
@ -932,17 +941,15 @@ abstract class AbstractConfigAPI_CITCase {
}
/**
* @TCDescription : nacos_openAPI_模糊查询配置信息
* @TestStep : 1. 发布配置 2. 模糊查询
* @ExpectResult : 获取查询到配置
* Verify fuzzy search of configuration information using Nacos Open API.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_openAPI_fuzzySearchConfig() {
public void testOpenApiFuzzySearchConfig() {
Assertions.assertDoesNotThrow(() -> {
HttpRestResult<String> result;
final String content = "test123";
boolean ret = iconfig.publishConfig(dataId, group, content);
Thread.sleep(TIME_OUT);
@ -953,27 +960,27 @@ abstract class AbstractConfigAPI_CITCase {
params.put("pageNo", "1");
params.put("pageSize", "10");
params.put("search", "blur");
result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT);
HttpRestResult<String> result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(),
TIME_OUT);
assertEquals(HttpURLConnection.HTTP_OK, result.getCode());
assertTrue(JacksonUtils.toObj(result.getData()).get("totalCount").intValue() >= 1);
assertTrue(JacksonUtils.toObj(result.getData()).get("pageItems").get(0).get("content").textValue().startsWith(content));
assertTrue(JacksonUtils.toObj(result.getData()).get("pageItems").get(0).get("content").textValue()
.startsWith(content));
});
}
/**
* @TCDescription : nacos_openAPI_模糊查询配置信息
* @TestStep : 1. 发布配置 2. 查询配置信息
* @ExpectResult : 获取查询到配置
* Verify fuzzy search of configuration information using Nacos Open API.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_openAPI_fuzzySearchConfig_1() {
public void testOpenApiFuzzySearchConfig1() {
Assertions.assertDoesNotThrow(() -> {
HttpRestResult<String> result;
final String content = "test123";
boolean ret = iconfig.publishConfig(dataId, group, content);
Thread.sleep(TIME_OUT);
@ -984,28 +991,28 @@ abstract class AbstractConfigAPI_CITCase {
params.put("pageNo", "1");
params.put("pageSize", "10");
params.put("search", "blur");
result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT);
HttpRestResult<String> result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(),
TIME_OUT);
assertEquals(HttpURLConnection.HTTP_OK, result.getCode());
assertTrue(JacksonUtils.toObj(result.getData()).get("totalCount").intValue() >= 1);
assertEquals(content, JacksonUtils.toObj(result.getData()).get("pageItems").get(0).get("content").textValue());
assertEquals(content,
JacksonUtils.toObj(result.getData()).get("pageItems").get(0).get("content").textValue());
});
}
/**
* @TCDescription : nacos_openAPI_查询配置信息
* @TestStep : 1. 发布配置 2. 查询配置信息
* @ExpectResult : 获取查询到配置
* Verify accurate search of configuration information using Nacos Open API.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_openAPI_searchConfig() {
public void testOpenApiSearchConfig() {
Assertions.assertDoesNotThrow(() -> {
HttpRestResult<String> result;
final String content = "test123";
boolean ret = iconfig.publishConfig(dataId, group, content);
assertTrue(ret);
@ -1016,28 +1023,28 @@ abstract class AbstractConfigAPI_CITCase {
params.put("pageNo", "1");
params.put("pageSize", "10");
params.put("search", "accurate");
result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT);
HttpRestResult<String> result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(),
TIME_OUT);
assertEquals(HttpURLConnection.HTTP_OK, result.getCode());
assertEquals(1, JacksonUtils.toObj(result.getData()).get("totalCount").intValue());
assertEquals(content, JacksonUtils.toObj(result.getData()).get("pageItems").get(0).get("content").textValue());
assertEquals(content,
JacksonUtils.toObj(result.getData()).get("pageItems").get(0).get("content").textValue());
});
}
/**
* @TCDescription : nacos_openAPI_查询配置信息包含中文utf-8
* @TestStep : 1. 发布配置 2. 查询配置信息
* @ExpectResult : 获取查询到配置
* Verify search of configuration information including Chinese characters using Nacos Open API.
*
* @author xiaochun.xxc
* @since 3.6.8
*/
@Test
@Timeout(value = 5 * TIME_OUT, unit = TimeUnit.MILLISECONDS)
public void nacos_openAPI_searchConfig_2() {
public void testOpenApiSearchConfigChinese() {
Assertions.assertDoesNotThrow(() -> {
HttpRestResult<String> result;
final String content = "test测试";
boolean ret = iconfig.publishConfig(dataId, group, content);
assertTrue(ret);
@ -1049,12 +1056,13 @@ abstract class AbstractConfigAPI_CITCase {
params.put("pageNo", "1");
params.put("pageSize", "10");
params.put("search", "accurate");
result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT);
HttpRestResult<String> result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(),
TIME_OUT);
assertEquals(HttpURLConnection.HTTP_OK, result.getCode());
assertEquals(1, JacksonUtils.toObj(result.getData()).get("totalCount").intValue());
assertEquals(content, JacksonUtils.toObj(result.getData()).get("pageItems").get(0).get("content").textValue());
assertEquals(content,
JacksonUtils.toObj(result.getData()).get("pageItems").get(0).get("content").textValue());
});
}
}

View File

@ -25,16 +25,19 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Integration tests for Config API Config.
*
* @author xiaochun.xxc
*/
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Nacos.class, properties = {
"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class ConfigAPI_CITCase extends AbstractConfigAPI_CITCase {
class ConfigAPIConfigITCase extends AbstractConfigAPIConfigITCase {
@BeforeAll
static void beforeClass() {
ConfigCleanUtils.changeToNewTestNacosHome(ConfigAPI_CITCase.class.getSimpleName());
ConfigCleanUtils.changeToNewTestNacosHome(ConfigAPIConfigITCase.class.getSimpleName());
}
@BeforeAll

View File

@ -39,18 +39,21 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
import java.net.URL;
import java.util.Random;
import static com.alibaba.nacos.test.config.ConfigAPI_V2_CITCase.CONTEXT_PATH;
import static com.alibaba.nacos.test.config.ConfigAPIV2ConfigITCase.CONTEXT_PATH;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Integration tests for Config API V2.
*
* @author karsonto
*/
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Nacos.class, properties = {
"server.servlet.context-path=" + CONTEXT_PATH}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@TestMethodOrder(MethodName.class)
public class ConfigAPI_V2_CITCase extends HttpClient4Test {
public class ConfigAPIV2ConfigITCase extends HttpClient4Test {
public static final long TIME_OUT = 5000;
@ -60,27 +63,29 @@ public class ConfigAPI_V2_CITCase extends HttpClient4Test {
private static final String CONTENT = randomContent();
private final String DATA_ID = "nacos.example";
private static final String DATA_ID = "nacos.example";
private final String GROUP = "DEFAULT_GROUP";
private static final String GROUP = "DEFAULT_GROUP";
private final String NAME_SPACE_ID = "public";
private static final String NAME_SPACE_ID = "public";
@LocalServerPort
private int port;
@BeforeAll
static void beforeClass() {
ConfigCleanUtils.changeToNewTestNacosHome(ConfigAPI_V2_CITCase.class.getSimpleName());
ConfigCleanUtils.changeToNewTestNacosHome(ConfigAPIV2ConfigITCase.class.getSimpleName());
}
@AfterAll
@BeforeAll
static void cleanClientCache() throws Exception {
ConfigCleanUtils.cleanClientCache();
}
/**
* Generates random content for testing purposes.
*/
public static String randomContent() {
StringBuilder sb = new StringBuilder();
Random rand = new Random();
@ -116,20 +121,25 @@ public class ConfigAPI_V2_CITCase extends HttpClient4Test {
assertTrue(thrown);
}
/**
* Publishes a configuration.
*
* @throws Exception if an error occurs during the test.
*/
public void publishConfig() throws Exception {
ResponseEntity<String> response = request(CONFIG_V2_CONTROLLER_PATH,
Params.newParams().appendParam("dataId", DATA_ID).appendParam("group", GROUP).appendParam("namespaceId", NAME_SPACE_ID)
.appendParam("content", CONTENT).done(), String.class, HttpMethod.POST);
Params.newParams().appendParam("dataId", DATA_ID).appendParam("group", GROUP)
.appendParam("namespaceId", NAME_SPACE_ID).appendParam("content", CONTENT).done(), String.class,
HttpMethod.POST);
assertTrue(response.getStatusCode().is2xxSuccessful());
JsonNode json = JacksonUtils.toObj(response.getBody());
assertTrue(json.get("data").asBoolean());
}
public String getConfig(boolean ignoreStatusCode) throws Exception {
ResponseEntity<String> response = request(CONFIG_V2_CONTROLLER_PATH,
Params.newParams().appendParam("dataId", DATA_ID).appendParam("group", GROUP).appendParam("namespaceId", NAME_SPACE_ID)
.done(), String.class, HttpMethod.GET);
Params.newParams().appendParam("dataId", DATA_ID).appendParam("group", GROUP)
.appendParam("namespaceId", NAME_SPACE_ID).done(), String.class, HttpMethod.GET);
if (!ignoreStatusCode) {
if (!response.getStatusCode().is2xxSuccessful()) {
throw new RuntimeException("Fail to get config");
@ -141,13 +151,17 @@ public class ConfigAPI_V2_CITCase extends HttpClient4Test {
return json.get("data").asText();
}
/**
* Deletes a configuration.
*
* @throws Exception if an error occurs during the test.
*/
public void deleteConfig() throws Exception {
ResponseEntity<String> response = request(CONFIG_V2_CONTROLLER_PATH,
Params.newParams().appendParam("dataId", DATA_ID).appendParam("group", GROUP).appendParam("namespaceId", NAME_SPACE_ID)
.done(), String.class, HttpMethod.DELETE);
Params.newParams().appendParam("dataId", DATA_ID).appendParam("group", GROUP)
.appendParam("namespaceId", NAME_SPACE_ID).done(), String.class, HttpMethod.DELETE);
assertTrue(response.getStatusCode().is2xxSuccessful());
JsonNode json = JacksonUtils.toObj(response.getBody());
assertTrue(json.get("data").asBoolean());
}
}

View File

@ -32,14 +32,15 @@ import java.io.IOException;
*
* @see <a href="https://github.com/alibaba/nacos/issues/4181">#4171</a>
*/
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Nacos.class, properties = {"server.servlet.context-path=/",
"server.port=7001"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class ConfigAPI_With_RootContextPath_CITCase extends AbstractConfigAPI_CITCase {
class ConfigAPIWithRootContextPathConfigITCase extends AbstractConfigAPIConfigITCase {
@BeforeAll
static void beforeClass() throws IOException {
ConfigCleanUtils.changeToNewTestNacosHome(ConfigAPI_With_RootContextPath_CITCase.class.getSimpleName());
ConfigCleanUtils.changeToNewTestNacosHome(ConfigAPIWithRootContextPathConfigITCase.class.getSimpleName());
ConfigCleanUtils.cleanClientCache();
EnvUtil.setPort(7001);

View File

@ -44,13 +44,16 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Integration tests for Config API Beta functionality.
*
* @author xiaochun.xxc
* @date 2019-07-03
**/
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Nacos.class, properties = {
"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class ConfigBeta_CITCase {
class ConfigBetaConfigITCase {
static final String CONFIG_CONTROLLER_PATH = "/nacos/v1/cs";
@ -76,7 +79,7 @@ class ConfigBeta_CITCase {
@AfterAll
static void cleanClientCache() throws Exception {
ConfigCleanUtils.cleanClientCache();
ConfigCleanUtils.changeToNewTestNacosHome(ConfigBeta_CITCase.class.getSimpleName());
ConfigCleanUtils.changeToNewTestNacosHome(ConfigBetaConfigITCase.class.getSimpleName());
}
@BeforeEach
@ -85,9 +88,9 @@ class ConfigBeta_CITCase {
}
/**
* @TCDescription : 正常发布Beta配置
* @TestStep :
* @ExpectResult :
* Tests publishing a Beta configuration with all required parameters.
*
* @throws Exception if an error occurs during the publishing process
*/
@Test
void publishBetaConfig() throws Exception {
@ -95,63 +98,64 @@ class ConfigBeta_CITCase {
headers.add("betaIps", "127.0.0.1,127.0.0.2");
ResponseEntity<String> response = request(CONFIG_CONTROLLER_PATH + "/configs", headers,
Params.newParams().appendParam("dataId", dataId).appendParam("group", group).appendParam("tenant", tenant)
.appendParam("content", content).appendParam("config_tags", "").appendParam("appName", appName).done(),
String.class, HttpMethod.POST);
Params.newParams().appendParam("dataId", dataId).appendParam("group", group)
.appendParam("tenant", tenant).appendParam("content", content).appendParam("config_tags", "")
.appendParam("appName", appName).done(), String.class, HttpMethod.POST);
System.out.println("publishBetaConfig : " + response);
assertTrue(response.getStatusCode().is2xxSuccessful());
assertEquals("true", response.getBody());
}
/**
* @TCDescription : 必选content未设置的发布Beta配置
* @TestStep :
* @ExpectResult :
* Tests publishing a Beta configuration without the required content parameter.
*
* @throws Exception if an error occurs during the publishing process
*/
@Test
void publishBetaConfig_no_content() throws Exception {
void publishBetaConfigNoContent() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add("betaIps", "127.0.0.1,127.0.0.2");
ResponseEntity<String> response = request(CONFIG_CONTROLLER_PATH + "/configs", headers,
Params.newParams().appendParam("dataId", dataId).appendParam("group", group).appendParam("tenant", tenant)
.appendParam("config_tags", "").appendParam("appName", appName).done(), String.class, HttpMethod.POST);
Params.newParams().appendParam("dataId", dataId).appendParam("group", group)
.appendParam("tenant", tenant).appendParam("config_tags", "").appendParam("appName", appName)
.done(), String.class, HttpMethod.POST);
System.out.println("publishBetaConfig_no_content : " + response);
assertFalse(response.getStatusCode().is2xxSuccessful());
}
/**
* @TCDescription : 可选参数betaIps不存在时发布Beta配置应该不成功
* @TestStep :
* @ExpectResult :
* Tests publishing and retrieving a Beta configuration without beta IPs, expecting failure.
*
* @throws Exception if an error occurs during the publishing process
*/
@Test
void publishBetaConfig_noBetaIps_beta() throws Exception {
void publishBetaConfigNoBetaIpsBeta() throws Exception {
HttpHeaders headers = new HttpHeaders(); //不存在betaIps
ResponseEntity<String> response = request(CONFIG_CONTROLLER_PATH + "/configs", headers,
Params.newParams().appendParam("dataId", dataId).appendParam("group", group).appendParam("tenant", tenant)
.appendParam("content", content).appendParam("config_tags", "").appendParam("appName", appName).done(),
String.class, HttpMethod.POST);
Params.newParams().appendParam("dataId", dataId).appendParam("group", group)
.appendParam("tenant", tenant).appendParam("content", content).appendParam("config_tags", "")
.appendParam("appName", appName).done(), String.class, HttpMethod.POST);
System.out.println("publishBetaConfig_noBetaIps_beta post : " + response);
assertTrue(response.getStatusCode().is2xxSuccessful());
assertEquals("true", response.getBody());
ResponseEntity<String> response1 = request(CONFIG_CONTROLLER_PATH + "/configs?beta=true",
Params.newParams().appendParam("dataId", dataId).appendParam("group", group).appendParam("tenant", tenant).done(),
String.class, HttpMethod.GET);
Params.newParams().appendParam("dataId", dataId).appendParam("group", group)
.appendParam("tenant", tenant).done(), String.class, HttpMethod.GET);
System.out.println("publishBetaConfig_noBetaIps_beta get : " + response);
assertTrue(response1.getStatusCode().is2xxSuccessful());
assertTrue(JacksonUtils.toObj(response1.getBody()).get("data").isNull());
}
/**
* @TCDescription : 可选参数betaIps不存在时发布Beta配置应该不成功
* @TestStep :
* @ExpectResult :
* Tests publishing and retrieving a Beta configuration without beta IPs.
*
* @throws Exception if an error occurs during the process
*/
@Test
void publishBetaConfig_noBetaIps() throws Exception {
void publishBetaConfigNoBetaIps() throws Exception {
HttpHeaders headers = new HttpHeaders(); //不存在betaIps
@ -160,9 +164,9 @@ class ConfigBeta_CITCase {
final String content = "publishBetaConfig_noBetaIps";
ResponseEntity<String> response = request(CONFIG_CONTROLLER_PATH + "/configs", headers,
Params.newParams().appendParam("dataId", dataId).appendParam("group", groupId).appendParam("tenant", tenant)
.appendParam("content", content).appendParam("config_tags", "").appendParam("appName", appName).done(),
String.class, HttpMethod.POST);
Params.newParams().appendParam("dataId", dataId).appendParam("group", groupId)
.appendParam("tenant", tenant).appendParam("content", content).appendParam("config_tags", "")
.appendParam("appName", appName).done(), String.class, HttpMethod.POST);
System.out.println("publishBetaConfig_noBetaIps post : " + response);
assertTrue(response.getStatusCode().is2xxSuccessful());
assertEquals("true", response.getBody());
@ -170,17 +174,17 @@ class ConfigBeta_CITCase {
ThreadUtils.sleep(10_000L);
response = request(CONFIG_CONTROLLER_PATH + "/configs?beta=false",
Params.newParams().appendParam("dataId", dataId).appendParam("group", groupId).appendParam("tenant", tenant).done(),
String.class, HttpMethod.GET);
Params.newParams().appendParam("dataId", dataId).appendParam("group", groupId)
.appendParam("tenant", tenant).done(), String.class, HttpMethod.GET);
System.out.println("publishBetaConfig_noBetaIps get : " + response);
assertTrue(response.getStatusCode().is2xxSuccessful());
assertEquals(content, response.getBody());
}
/**
* @TCDescription : 正常获取Beta配置
* @TestStep :
* @ExpectResult :
* Tests retrieving a Beta configuration.
*
* @throws Exception if an error occurs during the process
*/
@Test
void getBetaConfig() throws Exception {
@ -188,25 +192,25 @@ class ConfigBeta_CITCase {
headers.add("betaIps", "127.0.0.1,127.0.0.2");
ResponseEntity<String> response = request(CONFIG_CONTROLLER_PATH + "/configs", headers,
Params.newParams().appendParam("dataId", dataId).appendParam("group", group).appendParam("tenant", tenant)
.appendParam("content", content).appendParam("config_tags", "").appendParam("appName", appName).done(),
String.class, HttpMethod.POST);
Params.newParams().appendParam("dataId", dataId).appendParam("group", group)
.appendParam("tenant", tenant).appendParam("content", content).appendParam("config_tags", "")
.appendParam("appName", appName).done(), String.class, HttpMethod.POST);
System.out.println("getBetaConfig post : " + response);
assertTrue(response.getStatusCode().is2xxSuccessful());
assertEquals("true", response.getBody());
response = request(CONFIG_CONTROLLER_PATH + "/configs?beta=true",
Params.newParams().appendParam("dataId", dataId).appendParam("group", group).appendParam("tenant", tenant).done(),
String.class, HttpMethod.GET);
Params.newParams().appendParam("dataId", dataId).appendParam("group", group)
.appendParam("tenant", tenant).done(), String.class, HttpMethod.GET);
System.out.println("getBetaConfig get : " + response);
assertTrue(response.getStatusCode().is2xxSuccessful());
assertEquals("com.dungu.test", JacksonUtils.toObj(response.getBody()).get("data").get("dataId").asText());
}
/**
* @TCDescription : 正常删除Beta配置
* @TestStep :
* @ExpectResult :
* Delete Beta configuration successfully.
*
* @throws Exception if an error occurs during the process
*/
@Test
void deleteBetaConfig() throws Exception {
@ -215,30 +219,30 @@ class ConfigBeta_CITCase {
headers.add("betaIps", "127.0.0.1,127.0.0.2");
ResponseEntity<String> response = request(CONFIG_CONTROLLER_PATH + "/configs", headers,
Params.newParams().appendParam("dataId", dataId).appendParam("group", group).appendParam("tenant", tenant)
.appendParam("content", content).appendParam("config_tags", "").appendParam("appName", appName).done(),
String.class, HttpMethod.POST);
Params.newParams().appendParam("dataId", dataId).appendParam("group", group)
.appendParam("tenant", tenant).appendParam("content", content).appendParam("config_tags", "")
.appendParam("appName", appName).done(), String.class, HttpMethod.POST);
System.out.println("deleteBetaConfig post : " + response);
assertTrue(response.getStatusCode().is2xxSuccessful());
assertEquals("true", response.getBody());
response = request(CONFIG_CONTROLLER_PATH + "/configs?beta=true",
Params.newParams().appendParam("dataId", dataId).appendParam("group", group).appendParam("tenant", tenant).done(),
String.class, HttpMethod.GET);
Params.newParams().appendParam("dataId", dataId).appendParam("group", group)
.appendParam("tenant", tenant).done(), String.class, HttpMethod.GET);
System.out.println("deleteBetaConfig get : " + response);
assertTrue(response.getStatusCode().is2xxSuccessful());
assertEquals("com.dungu.test", JacksonUtils.toObj(response.getBody()).get("data").get("dataId").asText());
response = request(CONFIG_CONTROLLER_PATH + "/configs?beta=true",
Params.newParams().appendParam("dataId", dataId).appendParam("group", group).appendParam("tenant", tenant).done(),
String.class, HttpMethod.DELETE);
Params.newParams().appendParam("dataId", dataId).appendParam("group", group)
.appendParam("tenant", tenant).done(), String.class, HttpMethod.DELETE);
System.out.println("deleteBetaConfig delete : " + response);
assertTrue(response.getStatusCode().is2xxSuccessful());
assertEquals("true", JacksonUtils.toObj(response.getBody()).get("data").asText());
response = request(CONFIG_CONTROLLER_PATH + "/configs?beta=true",
Params.newParams().appendParam("dataId", dataId).appendParam("group", group).appendParam("tenant", tenant).done(),
String.class, HttpMethod.GET);
Params.newParams().appendParam("dataId", dataId).appendParam("group", group)
.appendParam("tenant", tenant).done(), String.class, HttpMethod.GET);
System.out.println("deleteBetaConfig after delete then get : " + response);
assertTrue(response.getStatusCode().is2xxSuccessful());
assertTrue(JacksonUtils.toObj(response.getBody()).get("data").isNull());
@ -246,47 +250,48 @@ class ConfigBeta_CITCase {
/**
* @TCDescription : beta=false时删除Beta配置
* @TestStep :
* @ExpectResult :
* Delete Beta configuration with beta=false.
*
* @throws Exception if an error occurs during the process
*/
@Test
void deleteBetaConfig_delete_beta_false() throws Exception {
void deleteBetaConfigDeleteBetaFalse() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add("betaIps", "127.0.0.1,127.0.0.2");
ResponseEntity<String> response = request(CONFIG_CONTROLLER_PATH + "/configs", headers,
Params.newParams().appendParam("dataId", dataId).appendParam("group", group).appendParam("tenant", tenant)
.appendParam("content", content).appendParam("config_tags", "").appendParam("appName", appName).done(),
String.class, HttpMethod.POST);
Params.newParams().appendParam("dataId", dataId).appendParam("group", group)
.appendParam("tenant", tenant).appendParam("content", content).appendParam("config_tags", "")
.appendParam("appName", appName).done(), String.class, HttpMethod.POST);
System.out.println("deleteBetaConfig_delete_beta_false post : " + response);
assertTrue(response.getStatusCode().is2xxSuccessful());
assertEquals("true", response.getBody());
response = request(CONFIG_CONTROLLER_PATH + "/configs?beta=true",
Params.newParams().appendParam("dataId", dataId).appendParam("group", group).appendParam("tenant", tenant).done(),
String.class, HttpMethod.GET);
Params.newParams().appendParam("dataId", dataId).appendParam("group", group)
.appendParam("tenant", tenant).done(), String.class, HttpMethod.GET);
System.out.println("deleteBetaConfig_delete_beta_false get : " + response);
assertTrue(response.getStatusCode().is2xxSuccessful());
assertEquals("com.dungu.test", JacksonUtils.toObj(response.getBody()).get("data").get("dataId").asText());
response = request(CONFIG_CONTROLLER_PATH + "/configs?beta=false",
Params.newParams().appendParam("dataId", dataId).appendParam("group", group).appendParam("tenant", tenant).done(),
String.class, HttpMethod.DELETE);
Params.newParams().appendParam("dataId", dataId).appendParam("group", group)
.appendParam("tenant", tenant).done(), String.class, HttpMethod.DELETE);
System.out.println("deleteBetaConfig_delete_beta_false delete : " + response);
assertTrue(response.getStatusCode().is2xxSuccessful());
assertEquals("true", response.getBody());
response = request(CONFIG_CONTROLLER_PATH + "/configs?beta=true",
Params.newParams().appendParam("dataId", dataId).appendParam("group", group).appendParam("tenant", tenant).done(),
String.class, HttpMethod.GET);
Params.newParams().appendParam("dataId", dataId).appendParam("group", group)
.appendParam("tenant", tenant).done(), String.class, HttpMethod.GET);
System.out.println("deleteBetaConfig_delete_beta_false after delete then get : " + response);
assertTrue(response.getStatusCode().is2xxSuccessful());
assertEquals("com.dungu.test", JacksonUtils.toObj(response.getBody()).get("data").get("dataId").asText());
}
<T> ResponseEntity<T> request(String path, MultiValueMap<String, String> params, Class<T> clazz, HttpMethod httpMethod) {
<T> ResponseEntity<T> request(String path, MultiValueMap<String, String> params, Class<T> clazz,
HttpMethod httpMethod) {
HttpHeaders headers = new HttpHeaders();
@ -297,8 +302,8 @@ class ConfigBeta_CITCase {
return this.restTemplate.exchange(builder.toUriString(), httpMethod, entity, clazz);
}
<T> ResponseEntity<T> request(String path, HttpHeaders headers, MultiValueMap<String, String> params, Class<T> clazz,
HttpMethod httpMethod) {
<T> ResponseEntity<T> request(String path, HttpHeaders headers, MultiValueMap<String, String> params,
Class<T> clazz, HttpMethod httpMethod) {
HttpEntity<?> entity = new HttpEntity<T>(headers);

View File

@ -48,12 +48,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
*
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Nacos.class, properties = {
"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class ConfigDerbyImport_CITCase {
class ConfigDerbyImportConfigITCase {
private static String SQL_SCRIPT_CONTEXT =
private static final String SQL_SCRIPT_CONTEXT =
"INSERT INTO `config_info` (`id`, `data_id`, `group_id`, `content`, `md5`, `gmt_create`, `gmt_modified`, `src_user`, `src_ip`, `app_name`, `tenant_id`, `c_desc`, `c_use`, `effect`, `type`, `c_schema`) VALUES (1,'boot-test','ALIBABA','dept:123123123\\ngroup:123123123','2ca50d002a7dabf81497f666a7967e15','2020-04-13 13:44:43','2020-04-30 10:45:21',NULL,'127.0.0.1','','',NULL,NULL,NULL,NULL,NULL);\n"
+ "INSERT INTO `config_info` (`id`, `data_id`, `group_id`, `content`, `md5`, `gmt_create`, `gmt_modified`, `src_user`, `src_ip`, `app_name`, `tenant_id`, `c_desc`, `c_use`, `effect`, `type`, `c_schema`) VALUES (2,'people','DEFAULT_GROUP','people.enable=true','d92cbf8d02080017a805b7efc4481b6c','2020-04-13 13:44:43','2020-04-30 10:45:21',NULL,'127.0.0.1','','',NULL,NULL,NULL,NULL,NULL);\n"
+ "INSERT INTO `config_info` (`id`, `data_id`, `group_id`, `content`, `md5`, `gmt_create`, `gmt_modified`, `src_user`, `src_ip`, `app_name`, `tenant_id`, `c_desc`, `c_use`, `effect`, `type`, `c_schema`) VALUES (3,'apple','DEFAULT_GROUP','apple:\\n list:\\n - 1\\n - 2\\n - 3\\n - 4\\n listMap:\\n key-1:\\n - 1\\n - 2\\n - 3\\n - 4\\n key-2:\\n - aa\\n - dd\\n - ee\\n - rr','4eb5a2258ba6ecddd9631ec10cf36342','2020-04-13 13:44:43','2020-04-30 10:45:21',NULL,'127.0.0.1','','',NULL,NULL,NULL,NULL,NULL);\n"
@ -78,7 +79,7 @@ class ConfigDerbyImport_CITCase {
@BeforeAll
static void beforeClass() {
ConfigCleanUtils.changeToNewTestNacosHome(ConfigDerbyImport_CITCase.class.getSimpleName());
ConfigCleanUtils.changeToNewTestNacosHome(ConfigDerbyImportConfigITCase.class.getSimpleName());
}
@BeforeEach

View File

@ -58,20 +58,22 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Integration tests for Derby Raft configuration in the cluster environment.
*
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
@SuppressWarnings("all")
@TestMethodOrder(MethodName.class)
// todo the suffix is _DITCase, the case will be skipped by default
class ConfigDerbyRaft_DITCase extends BaseClusterTest {
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@TestMethodOrder(MethodName.class)
class ConfigDerbyRaftConfigITCase extends BaseClusterTest {
@BeforeAll
static void beforeClass() {
ConfigCleanUtils.changeToNewTestNacosHome(ConfigDerbyRaft_DITCase.class.getSimpleName());
ConfigCleanUtils.changeToNewTestNacosHome(ConfigDerbyRaftConfigITCase.class.getSimpleName());
}
@Test
void test_a_publish_config() throws Exception {
void testPublishConfigRaftCluster() throws Exception {
boolean result = iconfig7.publishConfig("raft_test", "cluster_test_1", "this.is.raft_cluster=lessspring_7");
assertTrue(result);
@ -89,12 +91,13 @@ class ConfigDerbyRaft_DITCase extends BaseClusterTest {
String s8 = operate8.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
String s9 = operate9.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
assertArrayEquals(new String[] {s7, s8, s9}, new String[] {"this.is.raft_cluster=lessspring_7", "this.is.raft_cluster=lessspring_7",
assertArrayEquals(new String[] {s7, s8, s9},
new String[] {"this.is.raft_cluster=lessspring_7", "this.is.raft_cluster=lessspring_7",
"this.is.raft_cluster=lessspring_7"}, "The three nodes must have consistent data");
}
@Test
void test_b_publish_config() throws Exception {
void testPublishConfigCluster() throws Exception {
ThreadUtils.sleep(5000);
boolean result = iconfig8.publishConfig("raft_test", "cluster_test_2", "this.is.raft_cluster=lessspring_8");
@ -114,12 +117,13 @@ class ConfigDerbyRaft_DITCase extends BaseClusterTest {
String s8 = operate8.findConfigInfo("raft_test", "cluster_test_2", "").getContent();
String s9 = operate9.findConfigInfo("raft_test", "cluster_test_2", "").getContent();
assertArrayEquals(new String[] {s7, s8, s9}, new String[] {"this.is.raft_cluster=lessspring_8", "this.is.raft_cluster=lessspring_8",
assertArrayEquals(new String[] {s7, s8, s9},
new String[] {"this.is.raft_cluster=lessspring_8", "this.is.raft_cluster=lessspring_8",
"this.is.raft_cluster=lessspring_8"}, "The three nodes must have consistent data");
}
@Test
void test_c_publish_config() throws Exception {
void testPublishConfigRaftClusterNew() throws Exception {
ThreadUtils.sleep(5000);
boolean result = iconfig9.publishConfig("raft_test", "cluster_test_2", "this.is.raft_cluster=lessspring_9");
assertTrue(result);
@ -138,13 +142,15 @@ class ConfigDerbyRaft_DITCase extends BaseClusterTest {
String s8 = operate8.findConfigInfo("raft_test", "cluster_test_2", "").getContent();
String s9 = operate9.findConfigInfo("raft_test", "cluster_test_2", "").getContent();
assertArrayEquals(new String[] {s7, s8, s9}, new String[] {"this.is.raft_cluster=lessspring_9", "this.is.raft_cluster=lessspring_9",
assertArrayEquals(new String[] {s7, s8, s9},
new String[] {"this.is.raft_cluster=lessspring_9", "this.is.raft_cluster=lessspring_9",
"this.is.raft_cluster=lessspring_9"}, "The three nodes must have consistent data");
}
@Test
void test_d_modify_config() throws Exception {
boolean result = iconfig7.publishConfig("raft_test", "cluster_test_1", "this.is.raft_cluster=lessspring_7_it_is_for_modify");
void testModifyConfigRaftCluster() throws Exception {
boolean result = iconfig7.publishConfig("raft_test", "cluster_test_1",
"this.is.raft_cluster=lessspring_7_it_is_for_modify");
assertTrue(result);
ThreadUtils.sleep(5000);
@ -161,13 +167,13 @@ class ConfigDerbyRaft_DITCase extends BaseClusterTest {
String s8 = operate8.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
String s9 = operate9.findConfigInfo("raft_test", "cluster_test_1", "").getContent();
assertArrayEquals(new String[] {s7, s8, s9},
new String[] {"this.is.raft_cluster=lessspring_7_it_is_for_modify", "this.is.raft_cluster=lessspring_7_it_is_for_modify",
assertArrayEquals(new String[] {s7, s8, s9}, new String[] {"this.is.raft_cluster=lessspring_7_it_is_for_modify",
"this.is.raft_cluster=lessspring_7_it_is_for_modify",
"this.is.raft_cluster=lessspring_7_it_is_for_modify"}, "The three nodes must have consistent data");
}
@Test
void test_l_client_operation() throws Exception {
void testClientOperationConfig() throws Exception {
final String dataId = "test_l_client_operation";
final String groupId = "test_l_client_operation";
String content = "test_l_client_operation" + System.currentTimeMillis();
@ -177,13 +183,13 @@ class ConfigDerbyRaft_DITCase extends BaseClusterTest {
assertTrue(result);
ThreadUtils.sleep(5000);
String v1_7 = iconfig7.getConfig(dataId, groupId, 5000L);
String v1_8 = iconfig8.getConfig(dataId, groupId, 5000L);
String v1_9 = iconfig9.getConfig(dataId, groupId, 5000L);
String v1Config7 = iconfig7.getConfig(dataId, groupId, 5000L);
String v1Config8 = iconfig8.getConfig(dataId, groupId, 5000L);
String v1Config9 = iconfig9.getConfig(dataId, groupId, 5000L);
assertEquals(content, v1_7);
assertEquals(content, v1_8);
assertEquals(content, v1_9);
assertEquals(content, v1Config7);
assertEquals(content, v1Config8);
assertEquals(content, v1Config9);
// publish by 8848
content = "test_l_client_operation" + System.currentTimeMillis();
@ -191,13 +197,13 @@ class ConfigDerbyRaft_DITCase extends BaseClusterTest {
assertTrue(result);
ThreadUtils.sleep(5000);
String v2_7 = iconfig7.getConfig(dataId, groupId, 5000L);
String v2_8 = iconfig8.getConfig(dataId, groupId, 5000L);
String v2_9 = iconfig9.getConfig(dataId, groupId, 5000L);
String v2Config7 = iconfig7.getConfig(dataId, groupId, 5000L);
String v2Config8 = iconfig8.getConfig(dataId, groupId, 5000L);
String v2Config9 = iconfig9.getConfig(dataId, groupId, 5000L);
assertEquals(content, v2_7);
assertEquals(content, v2_8);
assertEquals(content, v2_9);
assertEquals(content, v2Config7);
assertEquals(content, v2Config8);
assertEquals(content, v2Config9);
// publish by 8849
content = "test_l_client_operation" + System.currentTimeMillis();
@ -205,30 +211,30 @@ class ConfigDerbyRaft_DITCase extends BaseClusterTest {
assertTrue(result);
ThreadUtils.sleep(5000);
String v3_7 = iconfig7.getConfig(dataId, groupId, 5000L);
String v3_8 = iconfig8.getConfig(dataId, groupId, 5000L);
String v3_9 = iconfig9.getConfig(dataId, groupId, 5000L);
String v3Config7 = iconfig7.getConfig(dataId, groupId, 5000L);
String v3Config8 = iconfig8.getConfig(dataId, groupId, 5000L);
String v3Config9 = iconfig9.getConfig(dataId, groupId, 5000L);
assertEquals(content, v3_7);
assertEquals(content, v3_8);
assertEquals(content, v3_9);
assertEquals(content, v3Config7);
assertEquals(content, v3Config8);
assertEquals(content, v3Config9);
// delete by 8849
result = iconfig9.removeConfig(dataId, groupId);
assertTrue(result);
ThreadUtils.sleep(5000);
String v4_7 = iconfig7.getConfig(dataId, groupId, 5000L);
String v4_8 = iconfig8.getConfig(dataId, groupId, 5000L);
String v4_9 = iconfig9.getConfig(dataId, groupId, 5000L);
String v4Config7 = iconfig7.getConfig(dataId, groupId, 5000L);
String v4Config8 = iconfig8.getConfig(dataId, groupId, 5000L);
String v4Config9 = iconfig9.getConfig(dataId, groupId, 5000L);
assertNull(v4_7);
assertNull(v4_8);
assertNull(v4_9);
assertNull(v4Config7);
assertNull(v4Config8);
assertNull(v4Config9);
}
@Test
void test_k_config_listener() throws Exception {
void testConfigListener() throws Exception {
String dataId = "test_h_config_listener";
String group = "test_h_config_listener";
String content = "test_h_config_listener";
@ -261,7 +267,7 @@ class ConfigDerbyRaft_DITCase extends BaseClusterTest {
}
@Test
void test_e_derby_ops() throws Exception {
void testDerbyOperations() throws Exception {
String url = "http://127.0.0.1:8848/nacos/v1/cs/ops/derby";
Query query = Query.newInstance().addParam("sql", "select * from users");
RestResult<List<Map<String, Object>>> result = NACOS_REST_TEMPLATE.get(url, Header.EMPTY, query,
@ -275,10 +281,11 @@ class ConfigDerbyRaft_DITCase extends BaseClusterTest {
}
@Test
void test_g_derby_ops_no_select() throws Exception {
void testDerbyOperationsNoSelect() throws Exception {
String url = "http://127.0.0.1:8848/nacos/v1/cs/ops/derby";
Query query = Query.newInstance().addParam("sql", "update users set username='nacos'");
RestResult<Object> result = NACOS_REST_TEMPLATE.get(url, Header.EMPTY, query, new GenericType<RestResult<Object>>() {
RestResult<Object> result = NACOS_REST_TEMPLATE.get(url, Header.EMPTY, query,
new GenericType<RestResult<Object>>() {
}.getType());
System.out.println(result);
assertFalse(result.ok());
@ -286,11 +293,12 @@ class ConfigDerbyRaft_DITCase extends BaseClusterTest {
}
@Test
void test_h_derby_has_error() throws Exception {
void testDerbyWithErrorHandling() throws Exception {
ThreadUtils.sleep(5000);
boolean result = iconfig7.publishConfig("raft_test_raft_error", "cluster_test_1", "this.is.raft_cluster=lessspring_7");
boolean result = iconfig7.publishConfig("raft_test_raft_error", "cluster_test_1",
"this.is.raft_cluster=lessspring_7");
assertTrue(result);
NotifyCenter.registerToPublisher(RaftDbErrorRecoverEvent.class, 8);
@ -334,7 +342,7 @@ class ConfigDerbyRaft_DITCase extends BaseClusterTest {
}
@Test
void test_f_id_generator_leader_transfer() throws Exception {
void testIdGeneratorLeaderTransfer() throws Exception {
ConfigurableApplicationContext context7 = applications.get("8847");
ConfigurableApplicationContext context8 = applications.get("8848");
ConfigurableApplicationContext context9 = applications.get("8849");
@ -348,7 +356,6 @@ class ConfigDerbyRaft_DITCase extends BaseClusterTest {
final String configGroup = PersistenceConstant.CONFIG_MODEL_RAFT_GROUP;
long preId = -1L;
long currentId = -1L;
if (protocol7.isLeader(configGroup)) {
preId = manager7.nextId(CONFIG_INFO_ID);
@ -371,7 +378,7 @@ class ConfigDerbyRaft_DITCase extends BaseClusterTest {
TimeUnit.SECONDS.sleep(2);
assertTrue(protocol7.isLeader(configGroup));
currentId = manager7.nextId(CONFIG_INFO_ID);
long currentId = manager7.nextId(CONFIG_INFO_ID);
assertNotEquals(preId, currentId);
preId = currentId;
@ -403,7 +410,6 @@ class ConfigDerbyRaft_DITCase extends BaseClusterTest {
assertTrue(protocol9.isLeader(configGroup));
currentId = manager9.nextId(CONFIG_INFO_ID);
assertNotEquals(preId, currentId);
}
}

View File

@ -80,11 +80,11 @@ import static org.junit.jupiter.api.Assertions.fail;
* @author klw
* @date 2019/5/23 15:26
*/
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Nacos.class, properties = {
"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@SuppressWarnings({"checkstyle:TypeName", "checkstyle:AbbreviationAsWordInName"})
class ConfigExportAndImportAPI_CITCase {
class ConfigExportAndImportAPIConfigITCase {
private static final long TIME_OUT = 2000;
@ -103,7 +103,7 @@ class ConfigExportAndImportAPI_CITCase {
@AfterAll
static void cleanClientCache() throws Exception {
ConfigCleanUtils.cleanClientCache();
ConfigCleanUtils.changeToNewTestNacosHome(ConfigExportAndImportAPI_CITCase.class.getSimpleName());
ConfigCleanUtils.changeToNewTestNacosHome(ConfigExportAndImportAPIConfigITCase.class.getSimpleName());
}
@BeforeEach
@ -112,8 +112,10 @@ class ConfigExportAndImportAPI_CITCase {
// register a handler to process byte[] result
nacosRestTemplate.registerResponseHandler(byte[].class.getName(), new AbstractResponseHandler() {
@Override
public HttpRestResult<byte[]> convertResult(HttpClientResponse response, Type responseType) throws Exception {
return new HttpRestResult(response.getHeaders(), response.getStatusCode(), IOUtils.toByteArray(response.getBody()), null);
public HttpRestResult<byte[]> convertResult(HttpClientResponse response, Type responseType)
throws Exception {
return new HttpRestResult(response.getHeaders(), response.getStatusCode(),
IOUtils.toByteArray(response.getBody()), null);
}
});
@ -149,12 +151,12 @@ class ConfigExportAndImportAPI_CITCase {
@AfterEach
void cleanup() throws Exception {
Assertions.assertDoesNotThrow(() -> {
HttpRestResult<String> result;
Map<String, String> params = new HashMap<>();
params.put("dataId", "testNoAppname1.yml");
params.put("group", "EXPORT_IMPORT_TEST_GROUP");
params.put("beta", "false");
result = agent.httpDelete(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT);
HttpRestResult<String> result = agent.httpDelete(CONFIG_CONTROLLER_PATH + "/", null, params,
agent.getEncode(), TIME_OUT);
assertEquals(HttpURLConnection.HTTP_OK, result.getCode());
params.put("dataId", "testNoAppname2.txt");
@ -305,8 +307,8 @@ class ConfigExportAndImportAPI_CITCase {
String config3Name = "EXPORT_IMPORT_TEST_GROUP/testHasAppname1.properties";
int successCount = 0;
for (ZipUtils.ZipItem zipItem : zipItemList) {
if (config1Name.equals(zipItem.getItemName()) || config2Name.equals(zipItem.getItemName()) || config3Name.equals(
zipItem.getItemName())) {
if (config1Name.equals(zipItem.getItemName()) || config2Name.equals(zipItem.getItemName())
|| config3Name.equals(zipItem.getItemName())) {
successCount++;
}
}
@ -334,8 +336,8 @@ class ConfigExportAndImportAPI_CITCase {
final String importUrl = "?import=true&namespace=";
Map<String, String> importPrarm = new HashMap<>(1);
importPrarm.put("policy", "OVERWRITE");
String importResult = uploadZipFile(serverAddr + CONFIG_CONTROLLER_PATH + importUrl, importPrarm, "testImport.zip",
ZipUtils.zip(zipItemList));
String importResult = uploadZipFile(serverAddr + CONFIG_CONTROLLER_PATH + importUrl, importPrarm,
"testImport.zip", ZipUtils.zip(zipItemList));
System.out.println("importResult: " + importResult);
// test unrecognizedData
@ -396,7 +398,8 @@ class ConfigExportAndImportAPI_CITCase {
private String packageMetaName(String group, String dataId) {
String tempDataId = dataId;
if (tempDataId.contains(".")) {
tempDataId = tempDataId.substring(0, tempDataId.lastIndexOf(".")) + "~" + tempDataId.substring(tempDataId.lastIndexOf(".") + 1);
tempDataId = tempDataId.substring(0, tempDataId.lastIndexOf(".")) + "~" + tempDataId.substring(
tempDataId.lastIndexOf(".") + 1);
}
return group + "." + tempDataId + ".app";
}
@ -404,7 +407,8 @@ class ConfigExportAndImportAPI_CITCase {
@Test
void testExportV2() {
String dataId = "testNoAppname2.txt";
String getDataUrl = "?search=accurate&group=TEST1_GROUP&pageNo=1&pageSize=10&tenant=&namespaceId=&dataId=" + dataId;
String getDataUrl =
"?search=accurate&group=TEST1_GROUP&pageNo=1&pageSize=10&tenant=&namespaceId=&dataId=" + dataId;
String queryResult = httpGetString(serverAddr + CONFIG_CONTROLLER_PATH + getDataUrl, null);
JsonNode resultObj = JacksonUtils.toObj(queryResult);
JsonNode resultConfigs = resultObj.get("pageItems");
@ -441,8 +445,10 @@ class ConfigExportAndImportAPI_CITCase {
config1Metadata.setDataId(dataId);
config1Metadata.setGroup(group);
config1Metadata.setType(configDetailResult.get("type").asText());
config1Metadata.setAppName(configDetailResult.get("appName") == null ? null : configDetailResult.get("appName").asText());
config1Metadata.setDesc(configDetailResult.get("desc") == null ? null : configDetailResult.get("desc").asText());
config1Metadata.setAppName(
configDetailResult.get("appName") == null ? null : configDetailResult.get("appName").asText());
config1Metadata.setDesc(
configDetailResult.get("desc") == null ? null : configDetailResult.get("desc").asText());
ConfigMetadata.ConfigExportItem configExportItem1 = configMetadata.getMetadata().get(0);
assertEquals(configExportItem1, config1Metadata);
@ -452,22 +458,21 @@ class ConfigExportAndImportAPI_CITCase {
void testImportV2() {
List<ZipUtils.ZipItem> zipItemList = new ArrayList<>(3);
zipItemList.add(new ZipUtils.ZipItem("TEST_IMPORT2/test1", "test: test1"));
String metaDataStr =
"metadata:\n" + "- appName: testAppName\n" + " dataId: test1\n" + " desc: testDesc\n" + " group: TEST_IMPORT2\n"
+ " type: yaml";
String metaDataStr = "metadata:\n" + "- appName: testAppName\n" + " dataId: test1\n" + " desc: testDesc\n"
+ " group: TEST_IMPORT2\n" + " type: yaml";
zipItemList.add(new ZipUtils.ZipItem(Constants.CONFIG_EXPORT_METADATA_NEW, metaDataStr));
final String importUrl = "?import=true&namespace=";
Map<String, String> importPrarm = new HashMap<>(1);
importPrarm.put("policy", "OVERWRITE");
String importResult = uploadZipFile(serverAddr + CONFIG_CONTROLLER_PATH + importUrl, importPrarm, "testImport.zip",
ZipUtils.zip(zipItemList));
String importResult = uploadZipFile(serverAddr + CONFIG_CONTROLLER_PATH + importUrl, importPrarm,
"testImport.zip", ZipUtils.zip(zipItemList));
JsonNode importResObj = JacksonUtils.toObj(importResult);
assertEquals(1, importResObj.get("data").get("succCount").asInt());
String queryConfigDetailResult = httpGetString(serverAddr + CONFIG_CONTROLLER_PATH + "?show=all&dataId=test1&group=TEST_IMPORT2",
null);
String queryConfigDetailResult = httpGetString(
serverAddr + CONFIG_CONTROLLER_PATH + "?show=all&dataId=test1&group=TEST_IMPORT2", null);
JsonNode configDetailResult = JacksonUtils.toObj(queryConfigDetailResult);
assertNotNull(configDetailResult);
@ -482,14 +487,16 @@ class ConfigExportAndImportAPI_CITCase {
void testImportV2MetadataError() {
List<ZipUtils.ZipItem> zipItemList = new ArrayList<>(3);
zipItemList.add(new ZipUtils.ZipItem("TEST_IMPORT2/test2", "test: test2"));
String metaDataStr = "metadata:\n" + "- appName: testAppName\n" + " desc: test desc\n" + " group: TEST_IMPORT\n" + " type: yaml";
String metaDataStr =
"metadata:\n" + "- appName: testAppName\n" + " desc: test desc\n" + " group: TEST_IMPORT\n"
+ " type: yaml";
zipItemList.add(new ZipUtils.ZipItem(Constants.CONFIG_EXPORT_METADATA_NEW, metaDataStr));
final String importUrl = "?import=true&namespace=";
Map<String, String> importPrarm = new HashMap<>(1);
importPrarm.put("policy", "OVERWRITE");
String importResult = uploadZipFile(serverAddr + CONFIG_CONTROLLER_PATH + importUrl, importPrarm, "testImport.zip",
ZipUtils.zip(zipItemList));
String importResult = uploadZipFile(serverAddr + CONFIG_CONTROLLER_PATH + importUrl, importPrarm,
"testImport.zip", ZipUtils.zip(zipItemList));
JsonNode importResObj = JacksonUtils.toObj(importResult);
assertEquals(importResObj.get("code").intValue(), ResultCodeEnum.METADATA_ILLEGAL.getCode());
@ -500,15 +507,15 @@ class ConfigExportAndImportAPI_CITCase {
void testImportV2MetadataNotFind() {
List<ZipUtils.ZipItem> zipItemList = new ArrayList<>(3);
zipItemList.add(new ZipUtils.ZipItem("TEST_IMPORT2/test3.yml", "test: test3"));
String metaDataStr = "metadata:\n" + "- dataId: notExist\n" + " group: TEST_IMPORT2\n" + " type: yaml\n" + "- dataId: test3.yml\n"
+ " group: TEST_IMPORT2\n" + " type: yaml";
String metaDataStr = "metadata:\n" + "- dataId: notExist\n" + " group: TEST_IMPORT2\n" + " type: yaml\n"
+ "- dataId: test3.yml\n" + " group: TEST_IMPORT2\n" + " type: yaml";
zipItemList.add(new ZipUtils.ZipItem(Constants.CONFIG_EXPORT_METADATA_NEW, metaDataStr));
final String importUrl = "?import=true&namespace=";
Map<String, String> importPrarm = new HashMap<>(1);
importPrarm.put("policy", "OVERWRITE");
String importResult = uploadZipFile(serverAddr + CONFIG_CONTROLLER_PATH + importUrl, importPrarm, "testImport.zip",
ZipUtils.zip(zipItemList));
String importResult = uploadZipFile(serverAddr + CONFIG_CONTROLLER_PATH + importUrl, importPrarm,
"testImport.zip", ZipUtils.zip(zipItemList));
JsonNode importResObj = JacksonUtils.toObj(importResult);
JsonNode data = importResObj.get("data");
@ -526,16 +533,15 @@ class ConfigExportAndImportAPI_CITCase {
List<ZipUtils.ZipItem> zipItemList = new ArrayList<>(3);
zipItemList.add(new ZipUtils.ZipItem("TEST_IMPORT2/test4", "test: test4"));
zipItemList.add(new ZipUtils.ZipItem("TEST_IMPORT2/ignore.yml", "test: test4"));
String metaDataStr =
"metadata:\n" + "- appName: testAppName\n" + " dataId: test4\n" + " desc: testDesc\n" + " group: TEST_IMPORT2\n"
+ " type: yaml";
String metaDataStr = "metadata:\n" + "- appName: testAppName\n" + " dataId: test4\n" + " desc: testDesc\n"
+ " group: TEST_IMPORT2\n" + " type: yaml";
zipItemList.add(new ZipUtils.ZipItem(Constants.CONFIG_EXPORT_METADATA_NEW, metaDataStr));
final String importUrl = "?import=true&namespace=";
Map<String, String> importPrarm = new HashMap<>(1);
importPrarm.put("policy", "OVERWRITE");
String importResult = uploadZipFile(serverAddr + CONFIG_CONTROLLER_PATH + importUrl, importPrarm, "testImport.zip",
ZipUtils.zip(zipItemList));
String importResult = uploadZipFile(serverAddr + CONFIG_CONTROLLER_PATH + importUrl, importPrarm,
"testImport.zip", ZipUtils.zip(zipItemList));
JsonNode importResObj = JacksonUtils.toObj(importResult);
JsonNode data = importResObj.get("data");
@ -587,7 +593,8 @@ class ConfigExportAndImportAPI_CITCase {
int connectTimeout = 10000;
int socketTimeout = 10000;
HttpPost httpPost = new HttpPost(url);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(connectTimeout).setSocketTimeout(socketTimeout).build();
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(connectTimeout)
.setSocketTimeout(socketTimeout).build();
httpPost.setConfig(requestConfig);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();

View File

@ -38,13 +38,16 @@ import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
/**
* Integration test case for long polling configuration updates using Nacos.
*
* @author liaochuntao
* @date 2019-06-07 22:24
**/
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Nacos.class, properties = {
"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class ConfigLongPoll_CITCase {
class ConfigLongPollConfigITCase {
@LocalServerPort
private int port;
@ -55,7 +58,7 @@ class ConfigLongPoll_CITCase {
@AfterAll
static void cleanClientCache() throws Exception {
ConfigCleanUtils.cleanClientCache();
ConfigCleanUtils.changeToNewTestNacosHome(ConfigLongPoll_CITCase.class.getSimpleName());
ConfigCleanUtils.changeToNewTestNacosHome(ConfigLongPollConfigITCase.class.getSimpleName());
}
@ -74,6 +77,7 @@ class ConfigLongPoll_CITCase {
try {
configService.shutDown();
} catch (NacosException ex) {
// ignore
}
}

View File

@ -44,10 +44,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Nacos.class, properties = {
"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class ConfigLongPollReturnChanges_CITCase {
class ConfigLongPollReturnChangesConfigITCase {
@LocalServerPort
private int port;
@ -58,7 +59,7 @@ class ConfigLongPollReturnChanges_CITCase {
@AfterAll
static void cleanClientCache() throws Exception {
ConfigCleanUtils.cleanClientCache();
ConfigCleanUtils.changeToNewTestNacosHome(ConfigLongPollReturnChanges_CITCase.class.getSimpleName());
ConfigCleanUtils.changeToNewTestNacosHome(ConfigLongPollReturnChangesConfigITCase.class.getSimpleName());
}
@BeforeEach
@ -76,6 +77,7 @@ class ConfigLongPollReturnChanges_CITCase {
try {
configService.shutDown();
} catch (NacosException ex) {
// ignore
}
}

View File

@ -31,19 +31,22 @@ import java.util.concurrent.Executors;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Integration test case for managing embedded storage contexts using utilities.
*
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
class EmbeddedStorageContextUtils_CITCase {
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
class EmbeddedStorageContextUtilsConfigITCase {
@BeforeAll
@AfterAll
static void cleanClientCache() throws Exception {
ConfigCleanUtils.cleanClientCache();
ConfigCleanUtils.changeToNewTestNacosHome(EmbeddedStorageContextUtils_CITCase.class.getSimpleName());
ConfigCleanUtils.changeToNewTestNacosHome(EmbeddedStorageContextUtilsConfigITCase.class.getSimpleName());
}
@Test
void test_multi_thread_sql_contexts() throws Exception {
void testMultiThreadSqlContexts() throws Exception {
CountDownLatch latch = new CountDownLatch(3);
ExecutorService service = Executors.newFixedThreadPool(3);

View File

@ -26,7 +26,6 @@ import com.alibaba.nacos.common.remote.client.RpcConstants;
import com.alibaba.nacos.test.base.ConfigCleanUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.MethodOrderer.MethodName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
@ -44,22 +43,24 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* use configPublishRequest for communication verification between client and server.
* Use configPublishRequest for communication verification between client and server.
*
* @author githubcheng2978.
*/
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@ExtendWith(SpringExtension.class)
@TestMethodOrder(MethodName.class)
@SpringBootTest(classes = {Nacos.class}, properties = {"nacos.standalone=true", RpcConstants.NACOS_SERVER_RPC + ".enableTls=true",
RpcConstants.NACOS_SERVER_RPC + ".compatibility=true", RpcConstants.NACOS_SERVER_RPC + ".certChainFile=test-server-cert.pem",
RpcConstants.NACOS_SERVER_RPC + ".certPrivateKey=test-server-key.pem"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class NacosConfigServiceComTlsGrpcClient_CITCase {
@SpringBootTest(classes = {Nacos.class}, properties = {"nacos.standalone=true",
RpcConstants.NACOS_SERVER_RPC + ".enableTls=true", RpcConstants.NACOS_SERVER_RPC + ".compatibility=true",
RpcConstants.NACOS_SERVER_RPC + ".certChainFile=test-server-cert.pem", RpcConstants.NACOS_SERVER_RPC
+ ".certPrivateKey=test-server-key.pem"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class NacosConfigServiceComTlsGrpcClientConfigITCase {
public static AtomicInteger increment = new AtomicInteger(100);
@BeforeAll
static void beforeClass() throws IOException {
ConfigCleanUtils.changeToNewTestNacosHome(NacosConfigServiceComTlsGrpcClient_CITCase.class.getSimpleName());
ConfigCleanUtils.changeToNewTestNacosHome(NacosConfigServiceComTlsGrpcClientConfigITCase.class.getSimpleName());
}
@BeforeAll
@ -69,7 +70,7 @@ public class NacosConfigServiceComTlsGrpcClient_CITCase {
}
@Test
void test_e_TlsServerAndPlainClient() throws Exception {
void testTlsServerAndPlainClient() throws Exception {
Properties propertiesfalse = new Properties();
propertiesfalse.put(RpcConstants.RPC_CLIENT_TLS_ENABLE, "false");
propertiesfalse.put("serverAddr", "127.0.0.1");

View File

@ -43,21 +43,22 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* use configPublishRequest for communication verification between client and server.
* Use configPublishRequest for communication verification between client and server.
*
* @author githubcheng2978.
*/
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = {Nacos.class}, properties = {"nacos.standalone=true", RpcConstants.NACOS_SERVER_RPC + ".enableTls=true",
RpcConstants.NACOS_SERVER_RPC + ".compatibility=false", RpcConstants.NACOS_SERVER_RPC + ".certChainFile=test-server-cert.pem",
RpcConstants.NACOS_SERVER_RPC + ".certPrivateKey=test-server-key.pem"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class NacosConfigServiceNoComTlsGrpcClient_CITCase {
public class NacosConfigServiceNoComTlsGrpcClientConfigITCase {
public static AtomicInteger increment = new AtomicInteger(100);
@BeforeAll
static void beforeClass() throws IOException {
ConfigCleanUtils.changeToNewTestNacosHome(NacosConfigServiceNoComTlsGrpcClient_CITCase.class.getSimpleName());
ConfigCleanUtils.changeToNewTestNacosHome(NacosConfigServiceNoComTlsGrpcClientConfigITCase.class.getSimpleName());
}
@BeforeAll
@ -68,7 +69,7 @@ public class NacosConfigServiceNoComTlsGrpcClient_CITCase {
@Test
@Disabled("TODO, Fix cert expired problem")
void test_e_TlsServerAndTlsClient() throws Exception {
void testTlsServerAndTlsClient() throws Exception {
Properties properties = new Properties();
properties.put(RpcConstants.RPC_CLIENT_TLS_ENABLE, "true");
properties.put(RpcConstants.RPC_CLIENT_TLS_PROVIDER, "openssl");
@ -97,7 +98,7 @@ public class NacosConfigServiceNoComTlsGrpcClient_CITCase {
}
@Test
void test_e_TlsServerAndPlainClient() throws Exception {
void testTlsServerAndPlainClient() throws Exception {
Properties propertiesfalse = new Properties();
propertiesfalse.put(RpcConstants.RPC_CLIENT_TLS_ENABLE, "false");
propertiesfalse.put("serverAddr", "127.0.0.1");

View File

@ -43,24 +43,24 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* use configPublishRequest for communication verification between client and server.
* Use configPublishRequest for communication verification between client and server.
*
* @author githubcheng2978.
*/
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = {Nacos.class}, properties = {"nacos.standalone=true", RpcConstants.NACOS_SERVER_RPC + ".enableTls=true",
RpcConstants.NACOS_SERVER_RPC + ".mutualAuthEnable=true", RpcConstants.NACOS_SERVER_RPC + ".compatibility=false",
RpcConstants.NACOS_SERVER_RPC + ".certChainFile=test-server-cert.pem",
RpcConstants.NACOS_SERVER_RPC + ".certPrivateKey=test-server-key.pem", RpcConstants.NACOS_SERVER_RPC
+ ".trustCollectionCertFile=test-ca-cert.pem"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class NacosConfigV2MutualAuth_CITCase {
public class NacosConfigV2MutualAuthConfigITCase {
public static AtomicInteger increment = new AtomicInteger(100);
@BeforeAll
static void beforeClass() throws IOException {
ConfigCleanUtils.changeToNewTestNacosHome(NacosConfigV2MutualAuth_CITCase.class.getSimpleName());
ConfigCleanUtils.changeToNewTestNacosHome(NacosConfigV2MutualAuthConfigITCase.class.getSimpleName());
}
@ -71,7 +71,7 @@ public class NacosConfigV2MutualAuth_CITCase {
@Test
@Disabled("TODO, Fix cert expired problem")
void test_d_MutualAuth() throws Exception {
void testMutualAuth() throws Exception {
Properties propertiesfalse = new Properties();
propertiesfalse.put(RpcConstants.RPC_CLIENT_TLS_ENABLE, "true");
propertiesfalse.put(RpcConstants.RPC_CLIENT_MUTUAL_AUTH, "true");
@ -101,7 +101,7 @@ public class NacosConfigV2MutualAuth_CITCase {
}
@Test
void test_d_MutualAuthButClientNot() throws Exception {
void testMutualAuthButClientNot() throws Exception {
Properties propertiesfalse = new Properties();
propertiesfalse.put(RpcConstants.RPC_CLIENT_TLS_ENABLE, "true");