提交 39d2713d 编写于 作者: S simon

Using Jackson instead of Fastjson

上级 e386af70
......@@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import org.apache.dolphinscheduler.common.utils.*;
import static org.junit.Assert.*;
......@@ -46,11 +47,11 @@ public class JSONUtilsTest {
//Initial map
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
map.put("mysql service name","mysql200");
map.put("mysql address","192.168.xx.xx");
map.put("port","3306");
map.put("no index of number","80");
map.put("database client connections","190");
map.put("mysql service name", "mysql200");
map.put("mysql address", "192.168.xx.xx");
map.put("port", "3306");
map.put("no index of number", "80");
map.put("database client connections", "190");
//Add map into list
list.add(map);
......@@ -68,7 +69,8 @@ public class JSONUtilsTest {
logger.info(result);
//Equal result with expected string
assertEquals(result,"[{\"database client connections\":\"190\",\"mysql address\":\"192.168.xx.xx\",\"mysql service name\":\"mysql200\",\"no index of number\":\"80\",\"port\":\"3306\"}]");
assertEquals(result, expected);
// assertEquals(result, "[{\"database client connections\":\"190\",\"mysql address\":\"192.168.xx.xx\",\"mysql service name\":\"mysql200\",\"no index of number\":\"80\",\"port\":\"3306\"}]");
//If param is null, then return null string
result = JSONUtils.toJsonString(null);
......@@ -85,27 +87,27 @@ public class JSONUtilsTest {
public void testToList() {
//Invoke toList
List<LinkedHashMap> result = JSONUtils.toList(expected ,LinkedHashMap.class);
List<LinkedHashMap> result = JSONUtils.toList(expected, LinkedHashMap.class);
//Equal list size=1
assertEquals(1,result.size());
assertEquals(1, result.size());
//Transform entity to LinkedHashMap<String, Object>
LinkedHashMap<String, Object> entity = result.get(0);
//Equal expected values
assertEquals("mysql200",entity.get("mysql service name"));
assertEquals("mysql200", entity.get("mysql service name"));
assertEquals("192.168.xx.xx", entity.get("mysql address"));
assertEquals("3306", entity.get("port"));
assertEquals("80", entity.get("no index of number"));
assertEquals("190", entity.get("database client connections"));
//If param is null, then return empty list
result = JSONUtils.toList(null ,LinkedHashMap.class);
result = JSONUtils.toList(null, LinkedHashMap.class);
assertNotNull(result);
assertTrue(result.isEmpty());
//If param is incorrect, then return empty list and log error message
result = JSONUtils.toList("}{" ,LinkedHashMap.class);
result = JSONUtils.toList("}{", LinkedHashMap.class);
assertNotNull(result);
assertTrue(result.isEmpty());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册