From 9e21a2cf4695ac0e49ae2be2c68bffedad66f4bc Mon Sep 17 00:00:00 2001 From: KomachiSion <263976490@qq.com> Date: Wed, 3 Jun 2020 14:38:23 +0800 Subject: [PATCH 1/6] Replace fastjson with jackson for nacos-test/common --- test/src/test/java/com/alibaba/nacos/test/BaseTest.java | 4 ++-- .../com/alibaba/nacos/test/common/HttpUtils_ITCase.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/src/test/java/com/alibaba/nacos/test/BaseTest.java b/test/src/test/java/com/alibaba/nacos/test/BaseTest.java index 343b71494..b88465e03 100644 --- a/test/src/test/java/com/alibaba/nacos/test/BaseTest.java +++ b/test/src/test/java/com/alibaba/nacos/test/BaseTest.java @@ -16,7 +16,7 @@ package com.alibaba.nacos.test; -import com.alibaba.fastjson.JSON; +import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.naming.healthcheck.RsInfo; import org.junit.Test; @@ -32,7 +32,7 @@ public class BaseTest { @Test public void test_rs_json() { String json = "{\"cluster\":\"DEFAULT\",\"ip\":\"127.0.0.1\",\"metadata\":{},\"port\":60000,\"scheduled\":true,\"serviceName\":\"DEFAULT_GROUP@@jinhan9J7ye.Vj6hx.net\",\"weight\":1.0}"; - RsInfo client = JSON.parseObject(json, RsInfo.class); + RsInfo client = JacksonUtils.toObj(json, RsInfo.class); System.out.println(client); } diff --git a/test/src/test/java/com/alibaba/nacos/test/common/HttpUtils_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/common/HttpUtils_ITCase.java index 647a7e2ac..bcd483e56 100644 --- a/test/src/test/java/com/alibaba/nacos/test/common/HttpUtils_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/common/HttpUtils_ITCase.java @@ -16,11 +16,11 @@ package com.alibaba.nacos.test.common; -import com.alibaba.fastjson.JSON; import com.alibaba.nacos.common.http.HttpUtils; import com.alibaba.nacos.common.http.handler.ResponseHandler; import com.alibaba.nacos.common.http.param.Query; import com.alibaba.nacos.common.model.RestResult; +import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.core.utils.ClassUtils; import com.alibaba.nacos.core.utils.GenericType; import org.junit.Assert; @@ -44,7 +44,7 @@ public class HttpUtils_ITCase { @Test public void test_deserialization_type() throws Exception { - String json = JSON.toJSONString(list); + String json = JacksonUtils.toJson(list); ArrayList tmp = ResponseHandler.convert(json, new GenericType>(){}.getType()); Assert.assertEquals(list, tmp); } @@ -58,7 +58,7 @@ public class HttpUtils_ITCase { @Test public void test_deserialization_class() throws Exception { - String json = JSON.toJSONString(list); + String json = JacksonUtils.toJson(list); ArrayList tmp = ResponseHandler.convert(json, ClassUtils.resolveGenericType(new GenericType>(){}.getClass())); Assert.assertEquals(list, tmp); } From c0b43852879fca1521641a4ba161bfce46613b58 Mon Sep 17 00:00:00 2001 From: KomachiSion <263976490@qq.com> Date: Wed, 3 Jun 2020 14:39:05 +0800 Subject: [PATCH 2/6] Replace fastjson with jackson for nacos-test/config --- .../nacos/test/config/ConfigAPI_ITCase.java | 28 +++++----- .../nacos/test/config/ConfigBeta_ITCase.java | 20 +++---- .../ConfigExportAndImportAPI_ITCase.java | 52 +++++++++---------- 3 files changed, 47 insertions(+), 53 deletions(-) diff --git a/test/src/test/java/com/alibaba/nacos/test/config/ConfigAPI_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/config/ConfigAPI_ITCase.java index 7b47b2415..d72538266 100644 --- a/test/src/test/java/com/alibaba/nacos/test/config/ConfigAPI_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/config/ConfigAPI_ITCase.java @@ -15,7 +15,6 @@ */ package com.alibaba.nacos.test.config; -import com.alibaba.fastjson.JSON; import com.alibaba.nacos.Nacos; import com.alibaba.nacos.api.NacosFactory; import com.alibaba.nacos.api.PropertyKeyConst; @@ -28,6 +27,7 @@ import com.alibaba.nacos.client.config.http.HttpAgent; import com.alibaba.nacos.client.config.http.MetricsHttpAgent; import com.alibaba.nacos.client.config.http.ServerHttpAgent; import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult; +import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.common.utils.ThreadUtils; import org.junit.After; import org.junit.Assert; @@ -84,7 +84,7 @@ public class ConfigAPI_ITCase { List params = Arrays.asList("dataId", dataId, "group", group, "beta", "true"); result = agent.httpDelete(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); - Assert.assertEquals(true, JSON.parseObject(result.content).getBoolean("data")); + Assert.assertTrue(JacksonUtils.toObj(result.content).get("data").booleanValue()); } catch (Exception e) { e.printStackTrace(); Assert.fail(); @@ -660,7 +660,7 @@ public class ConfigAPI_ITCase { result = agent.httpGet(CONFIG_CONTROLLER_PATH, null, params, agent.getEncode(), TIME_OUT); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); - Assert.assertEquals(content, JSON.parseObject(result.content).getString("content")); + Assert.assertEquals(content, JacksonUtils.toObj(result.content).get("content").textValue()); } catch (Exception e) { Assert.fail(); } @@ -688,7 +688,7 @@ public class ConfigAPI_ITCase { Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); System.out.println(result.content); - Assert.assertNotNull(JSON.parseObject(result.content).getString("data")); + Assert.assertFalse(JacksonUtils.toObj(result.content).get("data").isNull()); } catch (Exception e) { Assert.fail(); @@ -717,7 +717,7 @@ public class ConfigAPI_ITCase { List params = Arrays.asList("dataId", dataId, "group", group, "beta", "true"); result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); - Assert.assertEquals(content, JSON.parseObject(result.content).getJSONObject("data").getString("content")); + Assert.assertEquals(content, JacksonUtils.toObj(result.content).get("data").get("content").textValue()); // delete data result = agent.httpDelete(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); @@ -751,7 +751,7 @@ public class ConfigAPI_ITCase { result = agent.httpDelete(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); - Assert.assertEquals(true, JSON.parseObject(result.content).getBoolean("data")); + Assert.assertTrue(JacksonUtils.toObj(result.content).get("data").booleanValue()); } catch (Exception e) { e.printStackTrace(); Assert.fail(); @@ -780,8 +780,8 @@ public class ConfigAPI_ITCase { result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); - Assert.assertTrue(JSON.parseObject(result.content).getIntValue("totalCount") >= 1); - Assert.assertTrue(JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content").startsWith(content)); + Assert.assertTrue(JacksonUtils.toObj(result.content).get("totalCount").intValue() >= 1); + Assert.assertTrue(JacksonUtils.toObj(result.content).get("pageItems").get(0).get("content").textValue().startsWith(content)); } catch (Exception e) { Assert.fail(); } @@ -809,8 +809,8 @@ public class ConfigAPI_ITCase { result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); - Assert.assertTrue(JSON.parseObject(result.content).getIntValue("totalCount") >= 1); - Assert.assertEquals(content, JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content")); + Assert.assertTrue(JacksonUtils.toObj(result.content).get("totalCount").intValue() >= 1); + Assert.assertEquals(content, JacksonUtils.toObj(result.content).get("pageItems").get(0).get("content").textValue()); } catch (Exception e) { Assert.fail(); @@ -839,8 +839,8 @@ public class ConfigAPI_ITCase { result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, agent.getEncode(), TIME_OUT); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); - Assert.assertEquals(1, JSON.parseObject(result.content).getIntValue("totalCount")); - Assert.assertEquals(content, JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content")); + Assert.assertEquals(1, JacksonUtils.toObj(result.content).get("totalCount").intValue()); + Assert.assertEquals(content, JacksonUtils.toObj(result.content).get("pageItems").get(0).get("content").textValue()); } catch (Exception e) { Assert.fail(); @@ -868,8 +868,8 @@ public class ConfigAPI_ITCase { List params = Arrays.asList("dataId", dataId, "group", group, "pageNo","1", "pageSize","10", "search", "accurate"); result = agent.httpGet(CONFIG_CONTROLLER_PATH + "/", null, params, "utf-8", TIME_OUT); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); - Assert.assertEquals(1, JSON.parseObject(result.content).getIntValue("totalCount")); - Assert.assertEquals(content, JSON.parseObject(result.content).getJSONArray("pageItems").getJSONObject(0).getString("content")); + Assert.assertEquals(1, JacksonUtils.toObj(result.content).get("totalCount").intValue()); + Assert.assertEquals(content, JacksonUtils.toObj(result.content).get("pageItems").get(0).get("content").textValue()); } catch (Exception e) { Assert.fail(); } diff --git a/test/src/test/java/com/alibaba/nacos/test/config/ConfigBeta_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/config/ConfigBeta_ITCase.java index 0f966ceba..5fdee08e6 100644 --- a/test/src/test/java/com/alibaba/nacos/test/config/ConfigBeta_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/config/ConfigBeta_ITCase.java @@ -16,11 +16,9 @@ package com.alibaba.nacos.test.config; -import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.Nacos; -import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.core.utils.ApplicationUtils; +import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.test.base.Params; import org.junit.Assert; import org.junit.Before; @@ -38,8 +36,6 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.MultiValueMap; import org.springframework.web.util.UriComponentsBuilder; -import java.util.concurrent.CountDownLatch; - /** * @author xiaochun.xxc * @date 2019-07-03 @@ -151,7 +147,7 @@ public class ConfigBeta_ITCase { String.class, HttpMethod.GET); Assert.assertTrue(response1.getStatusCode().is2xxSuccessful()); - Assert.assertEquals(null, JSONObject.parseObject(response1.getBody()).getString("data")); + Assert.assertTrue(JacksonUtils.toObj(response1.getBody()).get("data").isNull()); } /** @@ -228,7 +224,7 @@ public class ConfigBeta_ITCase { String.class, HttpMethod.GET); Assert.assertTrue(response1.getStatusCode().is2xxSuccessful()); - Assert.assertEquals("com.dungu.test", JSONObject.parseObject(response1.getBody()).getJSONObject("data").getString("dataId")); + Assert.assertEquals("com.dungu.test", JacksonUtils.toObj(response1.getBody()).get("data").get("dataId").asText()); } /** @@ -265,7 +261,7 @@ public class ConfigBeta_ITCase { String.class, HttpMethod.GET); Assert.assertTrue(response1.getStatusCode().is2xxSuccessful()); - Assert.assertEquals("com.dungu.test", JSONObject.parseObject(response1.getBody()).getJSONObject("data").getString("dataId")); + Assert.assertEquals("com.dungu.test", JacksonUtils.toObj(response1.getBody()).get("data").get("dataId").asText()); ResponseEntity response2 = request(CONFIG_CONTROLLER_PATH + "/configs?beta=true", Params.newParams() @@ -276,7 +272,7 @@ public class ConfigBeta_ITCase { String.class, HttpMethod.DELETE); Assert.assertTrue(response2.getStatusCode().is2xxSuccessful()); - Assert.assertEquals("true", JSONObject.parseObject(response2.getBody()).getString("data")); + Assert.assertEquals("true", JacksonUtils.toObj(response2.getBody()).get("data").asText()); ResponseEntity response3 = request(CONFIG_CONTROLLER_PATH + "/configs?beta=true", Params.newParams() @@ -287,7 +283,7 @@ public class ConfigBeta_ITCase { String.class, HttpMethod.GET); Assert.assertTrue(response3.getStatusCode().is2xxSuccessful()); - Assert.assertEquals(null, JSONObject.parseObject(response3.getBody()).getString("data")); + Assert.assertTrue(JacksonUtils.toObj(response3.getBody()).get("data").isNull()); } @@ -325,7 +321,7 @@ public class ConfigBeta_ITCase { String.class, HttpMethod.GET); Assert.assertTrue(response1.getStatusCode().is2xxSuccessful()); - Assert.assertEquals("com.dungu.test", JSONObject.parseObject(response1.getBody()).getJSONObject("data").getString("dataId")); + Assert.assertEquals("com.dungu.test", JacksonUtils.toObj(response1.getBody()).get("data").get("dataId").asText()); ResponseEntity response2 = request(CONFIG_CONTROLLER_PATH + "/configs?beta=false", Params.newParams() @@ -347,7 +343,7 @@ public class ConfigBeta_ITCase { String.class, HttpMethod.GET); Assert.assertTrue(response3.getStatusCode().is2xxSuccessful()); - Assert.assertEquals("com.dungu.test", JSONObject.parseObject(response3.getBody()).getJSONObject("data").getString("dataId")); + Assert.assertEquals("com.dungu.test", JacksonUtils.toObj(response3.getBody()).get("data").get("dataId").asText()); } ResponseEntity request(String path, MultiValueMap params, Class clazz, HttpMethod httpMethod) { diff --git a/test/src/test/java/com/alibaba/nacos/test/config/ConfigExportAndImportAPI_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/config/ConfigExportAndImportAPI_ITCase.java index 65e9dfd67..a1e21e476 100644 --- a/test/src/test/java/com/alibaba/nacos/test/config/ConfigExportAndImportAPI_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/config/ConfigExportAndImportAPI_ITCase.java @@ -15,17 +15,15 @@ */ package com.alibaba.nacos.test.config; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.Nacos; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.client.config.http.HttpAgent; import com.alibaba.nacos.client.config.http.MetricsHttpAgent; import com.alibaba.nacos.client.config.http.ServerHttpAgent; import com.alibaba.nacos.client.config.impl.HttpSimpleClient; +import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.config.server.utils.ZipUtils; -import com.alibaba.nacos.core.utils.ApplicationUtils; +import com.fasterxml.jackson.databind.JsonNode; import com.github.keran213539.commonOkHttp.CommonOkHttpClient; import com.github.keran213539.commonOkHttp.CommonOkHttpClientBuilder; import com.github.keran213539.commonOkHttp.UploadByteFile; @@ -127,19 +125,19 @@ public class ConfigExportAndImportAPI_ITCase { public void testExportByIds(){ String getDataUrl = "?search=accurate&dataId=&group=&appName=&config_tags=&pageNo=1&pageSize=10&tenant=&namespaceId="; String queryResult = httpClient.get(SERVER_ADDR + CONFIG_CONTROLLER_PATH + getDataUrl, null); - JSONObject resultObj = JSON.parseObject(queryResult); - JSONArray resultConfigs = resultObj.getJSONArray("pageItems"); - JSONObject config1 = resultConfigs.getJSONObject(0); - JSONObject config2 = resultConfigs.getJSONObject(1); - String exportByIdsUrl = "?export=true&tenant=&group=&appName=&ids=" + config1.getLongValue("id") - + "," + config2.getLongValue("id"); + JsonNode resultObj = JacksonUtils.toObj(queryResult); + JsonNode resultConfigs = resultObj.get("pageItems"); + JsonNode config1 = resultConfigs.get(0); + JsonNode config2 = resultConfigs.get(1); + String exportByIdsUrl = "?export=true&tenant=&group=&appName=&ids=" + config1.get("id").longValue() + + "," + config2.get("id").longValue(); System.out.println(exportByIdsUrl); byte[] zipData = httpClient.download(SERVER_ADDR + CONFIG_CONTROLLER_PATH + exportByIdsUrl, null); ZipUtils.UnZipResult unZiped = ZipUtils.unzip(zipData); List zipItemList = unZiped.getZipItemList(); Assert.assertEquals(2, zipItemList.size()); - String config1Name = config1.getString("group") + "/" + config1.getString("dataId"); - String config2Name = config2.getString("group") + "/" + config2.getString("dataId"); + String config1Name = config1.get("group").textValue() + "/" + config1.get("dataId").textValue(); + String config2Name = config2.get("group").textValue() + "/" + config2.get("dataId").textValue(); for(ZipUtils.ZipItem zipItem : zipItemList){ if(!(config1Name.equals(zipItem.getItemName()) || config2Name.equals(zipItem.getItemName()))){ Assert.fail(); @@ -151,18 +149,18 @@ public class ConfigExportAndImportAPI_ITCase { public void testExportByGroup(){ String getDataUrl = "?search=accurate&dataId=&group=EXPORT_IMPORT_TEST_GROUP&appName=&config_tags=&pageNo=1&pageSize=10&tenant=&namespaceId="; String queryResult = httpClient.get(SERVER_ADDR + CONFIG_CONTROLLER_PATH + getDataUrl, null); - JSONObject resultObj = JSON.parseObject(queryResult); - JSONArray resultConfigs = resultObj.getJSONArray("pageItems"); + JsonNode resultObj = JacksonUtils.toObj(queryResult); + JsonNode resultConfigs = resultObj.get("pageItems"); Assert.assertEquals(2, resultConfigs.size()); - JSONObject config1 = resultConfigs.getJSONObject(0); - JSONObject config2 = resultConfigs.getJSONObject(1); + JsonNode config1 = resultConfigs.get(0); + JsonNode config2 = resultConfigs.get(1); String exportByIdsUrl = "?export=true&tenant=&group=EXPORT_IMPORT_TEST_GROUP&appName=&ids="; byte[] zipData = httpClient.download(SERVER_ADDR + CONFIG_CONTROLLER_PATH + exportByIdsUrl, null); ZipUtils.UnZipResult unZiped = ZipUtils.unzip(zipData); List zipItemList = unZiped.getZipItemList(); Assert.assertEquals(2, zipItemList.size()); - String config1Name = config1.getString("group") + "/" + config1.getString("dataId"); - String config2Name = config2.getString("group") + "/" + config2.getString("dataId"); + String config1Name = config1.get("group").textValue() + "/" + config1.get("dataId").textValue(); + String config2Name = config2.get("group").textValue() + "/" + config2.get("dataId").textValue(); for(ZipUtils.ZipItem zipItem : zipItemList){ if(!(config1Name.equals(zipItem.getItemName()) @@ -182,16 +180,16 @@ public class ConfigExportAndImportAPI_ITCase { public void testExportByGroupAndApp(){ String getDataUrl = "?search=accurate&dataId=&group=EXPORT_IMPORT_TEST_GROUP&appName=testApp1&config_tags=&pageNo=1&pageSize=10&tenant=&namespaceId="; String queryResult = httpClient.get(SERVER_ADDR + CONFIG_CONTROLLER_PATH + getDataUrl, null); - JSONObject resultObj = JSON.parseObject(queryResult); - JSONArray resultConfigs = resultObj.getJSONArray("pageItems"); + JsonNode resultObj = JacksonUtils.toObj(queryResult); + JsonNode resultConfigs = resultObj.get("pageItems"); Assert.assertEquals(1, resultConfigs.size()); - JSONObject config1 = resultConfigs.getJSONObject(0); + JsonNode config1 = resultConfigs.get(0); String exportByIdsUrl = "?export=true&tenant=&group=EXPORT_IMPORT_TEST_GROUP&appName=testApp1&ids="; byte[] zipData = httpClient.download(SERVER_ADDR + CONFIG_CONTROLLER_PATH + exportByIdsUrl, null); ZipUtils.UnZipResult unZiped = ZipUtils.unzip(zipData); List zipItemList = unZiped.getZipItemList(); Assert.assertEquals(1, zipItemList.size()); - String config1Name = config1.getString("group") + "/" + config1.getString("dataId"); + String config1Name = config1.get("group").textValue() + "/" + config1.get("dataId").textValue(); for(ZipUtils.ZipItem zipItem : zipItemList){ if(!config1Name.equals(zipItem.getItemName())){ Assert.fail(); @@ -249,15 +247,15 @@ public class ConfigExportAndImportAPI_ITCase { httpClient.post(SERVER_ADDR + CONFIG_CONTROLLER_PATH + importUrl, importPrarm, Collections.singletonList(uploadByteFile), null); String getDataUrl = "?search=accurate&dataId=&group=TEST_IMPORT&appName=&config_tags=&pageNo=1&pageSize=10&tenant=&namespaceId="; String queryResult = httpClient.get(SERVER_ADDR + CONFIG_CONTROLLER_PATH + getDataUrl, null); - JSONObject resultObj = JSON.parseObject(queryResult); - JSONArray resultConfigs = resultObj.getJSONArray("pageItems"); + JsonNode resultObj = JacksonUtils.toObj(queryResult); + JsonNode resultConfigs = resultObj.get("pageItems"); Assert.assertEquals(3, resultConfigs.size()); for(int i = 0; i < resultConfigs.size(); i++){ - JSONObject config = resultConfigs.getJSONObject(i); - if(!"TEST_IMPORT".equals(config.getString("group"))){ + JsonNode config = resultConfigs.get(i); + if(!"TEST_IMPORT".equals(config.get("group").textValue())){ Assert.fail(); } - switch (config.getString("dataId")){ + switch (config.get("dataId").textValue()){ case "test1.yml": case "test2.txt": case "test3.properties": From 4dbe81418bd881e74358d47e078c411b02a0a48a Mon Sep 17 00:00:00 2001 From: KomachiSion <263976490@qq.com> Date: Wed, 3 Jun 2020 14:39:17 +0800 Subject: [PATCH 3/6] Replace fastjson with jackson for nacos-test/auth --- .../nacos/test/core/auth/AuthBase.java | 11 ++++---- .../test/core/auth/Permission_ITCase.java | 25 ++++++++--------- .../nacos/test/core/auth/Role_ITCase.java | 27 ++++++++----------- .../nacos/test/core/auth/User_ITCase.java | 23 +++++++--------- 4 files changed, 38 insertions(+), 48 deletions(-) diff --git a/test/src/test/java/com/alibaba/nacos/test/core/auth/AuthBase.java b/test/src/test/java/com/alibaba/nacos/test/core/auth/AuthBase.java index dfec773ba..306007880 100644 --- a/test/src/test/java/com/alibaba/nacos/test/core/auth/AuthBase.java +++ b/test/src/test/java/com/alibaba/nacos/test/core/auth/AuthBase.java @@ -15,12 +15,13 @@ */ package com.alibaba.nacos.test.core.auth; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.api.PropertyKeyConst; +import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.core.auth.AuthConfigs; import com.alibaba.nacos.test.base.HttpClient4Test; import com.alibaba.nacos.test.base.Params; +import com.fasterxml.jackson.databind.JsonNode; + import org.junit.Assert; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; @@ -66,9 +67,9 @@ public class AuthBase extends HttpClient4Test { HttpMethod.POST); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertTrue(json.containsKey("accessToken")); - return json.getString("accessToken"); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertTrue(json.has("accessToken")); + return json.get("accessToken").textValue(); } protected void init(int port) throws Exception { diff --git a/test/src/test/java/com/alibaba/nacos/test/core/auth/Permission_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/core/auth/Permission_ITCase.java index cfa01a466..61c343db7 100644 --- a/test/src/test/java/com/alibaba/nacos/test/core/auth/Permission_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/core/auth/Permission_ITCase.java @@ -15,16 +15,15 @@ */ package com.alibaba.nacos.test.core.auth; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; import com.alibaba.nacos.Nacos; +import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.config.server.model.Page; import com.alibaba.nacos.core.auth.Permission; -import com.alibaba.nacos.core.utils.ApplicationUtils; import com.alibaba.nacos.test.base.HttpClient4Test; import com.alibaba.nacos.test.base.Params; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; + import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -125,9 +124,9 @@ public class Permission_ITCase extends HttpClient4Test { HttpMethod.POST); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertTrue(json.containsKey("accessToken")); - accessToken = json.getString("accessToken"); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertTrue(json.has("accessToken")); + accessToken = json.get("accessToken").textValue(); } @Test @@ -196,10 +195,10 @@ public class Permission_ITCase extends HttpClient4Test { String.class, HttpMethod.GET); + System.out.println(response); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - Page permissionPage = JSON.parseObject(response.getBody(), new TypeReference>() { - }); + Page permissionPage = JacksonUtils.toObj(response.getBody(), new TypeReference>() {}); Assert.assertNotNull(permissionPage); Assert.assertNotNull(permissionPage.getPageItems()); @@ -245,8 +244,7 @@ public class Permission_ITCase extends HttpClient4Test { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - permissionPage = JSON.parseObject(response.getBody(), new TypeReference>() { - }); + permissionPage = JacksonUtils.toObj(response.getBody(), new TypeReference>() {}); Assert.assertNotNull(permissionPage); Assert.assertNotNull(permissionPage.getPageItems()); @@ -291,8 +289,7 @@ public class Permission_ITCase extends HttpClient4Test { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - permissionPage = JSON.parseObject(response.getBody(), new TypeReference>() { - }); + permissionPage = JacksonUtils.toObj(response.getBody(), new TypeReference>() {}); Assert.assertNotNull(permissionPage); Assert.assertNotNull(permissionPage.getPageItems()); diff --git a/test/src/test/java/com/alibaba/nacos/test/core/auth/Role_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/core/auth/Role_ITCase.java index 3e810d422..bffa89207 100644 --- a/test/src/test/java/com/alibaba/nacos/test/core/auth/Role_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/core/auth/Role_ITCase.java @@ -15,16 +15,15 @@ */ package com.alibaba.nacos.test.core.auth; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; import com.alibaba.nacos.Nacos; +import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.config.server.auth.RoleInfo; import com.alibaba.nacos.config.server.model.Page; -import com.alibaba.nacos.core.utils.ApplicationUtils; import com.alibaba.nacos.test.base.HttpClient4Test; import com.alibaba.nacos.test.base.Params; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; + import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -111,9 +110,9 @@ public class Role_ITCase extends HttpClient4Test { HttpMethod.POST); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertTrue(json.containsKey("accessToken")); - accessToken = json.getString("accessToken"); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertTrue(json.has("accessToken")); + accessToken = json.get("accessToken").textValue(); } @Test @@ -158,8 +157,7 @@ public class Role_ITCase extends HttpClient4Test { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - Page roleInfoPage = JSON.parseObject(response.getBody(), new TypeReference>() { - }); + Page roleInfoPage = JacksonUtils.toObj(response.getBody(), new TypeReference>() {}); Assert.assertNotNull(roleInfoPage); Assert.assertNotNull(roleInfoPage.getPageItems()); @@ -197,8 +195,7 @@ public class Role_ITCase extends HttpClient4Test { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - roleInfoPage = JSON.parseObject(response.getBody(), new TypeReference>() { - }); + roleInfoPage = JacksonUtils.toObj(response.getBody(), new TypeReference>() {}); Assert.assertNotNull(roleInfoPage); Assert.assertNotNull(roleInfoPage.getPageItems()); @@ -243,8 +240,7 @@ public class Role_ITCase extends HttpClient4Test { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - roleInfoPage = JSON.parseObject(response.getBody(), new TypeReference>() { - }); + roleInfoPage = JacksonUtils.toObj(response.getBody(), new TypeReference>() {}); Assert.assertNotNull(roleInfoPage); Assert.assertNotNull(roleInfoPage.getPageItems()); @@ -286,8 +282,7 @@ public class Role_ITCase extends HttpClient4Test { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - roleInfoPage = JSON.parseObject(response.getBody(), new TypeReference>() { - }); + roleInfoPage = JacksonUtils.toObj(response.getBody(), new TypeReference>() {}); Assert.assertNotNull(roleInfoPage); Assert.assertNotNull(roleInfoPage.getPageItems()); diff --git a/test/src/test/java/com/alibaba/nacos/test/core/auth/User_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/core/auth/User_ITCase.java index a470ca111..f2e53363f 100644 --- a/test/src/test/java/com/alibaba/nacos/test/core/auth/User_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/core/auth/User_ITCase.java @@ -15,16 +15,16 @@ */ package com.alibaba.nacos.test.core.auth; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.TypeReference; import com.alibaba.nacos.Nacos; +import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.config.server.model.Page; import com.alibaba.nacos.config.server.model.User; import com.alibaba.nacos.console.utils.PasswordEncoderUtil; -import com.alibaba.nacos.core.utils.ApplicationUtils; import com.alibaba.nacos.test.base.HttpClient4Test; import com.alibaba.nacos.test.base.Params; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; + import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -88,9 +88,9 @@ public class User_ITCase extends HttpClient4Test { HttpMethod.POST); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertTrue(json.containsKey("accessToken")); - accessToken = json.getString("accessToken"); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertTrue(json.has("accessToken")); + accessToken = json.get("accessToken").textValue(); } @Test @@ -121,8 +121,7 @@ public class User_ITCase extends HttpClient4Test { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - Page userPage = JSON.parseObject(response.getBody(), new TypeReference>() { - }); + Page userPage = JacksonUtils.toObj(response.getBody(), new TypeReference>() {}); Assert.assertNotNull(userPage); Assert.assertNotNull(userPage.getPageItems()); @@ -159,8 +158,7 @@ public class User_ITCase extends HttpClient4Test { .done(), String.class); - userPage = JSON.parseObject(response.getBody(), new TypeReference>() { - }); + userPage = JacksonUtils.toObj(response.getBody(), new TypeReference>() {}); Assert.assertNotNull(userPage); Assert.assertNotNull(userPage.getPageItems()); @@ -198,8 +196,7 @@ public class User_ITCase extends HttpClient4Test { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - userPage = JSON.parseObject(response.getBody(), new TypeReference>() { - }); + userPage = JacksonUtils.toObj(response.getBody(), new TypeReference>() {}); Assert.assertNotNull(userPage); Assert.assertNotNull(userPage.getPageItems()); From e9adf975af7d5d34ad5903461e068abd4ab08abe Mon Sep 17 00:00:00 2001 From: KomachiSion <263976490@qq.com> Date: Wed, 3 Jun 2020 14:39:28 +0800 Subject: [PATCH 4/6] Replace fastjson with jackson for nacos-test/naming --- .../test/naming/CPInstancesAPI_ITCase.java | 26 ++--- .../nacos/test/naming/Cmdb_ITCase.java | 106 +++++++++--------- .../MultiTenant_InstanceAPI_ITCase.java | 84 +++++++------- .../nacos/test/naming/RestAPI_ITCase.java | 32 +++--- .../nacos/test/naming/Subscribe_ITCase.java | 14 +-- 5 files changed, 131 insertions(+), 131 deletions(-) diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java index 643e0c479..674493b96 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java @@ -15,8 +15,6 @@ */ package com.alibaba.nacos.test.naming; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.Nacos; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.common.Constants; @@ -24,8 +22,10 @@ import com.alibaba.nacos.api.naming.NamingFactory; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.ListView; -import com.alibaba.nacos.core.utils.ApplicationUtils; +import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.test.base.Params; +import com.fasterxml.jackson.databind.JsonNode; + import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -223,9 +223,9 @@ public class CPInstancesAPI_ITCase { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertEquals(serviceName, json.getString("name")); - Assert.assertEquals("0.5", json.getString("protectThreshold")); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(serviceName, json.get("name").textValue()); + Assert.assertEquals("0.5", json.get("protectThreshold").asText()); namingServiceDelete(serviceName, TEST_NAMESPACE_1); } @@ -271,9 +271,9 @@ public class CPInstancesAPI_ITCase { System.out.println("json = " + response.getBody()); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - int count = json.getIntValue("count"); - Assert.assertEquals(listView.getCount()+1, count); + JsonNode json = JacksonUtils.toObj(response.getBody()); + int count = json.get("count").intValue(); + Assert.assertEquals(listView.getCount() + 1, count); namingServiceDelete(serviceName, Constants.DEFAULT_NAMESPACE_ID); } @@ -297,8 +297,8 @@ public class CPInstancesAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(1, json.get("hosts").size()); instanceDeregister(serviceName, Constants.DEFAULT_NAMESPACE_ID, "33.33.33.33", TEST_PORT2_4_DOM_1); @@ -351,8 +351,8 @@ public class CPInstancesAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(1, json.get("hosts").size()); instanceDeregister(serviceName, Constants.DEFAULT_NAMESPACE_ID, "33.33.33.33", TEST_PORT2_4_DOM_1); instanceDeregister(serviceName, Constants.DEFAULT_NAMESPACE_ID, TEST_GROUP_1, "22.22.22.22", TEST_PORT2_4_DOM_1); diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/Cmdb_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/Cmdb_ITCase.java index 5511ffeb1..11c37f47e 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/Cmdb_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/Cmdb_ITCase.java @@ -15,14 +15,15 @@ */ package com.alibaba.nacos.test.naming; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.Nacos; import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.naming.NamingFactory; import com.alibaba.nacos.api.naming.NamingService; -import com.alibaba.nacos.core.utils.ApplicationUtils; +import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.test.base.Params; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + import org.junit.*; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -100,14 +101,14 @@ public class Cmdb_ITCase { TimeUnit.SECONDS.sleep(5L); - JSONObject json = new JSONObject(); + ObjectNode json = JacksonUtils.createEmptyJsonNode(); json.put("type", "label"); json.put("expression", "CONSUMER.label.label1 = PROVIDER.label.label1"); ResponseEntity httpResult = request("/nacos/v1/ns/service", Params.newParams() .appendParam("serviceName", serviceName) .appendParam("protectThreshold", "0") - .appendParam("selector", json.toJSONString()) + .appendParam("selector", json.toString()) .done(), String.class, HttpMethod.PUT); @@ -121,8 +122,8 @@ public class Cmdb_ITCase { String.class, HttpMethod.GET); Assert.assertEquals(HttpURLConnection.HTTP_OK, httpResult.getStatusCodeValue()); - json = JSON.parseObject(httpResult.getBody()); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); + JsonNode result = JacksonUtils.toObj(httpResult.getBody()); + Assert.assertEquals(1, result.get("hosts").size()); } @@ -150,14 +151,14 @@ public class Cmdb_ITCase { TimeUnit.SECONDS.sleep(10); - JSONObject json = new JSONObject(); + ObjectNode json = JacksonUtils.createEmptyJsonNode(); json.put("type", "label"); json.put("expression", "CONSUMER.label.label1 = PROVIDER.label.label1"); ResponseEntity httpResult = request("/nacos/v1/ns/service", Params.newParams() .appendParam("serviceName", serviceName) .appendParam("protectThreshold", "0") - .appendParam("selector", json.toJSONString()) + .appendParam("selector", json.toString()) .done(), String.class, HttpMethod.PUT); @@ -170,8 +171,8 @@ public class Cmdb_ITCase { String.class, HttpMethod.GET); Assert.assertEquals(HttpURLConnection.HTTP_OK, httpResult.getStatusCodeValue()); - json = JSON.parseObject(httpResult.getBody()); - Assert.assertEquals(6, json.getJSONArray("hosts").size()); + JsonNode result = JacksonUtils.toObj(httpResult.getBody()); + Assert.assertEquals(6, result.get("hosts").size()); } /** @@ -198,7 +199,7 @@ public class Cmdb_ITCase { TimeUnit.SECONDS.sleep(10); - JSONObject json = new JSONObject(); + ObjectNode json = JacksonUtils.createEmptyJsonNode(); json.put("type", "label"); json.put("expression", "CONSUMER.label.label1 = PROVIDER.label.label1 & CONSUMER.label.label2 = PROVIDER.label.label2"); @@ -206,7 +207,7 @@ public class Cmdb_ITCase { Params.newParams() .appendParam("serviceName", serviceName) .appendParam("protectThreshold", "0") - .appendParam("selector", json.toJSONString()) + .appendParam("selector", json.toString()) .done(), String.class, HttpMethod.PUT); @@ -220,9 +221,9 @@ public class Cmdb_ITCase { String.class, HttpMethod.GET); Assert.assertEquals(HttpURLConnection.HTTP_OK, httpResult.getStatusCodeValue()); - json = JSON.parseObject(httpResult.getBody()); - System.out.println("instance list = " + json); - Assert.assertEquals(2, json.getJSONArray("hosts").size()); + JsonNode result = JacksonUtils.toObj(httpResult.getBody()); + System.out.println("instance list = " + result); + Assert.assertEquals(2, result.get("hosts").size()); } /** @@ -250,14 +251,14 @@ public class Cmdb_ITCase { TimeUnit.SECONDS.sleep(10); - JSONObject json = new JSONObject(); + ObjectNode json = JacksonUtils.createEmptyJsonNode(); json.put("type", "label"); json.put("expression", "CONSUMER.label.label1 = PROVIDER.label.label1 & CONSUMER.label.label2 = PROVIDER.label.label2"); ResponseEntity httpResult = request("/nacos/v1/ns/service", Params.newParams() .appendParam("serviceName", serviceName) .appendParam("protectThreshold", "0") - .appendParam("selector", json.toJSONString()) + .appendParam("selector", json.toString()) .done(), String.class, HttpMethod.PUT); @@ -270,7 +271,7 @@ public class Cmdb_ITCase { .done(), String.class, HttpMethod.GET); - System.out.println("service list = " + JSON.parseObject(httpResult.getBody())); + System.out.println("service list = " + JacksonUtils.toObj(httpResult.getBody())); httpResult = request("/nacos/v1/ns/instance/list", Params.newParams() @@ -280,10 +281,9 @@ public class Cmdb_ITCase { String.class, HttpMethod.GET); Assert.assertEquals(HttpURLConnection.HTTP_OK, httpResult.getStatusCodeValue()); - json = JSON.parseObject(httpResult.getBody()); - - System.out.println("instance list = " + json); - Assert.assertEquals(2, json.getJSONArray("hosts").size()); + JsonNode result = JacksonUtils.toObj(httpResult.getBody()); + System.out.println("instance list = " + result); + Assert.assertEquals(2, result.get("hosts").size()); } @@ -312,14 +312,14 @@ public class Cmdb_ITCase { TimeUnit.SECONDS.sleep(10); - JSONObject json = new JSONObject(); + ObjectNode json = JacksonUtils.createEmptyJsonNode(); json.put("type", "label"); json.put("expression", "CONSUMER.label.label1 = PROVIDER.label.label1 & CONSUMER.label.label2 = PROVIDER.label.label2"); ResponseEntity httpResult = request("/nacos/v1/ns/service", Params.newParams() .appendParam("serviceName", serviceName) .appendParam("protectThreshold", "0") - .appendParam("selector", json.toJSONString()) + .appendParam("selector", json.toString()) .done(), String.class, HttpMethod.PUT); @@ -333,9 +333,9 @@ public class Cmdb_ITCase { String.class, HttpMethod.GET); Assert.assertEquals(HttpURLConnection.HTTP_OK, httpResult.getStatusCodeValue()); - json = JSON.parseObject(httpResult.getBody()); - System.out.println("instance list = " + json); - Assert.assertEquals(6, json.getJSONArray("hosts").size()); + JsonNode result = JacksonUtils.toObj(httpResult.getBody()); + System.out.println("instance list = " + result); + Assert.assertEquals(6, result.get("hosts").size()); } /** @@ -363,14 +363,14 @@ public class Cmdb_ITCase { TimeUnit.SECONDS.sleep(10); - JSONObject json = new JSONObject(); + ObjectNode json = JacksonUtils.createEmptyJsonNode(); json.put("type", "label"); json.put("expression", "CONSUMER.label.label1 = PROVIDER.label.label1 & CONSUMER.label.label2 = PROVIDER.label.label2"); ResponseEntity httpResult = request("/nacos/v1/ns/service", Params.newParams() .appendParam("serviceName", serviceName) .appendParam("protectThreshold", "0") - .appendParam("selector", json.toJSONString()) + .appendParam("selector", json.toString()) .done(), String.class, HttpMethod.PUT); @@ -384,10 +384,10 @@ public class Cmdb_ITCase { String.class, HttpMethod.GET); Assert.assertEquals(HttpURLConnection.HTTP_OK, httpResult.getStatusCodeValue()); - json = JSON.parseObject(httpResult.getBody()); + JsonNode result = JacksonUtils.toObj(httpResult.getBody()); - System.out.println("instance list = " + json); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); + System.out.println("instance list = " + result); + Assert.assertEquals(1, result.get("hosts").size()); } /** @@ -416,7 +416,7 @@ public class Cmdb_ITCase { TimeUnit.SECONDS.sleep(10); - JSONObject json = new JSONObject(); + ObjectNode json = JacksonUtils.createEmptyJsonNode(); json.put("type", "label"); json.put("expression", "CONSUMER.label.label1 = PROVIDER.label.label1 & CONSUMER.label.label2 = PROVIDER.label.label2"); List params = Arrays.asList("serviceName", serviceName, "protectThreshold", "0", "selector", json.toString()); @@ -426,7 +426,7 @@ public class Cmdb_ITCase { Params.newParams() .appendParam("serviceName", serviceName) .appendParam("protectThreshold", "0") - .appendParam("selector", json.toJSONString()) + .appendParam("selector", json.toString()) .done(), String.class, HttpMethod.PUT); @@ -440,9 +440,9 @@ public class Cmdb_ITCase { String.class, HttpMethod.GET); Assert.assertEquals(HttpURLConnection.HTTP_OK, httpResult.getStatusCodeValue()); - json = JSON.parseObject(httpResult.getBody()); - System.out.println("instance list = " + json); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); + JsonNode result = JacksonUtils.toObj(httpResult.getBody()); + System.out.println("instance list = " + result); + Assert.assertEquals(1, json.get("hosts").size()); httpResult = request("/nacos/v1/ns/service", Params.newParams() @@ -462,10 +462,10 @@ public class Cmdb_ITCase { String.class, HttpMethod.GET); Assert.assertEquals(HttpURLConnection.HTTP_OK, httpResult.getStatusCodeValue()); - json = JSON.parseObject(httpResult.getBody()); + result = JacksonUtils.toObj(httpResult.getBody()); - System.out.println("instance list = " + json); - Assert.assertEquals(6, json.getJSONArray("hosts").size()); + System.out.println("instance list = " + result); + Assert.assertEquals(6, result.get("hosts").size()); } @@ -494,14 +494,14 @@ public class Cmdb_ITCase { TimeUnit.SECONDS.sleep(10); - JSONObject json = new JSONObject(); + ObjectNode json = JacksonUtils.createEmptyJsonNode(); json.put("type", "label"); json.put("expression", ""); ResponseEntity httpResult = request("/nacos/v1/ns/service", Params.newParams() .appendParam("serviceName", serviceName) .appendParam("protectThreshold", "0") - .appendParam("selector", json.toJSONString()) + .appendParam("selector", json.toString()) .done(), String.class, HttpMethod.PUT); @@ -515,9 +515,9 @@ public class Cmdb_ITCase { String.class, HttpMethod.GET); Assert.assertEquals(HttpURLConnection.HTTP_OK, httpResult.getStatusCodeValue()); - json = JSON.parseObject(httpResult.getBody()); - System.out.println("instance list = " + json); - Assert.assertEquals(6, json.getJSONArray("hosts").size()); + JsonNode result = JacksonUtils.toObj(httpResult.getBody()); + System.out.println("instance list = " + result); + Assert.assertEquals(6, result.get("hosts").size()); } /** @@ -546,14 +546,14 @@ public class Cmdb_ITCase { TimeUnit.SECONDS.sleep(10); - JSONObject json = new JSONObject(); + ObjectNode json = JacksonUtils.createEmptyJsonNode(); json.put("type", "label"); json.put("expression", ""); ResponseEntity httpResult = request("/nacos/v1/ns/service", Params.newParams() .appendParam("serviceName", serviceName) .appendParam("protectThreshold", "0") - .appendParam("selector", json.toJSONString()) + .appendParam("selector", json.toString()) .done(), String.class, HttpMethod.PUT); @@ -567,9 +567,9 @@ public class Cmdb_ITCase { String.class, HttpMethod.GET); Assert.assertEquals(HttpURLConnection.HTTP_OK, httpResult.getStatusCodeValue()); - json = JSON.parseObject(httpResult.getBody()); - System.out.println("instance list = " + json); - Assert.assertEquals(6, json.getJSONArray("hosts").size()); + JsonNode result = JacksonUtils.toObj(httpResult.getBody()); + System.out.println("instance list = " + result); + Assert.assertEquals(6, result.get("hosts").size()); } /** @@ -597,14 +597,14 @@ public class Cmdb_ITCase { TimeUnit.SECONDS.sleep(10); - JSONObject json = new JSONObject(); + ObjectNode json = JacksonUtils.createEmptyJsonNode(); json.put("type", "label1"); json.put("expression", "CONSUMER.label.label1 = PROVIDER.label.label1 & CONSUMER.label.label2 = PROVIDER.label.label2"); ResponseEntity httpResult = request("/nacos/v1/ns/service", Params.newParams() .appendParam("serviceName", serviceName) .appendParam("protectThreshold", "0") - .appendParam("selector", json.toJSONString()) + .appendParam("selector", json.toString()) .done(), String.class, HttpMethod.PUT); diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_InstanceAPI_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_InstanceAPI_ITCase.java index 283af2c69..47b4e4b55 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_InstanceAPI_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_InstanceAPI_ITCase.java @@ -1,7 +1,5 @@ package com.alibaba.nacos.test.naming; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.Nacos; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.common.Constants; @@ -9,8 +7,10 @@ import com.alibaba.nacos.api.naming.NamingFactory; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.client.naming.NacosNamingService; -import com.alibaba.nacos.core.utils.ApplicationUtils; +import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.test.base.Params; +import com.fasterxml.jackson.databind.JsonNode; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -109,9 +109,9 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); + JsonNode json = JacksonUtils.toObj(response.getBody()); - Assert.assertEquals("11.11.11.11", json.getJSONArray("hosts").getJSONObject(0).getString("ip")); + Assert.assertEquals("11.11.11.11", json.get("hosts").get(0).get("ip").asText()); response = request(url, Params.newParams() @@ -119,9 +119,9 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - json = JSON.parseObject(response.getBody()); + json = JacksonUtils.toObj(response.getBody()); - Assert.assertEquals(2, json.getJSONArray("hosts").size()); + Assert.assertEquals(2, json.get("hosts").size()); } /** @@ -151,9 +151,9 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); + JsonNode json = JacksonUtils.toObj(response.getBody()); - Assert.assertEquals("11.11.11.11", json.getJSONArray("hosts").getJSONObject(0).getString("ip")); + Assert.assertEquals("11.11.11.11", json.get("hosts").get(0).get("ip").asText()); response = request(url, Params.newParams() @@ -162,10 +162,10 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - json = JSON.parseObject(response.getBody()); + json = JacksonUtils.toObj(response.getBody()); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); - Assert.assertEquals("33.33.33.33", json.getJSONArray("hosts").getJSONObject(0).getString("ip")); + Assert.assertEquals(1, json.get("hosts").size()); + Assert.assertEquals("33.33.33.33", json.get("hosts").get(0).get("ip").asText()); } /** @@ -204,9 +204,9 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); - Assert.assertEquals("33.33.33.33", json.getJSONArray("hosts").getJSONObject(0).getString("ip")); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(1, json.get("hosts").size()); + Assert.assertEquals("33.33.33.33", json.get("hosts").get(0).get("ip").asText()); } /** @@ -246,9 +246,9 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); - Assert.assertEquals("44.44.44.44", json.getJSONArray("hosts").getJSONObject(0).getString("ip")); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(1, json.get("hosts").size()); + Assert.assertEquals("44.44.44.44", json.get("hosts").get(0).get("ip").asText()); } /** @@ -290,8 +290,8 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertEquals(2, json.getJSONArray("hosts").size()); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(2, json.get("hosts").size()); } /** @@ -334,8 +334,8 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertEquals(0, json.getJSONArray("hosts").size()); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(0, json.get("hosts").size()); } /** @@ -373,8 +373,8 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(1, json.get("hosts").size()); //namespace-2个数 response = request("/nacos/v1/ns/instance/list", @@ -384,9 +384,9 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - json = JSON.parseObject(response.getBody()); + json = JacksonUtils.toObj(response.getBody()); System.out.println(json); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); + Assert.assertEquals(1, json.get("hosts").size()); } /** @@ -424,9 +424,9 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); - Assert.assertEquals("8.0", json.getJSONArray("hosts").getJSONObject(0).getString("weight")); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(1, json.get("hosts").size()); + Assert.assertEquals("8.0", json.get("hosts").get(0).get("weight").asText()); } /** @@ -476,9 +476,9 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); - Assert.assertEquals("8.0", json.getJSONArray("hosts").getJSONObject(0).getString("weight")); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(1, json.get("hosts").size()); + Assert.assertEquals("8.0", json.get("hosts").get(0).get("weight").asText()); } /** @@ -517,8 +517,8 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertEquals(2, json.getJSONArray("hosts").size()); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(2, json.get("hosts").size()); //namespace-2个数 response = request("/nacos/v1/ns/instance/list", @@ -528,8 +528,8 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - json = JSON.parseObject(response.getBody()); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); + json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(1, json.get("hosts").size()); } /** @@ -565,8 +565,8 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertEquals("33.33.33.33", json.getJSONArray("hosts").getJSONObject(0).getString("ip")); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals("33.33.33.33", json.get("hosts").get(0).get("ip").asText()); } /** @@ -603,8 +603,8 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(1, json.get("hosts").size()); //namespace-2个数 response = request("/nacos/v1/ns/instance/list", @@ -614,8 +614,8 @@ public class MultiTenant_InstanceAPI_ITCase { .done(), String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - json = JSON.parseObject(response.getBody()); - Assert.assertEquals(1, json.getJSONArray("hosts").size()); + json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(1, json.get("hosts").size()); } private void verifyInstanceListForNaming(NamingService naming, int size, String serviceName) throws Exception { diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/RestAPI_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/RestAPI_ITCase.java index e08660a08..48d0ff0bd 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/RestAPI_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/RestAPI_ITCase.java @@ -15,11 +15,11 @@ */ package com.alibaba.nacos.test.naming; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.Nacos; -import com.alibaba.nacos.core.utils.ApplicationUtils; +import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.test.base.Params; +import com.fasterxml.jackson.databind.JsonNode; + import org.junit.*; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @@ -63,11 +63,11 @@ public class RestAPI_ITCase extends NamingBase { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertTrue(json.getIntValue("serviceCount") > 0); - Assert.assertTrue(json.getIntValue("instanceCount") > 0); - Assert.assertTrue(json.getIntValue("responsibleServiceCount") > 0); - Assert.assertTrue(json.getIntValue("responsibleInstanceCount") > 0); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertTrue(json.get("serviceCount").asInt() > 0); + Assert.assertTrue(json.get("instanceCount").asInt() > 0); + Assert.assertTrue(json.get("responsibleServiceCount").asInt() > 0); + Assert.assertTrue(json.get("responsibleInstanceCount").asInt() > 0); } /** @@ -119,8 +119,8 @@ public class RestAPI_ITCase extends NamingBase { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - Assert.assertEquals(serviceName, json.getString("name")); + JsonNode json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(serviceName, json.get("name").asText()); namingServiceDelete(serviceName); } @@ -143,8 +143,8 @@ public class RestAPI_ITCase extends NamingBase { String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); - int count = json.getIntValue("count"); + JsonNode json = JacksonUtils.toObj(response.getBody()); + int count = json.get("count").asInt(); Assert.assertTrue(count >= 0); response = request(NamingBase.NAMING_CONTROLLER_PATH + "/service", @@ -166,8 +166,8 @@ public class RestAPI_ITCase extends NamingBase { String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - json = JSON.parseObject(response.getBody()); - Assert.assertEquals(count + 1, json.getIntValue("count")); + json = JacksonUtils.toObj(response.getBody()); + Assert.assertEquals(count + 1, json.get("count").asInt()); namingServiceDelete(serviceName); } @@ -211,9 +211,9 @@ public class RestAPI_ITCase extends NamingBase { String.class); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject json = JSON.parseObject(response.getBody()); + JsonNode json = JacksonUtils.toObj(response.getBody()); System.out.println(json); - Assert.assertEquals(0.3f, json.getFloatValue("protectThreshold"), 0.0f); + Assert.assertEquals(0.3f, json.get("protectThreshold").floatValue(), 0.0f); namingServiceDelete(serviceName); } diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/Subscribe_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/Subscribe_ITCase.java index def237b05..77b9be11f 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/Subscribe_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/Subscribe_ITCase.java @@ -15,8 +15,6 @@ */ package com.alibaba.nacos.test.naming; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import com.alibaba.nacos.Nacos; import com.alibaba.nacos.api.naming.NamingFactory; import com.alibaba.nacos.api.naming.NamingService; @@ -24,8 +22,10 @@ import com.alibaba.nacos.api.naming.listener.Event; import com.alibaba.nacos.api.naming.listener.EventListener; import com.alibaba.nacos.api.naming.listener.NamingEvent; import com.alibaba.nacos.api.naming.pojo.Instance; -import com.alibaba.nacos.core.utils.ApplicationUtils; +import com.alibaba.nacos.common.utils.JacksonUtils; import com.alibaba.nacos.test.base.Params; +import com.fasterxml.jackson.databind.JsonNode; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -227,9 +227,9 @@ public class Subscribe_ITCase extends RestAPI_ITCase { HttpMethod.GET); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - JSONObject body = JSON.parseObject(response.getBody()); + JsonNode body = JacksonUtils.toObj(response.getBody()); - Assert.assertEquals(1, body.getJSONArray("subscribers").size()); + Assert.assertEquals(1, body.get("subscribers").size()); NamingService naming2 = NamingFactory.createNamingService("127.0.0.1" + ":" + port); @@ -254,9 +254,9 @@ public class Subscribe_ITCase extends RestAPI_ITCase { HttpMethod.GET); Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - body = JSON.parseObject(response.getBody()); + body = JacksonUtils.toObj(response.getBody()); - Assert.assertEquals(2, body.getJSONArray("subscribers").size()); + Assert.assertEquals(2, body.get("subscribers").size()); } } From 56da41357e98e9f35e5917edd6eee7599b901c09 Mon Sep 17 00:00:00 2001 From: KomachiSion <263976490@qq.com> Date: Wed, 3 Jun 2020 14:42:25 +0800 Subject: [PATCH 5/6] Remove fastjson dependency from pom --- pom.xml | 8 -------- test/pom.xml | 5 ----- 2 files changed, 13 deletions(-) diff --git a/pom.xml b/pom.xml index bd567d48e..350e59fb1 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,6 @@ 2.1.1.RELEASE - 1.2.58 3.0 2.6 3.4 @@ -618,13 +617,6 @@ ${project.version} - - - com.alibaba - fastjson - ${fastjson.version} - - javax.servlet servlet-api diff --git a/test/pom.xml b/test/pom.xml index c6f3c3e80..04b5d1495 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -52,11 +52,6 @@ truth - - com.alibaba - fastjson - - ${project.groupId} nacos-api From 74a2995709ebb5e496658374659f980862a31b18 Mon Sep 17 00:00:00 2001 From: KomachiSion <263976490@qq.com> Date: Wed, 3 Jun 2020 14:43:12 +0800 Subject: [PATCH 6/6] Remove fastjson LICENSE --- distribution/LICENSE-BIN | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/distribution/LICENSE-BIN b/distribution/LICENSE-BIN index 372617233..5be5ed219 100644 --- a/distribution/LICENSE-BIN +++ b/distribution/LICENSE-BIN @@ -245,24 +245,6 @@ The source code of slf4j can be found at https://github.com/qos-ch/slf4j. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------- -This product has a bundle fastjson, which is available under the ASL2 License. -The source code of fastjson can be found at https://github.com/alibaba/fastjson. - - Copyright 1999-2016 Alibaba Group Holding Ltd. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ------ This product has a bundle javassist, which is available under the ASL2 License. The source code of javassist can be found at https://github.com/jboss-javassist/javassist. @@ -301,7 +283,7 @@ The source code of jna can be found at https://github.com/java-native-access/jna This product has a bundle guava, which is available under the ASL2 License. The source code of guava can be found at https://github.com/google/guava. - Copyright (C) 2007 The Guava authors + Copyright (C) 2007 The Guava authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.