添加多媒体文件下载支持
This commit is contained in:
@@ -2,6 +2,8 @@ package chanjarster.weixin.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
@@ -19,14 +21,17 @@ import chanjarster.weixin.bean.WxMenu;
|
||||
import chanjarster.weixin.bean.WxMenu.WxMenuButton;
|
||||
import chanjarster.weixin.bean.result.WxUploadResult;
|
||||
import chanjarster.weixin.exception.WxErrorException;
|
||||
import chanjarster.weixin.util.XmlTransformer;
|
||||
import chanjarster.weixin.util.xml.XmlTransformer;
|
||||
|
||||
public class WxServiceTest {
|
||||
|
||||
private WxServiceImpl wxService;
|
||||
|
||||
private List<String> media_ids = new ArrayList<String>();
|
||||
|
||||
@BeforeTest
|
||||
public void prepare() throws JAXBException {
|
||||
this.wxService = null;
|
||||
InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml");
|
||||
WxXmlConfigStorage config = XmlTransformer.fromXml(WxXmlConfigStorage.class, is1);
|
||||
this.wxService = new WxServiceImpl();
|
||||
@@ -66,32 +71,51 @@ public class WxServiceTest {
|
||||
Assert.assertNotNull(wxService.getMenu());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "testRefreshAccessToken", "testGetMenu" }, enabled = true)
|
||||
@Test(dependsOnMethods = { "testRefreshAccessToken", "testGetMenu"}, enabled = true)
|
||||
public void testDeleteMenu() throws WxErrorException {
|
||||
wxService.deleteMenu();
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "testRefreshAccessToken" }, dataProvider="uploadFiles", enabled = true)
|
||||
@Test(dependsOnMethods = { "testRefreshAccessToken" }, dataProvider="uploadMedia", enabled = true)
|
||||
public void testUploadMedia1(String mediaType, String fileType, String fileName) throws WxErrorException, IOException {
|
||||
InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName);
|
||||
WxUploadResult res = wxService.uploadMedia(mediaType, fileType, inputStream);
|
||||
Assert.assertNotNull(res.getType());
|
||||
Assert.assertNotNull(res.getCreated_at());
|
||||
Assert.assertTrue(res.getMedia_id() != null || res.getThumb_media_id() != null);
|
||||
|
||||
if (res.getMedia_id() != null) {
|
||||
media_ids.add(res.getMedia_id());
|
||||
}
|
||||
if (res.getThumb_media_id() != null) {
|
||||
media_ids.add(res.getThumb_media_id());
|
||||
}
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] uploadFiles() {
|
||||
public Object[][] uploadMedia() {
|
||||
return new Object[][] {
|
||||
new Object[] { WxConsts.MEDIA_IMAGE, WxConsts.FILE_PNG, "mm.png" },
|
||||
new Object[] { WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, "mm.jpeg" },
|
||||
new Object[] { WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, "mm.mp3" },
|
||||
new Object[] { WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, "mm.mp4" },
|
||||
new Object[] { WxConsts.MEDIA_THUMB, WxConsts.FILE_PNG, "mm.png" },
|
||||
new Object[] { WxConsts.MEDIA_THUMB, WxConsts.FILE_JPG, "mm.jpeg" }
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "testUploadMedia1" }, dataProvider="downloadMedia")
|
||||
public void testDownloadMedia(String media_id) throws WxErrorException {
|
||||
wxService.downloadMedia(media_id);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] downloadMedia() {
|
||||
Object[][] params = new Object[this.media_ids.size()][];
|
||||
for (int i = 0; i < this.media_ids.size(); i++) {
|
||||
params[i] = new Object[] { this.media_ids.get(i) };
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
@Test(enabled = true)
|
||||
public void testCheckSignature() throws WxErrorException {
|
||||
String timestamp = "23234235423246";
|
||||
|
||||
Reference in New Issue
Block a user