Skip to content

Commit 29cfa77

Browse files
committed
优化客服管理接口的单元测试
1 parent f902281 commit 29cfa77

4 files changed

Lines changed: 49 additions & 20 deletions

File tree

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,10 @@ public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) {
825825
this.httpClient = apacheHttpClientBuilder.build();
826826
}
827827

828+
public WxMpConfigStorage getWxMpConfigStorage() {
829+
return this.wxMpConfigStorage;
830+
}
831+
828832
@Override
829833
public void setRetrySleepMillis(int retrySleepMillis) {
830834
this.retrySleepMillis = retrySleepMillis;

‎weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.thoughtworks.xstream.annotations.XStreamAlias;
1212

1313
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
14-
import me.chanjar.weixin.mp.api.impl.WxMpKefuServiceImpl;
1514

1615
public class ApiTestModule implements Module {
1716

@@ -23,7 +22,7 @@ public void configure(Binder binder) {
2322
WxXmlMpInMemoryConfigStorage.class, is1);
2423
WxMpServiceImpl wxService = new WxMpServiceImpl();
2524
wxService.setWxMpConfigStorage(config);
26-
25+
2726
binder.bind(WxMpServiceImpl.class).toInstance(wxService);
2827
binder.bind(WxMpConfigStorage.class).toInstance(config);
2928
} catch (IOException e) {
@@ -42,7 +41,8 @@ public static <T> T fromXml(Class<T> clazz, InputStream is) {
4241
public static class WxXmlMpInMemoryConfigStorage
4342
extends WxMpInMemoryConfigStorage {
4443

45-
protected String openId;
44+
private String openId;
45+
private String kfAccount;
4646

4747
public String getOpenId() {
4848
return this.openId;
@@ -57,6 +57,14 @@ public String toString() {
5757
return ToStringBuilder.reflectionToString(this);
5858
}
5959

60+
public String getKfAccount() {
61+
return this.kfAccount;
62+
}
63+
64+
public void setKfAccount(String kfAccount) {
65+
this.kfAccount = kfAccount;
66+
}
67+
6068
}
6169

6270
}

‎weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuImplTest.java‎

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package me.chanjar.weixin.mp.api.impl;
22

3+
import org.testng.annotations.DataProvider;
34
import org.testng.annotations.Guice;
45
import org.testng.annotations.Test;
56

67
import com.google.inject.Inject;
78

89
import me.chanjar.weixin.common.exception.WxErrorException;
910
import me.chanjar.weixin.mp.api.ApiTestModule;
11+
import me.chanjar.weixin.mp.api.ApiTestModule.WxXmlMpInMemoryConfigStorage;
12+
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
1013
import me.chanjar.weixin.mp.api.WxMpServiceImpl;
1114
import me.chanjar.weixin.mp.bean.customerservice.request.WxMpKfAccountRequest;
1215
import me.chanjar.weixin.mp.bean.customerservice.result.WxMpKfList;
@@ -24,8 +27,7 @@
2427
@Test
2528
@Guice(modules = ApiTestModule.class)
2629
public class WxMpKefuImplTest {
27-
private static final String KF_ACCOUNT = "kf2009@youxintest";
28-
30+
2931
@Inject
3032
protected WxMpServiceImpl wxService;
3133

@@ -36,34 +38,48 @@ public void testKfList() throws WxErrorException {
3638
}
3739

3840
public void testKfOnlineList() throws WxErrorException {
39-
WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService().kfOnlineList();
41+
WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService()
42+
.kfOnlineList();
4043
Assert.assertNotNull(kfOnlineList);
4144
System.err.println(kfOnlineList);
4245
}
4346

44-
public void testKfAccountAdd() throws WxErrorException {
47+
@DataProvider
48+
public Object[][] getKfAccount() {
49+
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService
50+
.getWxMpConfigStorage();
51+
return new Object[][] { { configStorage.getKfAccount() } };
52+
}
53+
54+
@Test(dataProvider = "getKfAccount")
55+
public void testKfAccountAdd(String kfAccount) throws WxErrorException {
4556
WxMpKfAccountRequest request = WxMpKfAccountRequest.builder()
46-
.kfAccount(KF_ACCOUNT).nickName("我晕").rawPassword("123").build();
57+
.kfAccount(kfAccount).nickName("我晕").rawPassword("123").build();
4758
Assert.assertTrue(this.wxService.getKefuService().kfAccountAdd(request));
4859
}
49-
50-
@Test(dependsOnMethods = { "testKfAccountAdd" })
51-
public void testKfAccountUpdate() throws WxErrorException {
60+
61+
@Test(dependsOnMethods = {
62+
"testKfAccountAdd" }, dataProvider = "getKfAccount")
63+
public void testKfAccountUpdate(String kfAccount) throws WxErrorException {
5264
WxMpKfAccountRequest request = WxMpKfAccountRequest.builder()
53-
.kfAccount(KF_ACCOUNT).nickName("我晕").rawPassword("123").build();
65+
.kfAccount(kfAccount).nickName("我晕").rawPassword("123").build();
5466
Assert.assertTrue(this.wxService.getKefuService().kfAccountUpdate(request));
5567
}
56-
57-
@Test(dependsOnMethods = { "testKfAccountUpdate" })
58-
public void testKfAccountUploadHeadImg() throws WxErrorException {
68+
69+
@Test(dependsOnMethods = {
70+
"testKfAccountUpdate" }, dataProvider = "getKfAccount")
71+
public void testKfAccountUploadHeadImg(String kfAccount)
72+
throws WxErrorException {
5973
File imgFile = new File("src\\test\\resources\\mm.jpeg");
60-
boolean result = this.wxService.getKefuService().kfAccountUploadHeadImg(KF_ACCOUNT, imgFile);
74+
boolean result = this.wxService.getKefuService()
75+
.kfAccountUploadHeadImg(kfAccount, imgFile);
6176
Assert.assertTrue(result);
6277
}
63-
64-
@Test(dependsOnMethods = { "testKfAccountUploadHeadImg" })
65-
public void testKfAccountDel() throws WxErrorException {
66-
boolean result = this.wxService.getKefuService().kfAccountDel(KF_ACCOUNT);
78+
79+
@Test(dependsOnMethods = {
80+
"testKfAccountUploadHeadImg" }, dataProvider = "getKfAccount")
81+
public void testKfAccountDel(String kfAccount) throws WxErrorException {
82+
boolean result = this.wxService.getKefuService().kfAccountDel(kfAccount);
6783
Assert.assertTrue(result);
6884
}
6985

‎weixin-java-mp/src/test/resources/test-config.sample.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
<expiresTime>可以不填写</expiresTime>
88
<openId>某个加你公众号的用户的openId</openId>
99
<oauth2redirectUri>网页授权获取用户信息回调地址</oauth2redirectUri>
10+
<kfAccount>完整客服账号,格式为:账号前缀@公众号微信号</kfAccount>
1011
</xml>

0 commit comments

Comments
 (0)