PageRenderTime 67ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/dubbo-common/src/test/java/com/alibaba/dubbo/common/serialize/serialization/FastJsonSerializationTest.java

https://gitlab.com/zouxc/dubbo
Java | 266 lines | 186 code | 57 blank | 23 comment | 6 complexity | 807f4ea52cf8a3100c647cc64abc353e MD5 | raw file
  1. /*
  2. * Copyright 1999-2011 Alibaba Group.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.alibaba.dubbo.common.serialize.serialization;
  17. import static org.junit.Assert.fail;
  18. import java.io.ByteArrayInputStream;
  19. import org.junit.Ignore;
  20. import org.junit.Test;
  21. import com.alibaba.dubbo.common.model.media.MediaContent;
  22. import com.alibaba.dubbo.common.serialize.ObjectInput;
  23. import com.alibaba.dubbo.common.serialize.ObjectOutput;
  24. import com.alibaba.dubbo.common.serialize.support.json.FastJsonSerialization;
  25. import com.alibaba.fastjson.JSONException;
  26. /**
  27. * FIXME FastJson Serialization的失败,被暂时被忽略
  28. *
  29. * @author ding.lid
  30. */
  31. public class FastJsonSerializationTest extends AbstractSerializationPersionOkTest {
  32. {
  33. serialization = new FastJsonSerialization();
  34. }
  35. @Ignore // FIXME
  36. @Test
  37. public void test_BytesRange() throws Exception {}
  38. @Ignore("bool[] type missing to JSONArray")
  39. @Test
  40. public void test_boolArray() throws Exception {}
  41. @Ignore("FastJson bug: com.alibaba.fastjson.JSONException: create asm serilizer error, class char")
  42. @Test
  43. public void test_charArray() throws Exception {}
  44. @Ignore("FastJson bug: com.alibaba.fastjson.JSONException: create asm serilizer error, class char")
  45. @Test
  46. public void test_charArray_withType() throws Exception {}
  47. @Ignore("short[] type missing to JSONArray")
  48. @Test
  49. public void test_shortArray() throws Exception {}
  50. @Ignore("int[] type missing to JSONArray")
  51. @Test
  52. public void test_intArray() throws Exception {}
  53. @Ignore("long[] type missing to JSONArray")
  54. @Test
  55. public void test_longArray() throws Exception {}
  56. @Ignore("float[] type missing to JSONArray")
  57. @Test
  58. public void test_floatArray() throws Exception {}
  59. @Ignore("double[] type missing to JSONArray")
  60. @Test
  61. public void test_doubleArray() throws Exception {}
  62. @Ignore("String[] type missing to JSONArray")
  63. @Test
  64. public void test_StringArray() throws Exception {}
  65. @Ignore("Integer[] type missing to JSONArray")
  66. @Test
  67. public void test_IntegerArray() throws Exception {}
  68. @Ignore("Integer[] type missing to JSONArray")
  69. @Test
  70. public void test_EnumArray() throws Exception {}
  71. @Ignore("type mising to Long")
  72. @Test
  73. public void test_Date() throws Exception {}
  74. @Ignore("type mising to Long")
  75. @Test
  76. public void test_Time() throws Exception {}
  77. @Ignore("com.alibaba.fastjson.JSONException: create asm deserializer error, java.sql.Time")
  78. @Test
  79. public void test_Time_withType() throws Exception {}
  80. @Ignore("type mising to Integer")
  81. @Test
  82. public void test_ByteWrap() throws Exception {}
  83. @Ignore("type mising to Integer")
  84. @Test
  85. public void test_LongWrap() throws Exception {}
  86. @Ignore("type mising to Long")
  87. @Test
  88. public void test_BigInteger() throws Exception {}
  89. @Ignore("SPerson type missing")
  90. @Test
  91. public void test_SPerson() throws Exception {}
  92. @Ignore("BizException type missing to Map")
  93. @Test
  94. public void test_BizException() throws Exception {}
  95. @Ignore("BizExceptionNoDefaultConstructor type missing to Map")
  96. @Test
  97. public void test_BizExceptionNoDefaultConstructor() throws Exception {}
  98. // FIXME 没有缺省构造函数失败
  99. @Ignore("NoDefaultConstructor")
  100. @Test
  101. public void test_BizExceptionNoDefaultConstructor_WithType() throws Exception {}
  102. @Ignore("Enum type missing to String")
  103. @Test
  104. public void test_enum() throws Exception {}
  105. @Ignore("String set missing to JSONArray")
  106. @Test
  107. public void test_StringSet() throws Exception {}
  108. @Ignore("LinkedHashMap type missing to Map")
  109. @Test
  110. public void test_LinkedHashMap() throws Exception {}
  111. @Ignore("person type missing")
  112. @Test
  113. public void test_SPersonList() throws Exception {}
  114. @Ignore("person type missing")
  115. @Test
  116. public void test_SPersonSet() throws Exception {}
  117. @Ignore("FastJson bug: com.alibaba.fastjson.JSONException: illegal identifier : 1")
  118. @Test
  119. public void test_IntSPersonMap() throws Exception {}
  120. @Ignore("person type missing")
  121. @Test
  122. public void test_StringSPersonMap() throws Exception {}
  123. @Ignore("person type missing")
  124. @Test
  125. public void test_StringSPersonListMap() throws Exception {}
  126. @Ignore("person type missing")
  127. @Test
  128. public void test_SPersonListList() throws Exception {}
  129. @Ignore("BigPerson type missing")
  130. @Test
  131. public void test_BigPerson() throws Exception {}
  132. @Ignore("MediaContent type missing")
  133. @Test
  134. public void test_MediaContent() throws Exception {}
  135. @Ignore("type missing")
  136. @Test
  137. public void test_MultiObject() throws Exception {}
  138. @Test
  139. public void test_MediaContent_badStream() throws Exception {
  140. ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
  141. objectOutput.writeObject(mediaContent);
  142. objectOutput.flushBuffer();
  143. byte[] byteArray = byteArrayOutputStream.toByteArray();
  144. for (int i = 0; i < byteArray.length; i++) {
  145. if(i%3 == 0) {
  146. byteArray[i] = (byte)~byteArray[i];
  147. }
  148. }
  149. ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
  150. try {
  151. ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
  152. @SuppressWarnings("unused") // local variable, convenient for debug
  153. Object read = deserialize.readObject();
  154. fail();
  155. } catch (JSONException expected) {
  156. System.out.println(expected);
  157. }
  158. }
  159. @Test
  160. public void test_MediaContent_WithType_badStream() throws Exception {
  161. ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
  162. objectOutput.writeObject(mediaContent);
  163. objectOutput.flushBuffer();
  164. byte[] byteArray = byteArrayOutputStream.toByteArray();
  165. for (int i = 0; i < byteArray.length; i++) {
  166. if(i%3 == 0) {
  167. byteArray[i] = (byte)~byteArray[i];
  168. }
  169. }
  170. ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
  171. try {
  172. ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);
  173. @SuppressWarnings("unused") // local variable, convenient for debug
  174. Object read = deserialize.readObject(MediaContent.class);
  175. fail();
  176. } catch (JSONException expected) {
  177. System.out.println(expected);
  178. }
  179. }
  180. // FIXME DUBBO-63
  181. @Ignore
  182. @Test
  183. public void test_URL_mutable_withType() throws Exception {}
  184. @Ignore
  185. @Test(timeout=3000)
  186. public void test_LoopReference() throws Exception {}
  187. // ========== Person
  188. @Ignore("person type missing")
  189. @Test
  190. public void test_Person() throws Exception {}
  191. @Ignore("person type missing")
  192. @Test
  193. public void test_PersonList() throws Exception {}
  194. @Ignore("person type missing")
  195. @Test
  196. public void test_PersonSet() throws Exception {}
  197. @Ignore("FastJson bug: com.alibaba.fastjson.JSONException: illegal identifier : 1")
  198. @Test
  199. public void test_IntPersonMap() throws Exception {}
  200. @Ignore("person type missing")
  201. @Test
  202. public void test_StringPersonMap() throws Exception {}
  203. @Ignore("person type missing")
  204. @Test
  205. public void test_StringPersonListMap() throws Exception {}
  206. @Ignore("person type missing")
  207. @Test
  208. public void test_PersonListList() throws Exception {}
  209. }