mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
add menu support
This commit is contained in:
@@ -13,7 +13,7 @@ public class WxCustomMessageTest {
|
||||
public void testTextReply() {
|
||||
WxCustomMessage reply = new WxCustomMessage();
|
||||
reply.setTouser("OPENID");
|
||||
reply.setMsgtype(WxConsts.TEXT);
|
||||
reply.setMsgtype(WxConsts.MSG_TEXT);
|
||||
reply.setContent("sfsfdsdf");
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class WxCustomMessageTest {
|
||||
public void testImageReply() {
|
||||
WxCustomMessage reply = new WxCustomMessage();
|
||||
reply.setTouser("OPENID");
|
||||
reply.setMsgtype(WxConsts.IMAGE);
|
||||
reply.setMsgtype(WxConsts.MSG_IMAGE);
|
||||
reply.setMedia_id("MEDIA_ID");
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class WxCustomMessageTest {
|
||||
public void testVoiceReply() {
|
||||
WxCustomMessage reply = new WxCustomMessage();
|
||||
reply.setTouser("OPENID");
|
||||
reply.setMsgtype(WxConsts.VOICE);
|
||||
reply.setMsgtype(WxConsts.MSG_VOICE);
|
||||
reply.setMedia_id("MEDIA_ID");
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class WxCustomMessageTest {
|
||||
public void testVideoReply() {
|
||||
WxCustomMessage reply = new WxCustomMessage();
|
||||
reply.setTouser("OPENID");
|
||||
reply.setMsgtype(WxConsts.VIDEO);
|
||||
reply.setMsgtype(WxConsts.MSG_VIDEO);
|
||||
reply.setMedia_id("MEDIA_ID");
|
||||
reply.setThumb_media_id("MEDIA_ID");
|
||||
reply.setTitle("TITLE");
|
||||
@@ -48,7 +48,7 @@ public class WxCustomMessageTest {
|
||||
public void testMusicReply() {
|
||||
WxCustomMessage reply = new WxCustomMessage();
|
||||
reply.setTouser("OPENID");
|
||||
reply.setMsgtype(WxConsts.MUSIC);
|
||||
reply.setMsgtype(WxConsts.MSG_MUSIC);
|
||||
reply.setThumb_media_id("MEDIA_ID");
|
||||
reply.setDescription("DESCRIPTION");
|
||||
reply.setTitle("TITLE");
|
||||
@@ -60,7 +60,7 @@ public class WxCustomMessageTest {
|
||||
public void testNewsReply() {
|
||||
WxCustomMessage reply = new WxCustomMessage();
|
||||
reply.setTouser("OPENID");
|
||||
reply.setMsgtype(WxConsts.NEWS);
|
||||
reply.setMsgtype(WxConsts.MSG_NEWS);
|
||||
|
||||
WxArticle article1 = new WxArticle();
|
||||
article1.setUrl("URL");
|
||||
@@ -77,7 +77,6 @@ public class WxCustomMessageTest {
|
||||
reply.getArticles().add(article2);
|
||||
|
||||
|
||||
System.out.println(reply.toJson());
|
||||
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\"}]}");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package chanjarster.weixin.bean;
|
||||
|
||||
import org.apache.http.util.Asserts;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
@@ -10,13 +9,13 @@ import chanjarster.weixin.bean.WxMenu.WxMenuButton;
|
||||
@Test
|
||||
public class WxMenuTest {
|
||||
|
||||
@Test(dataProvider="json")
|
||||
@Test(dataProvider="wxReturnMenu")
|
||||
public void testFromJson(String json) {
|
||||
WxMenu menu = WxMenu.fromJson(json);
|
||||
Assert.assertEquals(menu.getButton().size(), 3);
|
||||
}
|
||||
|
||||
@Test(dataProvider="json")
|
||||
@Test(dataProvider="wxPushMenu")
|
||||
public void testToJson(String json) {
|
||||
WxMenu menu = new WxMenu();
|
||||
WxMenuButton button1 = new WxMenuButton();
|
||||
@@ -55,12 +54,20 @@ public class WxMenuTest {
|
||||
button3.getSub_button().add(button32);
|
||||
button3.getSub_button().add(button33);
|
||||
|
||||
System.out.println(menu.toJson());
|
||||
Assert.assertEquals(menu.toJson(), json);
|
||||
}
|
||||
|
||||
@DataProvider(name="json")
|
||||
public Object[][] getMenuJson() {
|
||||
@Test(dataProvider="wxReturnMenu")
|
||||
public Object[][] wxReturnMenu() {
|
||||
Object[][] res = menuJson();
|
||||
String json = "{ \"menu\" : " + res[0][0] + " }";
|
||||
return new Object[][] {
|
||||
new Object[] { json }
|
||||
};
|
||||
}
|
||||
|
||||
@DataProvider(name="wxPushMenu")
|
||||
public Object[][] menuJson() {
|
||||
String json =
|
||||
"{"
|
||||
+"\"button\":["
|
||||
|
||||
@@ -40,7 +40,7 @@ public class WxXmlMessageTest {
|
||||
Assert.assertEquals(wxMessage.getToUserName(), "toUser");
|
||||
Assert.assertEquals(wxMessage.getFromUserName(), "fromUser");
|
||||
Assert.assertEquals(wxMessage.getCreateTime(), new Long(1348831860l));
|
||||
Assert.assertEquals(wxMessage.getMsgType(), WxConsts.TEXT);
|
||||
Assert.assertEquals(wxMessage.getMsgType(), WxConsts.MSG_TEXT);
|
||||
Assert.assertEquals(wxMessage.getContent(), "this is a test");
|
||||
Assert.assertEquals(wxMessage.getMsgId(), new Long(1234567890123456l));
|
||||
Assert.assertEquals(wxMessage.getPicUrl(), "this is a url");
|
||||
@@ -67,7 +67,7 @@ public class WxXmlMessageTest {
|
||||
wxMessage.setToUserName("toUser");
|
||||
wxMessage.setFromUserName("fromUser");
|
||||
wxMessage.setCreateTime(new Long(1348831860l));
|
||||
wxMessage.setMsgType(WxConsts.TEXT);
|
||||
wxMessage.setMsgType(WxConsts.MSG_TEXT);
|
||||
wxMessage.setContent("this is a test");
|
||||
wxMessage.setMsgId(new Long(1234567890123456l));
|
||||
wxMessage.setPicUrl("this is a url");
|
||||
|
||||
Reference in New Issue
Block a user