/src/test/java/com/alibaba/json/bvt/parser/number/NumberValueTest_error_13.java

https://github.com/alibaba/fastjson · Java · 409 lines · 360 code · 49 blank · 0 comment · 1 complexity · 23048c83a577e076c48b40f51621cb2a MD5 · raw file

  1. package com.alibaba.json.bvt.parser.number;
  2. import com.alibaba.fastjson.*;
  3. import com.alibaba.fastjson.serializer.SerializerFeature;
  4. import junit.framework.TestCase;
  5. import org.junit.Assert;
  6. import java.math.BigDecimal;
  7. import java.math.BigInteger;
  8. import java.sql.Timestamp;
  9. import java.util.concurrent.TimeUnit;
  10. public class NumberValueTest_error_13 extends TestCase {
  11. public void test_0() throws Exception {
  12. Exception error = null;
  13. try {
  14. JSON.parseObject("{\"v0\":49e99999999}", Model.class);
  15. } catch (JSONException ex) {
  16. error = ex;
  17. }
  18. assertNotNull(error);
  19. assertTrue(error.getCause() instanceof ArithmeticException);
  20. }
  21. public void test_1() throws Exception {
  22. Exception error = null;
  23. try {
  24. JSON.parseObject("{\"v1\":49e99999999}", Model.class);
  25. } catch (JSONException ex) {
  26. error = ex;
  27. }
  28. assertNotNull(error);
  29. assertTrue(error.getCause() instanceof ArithmeticException);
  30. }
  31. public void test_2() throws Exception {
  32. Exception error = null;
  33. try {
  34. JSON.parseObject("{\"v2\":49e99999999}", Model.class);
  35. } catch (JSONException ex) {
  36. error = ex;
  37. }
  38. assertNotNull(error);
  39. assertTrue(error.getCause() instanceof ArithmeticException);
  40. }
  41. public void test_3() throws Exception {
  42. Exception error = null;
  43. try {
  44. JSON.parseObject("{\"v3\":49e99999999}", Model.class);
  45. } catch (JSONException ex) {
  46. error = ex;
  47. }
  48. assertNotNull(error);
  49. assertTrue(error.getCause() instanceof ArithmeticException);
  50. }
  51. public void test_4() throws Exception {
  52. BigDecimal b = new BigDecimal("49e999999999");
  53. assertEquals("4.9E+1000000000", JSON.toJSONString(b, SerializerFeature.WriteBigDecimalAsPlain));
  54. assertEquals("{\"val\":4.9E+1000000000}", JSON.toJSONString(new M1(b), SerializerFeature.WriteBigDecimalAsPlain));
  55. }
  56. public void test_5() throws Exception {
  57. Exception error = null;
  58. try {
  59. JSON.parseObject("{\"v5\":49e99999999}", Model.class);
  60. } catch (JSONException ex) {
  61. error = ex;
  62. }
  63. assertNotNull(error);
  64. assertTrue(error.getCause() instanceof ArithmeticException);
  65. }
  66. public void test_6() throws Exception {
  67. Exception error = null;
  68. try {
  69. JSON.parseObject("{\"v6\":49e99999999}", Model.class);
  70. } catch (JSONException ex) {
  71. error = ex;
  72. }
  73. assertNotNull(error);
  74. assertTrue(error.getCause() instanceof ArithmeticException);
  75. }
  76. public void test_7() throws Exception {
  77. Exception error = null;
  78. try {
  79. JSON.parseObject("{\"v7\":49e99999999}", Model.class);
  80. } catch (JSONException ex) {
  81. error = ex;
  82. }
  83. assertNotNull(error);
  84. assertTrue(error.getCause() instanceof ArithmeticException);
  85. }
  86. public void test_8() throws Exception {
  87. Exception error = null;
  88. try {
  89. JSON.parseObject("{\"v8\":49e99999999}", Model.class);
  90. } catch (JSONException ex) {
  91. error = ex;
  92. }
  93. assertNotNull(error);
  94. assertEquals(NumberFormatException.class, error.getCause().getClass());
  95. }
  96. public void test_9() throws Exception {
  97. Exception error = null;
  98. try {
  99. JSON.parseObject("{\"v9\":49e99999999}", Model.class);
  100. } catch (JSONException ex) {
  101. error = ex;
  102. }
  103. assertNotNull(error);
  104. assertEquals(ArithmeticException.class, error.getCause().getClass());
  105. }
  106. public void test_10() throws Exception {
  107. Exception error = null;
  108. try {
  109. JSON.parseObject("{\"v10\":49e99999999}", Model.class);
  110. } catch (JSONException ex) {
  111. error = ex;
  112. }
  113. assertNotNull(error);
  114. assertEquals(ArithmeticException.class, error.getCause().getClass());
  115. }
  116. public void test_11() throws Exception {
  117. Exception error = null;
  118. try {
  119. JSON.parseObject("{\"v11\":49e99999999}", Model.class);
  120. } catch (JSONException ex) {
  121. error = ex;
  122. }
  123. assertNotNull(error);
  124. assertEquals(ArithmeticException.class, error.getCause().getClass());
  125. }
  126. public void test_11_new() throws Exception {
  127. Exception error = null;
  128. try {
  129. JSON.parseObject("{\"v11\":new Date(49e99999999)}", Model.class);
  130. } catch (JSONException ex) {
  131. error = ex;
  132. }
  133. assertNotNull(error);
  134. }
  135. public void test_12() throws Exception {
  136. Exception error = null;
  137. try {
  138. JSON.parseObject("{\"v12\":49e99999999}", Model.class);
  139. } catch (JSONException ex) {
  140. error = ex;
  141. }
  142. assertNotNull(error);
  143. assertEquals(ArithmeticException.class, error.getCause().getClass());
  144. }
  145. public void test_13() throws Exception {
  146. Exception error = null;
  147. try {
  148. JSON.parseObject("{\"v13\":49e99999999}", Model.class);
  149. } catch (JSONException ex) {
  150. error = ex;
  151. }
  152. assertNotNull(error);
  153. assertEquals(ArithmeticException.class, error.getCause().getClass());
  154. }
  155. public void test_14() throws Exception {
  156. Exception error = null;
  157. try {
  158. JSON.parseObject("{\"v14\":49e99999999}", Model.class);
  159. } catch (JSONException ex) {
  160. error = ex;
  161. }
  162. assertNotNull(error);
  163. assertEquals(UnsupportedOperationException.class, error.getCause().getClass());
  164. }
  165. public void test_15() throws Exception {
  166. Exception error = null;
  167. try {
  168. JSON.parseObject("{\"v15\":49e99999999}", Model.class);
  169. } catch (JSONException ex) {
  170. error = ex;
  171. }
  172. assertNotNull(error);
  173. }
  174. public void test_16() throws Exception {
  175. Exception error = null;
  176. try {
  177. JSON.parseObject("{\"v16\":49e99999999}", Model.class);
  178. } catch (JSONException ex) {
  179. error = ex;
  180. }
  181. assertNotNull(error);
  182. }
  183. public void test_17() throws Exception {
  184. Exception error = null;
  185. try {
  186. JSON.parseObject("{\"v17\":49e99999999}", Model.class);
  187. } catch (JSONException ex) {
  188. error = ex;
  189. }
  190. assertNotNull(error);
  191. }
  192. public void test_17_1() throws Exception {
  193. Exception error = null;
  194. try {
  195. JSONObject jsonObject = JSON.parseObject("{\"v17\":49e99999999}");
  196. jsonObject.getObject("v17", TimeUnit.class);
  197. } catch (JSONException ex) {
  198. error = ex;
  199. }
  200. assertNotNull(error);
  201. }
  202. public void test_18() throws Exception {
  203. Exception error = null;
  204. try {
  205. JSON.parseObject("{\"v18\":49e99999999}", Model.class);
  206. } catch (JSONException ex) {
  207. error = ex;
  208. }
  209. assertNotNull(error);
  210. }
  211. public void test_20() throws Exception {
  212. JSONObject jsonObject = JSON.parseObject("{\"v\":49e99999999}");
  213. Exception error = null;
  214. try {
  215. jsonObject.getIntValue("v");
  216. } catch (ArithmeticException ex) {
  217. error = ex;
  218. }
  219. assertNotNull(error);
  220. }
  221. public void test_21() throws Exception {
  222. JSONObject jsonObject = JSON.parseObject("{\"v\":49e99999999}");
  223. Exception error = null;
  224. try {
  225. jsonObject.getDate("v");
  226. } catch (ArithmeticException ex) {
  227. error = ex;
  228. }
  229. assertNotNull(error);
  230. }
  231. public void test_22() throws Exception {
  232. JSONObject jsonObject = JSON.parseObject("{\"v\":49e99999999}");
  233. Exception error = null;
  234. try {
  235. jsonObject.getObject("v", java.sql.Date.class);
  236. } catch (ArithmeticException ex) {
  237. error = ex;
  238. }
  239. assertNotNull(error);
  240. }
  241. public void test_23() throws Exception {
  242. JSONObject jsonObject = JSON.parseObject("{\"v\":49e99999999}");
  243. Exception error = null;
  244. try {
  245. jsonObject.getObject("v", java.sql.Timestamp.class);
  246. } catch (ArithmeticException ex) {
  247. error = ex;
  248. }
  249. assertNotNull(error);
  250. }
  251. public void test_24() throws Exception {
  252. JSONObject jsonObject = JSON.parseObject("{\"v\":49e99999999}");
  253. Exception error = null;
  254. try {
  255. jsonObject.getObject("v", java.time.LocalDateTime.class);
  256. } catch (JSONException ex) {
  257. error = ex;
  258. }
  259. assertNotNull(error);
  260. }
  261. public void test_25() throws Exception {
  262. JSONObject jsonObject = JSON.parseObject("{\"lineNumber\":49e99999999}");
  263. Exception error = null;
  264. try {
  265. jsonObject.toJavaObject(StackTraceElement.class);
  266. } catch (JSONException ex) {
  267. error = ex;
  268. }
  269. assertNotNull(error);
  270. }
  271. public void test_26() throws Exception {
  272. JSONObject jsonObject = JSON.parseObject("{\"v\":49e99999999}");
  273. Exception error = null;
  274. try {
  275. jsonObject.getObject("v", java.sql.Time.class);
  276. } catch (ArithmeticException ex) {
  277. error = ex;
  278. }
  279. assertNotNull(error);
  280. }
  281. public void test_jsonpath() throws Exception {
  282. JSONObject jsonObject = JSON.parseObject("{\"v\":0}");
  283. Exception error = null;
  284. try {
  285. JSONPath.eval(jsonObject, "$.v in (49e99999999)");
  286. } catch (JSONPathException ex) {
  287. error = ex;
  288. }
  289. assertNotNull(error);
  290. }
  291. public void test_jsonpath_1() throws Exception {
  292. JSONArray jsonObject = JSON.parseArray("[{\"v\":49e99999999}]");
  293. JSONPath.eval(jsonObject, "[v=0]");
  294. }
  295. public void test_jsonpath_2() throws Exception {
  296. Model[] array = JSON.parseObject("[{\"v2\":0}]", Model[].class);
  297. JSONPath.eval(array, "[v='49e99999999']");
  298. }
  299. public void test_jsonpath_3() throws Exception {
  300. Model[] array = JSON.parseObject("[{\"v2\":0}]", Model[].class);
  301. Exception error = null;
  302. try {
  303. JSONPath.read("{\"a\":49e9999999}","[a in (123,2,3)]");
  304. } catch (Exception ex) {
  305. error = ex;
  306. }
  307. assertNotNull(error);
  308. }
  309. public void test_jsonpath_4() throws Exception {
  310. Model[] array = JSON.parseObject("[{\"v2\":0}]", Model[].class);
  311. Exception error = null;
  312. try {
  313. JSONPath.read("{\"a\":49e9999999}","[a between 1 and 3]");
  314. } catch (Exception ex) {
  315. error = ex;
  316. }
  317. assertNotNull(error);
  318. }
  319. public void test_27() throws Exception {
  320. JSONObject object = JSON.parseObject("{\n" +
  321. " \"connection_health\": {\"status\": \"good\", \"max_value\": 2.0, \"min_value\": 2.0, \"average_value\": 2.0}, \n" +
  322. " \"qps_health\": {\"status\": \"good\", \"max_value\": 5.3, \"min_value\": 4.29, \"average_value\": 4.6},\n" +
  323. " \"disksize_health\": {\"status\": \"good\", \"max_value\": 3089.0, \"min_value\": 3089.0, \"average_value\": 3089.0},\n" +
  324. " \"cpu_health\": {\"status\": \"good\", \"max_value\": 0.0, \"min_value\": 0.0, \"average_value\": 0.0}, \n" +
  325. " \"memory_health\": {\"status\": \"good\", \"max_value\": 17.1, \"min_value\": 17.1, \"average_value\": 17.1}, \n" +
  326. " \"iops_health\": {\"status\": \"good\", \"max_value\": 0.09, \"min_value\": 0.07, \"average_value\": 0.08}\n" +
  327. "}");
  328. for(String key : object.keySet()) {
  329. System.out.println("key = " + key);
  330. System.out.println("vaue = " + object.getJSONObject(key).getIntValue("max_value"));
  331. }
  332. }
  333. public static class Model {
  334. public byte v0;
  335. public short v1;
  336. public int v2;
  337. public long v3;
  338. public Byte v4;
  339. public Short v5;
  340. public Integer v6;
  341. public Long v7;
  342. public BigInteger v8;
  343. public Timestamp v9;
  344. public java.sql.Date v10;
  345. public java.util.Date v11;
  346. public java.util.Calendar v12;
  347. public java.sql.Timestamp v13;
  348. public java.time.LocalDateTime v14;
  349. public boolean v15;
  350. public Boolean v16;
  351. public TimeUnit v17;
  352. public java.sql.Time v18;
  353. }
  354. public static class M1 {
  355. public BigDecimal val;
  356. public M1(BigDecimal val) {
  357. this.val = val;
  358. }
  359. }
  360. }