mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-14 18:25:10 +08:00
补充群发单元测试用例
This commit is contained in:
@@ -10,7 +10,7 @@ import chanjarster.weixin.util.json.WxGsonBuilder;
|
|||||||
*/
|
*/
|
||||||
public class WxMassGroupMessage {
|
public class WxMassGroupMessage {
|
||||||
|
|
||||||
private String group_id;
|
private long group_id;
|
||||||
private String msgtype;
|
private String msgtype;
|
||||||
private String content;
|
private String content;
|
||||||
private String media_id;
|
private String media_id;
|
||||||
@@ -31,6 +31,7 @@ public class WxMassGroupMessage {
|
|||||||
* {@link WxConsts#MASS_MSG_TEXT}
|
* {@link WxConsts#MASS_MSG_TEXT}
|
||||||
* {@link WxConsts#MASS_MSG_VIDEO}
|
* {@link WxConsts#MASS_MSG_VIDEO}
|
||||||
* {@link WxConsts#MASS_MSG_VOICE}
|
* {@link WxConsts#MASS_MSG_VOICE}
|
||||||
|
* 如果msgtype和media_id不匹配的话,会返回系统繁忙的错误
|
||||||
* </pre>
|
* </pre>
|
||||||
* @param msgtype
|
* @param msgtype
|
||||||
*/
|
*/
|
||||||
@@ -58,11 +59,11 @@ public class WxMassGroupMessage {
|
|||||||
return WxGsonBuilder.INSTANCE.create().toJson(this);
|
return WxGsonBuilder.INSTANCE.create().toJson(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGroup_id() {
|
public long getGroup_id() {
|
||||||
return group_id;
|
return group_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGroup_id(String group_id) {
|
public void setGroup_id(long group_id) {
|
||||||
this.group_id = group_id;
|
this.group_id = group_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,6 +34,7 @@ public class WxMassOpenIdsMessage {
|
|||||||
* {@link WxConsts#MASS_MSG_TEXT}
|
* {@link WxConsts#MASS_MSG_TEXT}
|
||||||
* {@link WxConsts#MASS_MSG_VIDEO}
|
* {@link WxConsts#MASS_MSG_VIDEO}
|
||||||
* {@link WxConsts#MASS_MSG_VOICE}
|
* {@link WxConsts#MASS_MSG_VOICE}
|
||||||
|
* 如果msgtype和media_id不匹配的话,会返回系统繁忙的错误
|
||||||
* </pre>
|
* </pre>
|
||||||
* @param msgtype
|
* @param msgtype
|
||||||
*/
|
*/
|
||||||
|
@@ -9,6 +9,7 @@ import org.testng.annotations.Guice;
|
|||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import chanjarster.weixin.api.ApiTestModule.WxXmlConfigStorage;
|
import chanjarster.weixin.api.ApiTestModule.WxXmlConfigStorage;
|
||||||
|
import chanjarster.weixin.bean.WxMassGroupMessage;
|
||||||
import chanjarster.weixin.bean.WxMassNews;
|
import chanjarster.weixin.bean.WxMassNews;
|
||||||
import chanjarster.weixin.bean.WxMassNews.WxMassNewsArticle;
|
import chanjarster.weixin.bean.WxMassNews.WxMassNewsArticle;
|
||||||
import chanjarster.weixin.bean.WxMassOpenIdsMessage;
|
import chanjarster.weixin.bean.WxMassOpenIdsMessage;
|
||||||
@@ -25,7 +26,7 @@ import com.google.inject.Inject;
|
|||||||
* @author chanjarster
|
* @author chanjarster
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Test(groups = "massAPI", dependsOnGroups = { "baseAPI", "mediaAPI"})
|
@Test(groups = "massAPI", dependsOnGroups = { "baseAPI", "mediaAPI", "groupAPI"})
|
||||||
@Guice(modules = ApiTestModule.class)
|
@Guice(modules = ApiTestModule.class)
|
||||||
public class WxMassMessageAPITest {
|
public class WxMassMessageAPITest {
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ public class WxMassMessageAPITest {
|
|||||||
protected WxServiceImpl wxService;
|
protected WxServiceImpl wxService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendMassTextByOpenIds() throws WxErrorException {
|
public void testTextMassOpenIdsMessageSend() throws WxErrorException {
|
||||||
// 发送群发消息
|
// 发送群发消息
|
||||||
WxXmlConfigStorage configProvider = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
WxXmlConfigStorage configProvider = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||||
WxMassOpenIdsMessage massMessage = new WxMassOpenIdsMessage();
|
WxMassOpenIdsMessage massMessage = new WxMassOpenIdsMessage();
|
||||||
@@ -47,7 +48,7 @@ public class WxMassMessageAPITest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test(dataProvider="massMessages")
|
@Test(dataProvider="massMessages")
|
||||||
public void testSendMassByOpenIds(String massMsgType, String mediaId) throws WxErrorException, IOException {
|
public void testMediaMassOpenIdsMessageSend(String massMsgType, String mediaId) throws WxErrorException, IOException {
|
||||||
// 发送群发消息
|
// 发送群发消息
|
||||||
WxXmlConfigStorage configProvider = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
WxXmlConfigStorage configProvider = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||||
WxMassOpenIdsMessage massMessage = new WxMassOpenIdsMessage();
|
WxMassOpenIdsMessage massMessage = new WxMassOpenIdsMessage();
|
||||||
@@ -60,6 +61,30 @@ public class WxMassMessageAPITest {
|
|||||||
Assert.assertNotNull(massResult.getMsg_id());
|
Assert.assertNotNull(massResult.getMsg_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTextMassGroupMessageSend() throws WxErrorException {
|
||||||
|
WxMassGroupMessage massMessage = new WxMassGroupMessage();
|
||||||
|
massMessage.setMsgtype(WxConsts.MASS_MSG_TEXT);
|
||||||
|
massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
|
||||||
|
massMessage.setGroup_id(wxService.groupGet().get(0).getId());
|
||||||
|
|
||||||
|
WxMassSendResult massResult = wxService.massGroupMessageSend(massMessage);
|
||||||
|
Assert.assertNotNull(massResult);
|
||||||
|
Assert.assertNotNull(massResult.getMsg_id());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dataProvider="massMessages")
|
||||||
|
public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) throws WxErrorException, IOException {
|
||||||
|
WxMassGroupMessage massMessage = new WxMassGroupMessage();
|
||||||
|
massMessage.setMsgtype(massMsgType);
|
||||||
|
massMessage.setMedia_id(mediaId);
|
||||||
|
massMessage.setGroup_id(wxService.groupGet().get(0).getId());
|
||||||
|
|
||||||
|
WxMassSendResult massResult = wxService.massGroupMessageSend(massMessage);
|
||||||
|
Assert.assertNotNull(massResult);
|
||||||
|
Assert.assertNotNull(massResult.getMsg_id());
|
||||||
|
}
|
||||||
|
|
||||||
@DataProvider
|
@DataProvider
|
||||||
public Object[][] massMessages() throws WxErrorException, IOException {
|
public Object[][] massMessages() throws WxErrorException, IOException {
|
||||||
Object[][] messages = new Object[4][];
|
Object[][] messages = new Object[4][];
|
||||||
@@ -134,7 +159,7 @@ public class WxMassMessageAPITest {
|
|||||||
WxMassUploadResult massUploadResult = wxService.massNewsUpload(news);
|
WxMassUploadResult massUploadResult = wxService.massNewsUpload(news);
|
||||||
Assert.assertNotNull(massUploadResult);
|
Assert.assertNotNull(massUploadResult);
|
||||||
Assert.assertNotNull(uploadMediaRes.getMedia_id());
|
Assert.assertNotNull(uploadMediaRes.getMedia_id());
|
||||||
messages[3] = new Object[] { WxConsts.MASS_MSG_VIDEO, massUploadResult.getMedia_id() };
|
messages[3] = new Object[] { WxConsts.MASS_MSG_NEWS, massUploadResult.getMedia_id() };
|
||||||
}
|
}
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
@@ -29,7 +29,7 @@ public class WxMediaAPITest {
|
|||||||
|
|
||||||
private List<String> media_ids = new ArrayList<String>();
|
private List<String> media_ids = new ArrayList<String>();
|
||||||
|
|
||||||
@Test(dataProvider="uploadMedia", enabled = true)
|
@Test(dataProvider="uploadMedia")
|
||||||
public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException {
|
public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException {
|
||||||
InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName);
|
InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName);
|
||||||
WxMediaUploadResult res = wxService.mediaUpload(mediaType, fileType, inputStream);
|
WxMediaUploadResult res = wxService.mediaUpload(mediaType, fileType, inputStream);
|
||||||
|
@@ -25,17 +25,17 @@ public class WxMenuAPITest {
|
|||||||
@Inject
|
@Inject
|
||||||
protected WxServiceImpl wxService;
|
protected WxServiceImpl wxService;
|
||||||
|
|
||||||
@Test(dataProvider = "menu", enabled = true)
|
@Test(dataProvider = "menu")
|
||||||
public void testCreateMenu(WxMenu wxMenu) throws WxErrorException {
|
public void testCreateMenu(WxMenu wxMenu) throws WxErrorException {
|
||||||
wxService.menuCreate(wxMenu);
|
wxService.menuCreate(wxMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = { "testCreateMenu"}, enabled = true)
|
@Test(dependsOnMethods = { "testCreateMenu"})
|
||||||
public void testGetMenu() throws WxErrorException {
|
public void testGetMenu() throws WxErrorException {
|
||||||
Assert.assertNotNull(wxService.menuGet());
|
Assert.assertNotNull(wxService.menuGet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = { "testGetMenu"}, enabled = true)
|
@Test(dependsOnMethods = { "testGetMenu"})
|
||||||
public void testDeleteMenu() throws WxErrorException {
|
public void testDeleteMenu() throws WxErrorException {
|
||||||
wxService.menuDelete();
|
wxService.menuDelete();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user