|
|
@@ -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.result.*; |
|
|
|
import org.joda.time.DateTime; |
|
|
|
import org.testng.*; |
|
|
|
import org.testng.annotations.*; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
|
|
|
/** |
|
|
|
* 测试客服相关接口 |
|
|
|
* |
|
|
@@ -29,53 +30,50 @@ public class WxMpKefuServiceImplTest { |
|
|
|
protected WxMpService wxService; |
|
|
|
|
|
|
|
public void testSendKefuMpNewsMessage() throws WxErrorException { |
|
|
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService |
|
|
|
.getWxMpConfigStorage(); |
|
|
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); |
|
|
|
WxMpKefuMessage message = new WxMpKefuMessage(); |
|
|
|
message.setMsgType(WxConsts.KefuMsgType.MPNEWS); |
|
|
|
message.setToUser(configStorage.getOpenid()); |
|
|
|
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 { |
|
|
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService |
|
|
|
.getWxMpConfigStorage(); |
|
|
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); |
|
|
|
WxMpKefuMessage message = new WxMpKefuMessage(); |
|
|
|
message.setMsgType(WxConsts.KefuMsgType.TEXT); |
|
|
|
message.setToUser(configStorage.getOpenid()); |
|
|
|
message.setContent( |
|
|
|
"欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); |
|
|
|
message.setContent("欢迎欢迎,热烈欢迎\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 { |
|
|
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService |
|
|
|
.getWxMpConfigStorage(); |
|
|
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); |
|
|
|
WxMpKefuMessage message = new WxMpKefuMessage(); |
|
|
|
message.setMsgType(WxConsts.KefuMsgType.TEXT); |
|
|
|
message.setToUser(configStorage.getOpenid()); |
|
|
|
message.setKfAccount(configStorage.getKfAccount()); |
|
|
|
message.setContent( |
|
|
|
"欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); |
|
|
|
message.setContent("欢迎欢迎,热烈欢迎\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 { |
|
|
|
WxMpKfList kfList = this.wxService.getKefuService().kfList(); |
|
|
|
Assert.assertNotNull(kfList); |
|
|
|
assertThat(kfList).isNotNull(); |
|
|
|
for (WxMpKfInfo k : kfList.getKfList()) { |
|
|
|
System.err.println(k); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void testKfOnlineList() throws WxErrorException { |
|
|
|
WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService() |
|
|
|
.kfOnlineList(); |
|
|
|
Assert.assertNotNull(kfOnlineList); |
|
|
|
WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService().kfOnlineList(); |
|
|
|
assertThat(kfOnlineList).isNotNull(); |
|
|
|
for (WxMpKfInfo k : kfOnlineList.getKfOnlineList()) { |
|
|
|
System.err.println(k); |
|
|
|
} |
|
|
@@ -83,8 +81,7 @@ public class WxMpKefuServiceImplTest { |
|
|
|
|
|
|
|
@DataProvider |
|
|
|
public Object[][] getKfAccount() { |
|
|
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService |
|
|
|
.getWxMpConfigStorage(); |
|
|
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); |
|
|
|
return new Object[][]{{configStorage.getKfAccount()}}; |
|
|
|
} |
|
|
|
|
|
|
@@ -92,7 +89,7 @@ public class WxMpKefuServiceImplTest { |
|
|
|
public void testKfAccountAdd(String kfAccount) throws WxErrorException { |
|
|
|
WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() |
|
|
|
.kfAccount(kfAccount).nickName("我晕").build(); |
|
|
|
Assert.assertTrue(this.wxService.getKefuService().kfAccountAdd(request)); |
|
|
|
assertThat(this.wxService.getKefuService().kfAccountAdd(request)).isTrue(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test(dependsOnMethods = { |
|
|
@@ -100,7 +97,7 @@ public class WxMpKefuServiceImplTest { |
|
|
|
public void testKfAccountUpdate(String kfAccount) throws WxErrorException { |
|
|
|
WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() |
|
|
|
.kfAccount(kfAccount).nickName("我晕").build(); |
|
|
|
Assert.assertTrue(this.wxService.getKefuService().kfAccountUpdate(request)); |
|
|
|
assertThat(this.wxService.getKefuService().kfAccountUpdate(request)).isTrue(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test(dependsOnMethods = { |
|
|
@@ -108,71 +105,59 @@ public class WxMpKefuServiceImplTest { |
|
|
|
public void testKfAccountInviteWorker(String kfAccount) throws WxErrorException { |
|
|
|
WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() |
|
|
|
.kfAccount(kfAccount).inviteWx(" ").build(); |
|
|
|
Assert.assertTrue(this.wxService.getKefuService().kfAccountInviteWorker(request)); |
|
|
|
assertThat(this.wxService.getKefuService().kfAccountInviteWorker(request)).isTrue(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test(dependsOnMethods = { |
|
|
|
"testKfAccountUpdate"}, dataProvider = "getKfAccount") |
|
|
|
public void testKfAccountUploadHeadImg(String kfAccount) |
|
|
|
throws WxErrorException { |
|
|
|
@Test(dependsOnMethods = {"testKfAccountUpdate", "testKfAccountAdd"}, dataProvider = "getKfAccount") |
|
|
|
public void testKfAccountUploadHeadImg(String kfAccount) throws WxErrorException { |
|
|
|
File imgFile = new File("src\\test\\resources\\mm.jpeg"); |
|
|
|
boolean result = this.wxService.getKefuService() |
|
|
|
.kfAccountUploadHeadImg(kfAccount, imgFile); |
|
|
|
Assert.assertTrue(result); |
|
|
|
boolean result = this.wxService.getKefuService().kfAccountUploadHeadImg(kfAccount, imgFile); |
|
|
|
assertThat(result).isTrue(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test(dataProvider = "getKfAccount") |
|
|
|
public void testKfAccountDel(String kfAccount) throws WxErrorException { |
|
|
|
boolean result = this.wxService.getKefuService().kfAccountDel(kfAccount); |
|
|
|
Assert.assertTrue(result); |
|
|
|
assertThat(result).isTrue(); |
|
|
|
} |
|
|
|
|
|
|
|
@DataProvider |
|
|
|
public Object[][] getKfAccountAndOpenid() { |
|
|
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService |
|
|
|
.getWxMpConfigStorage(); |
|
|
|
return new Object[][]{ |
|
|
|
{configStorage.getKfAccount(), configStorage.getOpenid()}}; |
|
|
|
TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); |
|
|
|
return new Object[][]{{configStorage.getKfAccount(), configStorage.getOpenid()}}; |
|
|
|
} |
|
|
|
|
|
|
|
@Test(dataProvider = "getKfAccountAndOpenid") |
|
|
|
public void testKfSessionCreate(String kfAccount, String openid) |
|
|
|
throws WxErrorException { |
|
|
|
boolean result = this.wxService.getKefuService().kfSessionCreate(openid, |
|
|
|
kfAccount); |
|
|
|
Assert.assertTrue(result); |
|
|
|
public void testKfSessionCreate(String kfAccount, String openid) throws WxErrorException { |
|
|
|
boolean result = this.wxService.getKefuService().kfSessionCreate(openid, kfAccount); |
|
|
|
assertThat(result).isTrue(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test(dataProvider = "getKfAccountAndOpenid") |
|
|
|
public void testKfSessionClose(String kfAccount, String openid) |
|
|
|
throws WxErrorException { |
|
|
|
boolean result = this.wxService.getKefuService().kfSessionClose(openid, |
|
|
|
kfAccount); |
|
|
|
Assert.assertTrue(result); |
|
|
|
boolean result = this.wxService.getKefuService().kfSessionClose(openid, kfAccount); |
|
|
|
assertThat(result).isTrue(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test(dataProvider = "getKfAccountAndOpenid") |
|
|
|
public void testKfSessionGet(@SuppressWarnings("unused") String kfAccount, |
|
|
|
String openid) throws WxErrorException { |
|
|
|
WxMpKfSessionGetResult result = this.wxService.getKefuService() |
|
|
|
.kfSessionGet(openid); |
|
|
|
Assert.assertNotNull(result); |
|
|
|
public void testKfSessionGet(@SuppressWarnings("unused") String kfAccount, String openid) throws WxErrorException { |
|
|
|
WxMpKfSessionGetResult result = this.wxService.getKefuService().kfSessionGet(openid); |
|
|
|
assertThat(result).isNotNull(); |
|
|
|
System.err.println(result); |
|
|
|
} |
|
|
|
|
|
|
|
@Test(dataProvider = "getKfAccount") |
|
|
|
public void testKfSessionList(String kfAccount) throws WxErrorException { |
|
|
|
WxMpKfSessionList result = this.wxService.getKefuService() |
|
|
|
.kfSessionList(kfAccount); |
|
|
|
Assert.assertNotNull(result); |
|
|
|
WxMpKfSessionList result = this.wxService.getKefuService().kfSessionList(kfAccount); |
|
|
|
assertThat(result).isNotNull(); |
|
|
|
System.err.println(result); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testKfSessionGetWaitCase() throws WxErrorException { |
|
|
|
WxMpKfSessionWaitCaseList result = this.wxService.getKefuService() |
|
|
|
.kfSessionGetWaitCase(); |
|
|
|
Assert.assertNotNull(result); |
|
|
|
WxMpKfSessionWaitCaseList result = this.wxService.getKefuService().kfSessionGetWaitCase(); |
|
|
|
assertThat(result).isNotNull(); |
|
|
|
System.err.println(result); |
|
|
|
} |
|
|
|
|
|
|
@@ -181,7 +166,7 @@ public class WxMpKefuServiceImplTest { |
|
|
|
Date startTime = DateTime.now().minusDays(1).toDate(); |
|
|
|
Date endTime = DateTime.now().minusDays(0).toDate(); |
|
|
|
WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime, endTime, 1L, 50); |
|
|
|
Assert.assertNotNull(result); |
|
|
|
assertThat(result).isNotNull(); |
|
|
|
System.err.println(result); |
|
|
|
} |
|
|
|
|
|
|
@@ -190,7 +175,7 @@ public class WxMpKefuServiceImplTest { |
|
|
|
Date startTime = DateTime.now().minusDays(1).toDate(); |
|
|
|
Date endTime = DateTime.now().minusDays(0).toDate(); |
|
|
|
WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime, endTime); |
|
|
|
Assert.assertNotNull(result); |
|
|
|
assertThat(result).isNotNull(); |
|
|
|
System.err.println(result); |
|
|
|
} |
|
|
|
} |