mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
优化部分测试代码
This commit is contained in:
parent
fb8de94181
commit
b44f9b315f
@ -65,6 +65,11 @@
|
|||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-guava</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
|
@ -10,12 +10,13 @@ import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
|||||||
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
|
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
|
||||||
import me.chanjar.weixin.mp.bean.kefu.result.*;
|
import me.chanjar.weixin.mp.bean.kefu.result.*;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.testng.*;
|
|
||||||
import org.testng.annotations.*;
|
import org.testng.annotations.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试客服相关接口
|
* 测试客服相关接口
|
||||||
*
|
*
|
||||||
@ -29,53 +30,50 @@ public class WxMpKefuServiceImplTest {
|
|||||||
protected WxMpService wxService;
|
protected WxMpService wxService;
|
||||||
|
|
||||||
public void testSendKefuMpNewsMessage() throws WxErrorException {
|
public void testSendKefuMpNewsMessage() throws WxErrorException {
|
||||||
TestConfigStorage configStorage = (TestConfigStorage) this.wxService
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage();
|
||||||
.getWxMpConfigStorage();
|
|
||||||
WxMpKefuMessage message = new WxMpKefuMessage();
|
WxMpKefuMessage message = new WxMpKefuMessage();
|
||||||
message.setMsgType(WxConsts.KefuMsgType.MPNEWS);
|
message.setMsgType(WxConsts.KefuMsgType.MPNEWS);
|
||||||
message.setToUser(configStorage.getOpenid());
|
message.setToUser(configStorage.getOpenid());
|
||||||
message.setMpNewsMediaId("52R6dL2FxDpM9N1rCY3sYBqHwq-L7K_lz1sPI71idMg");
|
message.setMpNewsMediaId("52R6dL2FxDpM9N1rCY3sYBqHwq-L7K_lz1sPI71idMg");
|
||||||
|
|
||||||
this.wxService.getKefuService().sendKefuMessage(message);
|
boolean result = this.wxService.getKefuService().sendKefuMessage(message);
|
||||||
|
assertThat(result).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendKefuMessage() throws WxErrorException {
|
public void testSendKefuMessage() throws WxErrorException {
|
||||||
TestConfigStorage configStorage = (TestConfigStorage) this.wxService
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage();
|
||||||
.getWxMpConfigStorage();
|
|
||||||
WxMpKefuMessage message = new WxMpKefuMessage();
|
WxMpKefuMessage message = new WxMpKefuMessage();
|
||||||
message.setMsgType(WxConsts.KefuMsgType.TEXT);
|
message.setMsgType(WxConsts.KefuMsgType.TEXT);
|
||||||
message.setToUser(configStorage.getOpenid());
|
message.setToUser(configStorage.getOpenid());
|
||||||
message.setContent(
|
message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
|
||||||
"欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
|
|
||||||
|
|
||||||
this.wxService.getKefuService().sendKefuMessage(message);
|
boolean result = this.wxService.getKefuService().sendKefuMessage(message);
|
||||||
|
assertThat(result).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSendKefuMessageWithKfAccount() throws WxErrorException {
|
public void testSendKefuMessageWithKfAccount() throws WxErrorException {
|
||||||
TestConfigStorage configStorage = (TestConfigStorage) this.wxService
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage();
|
||||||
.getWxMpConfigStorage();
|
|
||||||
WxMpKefuMessage message = new WxMpKefuMessage();
|
WxMpKefuMessage message = new WxMpKefuMessage();
|
||||||
message.setMsgType(WxConsts.KefuMsgType.TEXT);
|
message.setMsgType(WxConsts.KefuMsgType.TEXT);
|
||||||
message.setToUser(configStorage.getOpenid());
|
message.setToUser(configStorage.getOpenid());
|
||||||
message.setKfAccount(configStorage.getKfAccount());
|
message.setKfAccount(configStorage.getKfAccount());
|
||||||
message.setContent(
|
message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
|
||||||
"欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
|
|
||||||
|
|
||||||
this.wxService.getKefuService().sendKefuMessage(message);
|
boolean result = this.wxService.getKefuService().sendKefuMessage(message);
|
||||||
|
assertThat(result).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKfList() throws WxErrorException {
|
public void testKfList() throws WxErrorException {
|
||||||
WxMpKfList kfList = this.wxService.getKefuService().kfList();
|
WxMpKfList kfList = this.wxService.getKefuService().kfList();
|
||||||
Assert.assertNotNull(kfList);
|
assertThat(kfList).isNotNull();
|
||||||
for (WxMpKfInfo k : kfList.getKfList()) {
|
for (WxMpKfInfo k : kfList.getKfList()) {
|
||||||
System.err.println(k);
|
System.err.println(k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKfOnlineList() throws WxErrorException {
|
public void testKfOnlineList() throws WxErrorException {
|
||||||
WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService()
|
WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService().kfOnlineList();
|
||||||
.kfOnlineList();
|
assertThat(kfOnlineList).isNotNull();
|
||||||
Assert.assertNotNull(kfOnlineList);
|
|
||||||
for (WxMpKfInfo k : kfOnlineList.getKfOnlineList()) {
|
for (WxMpKfInfo k : kfOnlineList.getKfOnlineList()) {
|
||||||
System.err.println(k);
|
System.err.println(k);
|
||||||
}
|
}
|
||||||
@ -83,8 +81,7 @@ public class WxMpKefuServiceImplTest {
|
|||||||
|
|
||||||
@DataProvider
|
@DataProvider
|
||||||
public Object[][] getKfAccount() {
|
public Object[][] getKfAccount() {
|
||||||
TestConfigStorage configStorage = (TestConfigStorage) this.wxService
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage();
|
||||||
.getWxMpConfigStorage();
|
|
||||||
return new Object[][]{{configStorage.getKfAccount()}};
|
return new Object[][]{{configStorage.getKfAccount()}};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +89,7 @@ public class WxMpKefuServiceImplTest {
|
|||||||
public void testKfAccountAdd(String kfAccount) throws WxErrorException {
|
public void testKfAccountAdd(String kfAccount) throws WxErrorException {
|
||||||
WxMpKfAccountRequest request = WxMpKfAccountRequest.builder()
|
WxMpKfAccountRequest request = WxMpKfAccountRequest.builder()
|
||||||
.kfAccount(kfAccount).nickName("我晕").build();
|
.kfAccount(kfAccount).nickName("我晕").build();
|
||||||
Assert.assertTrue(this.wxService.getKefuService().kfAccountAdd(request));
|
assertThat(this.wxService.getKefuService().kfAccountAdd(request)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = {
|
@Test(dependsOnMethods = {
|
||||||
@ -100,7 +97,7 @@ public class WxMpKefuServiceImplTest {
|
|||||||
public void testKfAccountUpdate(String kfAccount) throws WxErrorException {
|
public void testKfAccountUpdate(String kfAccount) throws WxErrorException {
|
||||||
WxMpKfAccountRequest request = WxMpKfAccountRequest.builder()
|
WxMpKfAccountRequest request = WxMpKfAccountRequest.builder()
|
||||||
.kfAccount(kfAccount).nickName("我晕").build();
|
.kfAccount(kfAccount).nickName("我晕").build();
|
||||||
Assert.assertTrue(this.wxService.getKefuService().kfAccountUpdate(request));
|
assertThat(this.wxService.getKefuService().kfAccountUpdate(request)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = {
|
@Test(dependsOnMethods = {
|
||||||
@ -108,71 +105,59 @@ public class WxMpKefuServiceImplTest {
|
|||||||
public void testKfAccountInviteWorker(String kfAccount) throws WxErrorException {
|
public void testKfAccountInviteWorker(String kfAccount) throws WxErrorException {
|
||||||
WxMpKfAccountRequest request = WxMpKfAccountRequest.builder()
|
WxMpKfAccountRequest request = WxMpKfAccountRequest.builder()
|
||||||
.kfAccount(kfAccount).inviteWx(" ").build();
|
.kfAccount(kfAccount).inviteWx(" ").build();
|
||||||
Assert.assertTrue(this.wxService.getKefuService().kfAccountInviteWorker(request));
|
assertThat(this.wxService.getKefuService().kfAccountInviteWorker(request)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = {
|
@Test(dependsOnMethods = {"testKfAccountUpdate", "testKfAccountAdd"}, dataProvider = "getKfAccount")
|
||||||
"testKfAccountUpdate"}, dataProvider = "getKfAccount")
|
public void testKfAccountUploadHeadImg(String kfAccount) throws WxErrorException {
|
||||||
public void testKfAccountUploadHeadImg(String kfAccount)
|
|
||||||
throws WxErrorException {
|
|
||||||
File imgFile = new File("src\\test\\resources\\mm.jpeg");
|
File imgFile = new File("src\\test\\resources\\mm.jpeg");
|
||||||
boolean result = this.wxService.getKefuService()
|
boolean result = this.wxService.getKefuService().kfAccountUploadHeadImg(kfAccount, imgFile);
|
||||||
.kfAccountUploadHeadImg(kfAccount, imgFile);
|
assertThat(result).isTrue();
|
||||||
Assert.assertTrue(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dataProvider = "getKfAccount")
|
@Test(dataProvider = "getKfAccount")
|
||||||
public void testKfAccountDel(String kfAccount) throws WxErrorException {
|
public void testKfAccountDel(String kfAccount) throws WxErrorException {
|
||||||
boolean result = this.wxService.getKefuService().kfAccountDel(kfAccount);
|
boolean result = this.wxService.getKefuService().kfAccountDel(kfAccount);
|
||||||
Assert.assertTrue(result);
|
assertThat(result).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider
|
@DataProvider
|
||||||
public Object[][] getKfAccountAndOpenid() {
|
public Object[][] getKfAccountAndOpenid() {
|
||||||
TestConfigStorage configStorage = (TestConfigStorage) this.wxService
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage();
|
||||||
.getWxMpConfigStorage();
|
return new Object[][]{{configStorage.getKfAccount(), configStorage.getOpenid()}};
|
||||||
return new Object[][]{
|
|
||||||
{configStorage.getKfAccount(), configStorage.getOpenid()}};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dataProvider = "getKfAccountAndOpenid")
|
@Test(dataProvider = "getKfAccountAndOpenid")
|
||||||
public void testKfSessionCreate(String kfAccount, String openid)
|
public void testKfSessionCreate(String kfAccount, String openid) throws WxErrorException {
|
||||||
throws WxErrorException {
|
boolean result = this.wxService.getKefuService().kfSessionCreate(openid, kfAccount);
|
||||||
boolean result = this.wxService.getKefuService().kfSessionCreate(openid,
|
assertThat(result).isTrue();
|
||||||
kfAccount);
|
|
||||||
Assert.assertTrue(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dataProvider = "getKfAccountAndOpenid")
|
@Test(dataProvider = "getKfAccountAndOpenid")
|
||||||
public void testKfSessionClose(String kfAccount, String openid)
|
public void testKfSessionClose(String kfAccount, String openid)
|
||||||
throws WxErrorException {
|
throws WxErrorException {
|
||||||
boolean result = this.wxService.getKefuService().kfSessionClose(openid,
|
boolean result = this.wxService.getKefuService().kfSessionClose(openid, kfAccount);
|
||||||
kfAccount);
|
assertThat(result).isTrue();
|
||||||
Assert.assertTrue(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dataProvider = "getKfAccountAndOpenid")
|
@Test(dataProvider = "getKfAccountAndOpenid")
|
||||||
public void testKfSessionGet(@SuppressWarnings("unused") String kfAccount,
|
public void testKfSessionGet(@SuppressWarnings("unused") String kfAccount, String openid) throws WxErrorException {
|
||||||
String openid) throws WxErrorException {
|
WxMpKfSessionGetResult result = this.wxService.getKefuService().kfSessionGet(openid);
|
||||||
WxMpKfSessionGetResult result = this.wxService.getKefuService()
|
assertThat(result).isNotNull();
|
||||||
.kfSessionGet(openid);
|
|
||||||
Assert.assertNotNull(result);
|
|
||||||
System.err.println(result);
|
System.err.println(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dataProvider = "getKfAccount")
|
@Test(dataProvider = "getKfAccount")
|
||||||
public void testKfSessionList(String kfAccount) throws WxErrorException {
|
public void testKfSessionList(String kfAccount) throws WxErrorException {
|
||||||
WxMpKfSessionList result = this.wxService.getKefuService()
|
WxMpKfSessionList result = this.wxService.getKefuService().kfSessionList(kfAccount);
|
||||||
.kfSessionList(kfAccount);
|
assertThat(result).isNotNull();
|
||||||
Assert.assertNotNull(result);
|
|
||||||
System.err.println(result);
|
System.err.println(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKfSessionGetWaitCase() throws WxErrorException {
|
public void testKfSessionGetWaitCase() throws WxErrorException {
|
||||||
WxMpKfSessionWaitCaseList result = this.wxService.getKefuService()
|
WxMpKfSessionWaitCaseList result = this.wxService.getKefuService().kfSessionGetWaitCase();
|
||||||
.kfSessionGetWaitCase();
|
assertThat(result).isNotNull();
|
||||||
Assert.assertNotNull(result);
|
|
||||||
System.err.println(result);
|
System.err.println(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +166,7 @@ public class WxMpKefuServiceImplTest {
|
|||||||
Date startTime = DateTime.now().minusDays(1).toDate();
|
Date startTime = DateTime.now().minusDays(1).toDate();
|
||||||
Date endTime = DateTime.now().minusDays(0).toDate();
|
Date endTime = DateTime.now().minusDays(0).toDate();
|
||||||
WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime, endTime, 1L, 50);
|
WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime, endTime, 1L, 50);
|
||||||
Assert.assertNotNull(result);
|
assertThat(result).isNotNull();
|
||||||
System.err.println(result);
|
System.err.println(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,7 +175,7 @@ public class WxMpKefuServiceImplTest {
|
|||||||
Date startTime = DateTime.now().minusDays(1).toDate();
|
Date startTime = DateTime.now().minusDays(1).toDate();
|
||||||
Date endTime = DateTime.now().minusDays(0).toDate();
|
Date endTime = DateTime.now().minusDays(0).toDate();
|
||||||
WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime, endTime);
|
WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime, endTime);
|
||||||
Assert.assertNotNull(result);
|
assertThat(result).isNotNull();
|
||||||
System.err.println(result);
|
System.err.println(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user