Browse Source

优化客服管理接口的单元测试

master
BinaryWang 8 years ago
parent
commit
29cfa7762e
4 changed files with 49 additions and 20 deletions
  1. +4
    -0
      weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java
  2. +11
    -3
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java
  3. +33
    -17
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuImplTest.java
  4. +1
    -0
      weixin-java-mp/src/test/resources/test-config.sample.xml

+ 4
- 0
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java View File

@@ -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;


+ 11
- 3
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/ApiTestModule.java View File

@@ -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;
}

}

}

+ 33
- 17
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuImplTest.java View File

@@ -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);
}



+ 1
- 0
weixin-java-mp/src/test/resources/test-config.sample.xml View File

@@ -7,4 +7,5 @@
<expiresTime>可以不填写</expiresTime>
<openId>某个加你公众号的用户的openId</openId>
<oauth2redirectUri>网页授权获取用户信息回调地址</oauth2redirectUri>
<kfAccount>完整客服账号,格式为:账号前缀@公众号微信号</kfAccount>
</xml>

Loading…
Cancel
Save