8
8
import me .chanjar .weixin .mp .api .ApiTestModule ;
9
9
import me .chanjar .weixin .mp .api .WxMpService ;
10
10
import 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 .*;
15
13
16
14
/**
17
15
* 测试菜单
16
+ *
18
17
* @author chanjarster
19
18
* @author Binary Wang
20
- *
21
19
*/
22
- @ Test (groups = "menuAPI" )
20
+ @ Test (groups = "menuAPI" )
23
21
@ Guice (modules = ApiTestModule .class )
24
22
public class WxMpMenuServiceImplTest {
25
23
26
24
@ Inject
27
25
protected WxMpService wxService ;
26
+ private String menuId = null ;
28
27
29
28
@ Test (dataProvider = "menu" )
30
29
public void testMenuCreate (WxMenu wxMenu ) throws WxErrorException {
@@ -44,69 +43,111 @@ public void testGetSelfMenuInfo() throws Exception {
44
43
System .out .println (selfMenuInfo );
45
44
}
46
45
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
+
47
94
@ Test
48
95
public void testCreateMenu2 () throws WxErrorException {
49
96
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
+ + "}" ;
85
132
86
133
WxMenu menu = WxMenu .fromJson (a );
87
134
System .out .println (menu .toJson ());
88
135
this .wxService .getMenuService ().menuCreate (menu );
89
136
}
90
137
91
- @ Test (dependsOnMethods = { "testMenuCreate" })
138
+ @ Test (dependsOnMethods = {"testMenuCreate" })
92
139
public void testMenuGet () throws WxErrorException {
93
140
WxMenu wxMenu = this .wxService .getMenuService ().menuGet ();
94
141
Assert .assertNotNull (wxMenu );
95
142
System .out .println (wxMenu .toJson ());
96
143
}
97
144
98
- @ Test (dependsOnMethods = { "testMenuGet" })
145
+ @ Test (dependsOnMethods = {"testMenuGet" })
99
146
public void testMenuDelete () throws WxErrorException {
100
147
this .wxService .getMenuService ().menuDelete ();
101
148
}
102
149
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" )
110
151
public Object [][] getMenu () {
111
152
WxMenu menu = new WxMenu ();
112
153
WxMenuButton button1 = new WxMenuButton ();
@@ -145,10 +186,10 @@ public Object[][] getMenu() {
145
186
button3 .getSubButtons ().add (button32 );
146
187
button3 .getSubButtons ().add (button33 );
147
188
148
- return new Object [][] {
149
- new Object [] {
150
- menu
151
- }
189
+ return new Object [][]{
190
+ new Object []{
191
+ menu
192
+ }
152
193
};
153
194
154
195
}
0 commit comments