88import me .chanjar .weixin .mp .api .ApiTestModule ;
99import me .chanjar .weixin .mp .api .WxMpService ;
1010import me .chanjar .weixin .mp .bean .menu .WxMpGetSelfMenuInfoResult ;
11- import org .testng .Assert ;
12- import org .testng .annotations .DataProvider ;
13- import org .testng .annotations .Guice ;
14- import org .testng .annotations .Test ;
11+ import org .testng .*;
12+ import org .testng .annotations .*;
1513
1614/**
1715 * 测试菜单
16+ *
1817 * @author chanjarster
1918 * @author Binary Wang
20- *
2119 */
22- @ Test (groups = "menuAPI" )
20+ @ Test (groups = "menuAPI" )
2321@ Guice (modules = ApiTestModule .class )
2422public class WxMpMenuServiceImplTest {
2523
2624 @ Inject
2725 protected WxMpService wxService ;
26+ private String menuId = null ;
2827
2928 @ Test (dataProvider = "menu" )
3029 public void testMenuCreate (WxMenu wxMenu ) throws WxErrorException {
@@ -44,69 +43,111 @@ public void testGetSelfMenuInfo() throws Exception {
4443 System .out .println (selfMenuInfo );
4544 }
4645
46+ @ Test
47+ public void testCreateConditionalMenu () throws WxErrorException {
48+ String json = "{\n " +
49+ " \" button\" :[\n " +
50+ " {\n " +
51+ " \" type\" :\" click\" ,\n " +
52+ " \" name\" :\" 今日歌曲\" ,\n " +
53+ " \" key\" :\" V1001_TODAY_MUSIC\" \n " +
54+ " },\n " +
55+ " { \n " +
56+ "\" name\" :\" 菜单\" ,\n " +
57+ "\" sub_button\" :[\n " +
58+ " {\n " +
59+ "\" type\" :\" view\" ,\n " +
60+ "\" name\" :\" 搜索\" ,\n " +
61+ "\" url\" :\" http://www.soso.com/\" \n " +
62+ " },\n " +
63+ " {\n " +
64+ "\" type\" :\" view\" ,\n " +
65+ "\" name\" :\" 视频\" ,\n " +
66+ "\" url\" :\" http://v.qq.com/\" \n " +
67+ " },\n " +
68+ " {\n " +
69+ "\" type\" :\" click\" ,\n " +
70+ "\" name\" :\" 赞一下我们\" ,\n " +
71+ "\" key\" :\" V1001_GOOD\" \n " +
72+ " }]\n " +
73+ " }],\n " +
74+ "\" matchrule\" :{\n " +
75+ " \" tag_id\" :\" 2\" ,\n " +
76+ " \" sex\" :\" 1\" ,\n " +
77+ " \" country\" :\" 中国\" ,\n " +
78+ " \" province\" :\" 广东\" ,\n " +
79+ " \" city\" :\" 广州\" ,\n " +
80+ " \" client_platform_type\" :\" 2\" ,\n " +
81+ " \" language\" :\" zh_CN\" \n " +
82+ " }\n " +
83+ "}" ;
84+
85+ this .menuId = this .wxService .getMenuService ().menuCreate (json );
86+ System .out .println (this .menuId );
87+ }
88+
89+ @ Test (dependsOnMethods = {"testCreateConditionalMenu" })
90+ public void testDeleteConditionalMenu () throws WxErrorException {
91+ this .wxService .getMenuService ().menuDelete (menuId );
92+ }
93+
4794 @ Test
4895 public void testCreateMenu2 () throws WxErrorException {
4996 String a = "{\n "
50- + " \" menu\" : {\n "
51- + " \" button\" : [\n "
52- + " {\n "
53- + " \" type\" : \" click\" ,\n "
54- + " \" name\" : \" 今日歌曲\" ,\n "
55- + " \" key\" : \" V1001_TODAY_MUSIC\" \n "
56- + " },\n "
57- + " {\n "
58- + " \" type\" : \" click\" ,\n "
59- + " \" name\" : \" 歌手简介\" ,\n "
60- + " \" key\" : \" V1001_TODAY_SINGER\" \n "
61- + " },\n "
62- + " {\n "
63- + " \" name\" : \" 菜单\" ,\n "
64- + " \" sub_button\" : [\n "
65- + " {\n "
66- + " \" type\" : \" view\" ,\n "
67- + " \" name\" : \" 搜索\" ,\n "
68- + " \" url\" : \" http://www.soso.com/\" \n "
69- + " },\n "
70- + " {\n "
71- + " \" type\" : \" view\" ,\n "
72- + " \" name\" : \" 视频\" ,\n "
73- + " \" url\" : \" http://v.qq.com/\" \n "
74- + " },\n "
75- + " {\n "
76- + " \" type\" : \" click\" ,\n "
77- + " \" name\" : \" 赞一下我们\" ,\n "
78- + " \" key\" : \" V1001_GOOD\" \n "
79- + " }\n "
80- + " ]\n "
81- + " }\n "
82- + " ]\n "
83- + " }\n "
84- + "}" ;
97+ + " \" menu\" : {\n "
98+ + " \" button\" : [\n "
99+ + " {\n "
100+ + " \" type\" : \" click\" ,\n "
101+ + " \" name\" : \" 今日歌曲\" ,\n "
102+ + " \" key\" : \" V1001_TODAY_MUSIC\" \n "
103+ + " },\n "
104+ + " {\n "
105+ + " \" type\" : \" click\" ,\n "
106+ + " \" name\" : \" 歌手简介\" ,\n "
107+ + " \" key\" : \" V1001_TODAY_SINGER\" \n "
108+ + " },\n "
109+ + " {\n "
110+ + " \" name\" : \" 菜单\" ,\n "
111+ + " \" sub_button\" : [\n "
112+ + " {\n "
113+ + " \" type\" : \" view\" ,\n "
114+ + " \" name\" : \" 搜索\" ,\n "
115+ + " \" url\" : \" http://www.soso.com/\" \n "
116+ + " },\n "
117+ + " {\n "
118+ + " \" type\" : \" view\" ,\n "
119+ + " \" name\" : \" 视频\" ,\n "
120+ + " \" url\" : \" http://v.qq.com/\" \n "
121+ + " },\n "
122+ + " {\n "
123+ + " \" type\" : \" click\" ,\n "
124+ + " \" name\" : \" 赞一下我们\" ,\n "
125+ + " \" key\" : \" V1001_GOOD\" \n "
126+ + " }\n "
127+ + " ]\n "
128+ + " }\n "
129+ + " ]\n "
130+ + " }\n "
131+ + "}" ;
85132
86133 WxMenu menu = WxMenu .fromJson (a );
87134 System .out .println (menu .toJson ());
88135 this .wxService .getMenuService ().menuCreate (menu );
89136 }
90137
91- @ Test (dependsOnMethods = { "testMenuCreate" })
138+ @ Test (dependsOnMethods = {"testMenuCreate" })
92139 public void testMenuGet () throws WxErrorException {
93140 WxMenu wxMenu = this .wxService .getMenuService ().menuGet ();
94141 Assert .assertNotNull (wxMenu );
95142 System .out .println (wxMenu .toJson ());
96143 }
97144
98- @ Test (dependsOnMethods = { "testMenuGet" })
145+ @ Test (dependsOnMethods = {"testMenuGet" })
99146 public void testMenuDelete () throws WxErrorException {
100147 this .wxService .getMenuService ().menuDelete ();
101148 }
102149
103- @ Test
104- public void testDeleteConditionalMenu () throws WxErrorException {
105- String menuId = "123" ;
106- this .wxService .getMenuService ().menuDelete (menuId );
107- }
108-
109- @ DataProvider (name ="menu" )
150+ @ DataProvider (name = "menu" )
110151 public Object [][] getMenu () {
111152 WxMenu menu = new WxMenu ();
112153 WxMenuButton button1 = new WxMenuButton ();
@@ -145,10 +186,10 @@ public Object[][] getMenu() {
145186 button3 .getSubButtons ().add (button32 );
146187 button3 .getSubButtons ().add (button33 );
147188
148- return new Object [][] {
149- new Object [] {
150- menu
151- }
189+ return new Object [][]{
190+ new Object []{
191+ menu
192+ }
152193 };
153194
154195 }
0 commit comments