@@ -20,9 +20,9 @@ public class WxMpBaseAPITest { | |||||
protected WxMpServiceImpl wxService; | protected WxMpServiceImpl wxService; | ||||
public void testRefreshAccessToken() throws WxErrorException { | public void testRefreshAccessToken() throws WxErrorException { | ||||
WxMpConfigStorage configStorage = wxService.wxMpConfigStorage; | |||||
WxMpConfigStorage configStorage = this.wxService.wxMpConfigStorage; | |||||
String before = configStorage.getAccessToken(); | String before = configStorage.getAccessToken(); | ||||
wxService.getAccessToken(false); | |||||
this.wxService.getAccessToken(false); | |||||
String after = configStorage.getAccessToken(); | String after = configStorage.getAccessToken(); | ||||
Assert.assertNotEquals(before, after); | Assert.assertNotEquals(before, after); | ||||
@@ -26,21 +26,23 @@ public class WxMpMediaAPITest { | |||||
@Inject | @Inject | ||||
protected WxMpServiceImpl wxService; | protected WxMpServiceImpl wxService; | ||||
private List<String> media_ids = new ArrayList<String>(); | |||||
private List<String> media_ids = new ArrayList<>(); | |||||
@Test(dataProvider="uploadMedia") | @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); | |||||
WxMediaUploadResult res = wxService.mediaUpload(mediaType, fileType, inputStream); | |||||
Assert.assertNotNull(res.getType()); | |||||
Assert.assertNotNull(res.getCreatedAt()); | |||||
Assert.assertTrue(res.getMediaId() != null || res.getThumbMediaId() != null); | |||||
if (res.getMediaId() != null) { | |||||
media_ids.add(res.getMediaId()); | |||||
} | |||||
if (res.getThumbMediaId() != null) { | |||||
media_ids.add(res.getThumbMediaId()); | |||||
try(InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName)){ | |||||
WxMediaUploadResult res = this.wxService.mediaUpload(mediaType, fileType, inputStream); | |||||
Assert.assertNotNull(res.getType()); | |||||
Assert.assertNotNull(res.getCreatedAt()); | |||||
Assert.assertTrue(res.getMediaId() != null || res.getThumbMediaId() != null); | |||||
if (res.getMediaId() != null) { | |||||
this.media_ids.add(res.getMediaId()); | |||||
} | |||||
if (res.getThumbMediaId() != null) { | |||||
this.media_ids.add(res.getThumbMediaId()); | |||||
} | |||||
} | } | ||||
} | } | ||||
@@ -56,7 +58,7 @@ public class WxMpMediaAPITest { | |||||
@Test(dependsOnMethods = { "testUploadMedia" }, dataProvider="downloadMedia") | @Test(dependsOnMethods = { "testUploadMedia" }, dataProvider="downloadMedia") | ||||
public void testDownloadMedia(String media_id) throws WxErrorException { | public void testDownloadMedia(String media_id) throws WxErrorException { | ||||
wxService.mediaDownload(media_id); | |||||
this.wxService.mediaDownload(media_id); | |||||
} | } | ||||
@DataProvider | @DataProvider | ||||
@@ -22,23 +22,29 @@ public class WxMpQrCodeAPITest { | |||||
protected WxMpServiceImpl wxService; | protected WxMpServiceImpl wxService; | ||||
public void testQrCodeCreateTmpTicket() throws WxErrorException { | public void testQrCodeCreateTmpTicket() throws WxErrorException { | ||||
WxMpQrCodeTicket ticket = wxService.qrCodeCreateTmpTicket(1, null); | |||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateTmpTicket(1, null); | |||||
Assert.assertNotNull(ticket.getUrl()); | Assert.assertNotNull(ticket.getUrl()); | ||||
Assert.assertNotNull(ticket.getTicket()); | Assert.assertNotNull(ticket.getTicket()); | ||||
Assert.assertTrue(ticket.getExpire_seconds() != -1); | Assert.assertTrue(ticket.getExpire_seconds() != -1); | ||||
} | } | ||||
public void testQrCodeCreateLastTicket() throws WxErrorException { | public void testQrCodeCreateLastTicket() throws WxErrorException { | ||||
WxMpQrCodeTicket ticket = wxService.qrCodeCreateLastTicket(1); | |||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateLastTicket(1); | |||||
Assert.assertNotNull(ticket.getUrl()); | Assert.assertNotNull(ticket.getUrl()); | ||||
Assert.assertNotNull(ticket.getTicket()); | Assert.assertNotNull(ticket.getTicket()); | ||||
Assert.assertTrue(ticket.getExpire_seconds() == -1); | Assert.assertTrue(ticket.getExpire_seconds() == -1); | ||||
} | } | ||||
public void testQrCodePicture() throws WxErrorException { | public void testQrCodePicture() throws WxErrorException { | ||||
WxMpQrCodeTicket ticket = wxService.qrCodeCreateLastTicket(1); | |||||
File file = wxService.qrCodePicture(ticket); | |||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateLastTicket(1); | |||||
File file = this.wxService.qrCodePicture(ticket); | |||||
Assert.assertNotNull(file); | Assert.assertNotNull(file); | ||||
} | } | ||||
public void testQrCodePictureUrl() throws WxErrorException { | |||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateLastTicket(1); | |||||
String url = this.wxService.qrCodePictureUrl(ticket.getTicket()); | |||||
Assert.assertNotNull(url); | |||||
} | |||||
} | } |