diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java index 2260f48d..8841696d 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java @@ -825,6 +825,10 @@ public class WxMpServiceImpl implements WxMpService { this.httpClient = apacheHttpClientBuilder.build(); } + public WxMpConfigStorage getWxMpConfigStorage() { + return this.wxMpConfigStorage; + } + @Override public void setRetrySleepMillis(int retrySleepMillis) { this.retrySleepMillis = retrySleepMillis; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java index 154b06b6..32075154 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java @@ -11,7 +11,6 @@ import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; import me.chanjar.weixin.common.util.xml.XStreamInitializer; -import me.chanjar.weixin.mp.api.impl.WxMpKefuServiceImpl; public class ApiTestModule implements Module { @@ -23,7 +22,7 @@ public class ApiTestModule implements Module { WxXmlMpInMemoryConfigStorage.class, is1); WxMpServiceImpl wxService = new WxMpServiceImpl(); wxService.setWxMpConfigStorage(config); - + binder.bind(WxMpServiceImpl.class).toInstance(wxService); binder.bind(WxMpConfigStorage.class).toInstance(config); } catch (IOException e) { @@ -42,7 +41,8 @@ public class ApiTestModule implements Module { public static class WxXmlMpInMemoryConfigStorage extends WxMpInMemoryConfigStorage { - protected String openId; + private String openId; + private String kfAccount; public String getOpenId() { return this.openId; @@ -57,6 +57,14 @@ public class ApiTestModule implements Module { return ToStringBuilder.reflectionToString(this); } + public String getKfAccount() { + return this.kfAccount; + } + + public void setKfAccount(String kfAccount) { + this.kfAccount = kfAccount; + } + } } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuImplTest.java index f5d4ab04..f2045437 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuImplTest.java @@ -1,5 +1,6 @@ package me.chanjar.weixin.mp.api.impl; +import org.testng.annotations.DataProvider; import org.testng.annotations.Guice; import org.testng.annotations.Test; @@ -7,6 +8,8 @@ import com.google.inject.Inject; import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.mp.api.ApiTestModule; +import me.chanjar.weixin.mp.api.ApiTestModule.WxXmlMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.api.WxMpConfigStorage; import me.chanjar.weixin.mp.api.WxMpServiceImpl; import me.chanjar.weixin.mp.bean.customerservice.request.WxMpKfAccountRequest; import me.chanjar.weixin.mp.bean.customerservice.result.WxMpKfList; @@ -24,8 +27,7 @@ import org.testng.Assert; @Test @Guice(modules = ApiTestModule.class) public class WxMpKefuImplTest { - private static final String KF_ACCOUNT = "kf2009@youxintest"; - + @Inject protected WxMpServiceImpl wxService; @@ -36,34 +38,48 @@ public class WxMpKefuImplTest { } public void testKfOnlineList() throws WxErrorException { - WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService().kfOnlineList(); + WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService() + .kfOnlineList(); Assert.assertNotNull(kfOnlineList); System.err.println(kfOnlineList); } - public void testKfAccountAdd() throws WxErrorException { + @DataProvider + public Object[][] getKfAccount() { + WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService + .getWxMpConfigStorage(); + return new Object[][] { { configStorage.getKfAccount() } }; + } + + @Test(dataProvider = "getKfAccount") + public void testKfAccountAdd(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() - .kfAccount(KF_ACCOUNT).nickName("我晕").rawPassword("123").build(); + .kfAccount(kfAccount).nickName("我晕").rawPassword("123").build(); Assert.assertTrue(this.wxService.getKefuService().kfAccountAdd(request)); } - - @Test(dependsOnMethods = { "testKfAccountAdd" }) - public void testKfAccountUpdate() throws WxErrorException { + + @Test(dependsOnMethods = { + "testKfAccountAdd" }, dataProvider = "getKfAccount") + public void testKfAccountUpdate(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() - .kfAccount(KF_ACCOUNT).nickName("我晕").rawPassword("123").build(); + .kfAccount(kfAccount).nickName("我晕").rawPassword("123").build(); Assert.assertTrue(this.wxService.getKefuService().kfAccountUpdate(request)); } - - @Test(dependsOnMethods = { "testKfAccountUpdate" }) - public void testKfAccountUploadHeadImg() throws WxErrorException { + + @Test(dependsOnMethods = { + "testKfAccountUpdate" }, dataProvider = "getKfAccount") + public void testKfAccountUploadHeadImg(String kfAccount) + throws WxErrorException { File imgFile = new File("src\\test\\resources\\mm.jpeg"); - boolean result = this.wxService.getKefuService().kfAccountUploadHeadImg(KF_ACCOUNT, imgFile); + boolean result = this.wxService.getKefuService() + .kfAccountUploadHeadImg(kfAccount, imgFile); Assert.assertTrue(result); } - - @Test(dependsOnMethods = { "testKfAccountUploadHeadImg" }) - public void testKfAccountDel() throws WxErrorException { - boolean result = this.wxService.getKefuService().kfAccountDel(KF_ACCOUNT); + + @Test(dependsOnMethods = { + "testKfAccountUploadHeadImg" }, dataProvider = "getKfAccount") + public void testKfAccountDel(String kfAccount) throws WxErrorException { + boolean result = this.wxService.getKefuService().kfAccountDel(kfAccount); Assert.assertTrue(result); } diff --git a/weixin-java-mp/src/test/resources/test-config.sample.xml b/weixin-java-mp/src/test/resources/test-config.sample.xml index 6ec4825a..1f79bea2 100644 --- a/weixin-java-mp/src/test/resources/test-config.sample.xml +++ b/weixin-java-mp/src/test/resources/test-config.sample.xml @@ -7,4 +7,5 @@ 可以不填写 某个加你公众号的用户的openId 网页授权获取用户信息回调地址 + 完整客服账号,格式为:账号前缀@公众号微信号