PageRenderTime 66ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/test/performance/testcase/loop/XStreamLoopTest.java

http://github.com/pangwu86/XBlink
Java | 165 lines | 115 code | 50 blank | 0 comment | 0 complexity | 29c94e8c4e21e39e69f02d4ab0bbc2f8 MD5 | raw file
  1. package performance.testcase.loop;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import org.junit.Test;
  5. import performance.model.LoopA;
  6. import performance.model.LoopB;
  7. import performance.model.LoopC;
  8. import com.alibaba.fastjson.JSON;
  9. import com.alibaba.fastjson.serializer.SerializerFeature;
  10. import com.thoughtworks.xstream.XStream;
  11. import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
  12. import com.thoughtworks.xstream.io.xml.Xpp3Driver;
  13. public class XStreamLoopTest {
  14. public LoopA getLoopA() {
  15. LoopA loopA = new LoopA();
  16. loopA.setaName("AAAA");
  17. LoopB loopB = new LoopB();
  18. loopB.setbName("BBBB");
  19. LoopC loopC = new LoopC();
  20. loopC.setcName("iCCCC");
  21. loopA.setLoopBObj(loopB);
  22. loopA.setLoopCObj(loopC);
  23. loopB.setLoopCObj(loopC);
  24. loopC.setLoopAObj(loopA);
  25. return loopA;
  26. }
  27. public LoopA getLoopA2() {
  28. LoopA loopA = new LoopA();
  29. loopA.setaName("AAAA");
  30. LoopB loopB = new LoopB();
  31. loopB.setbName("BBBB");
  32. LoopC loopC = new LoopC();
  33. loopC.setcName("iCCCC");
  34. loopA.setLoopBObj(loopB);
  35. loopA.setLoopCObj(loopC);
  36. loopC.setLoopCObj(loopC);
  37. return loopA;
  38. }
  39. public LoopA getLoopA3() {
  40. LoopA loopA = new LoopA();
  41. loopA.setaName("AAAA");
  42. LoopA loopA2 = new LoopA();
  43. loopA2.setaName("AAAA2222222");
  44. LoopA loopA3 = new LoopA();
  45. loopA3.setaName("AAAA333333");
  46. List<LoopA> loopAs = new ArrayList<LoopA>();
  47. loopAs.add(loopA);
  48. loopAs.add(loopA2);
  49. loopAs.add(loopA3);
  50. LoopB loopB = new LoopB();
  51. loopB.setbName("BBBB");
  52. loopB.setLoopAList(loopAs);
  53. LoopC loopC = new LoopC();
  54. loopC.setcName("iCCCC");
  55. loopA.setLoopBObj(loopB);
  56. loopA.setLoopCObj(loopC);
  57. loopC.setLoopCObj(loopC);
  58. return loopA;
  59. }
  60. public LoopC getLoopC() {
  61. LoopC loopC = new LoopC();
  62. loopC.setcName("cdfdfd");
  63. loopC.setLoopAObj(getLoopA());
  64. return loopC;
  65. }
  66. @Test
  67. public void toXml1() throws Exception {
  68. XStream xStream = new XStream(new Xpp3Driver());
  69. xStream.processAnnotations(new Class[] { LoopA.class, LoopB.class, LoopC.class });
  70. String xml = xStream.toXML(getLoopA());
  71. System.out.println(xml);
  72. }
  73. @Test
  74. public void toXml2() throws Exception {
  75. XStream xStream = new XStream(new Xpp3Driver());
  76. xStream.processAnnotations(new Class[] { LoopA.class, LoopB.class, LoopC.class });
  77. String xml = xStream.toXML(getLoopA2());
  78. System.out.println(xml);
  79. }
  80. @Test
  81. public void toJSON1() throws Exception {
  82. String json = JSON.toJSONString(getLoopA(), SerializerFeature.PrettyFormat);
  83. System.out.println(json);
  84. }
  85. @Test
  86. public void toJSON1_2() throws Exception {
  87. String json = JSON.toJSONString(getLoopC(), SerializerFeature.PrettyFormat);
  88. System.out.println(json);
  89. XStream xStream = new XStream(new JsonHierarchicalStreamDriver());
  90. xStream.processAnnotations(new Class[] { LoopA.class, LoopB.class, LoopC.class });
  91. String xsJson = xStream.toXML(getLoopC());
  92. System.out.println(xsJson);
  93. }
  94. @Test
  95. public void toJSON2() throws Exception {
  96. String json = JSON.toJSONString(getLoopA2(), SerializerFeature.PrettyFormat);
  97. System.out.println(json);
  98. }
  99. @Test
  100. public void toXml3() throws Exception {
  101. XStream xStream = new XStream(new Xpp3Driver());
  102. xStream.processAnnotations(new Class[] { LoopA.class, LoopB.class, LoopC.class });
  103. String xml = xStream.toXML(getLoopA3());
  104. System.out.println(xml);
  105. }
  106. @Test
  107. public void toJSON3() throws Exception {
  108. String json = JSON.toJSONString(getLoopA3(), SerializerFeature.PrettyFormat);
  109. System.out.println(json);
  110. XStream xStream = new XStream(new JsonHierarchicalStreamDriver());
  111. xStream.processAnnotations(new Class[] { LoopA.class, LoopB.class, LoopC.class });
  112. String xsJson = xStream.toXML(getLoopA3());
  113. System.out.println(xsJson);
  114. }
  115. }