修复完善菜单特别是个性化菜单的创建和删除相关代码
This commit is contained in:
@@ -8,23 +8,22 @@ import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
/**
|
||||
* 测试菜单
|
||||
*
|
||||
* @author chanjarster
|
||||
* @author Binary Wang
|
||||
*
|
||||
*/
|
||||
@Test(groups="menuAPI")
|
||||
@Test(groups = "menuAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpMenuServiceImplTest {
|
||||
|
||||
@Inject
|
||||
protected WxMpService wxService;
|
||||
private String menuId = null;
|
||||
|
||||
@Test(dataProvider = "menu")
|
||||
public void testMenuCreate(WxMenu wxMenu) throws WxErrorException {
|
||||
@@ -44,69 +43,111 @@ public class WxMpMenuServiceImplTest {
|
||||
System.out.println(selfMenuInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateConditionalMenu() throws WxErrorException {
|
||||
String json = "{\n" +
|
||||
" \"button\":[\n" +
|
||||
" { \n" +
|
||||
" \"type\":\"click\",\n" +
|
||||
" \"name\":\"今日歌曲\",\n" +
|
||||
" \"key\":\"V1001_TODAY_MUSIC\" \n" +
|
||||
" },\n" +
|
||||
" { \n" +
|
||||
" \"name\":\"菜单\",\n" +
|
||||
" \"sub_button\":[\n" +
|
||||
" { \n" +
|
||||
" \"type\":\"view\",\n" +
|
||||
" \"name\":\"搜索\",\n" +
|
||||
" \"url\":\"http://www.soso.com/\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"type\":\"view\",\n" +
|
||||
" \"name\":\"视频\",\n" +
|
||||
" \"url\":\"http://v.qq.com/\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"type\":\"click\",\n" +
|
||||
" \"name\":\"赞一下我们\",\n" +
|
||||
" \"key\":\"V1001_GOOD\"\n" +
|
||||
" }]\n" +
|
||||
" }],\n" +
|
||||
"\"matchrule\":{\n" +
|
||||
" \"tag_id\":\"2\",\n" +
|
||||
" \"sex\":\"1\",\n" +
|
||||
" \"country\":\"中国\",\n" +
|
||||
" \"province\":\"广东\",\n" +
|
||||
" \"city\":\"广州\",\n" +
|
||||
" \"client_platform_type\":\"2\",\n" +
|
||||
" \"language\":\"zh_CN\"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
this.menuId = this.wxService.getMenuService().menuCreate(json);
|
||||
System.out.println(this.menuId);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = {"testCreateConditionalMenu"})
|
||||
public void testDeleteConditionalMenu() throws WxErrorException {
|
||||
this.wxService.getMenuService().menuDelete(menuId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateMenu2() throws WxErrorException {
|
||||
String a = "{\n"
|
||||
+ " \"menu\": {\n"
|
||||
+ " \"button\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"type\": \"click\",\n"
|
||||
+ " \"name\": \"今日歌曲\",\n"
|
||||
+ " \"key\": \"V1001_TODAY_MUSIC\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"type\": \"click\",\n"
|
||||
+ " \"name\": \"歌手简介\",\n"
|
||||
+ " \"key\": \"V1001_TODAY_SINGER\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"name\": \"菜单\",\n"
|
||||
+ " \"sub_button\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"type\": \"view\",\n"
|
||||
+ " \"name\": \"搜索\",\n"
|
||||
+ " \"url\": \"http://www.soso.com/\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"type\": \"view\",\n"
|
||||
+ " \"name\": \"视频\",\n"
|
||||
+ " \"url\": \"http://v.qq.com/\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"type\": \"click\",\n"
|
||||
+ " \"name\": \"赞一下我们\",\n"
|
||||
+ " \"key\": \"V1001_GOOD\"\n"
|
||||
+ " }\n"
|
||||
+ " ]\n"
|
||||
+ " }\n"
|
||||
+ " ]\n"
|
||||
+ " }\n"
|
||||
+ "}";
|
||||
+ " \"menu\": {\n"
|
||||
+ " \"button\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"type\": \"click\",\n"
|
||||
+ " \"name\": \"今日歌曲\",\n"
|
||||
+ " \"key\": \"V1001_TODAY_MUSIC\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"type\": \"click\",\n"
|
||||
+ " \"name\": \"歌手简介\",\n"
|
||||
+ " \"key\": \"V1001_TODAY_SINGER\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"name\": \"菜单\",\n"
|
||||
+ " \"sub_button\": [\n"
|
||||
+ " {\n"
|
||||
+ " \"type\": \"view\",\n"
|
||||
+ " \"name\": \"搜索\",\n"
|
||||
+ " \"url\": \"http://www.soso.com/\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"type\": \"view\",\n"
|
||||
+ " \"name\": \"视频\",\n"
|
||||
+ " \"url\": \"http://v.qq.com/\"\n"
|
||||
+ " },\n"
|
||||
+ " {\n"
|
||||
+ " \"type\": \"click\",\n"
|
||||
+ " \"name\": \"赞一下我们\",\n"
|
||||
+ " \"key\": \"V1001_GOOD\"\n"
|
||||
+ " }\n"
|
||||
+ " ]\n"
|
||||
+ " }\n"
|
||||
+ " ]\n"
|
||||
+ " }\n"
|
||||
+ "}";
|
||||
|
||||
WxMenu menu = WxMenu.fromJson(a);
|
||||
System.out.println(menu.toJson());
|
||||
this.wxService.getMenuService().menuCreate(menu);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "testMenuCreate"})
|
||||
@Test(dependsOnMethods = {"testMenuCreate"})
|
||||
public void testMenuGet() throws WxErrorException {
|
||||
WxMenu wxMenu = this.wxService.getMenuService().menuGet();
|
||||
Assert.assertNotNull(wxMenu);
|
||||
System.out.println(wxMenu.toJson());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "testMenuGet"})
|
||||
@Test(dependsOnMethods = {"testMenuGet"})
|
||||
public void testMenuDelete() throws WxErrorException {
|
||||
this.wxService.getMenuService().menuDelete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteConditionalMenu() throws WxErrorException {
|
||||
String menuId = "123";
|
||||
this.wxService.getMenuService().menuDelete(menuId);
|
||||
}
|
||||
|
||||
@DataProvider(name="menu")
|
||||
@DataProvider(name = "menu")
|
||||
public Object[][] getMenu() {
|
||||
WxMenu menu = new WxMenu();
|
||||
WxMenuButton button1 = new WxMenuButton();
|
||||
@@ -145,10 +186,10 @@ public class WxMpMenuServiceImplTest {
|
||||
button3.getSubButtons().add(button32);
|
||||
button3.getSubButtons().add(button33);
|
||||
|
||||
return new Object[][] {
|
||||
new Object[] {
|
||||
menu
|
||||
}
|
||||
return new Object[][]{
|
||||
new Object[]{
|
||||
menu
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user