Browse Source

Using Jackson instead of Fastjson

pull/2/head
simon 5 years ago
parent
commit
39d2713d0a
  1. 24
      dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/JSONUtilsTest.java

24
dolphinscheduler-alert/src/test/java/org/apache/dolphinscheduler/alert/utils/JSONUtilsTest.java

@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import org.apache.dolphinscheduler.common.utils.*; import org.apache.dolphinscheduler.common.utils.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -46,11 +47,11 @@ public class JSONUtilsTest {
//Initial map //Initial map
LinkedHashMap<String, Object> map = new LinkedHashMap<>(); LinkedHashMap<String, Object> map = new LinkedHashMap<>();
map.put("mysql service name","mysql200"); map.put("mysql service name", "mysql200");
map.put("mysql address","192.168.xx.xx"); map.put("mysql address", "192.168.xx.xx");
map.put("port","3306"); map.put("port", "3306");
map.put("no index of number","80"); map.put("no index of number", "80");
map.put("database client connections","190"); map.put("database client connections", "190");
//Add map into list //Add map into list
list.add(map); list.add(map);
@ -68,7 +69,8 @@ public class JSONUtilsTest {
logger.info(result); logger.info(result);
//Equal result with expected string //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 //If param is null, then return null string
result = JSONUtils.toJsonString(null); result = JSONUtils.toJsonString(null);
@ -85,27 +87,27 @@ public class JSONUtilsTest {
public void testToList() { public void testToList() {
//Invoke toList //Invoke toList
List<LinkedHashMap> result = JSONUtils.toList(expected ,LinkedHashMap.class); List<LinkedHashMap> result = JSONUtils.toList(expected, LinkedHashMap.class);
//Equal list size=1 //Equal list size=1
assertEquals(1,result.size()); assertEquals(1, result.size());
//Transform entity to LinkedHashMap<String, Object> //Transform entity to LinkedHashMap<String, Object>
LinkedHashMap<String, Object> entity = result.get(0); LinkedHashMap<String, Object> entity = result.get(0);
//Equal expected values //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("192.168.xx.xx", entity.get("mysql address"));
assertEquals("3306", entity.get("port")); assertEquals("3306", entity.get("port"));
assertEquals("80", entity.get("no index of number")); assertEquals("80", entity.get("no index of number"));
assertEquals("190", entity.get("database client connections")); assertEquals("190", entity.get("database client connections"));
//If param is null, then return empty list //If param is null, then return empty list
result = JSONUtils.toList(null ,LinkedHashMap.class); result = JSONUtils.toList(null, LinkedHashMap.class);
assertNotNull(result); assertNotNull(result);
assertTrue(result.isEmpty()); assertTrue(result.isEmpty());
//If param is incorrect, then return empty list and log error message //If param is incorrect, then return empty list and log error message
result = JSONUtils.toList("}{" ,LinkedHashMap.class); result = JSONUtils.toList("}{", LinkedHashMap.class);
assertNotNull(result); assertNotNull(result);
assertTrue(result.isEmpty()); assertTrue(result.isEmpty());

Loading…
Cancel
Save