dev --- 3.8.0.A版本, openProject引用 ; formao-live --- 3.7.0.B 版本, formallProject引用
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
5.8 KiB

  1. package chanjarster.weixin.bean;
  2. import org.testng.Assert;
  3. import org.testng.annotations.Test;
  4. import chanjarster.weixin.api.WxConsts;
  5. import chanjarster.weixin.bean.WxCustomMessage.WxArticle;
  6. @Test
  7. public class WxCustomMessageTest {
  8. public void testTextReply() {
  9. WxCustomMessage reply = new WxCustomMessage();
  10. reply.setTouser("OPENID");
  11. reply.setMsgtype(WxConsts.CUSTOM_MSG_TEXT);
  12. reply.setContent("sfsfdsdf");
  13. Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
  14. }
  15. public void testTextBuild() {
  16. WxCustomMessage reply = WxCustomMessage.TEXT().toUser("OPENID").content("sfsfdsdf").build();
  17. Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
  18. }
  19. public void testImageReply() {
  20. WxCustomMessage reply = new WxCustomMessage();
  21. reply.setTouser("OPENID");
  22. reply.setMsgtype(WxConsts.CUSTOM_MSG_IMAGE);
  23. reply.setMedia_id("MEDIA_ID");
  24. Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
  25. }
  26. public void testImageBuild() {
  27. WxCustomMessage reply = WxCustomMessage.IMAGE().toUser("OPENID").mediaId("MEDIA_ID").build();
  28. Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
  29. }
  30. public void testVoiceReply() {
  31. WxCustomMessage reply = new WxCustomMessage();
  32. reply.setTouser("OPENID");
  33. reply.setMsgtype(WxConsts.CUSTOM_MSG_VOICE);
  34. reply.setMedia_id("MEDIA_ID");
  35. Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
  36. }
  37. public void testVoiceBuild() {
  38. WxCustomMessage reply = WxCustomMessage.VOICE().toUser("OPENID").mediaId("MEDIA_ID").build();
  39. Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
  40. }
  41. public void testVideoReply() {
  42. WxCustomMessage reply = new WxCustomMessage();
  43. reply.setTouser("OPENID");
  44. reply.setMsgtype(WxConsts.CUSTOM_MSG_VIDEO);
  45. reply.setMedia_id("MEDIA_ID");
  46. reply.setThumb_media_id("MEDIA_ID");
  47. reply.setTitle("TITLE");
  48. reply.setDescription("DESCRIPTION");
  49. Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}");
  50. }
  51. public void testVideoBuild() {
  52. WxCustomMessage reply = WxCustomMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID").thumbMediaId("MEDIA_ID").description("DESCRIPTION").build();
  53. Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}");
  54. }
  55. public void testMusicReply() {
  56. WxCustomMessage reply = new WxCustomMessage();
  57. reply.setTouser("OPENID");
  58. reply.setMsgtype(WxConsts.CUSTOM_MSG_MUSIC);
  59. reply.setThumb_media_id("MEDIA_ID");
  60. reply.setDescription("DESCRIPTION");
  61. reply.setTitle("TITLE");
  62. reply.setMusicurl("MUSIC_URL");
  63. reply.setHqmusicurl("HQ_MUSIC_URL");
  64. Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}");
  65. }
  66. public void testMusicBuild() {
  67. WxCustomMessage reply = WxCustomMessage.MUSIC()
  68. .toUser("OPENID")
  69. .title("TITLE")
  70. .thumbMediaId("MEDIA_ID")
  71. .description("DESCRIPTION")
  72. .musicUrl("MUSIC_URL")
  73. .hqmusicUrl("HQ_MUSIC_URL")
  74. .build();
  75. Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}");
  76. }
  77. public void testNewsReply() {
  78. WxCustomMessage reply = new WxCustomMessage();
  79. reply.setTouser("OPENID");
  80. reply.setMsgtype(WxConsts.CUSTOM_MSG_NEWS);
  81. WxArticle article1 = new WxArticle();
  82. article1.setUrl("URL");
  83. article1.setPicurl("PIC_URL");
  84. article1.setDescription("Is Really A Happy Day");
  85. article1.setTitle("Happy Day");
  86. reply.getArticles().add(article1);
  87. WxArticle article2 = new WxArticle();
  88. article2.setUrl("URL");
  89. article2.setPicurl("PIC_URL");
  90. article2.setDescription("Is Really A Happy Day");
  91. article2.setTitle("Happy Day");
  92. reply.getArticles().add(article2);
  93. Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}");
  94. }
  95. public void testNewsBuild() {
  96. WxArticle article1 = new WxArticle();
  97. article1.setUrl("URL");
  98. article1.setPicurl("PIC_URL");
  99. article1.setDescription("Is Really A Happy Day");
  100. article1.setTitle("Happy Day");
  101. WxArticle article2 = new WxArticle();
  102. article2.setUrl("URL");
  103. article2.setPicurl("PIC_URL");
  104. article2.setDescription("Is Really A Happy Day");
  105. article2.setTitle("Happy Day");
  106. WxCustomMessage reply = WxCustomMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build();
  107. Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}");
  108. }
  109. }