| @@ -38,7 +38,7 @@ public class ApiTestModule implements Module { | |||
| protected String tagId; | |||
| public String getUserId() { | |||
| return userId; | |||
| return this.userId; | |||
| } | |||
| public void setUserId(String userId) { | |||
| @@ -46,7 +46,7 @@ public class ApiTestModule implements Module { | |||
| } | |||
| public String getDepartmentId() { | |||
| return departmentId; | |||
| return this.departmentId; | |||
| } | |||
| public void setDepartmentId(String departmentId) { | |||
| @@ -54,7 +54,7 @@ public class ApiTestModule implements Module { | |||
| } | |||
| public String getTagId() { | |||
| return tagId; | |||
| return this.tagId; | |||
| } | |||
| public void setTagId(String tagId) { | |||
| @@ -64,9 +64,9 @@ public class ApiTestModule implements Module { | |||
| @Override | |||
| public String toString() { | |||
| return super.toString() + " > WxXmlCpConfigStorage{" + | |||
| "userId='" + userId + '\'' + | |||
| ", departmentId='" + departmentId + '\'' + | |||
| ", tagId='" + tagId + '\'' + | |||
| "userId='" + this.userId + '\'' + | |||
| ", departmentId='" + this.departmentId + '\'' + | |||
| ", tagId='" + this.tagId + '\'' + | |||
| '}'; | |||
| } | |||
| } | |||
| @@ -20,9 +20,9 @@ public class WxCpBaseAPITest { | |||
| protected WxCpServiceImpl wxService; | |||
| public void testRefreshAccessToken() throws WxErrorException { | |||
| WxCpConfigStorage configStorage = wxService.wxCpConfigStorage; | |||
| WxCpConfigStorage configStorage = this.wxService.wxCpConfigStorage; | |||
| String before = configStorage.getAccessToken(); | |||
| wxService.getAccessToken(false); | |||
| this.wxService.getAccessToken(false); | |||
| String after = configStorage.getAccessToken(); | |||
| @@ -28,18 +28,18 @@ public class WxCpDepartAPITest { | |||
| depart.setName("子部门" + System.currentTimeMillis()); | |||
| depart.setParentId(1); | |||
| depart.setOrder(1); | |||
| Integer departId = wxCpService.departCreate(depart); | |||
| Integer departId = this.wxCpService.departCreate(depart); | |||
| } | |||
| @Test(dependsOnMethods = "testDepartCreate") | |||
| public void testDepartGet() throws WxErrorException { | |||
| System.out.println("=================获取部门"); | |||
| List<WxCpDepart> departList = wxCpService.departGet(); | |||
| List<WxCpDepart> departList = this.wxCpService.departGet(); | |||
| Assert.assertNotNull(departList); | |||
| Assert.assertTrue(departList.size() > 0); | |||
| for (WxCpDepart g : departList) { | |||
| depart = g; | |||
| System.out.println(depart.getId() + ":" + depart.getName()); | |||
| this.depart = g; | |||
| System.out.println(this.depart.getId() + ":" + this.depart.getName()); | |||
| Assert.assertNotNull(g.getName()); | |||
| } | |||
| } | |||
| @@ -47,15 +47,15 @@ public class WxCpDepartAPITest { | |||
| @Test(dependsOnMethods = {"testDepartGet", "testDepartCreate"}) | |||
| public void testDepartUpdate() throws WxErrorException { | |||
| System.out.println("=================更新部门"); | |||
| depart.setName("子部门改名" + System.currentTimeMillis()); | |||
| wxCpService.departUpdate(depart); | |||
| this.depart.setName("子部门改名" + System.currentTimeMillis()); | |||
| this.wxCpService.departUpdate(this.depart); | |||
| } | |||
| @Test(dependsOnMethods = "testDepartUpdate") | |||
| public void testDepartDelete() throws WxErrorException { | |||
| System.out.println("=================删除部门"); | |||
| System.out.println(depart.getId() + ":" + depart.getName()); | |||
| wxCpService.departDelete(depart.getId()); | |||
| System.out.println(this.depart.getId() + ":" + this.depart.getName()); | |||
| this.wxCpService.departDelete(this.depart.getId()); | |||
| } | |||
| } | |||
| @@ -27,21 +27,21 @@ public class WxCpMediaAPITest { | |||
| @Inject | |||
| protected WxCpServiceImpl wxService; | |||
| private List<String> media_ids = new ArrayList<String>(); | |||
| private List<String> media_ids = new ArrayList<>(); | |||
| @Test(dataProvider = "uploadMedia") | |||
| public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException { | |||
| InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName); | |||
| WxMediaUploadResult res = wxService.mediaUpload(mediaType, fileType, inputStream); | |||
| 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) { | |||
| media_ids.add(res.getMediaId()); | |||
| this.media_ids.add(res.getMediaId()); | |||
| } | |||
| if (res.getThumbMediaId() != null) { | |||
| media_ids.add(res.getThumbMediaId()); | |||
| this.media_ids.add(res.getThumbMediaId()); | |||
| } | |||
| } | |||
| @@ -57,7 +57,7 @@ public class WxCpMediaAPITest { | |||
| @Test(dependsOnMethods = {"testUploadMedia"}, dataProvider = "downloadMedia") | |||
| public void testDownloadMedia(String media_id) throws WxErrorException { | |||
| wxService.mediaDownload(media_id); | |||
| this.wxService.mediaDownload(media_id); | |||
| } | |||
| @DataProvider | |||
| @@ -20,13 +20,13 @@ public class WxCpMessageAPITest { | |||
| protected WxCpServiceImpl wxService; | |||
| public void testSendCustomMessage() throws WxErrorException { | |||
| ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlCpInMemoryConfigStorage) wxService.wxCpConfigStorage; | |||
| ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlCpInMemoryConfigStorage) this.wxService.wxCpConfigStorage; | |||
| WxCpMessage message1 = new WxCpMessage(); | |||
| message1.setAgentId(configStorage.getAgentId()); | |||
| message1.setMsgType(WxConsts.CUSTOM_MSG_TEXT); | |||
| message1.setToUser(configStorage.getUserId()); | |||
| message1.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); | |||
| wxService.messageSend(message1); | |||
| this.wxService.messageSend(message1); | |||
| WxCpMessage message2 = WxCpMessage | |||
| .TEXT() | |||
| @@ -34,7 +34,7 @@ public class WxCpMessageAPITest { | |||
| .toUser(configStorage.getUserId()) | |||
| .content("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>") | |||
| .build(); | |||
| wxService.messageSend(message2); | |||
| this.wxService.messageSend(message2); | |||
| } | |||
| @@ -286,7 +286,7 @@ public class WxCpMessageRouterTest { | |||
| @Override | |||
| public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage, Map<String, Object> context, WxCpService wxCpService, | |||
| WxSessionManager sessionManager) { | |||
| sb.append(this.echoStr).append(','); | |||
| this.sb.append(this.echoStr).append(','); | |||
| return null; | |||
| } | |||
| @@ -23,44 +23,44 @@ public class WxCpTagAPITest { | |||
| protected String tagId; | |||
| public void testTagCreate() throws Exception { | |||
| tagId = wxService.tagCreate("测试标签4"); | |||
| System.out.println(tagId); | |||
| this.tagId = this.wxService.tagCreate("测试标签4"); | |||
| System.out.println(this.tagId); | |||
| } | |||
| @Test(dependsOnMethods = "testTagCreate") | |||
| public void testTagUpdate() throws Exception { | |||
| wxService.tagUpdate(tagId, "测试标签-改名"); | |||
| this.wxService.tagUpdate(this.tagId, "测试标签-改名"); | |||
| } | |||
| @Test(dependsOnMethods = "testTagUpdate") | |||
| public void testTagGet() throws Exception { | |||
| List<WxCpTag> tags = wxService.tagGet(); | |||
| List<WxCpTag> tags = this.wxService.tagGet(); | |||
| Assert.assertNotEquals(tags.size(), 0); | |||
| } | |||
| @Test(dependsOnMethods = "testTagGet") | |||
| public void testTagAddUsers() throws Exception { | |||
| List<String> userIds = new ArrayList<String>(); | |||
| userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage) configStorage).getUserId()); | |||
| wxService.tagAddUsers(tagId, userIds, null); | |||
| List<String> userIds = new ArrayList<>(); | |||
| userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage) this.configStorage).getUserId()); | |||
| this.wxService.tagAddUsers(this.tagId, userIds, null); | |||
| } | |||
| @Test(dependsOnMethods = "testTagAddUsers") | |||
| public void testTagGetUsers() throws Exception { | |||
| List<WxCpUser> users = wxService.tagGetUsers(tagId); | |||
| List<WxCpUser> users = this.wxService.tagGetUsers(this.tagId); | |||
| Assert.assertNotEquals(users.size(), 0); | |||
| } | |||
| @Test(dependsOnMethods = "testTagGetUsers") | |||
| public void testTagRemoveUsers() throws Exception { | |||
| List<String> userIds = new ArrayList<String>(); | |||
| userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage) configStorage).getUserId()); | |||
| wxService.tagRemoveUsers(tagId, userIds); | |||
| List<String> userIds = new ArrayList<>(); | |||
| userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage) this.configStorage).getUserId()); | |||
| this.wxService.tagRemoveUsers(this.tagId, userIds); | |||
| } | |||
| @Test(dependsOnMethods = "testTagRemoveUsers") | |||
| public void testTagDelete() throws Exception { | |||
| wxService.tagDelete(tagId); | |||
| this.wxService.tagDelete(this.tagId); | |||
| } | |||
| } | |||
| @@ -35,7 +35,7 @@ public class WxCpUserAPITest { | |||
| user.setPosition("woman"); | |||
| user.setTel("3300393"); | |||
| user.addExtAttr("爱好", "table"); | |||
| wxCpService.userCreate(user); | |||
| this.wxCpService.userCreate(user); | |||
| } | |||
| @Test(dependsOnMethods = "testUserCreate") | |||
| @@ -44,23 +44,23 @@ public class WxCpUserAPITest { | |||
| user.setUserId("some.woman"); | |||
| user.setName("Some Woman"); | |||
| user.addExtAttr("爱好", "table2"); | |||
| wxCpService.userUpdate(user); | |||
| this.wxCpService.userUpdate(user); | |||
| } | |||
| @Test(dependsOnMethods = "testUserUpdate") | |||
| public void testUserGet() throws WxErrorException { | |||
| WxCpUser user = wxCpService.userGet("some.woman"); | |||
| WxCpUser user = this.wxCpService.userGet("some.woman"); | |||
| Assert.assertNotNull(user); | |||
| } | |||
| @Test(dependsOnMethods = "testUserGet") | |||
| public void testDepartGetUsers() throws WxErrorException { | |||
| List<WxCpUser> users = wxCpService.departGetUsers(1, true, 0); | |||
| List<WxCpUser> users = this.wxCpService.departGetUsers(1, true, 0); | |||
| Assert.assertNotEquals(users.size(), 0); | |||
| } | |||
| @Test(dependsOnMethods = "testDepartGetUsers") | |||
| public void testUserDelete() throws WxErrorException { | |||
| wxCpService.userDelete("some.woman"); | |||
| this.wxCpService.userDelete("some.woman"); | |||
| } | |||
| } | |||
| @@ -24,17 +24,17 @@ public class WxMenuAPITest { | |||
| @Test(dataProvider = "menu") | |||
| public void testCreateMenu(WxMenu wxMenu) throws WxErrorException { | |||
| wxService.menuCreate(wxMenu); | |||
| this.wxService.menuCreate(wxMenu); | |||
| } | |||
| @Test(dependsOnMethods = {"testCreateMenu"}) | |||
| public void testGetMenu() throws WxErrorException { | |||
| Assert.assertNotNull(wxService.menuGet()); | |||
| Assert.assertNotNull(this.wxService.menuGet()); | |||
| } | |||
| @Test(dependsOnMethods = {"testGetMenu"}) | |||
| public void testDeleteMenu() throws WxErrorException { | |||
| wxService.menuDelete(); | |||
| this.wxService.menuDelete(); | |||
| } | |||
| @DataProvider(name = "menu") | |||
| @@ -21,8 +21,8 @@ class WxCpDemoInMemoryConfigStorage extends WxCpInMemoryConfigStorage { | |||
| @Override | |||
| public String toString() { | |||
| return "SimpleWxConfigProvider [appidOrCorpid=" + corpId + ", corpSecret=" + corpSecret + ", accessToken=" + accessToken | |||
| + ", expiresTime=" + expiresTime + ", token=" + token + ", aesKey=" + aesKey + "]"; | |||
| return "SimpleWxConfigProvider [appidOrCorpid=" + this.corpId + ", corpSecret=" + this.corpSecret + ", accessToken=" + this.accessToken | |||
| + ", expiresTime=" + this.expiresTime + ", token=" + this.token + ", aesKey=" + this.aesKey + "]"; | |||
| } | |||
| } | |||
| @@ -43,12 +43,12 @@ public class WxCpEndpointServlet extends HttpServlet { | |||
| String echostr = request.getParameter("echostr"); | |||
| if (StringUtils.isNotBlank(echostr)) { | |||
| if (!wxCpService.checkSignature(msgSignature, timestamp, nonce, echostr)) { | |||
| if (!this.wxCpService.checkSignature(msgSignature, timestamp, nonce, echostr)) { | |||
| // 消息签名不正确,说明不是公众平台发过来的消息 | |||
| response.getWriter().println("非法请求"); | |||
| return; | |||
| } | |||
| WxCpCryptUtil cryptUtil = new WxCpCryptUtil(wxCpConfigStorage); | |||
| WxCpCryptUtil cryptUtil = new WxCpCryptUtil(this.wxCpConfigStorage); | |||
| String plainText = cryptUtil.decrypt(echostr); | |||
| // 说明是一个仅仅用来验证的请求,回显echostr | |||
| response.getWriter().println(plainText); | |||
| @@ -56,10 +56,10 @@ public class WxCpEndpointServlet extends HttpServlet { | |||
| } | |||
| WxCpXmlMessage inMessage = WxCpXmlMessage | |||
| .fromEncryptedXml(request.getInputStream(), wxCpConfigStorage, timestamp, nonce, msgSignature); | |||
| WxCpXmlOutMessage outMessage = wxCpMessageRouter.route(inMessage); | |||
| .fromEncryptedXml(request.getInputStream(), this.wxCpConfigStorage, timestamp, nonce, msgSignature); | |||
| WxCpXmlOutMessage outMessage = this.wxCpMessageRouter.route(inMessage); | |||
| if (outMessage != null) { | |||
| response.getWriter().write(outMessage.toEncryptedXml(wxCpConfigStorage)); | |||
| response.getWriter().write(outMessage.toEncryptedXml(this.wxCpConfigStorage)); | |||
| } | |||
| return; | |||
| @@ -30,7 +30,7 @@ public class WxCpOAuth2Servlet extends HttpServlet { | |||
| response.getWriter().println("<h1>code</h1>"); | |||
| response.getWriter().println(code); | |||
| String[] res = wxCpService.oauth2getUserInfo(code); | |||
| String[] res = this.wxCpService.oauth2getUserInfo(code); | |||
| response.getWriter().println("<h1>result</h1>"); | |||
| response.getWriter().println(Arrays.toString(res)); | |||
| } catch (WxErrorException e) { | |||