Merge pull request #2947 from KomachiSion/develop-issue#2842
[ISSUE #2842] Replace all fastjson with jackson
This commit is contained in:
commit
7ac0ff83b8
@ -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.
|
||||
|
8
pom.xml
8
pom.xml
@ -125,7 +125,6 @@
|
||||
|
||||
<!-- dependency version -->
|
||||
<spring-boot-dependencies.version>2.1.1.RELEASE</spring-boot-dependencies.version>
|
||||
<fastjson.version>1.2.58</fastjson.version>
|
||||
<servlet-api.version>3.0</servlet-api.version>
|
||||
<commons-lang.version>2.6</commons-lang.version>
|
||||
<commons-lang3.version>3.4</commons-lang3.version>
|
||||
@ -618,13 +617,6 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Alibaba libs-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>${fastjson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
|
@ -52,11 +52,6 @@
|
||||
<artifactId>truth</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>nacos-api</artifactId>
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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<Integer> tmp = ResponseHandler.convert(json, new GenericType<List<Integer>>(){}.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<Integer> tmp = ResponseHandler.convert(json, ClassUtils.resolveGenericType(new GenericType<List<Integer>>(){}.getClass()));
|
||||
Assert.assertEquals(list, tmp);
|
||||
}
|
||||
|
@ -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<String> 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<String> 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<String> 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();
|
||||
}
|
||||
|
@ -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<String> 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<String> 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<String> 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());
|
||||
}
|
||||
|
||||
<T> ResponseEntity<T> request(String path, MultiValueMap<String, String> params, Class<T> clazz, HttpMethod httpMethod) {
|
||||
|
@ -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<ZipUtils.ZipItem> 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<ZipUtils.ZipItem> 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<ZipUtils.ZipItem> 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":
|
||||
|
@ -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 {
|
||||
|
@ -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<Permission> permissionPage = JSON.parseObject(response.getBody(), new TypeReference<Page<Permission>>() {
|
||||
});
|
||||
Page<Permission> permissionPage = JacksonUtils.toObj(response.getBody(), new TypeReference<Page<Permission>>() {});
|
||||
|
||||
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<Page<Permission>>() {
|
||||
});
|
||||
permissionPage = JacksonUtils.toObj(response.getBody(), new TypeReference<Page<Permission>>() {});
|
||||
|
||||
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<Page<Permission>>() {
|
||||
});
|
||||
permissionPage = JacksonUtils.toObj(response.getBody(), new TypeReference<Page<Permission>>() {});
|
||||
|
||||
Assert.assertNotNull(permissionPage);
|
||||
Assert.assertNotNull(permissionPage.getPageItems());
|
||||
|
@ -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<RoleInfo> roleInfoPage = JSON.parseObject(response.getBody(), new TypeReference<Page<RoleInfo>>() {
|
||||
});
|
||||
Page<RoleInfo> roleInfoPage = JacksonUtils.toObj(response.getBody(), new TypeReference<Page<RoleInfo>>() {});
|
||||
|
||||
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<Page<RoleInfo>>() {
|
||||
});
|
||||
roleInfoPage = JacksonUtils.toObj(response.getBody(), new TypeReference<Page<RoleInfo>>() {});
|
||||
|
||||
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<Page<RoleInfo>>() {
|
||||
});
|
||||
roleInfoPage = JacksonUtils.toObj(response.getBody(), new TypeReference<Page<RoleInfo>>() {});
|
||||
|
||||
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<Page<RoleInfo>>() {
|
||||
});
|
||||
roleInfoPage = JacksonUtils.toObj(response.getBody(), new TypeReference<Page<RoleInfo>>() {});
|
||||
|
||||
Assert.assertNotNull(roleInfoPage);
|
||||
Assert.assertNotNull(roleInfoPage.getPageItems());
|
||||
|
@ -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<User> userPage = JSON.parseObject(response.getBody(), new TypeReference<Page<User>>() {
|
||||
});
|
||||
Page<User> userPage = JacksonUtils.toObj(response.getBody(), new TypeReference<Page<User>>() {});
|
||||
|
||||
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<Page<User>>() {
|
||||
});
|
||||
userPage = JacksonUtils.toObj(response.getBody(), new TypeReference<Page<User>>() {});
|
||||
|
||||
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<Page<User>>() {
|
||||
});
|
||||
userPage = JacksonUtils.toObj(response.getBody(), new TypeReference<Page<User>>() {});
|
||||
|
||||
Assert.assertNotNull(userPage);
|
||||
Assert.assertNotNull(userPage.getPageItems());
|
||||
|
@ -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);
|
||||
|
@ -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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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);
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user