|
|
|
@@ -2,8 +2,8 @@ package me.chanjar.weixin.mp.bean.kefu;
|
|
|
|
|
|
|
|
|
|
import me.chanjar.weixin.common.api.WxConsts;
|
|
|
|
|
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage.WxArticle;
|
|
|
|
|
import org.testng.*;
|
|
|
|
|
import org.testng.annotations.*;
|
|
|
|
|
import org.testng.Assert;
|
|
|
|
|
import org.testng.annotations.Test;
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public class WxMpKefuMessageTest {
|
|
|
|
@@ -13,12 +13,14 @@ public class WxMpKefuMessageTest {
|
|
|
|
|
reply.setToUser("OPENID");
|
|
|
|
|
reply.setMsgType(WxConsts.KefuMsgType.TEXT);
|
|
|
|
|
reply.setContent("sfsfdsdf");
|
|
|
|
|
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
|
|
|
|
|
Assert
|
|
|
|
|
.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testTextBuild() {
|
|
|
|
|
WxMpKefuMessage reply = WxMpKefuMessage.TEXT().toUser("OPENID").content("sfsfdsdf").build();
|
|
|
|
|
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
|
|
|
|
|
Assert
|
|
|
|
|
.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testImageReply() {
|
|
|
|
@@ -26,12 +28,14 @@ public class WxMpKefuMessageTest {
|
|
|
|
|
reply.setToUser("OPENID");
|
|
|
|
|
reply.setMsgType(WxConsts.KefuMsgType.IMAGE);
|
|
|
|
|
reply.setMediaId("MEDIA_ID");
|
|
|
|
|
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
|
|
|
|
|
Assert.assertEquals(reply.toJson(),
|
|
|
|
|
"{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testImageBuild() {
|
|
|
|
|
WxMpKefuMessage reply = WxMpKefuMessage.IMAGE().toUser("OPENID").mediaId("MEDIA_ID").build();
|
|
|
|
|
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
|
|
|
|
|
Assert.assertEquals(reply.toJson(),
|
|
|
|
|
"{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testVoiceReply() {
|
|
|
|
@@ -39,12 +43,14 @@ public class WxMpKefuMessageTest {
|
|
|
|
|
reply.setToUser("OPENID");
|
|
|
|
|
reply.setMsgType(WxConsts.KefuMsgType.VOICE);
|
|
|
|
|
reply.setMediaId("MEDIA_ID");
|
|
|
|
|
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
|
|
|
|
|
Assert.assertEquals(reply.toJson(),
|
|
|
|
|
"{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testVoiceBuild() {
|
|
|
|
|
WxMpKefuMessage reply = WxMpKefuMessage.VOICE().toUser("OPENID").mediaId("MEDIA_ID").build();
|
|
|
|
|
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
|
|
|
|
|
Assert.assertEquals(reply.toJson(),
|
|
|
|
|
"{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testVideoReply() {
|
|
|
|
@@ -55,12 +61,15 @@ public class WxMpKefuMessageTest {
|
|
|
|
|
reply.setThumbMediaId("MEDIA_ID");
|
|
|
|
|
reply.setTitle("TITLE");
|
|
|
|
|
reply.setDescription("DESCRIPTION");
|
|
|
|
|
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}");
|
|
|
|
|
Assert.assertEquals(reply.toJson(),
|
|
|
|
|
"{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testVideoBuild() {
|
|
|
|
|
WxMpKefuMessage reply = WxMpKefuMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID").thumbMediaId("MEDIA_ID").description("DESCRIPTION").build();
|
|
|
|
|
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}");
|
|
|
|
|
WxMpKefuMessage reply = WxMpKefuMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID")
|
|
|
|
|
.thumbMediaId("MEDIA_ID").description("DESCRIPTION").build();
|
|
|
|
|
Assert.assertEquals(reply.toJson(),
|
|
|
|
|
"{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testMusicReply() {
|
|
|
|
@@ -72,7 +81,8 @@ public class WxMpKefuMessageTest {
|
|
|
|
|
reply.setTitle("TITLE");
|
|
|
|
|
reply.setMusicUrl("MUSIC_URL");
|
|
|
|
|
reply.setHqMusicUrl("HQ_MUSIC_URL");
|
|
|
|
|
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\"}}");
|
|
|
|
|
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\"}}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testMusicBuild() {
|
|
|
|
@@ -84,7 +94,8 @@ public class WxMpKefuMessageTest {
|
|
|
|
|
.musicUrl("MUSIC_URL")
|
|
|
|
|
.hqMusicUrl("HQ_MUSIC_URL")
|
|
|
|
|
.build();
|
|
|
|
|
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\"}}");
|
|
|
|
|
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\"}}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testNewsReply() {
|
|
|
|
@@ -106,8 +117,8 @@ public class WxMpKefuMessageTest {
|
|
|
|
|
article2.setTitle("Happy Day");
|
|
|
|
|
reply.getArticles().add(article2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"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\"}]}}");
|
|
|
|
|
Assert.assertEquals(reply.toJson(),
|
|
|
|
|
"{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"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\"}]}}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testNewsBuild() {
|
|
|
|
@@ -125,7 +136,22 @@ public class WxMpKefuMessageTest {
|
|
|
|
|
|
|
|
|
|
WxMpKefuMessage reply = WxMpKefuMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build();
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"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\"}]}}");
|
|
|
|
|
Assert.assertEquals(reply.toJson(),
|
|
|
|
|
"{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"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\"}]}}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void testMiniProgramPageBuild() {
|
|
|
|
|
|
|
|
|
|
WxMpKefuMessage reply = WxMpKefuMessage.MINIPROGRAMPAGE()
|
|
|
|
|
.toUser("OPENID")
|
|
|
|
|
.title("title")
|
|
|
|
|
.appId("appid")
|
|
|
|
|
.pagePath("pagepath")
|
|
|
|
|
.thumbMediaId("thumb_media_id")
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(reply.toJson(),
|
|
|
|
|
"{\"touser\":\"OPENID\",\"msgtype\":\"miniprogrampage\",\"miniprogrampage\":{\"title\":\"title\",\"appid\":\"appid\",\"pagepath\":\"pagepath\",\"thumb_media_id\":\"thumb_media_id\"}}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|