重构测试类的包结构

This commit is contained in:
Binary Wang 2017-01-23 16:48:00 +08:00
parent 5f3623aa2b
commit 123eb5088d
21 changed files with 62 additions and 58 deletions

View File

@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.test.ApiTestModule;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;

View File

@ -1,5 +1,6 @@
package me.chanjar.weixin.mp.api; package me.chanjar.weixin.mp.api;
import me.chanjar.weixin.mp.api.test.ApiTestModule;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -4,6 +4,8 @@ import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.test.TestConfigStorage;
import me.chanjar.weixin.mp.bean.WxMpMassNews; import me.chanjar.weixin.mp.bean.WxMpMassNews;
import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage;
import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; import me.chanjar.weixin.mp.bean.WxMpMassTagMessage;
@ -33,7 +35,7 @@ public class WxMpMassMessageAPITest {
@Test @Test
public void testTextMassOpenIdsMessageSend() throws WxErrorException { public void testTextMassOpenIdsMessageSend() throws WxErrorException {
// 发送群发消息 // 发送群发消息
WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService TestConfigStorage configProvider = (TestConfigStorage) this.wxService
.getWxMpConfigStorage(); .getWxMpConfigStorage();
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
massMessage.setMsgType(WxConsts.MASS_MSG_TEXT); massMessage.setMsgType(WxConsts.MASS_MSG_TEXT);
@ -47,10 +49,9 @@ public class WxMpMassMessageAPITest {
} }
@Test(dataProvider = "massMessages") @Test(dataProvider = "massMessages")
public void testMediaMassOpenIdsMessageSend(String massMsgType, public void testMediaMassOpenIdsMessageSend(String massMsgType, String mediaId) throws WxErrorException {
String mediaId) throws WxErrorException {
// 发送群发消息 // 发送群发消息
WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService TestConfigStorage configProvider = (TestConfigStorage) this.wxService
.getWxMpConfigStorage(); .getWxMpConfigStorage();
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage(); WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
massMessage.setMsgType(massMsgType); massMessage.setMsgType(massMsgType);
@ -83,8 +84,7 @@ public class WxMpMassMessageAPITest {
WxMpMassTagMessage massMessage = new WxMpMassTagMessage(); WxMpMassTagMessage massMessage = new WxMpMassTagMessage();
massMessage.setMsgType(massMsgType); massMessage.setMsgType(massMsgType);
massMessage.setMediaId(mediaId); massMessage.setMediaId(mediaId);
massMessage massMessage.setTagId(this.wxService.getUserTagService().tagGet().get(0).getId());
.setTagId(this.wxService.getUserTagService().tagGet().get(0).getId());
WxMpMassSendResult massResult = this.wxService WxMpMassSendResult massResult = this.wxService
.massGroupMessageSend(massMessage); .massGroupMessageSend(massMessage);
@ -118,7 +118,7 @@ public class WxMpMassMessageAPITest {
messages[0] = new Object[]{WxConsts.MASS_MSG_VIDEO, uploadResult.getMediaId()}; messages[0] = new Object[]{WxConsts.MASS_MSG_VIDEO, uploadResult.getMediaId()};
} }
/** /*
* 图片素材 * 图片素材
*/ */
try (InputStream inputStream = ClassLoader try (InputStream inputStream = ClassLoader
@ -130,7 +130,7 @@ public class WxMpMassMessageAPITest {
messages[1] = new Object[]{WxConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId()}; messages[1] = new Object[]{WxConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId()};
} }
/** /*
* 语音素材 * 语音素材
*/ */
try (InputStream inputStream = ClassLoader try (InputStream inputStream = ClassLoader
@ -142,7 +142,7 @@ public class WxMpMassMessageAPITest {
messages[2] = new Object[]{WxConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId()}; messages[2] = new Object[]{WxConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId()};
} }
/** /*
* 图文素材 * 图文素材
*/ */
try (InputStream inputStream = ClassLoader try (InputStream inputStream = ClassLoader

View File

@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.test.ApiTestModule;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.test.ApiTestModule;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;

View File

@ -2,7 +2,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.bean.WxCardApiSignature; import me.chanjar.weixin.common.bean.WxCardApiSignature;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpCardResult; import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;

View File

@ -14,7 +14,7 @@ import org.testng.annotations.Test;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult;
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal;
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult; import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult;

View File

@ -3,7 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.device.WxDeviceQrCodeResult; import me.chanjar.weixin.mp.bean.device.WxDeviceQrCodeResult;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;

View File

@ -3,9 +3,9 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.api.test.TestConfigStorage;
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; 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.*;
@ -31,7 +31,7 @@ public class WxMpKefuServiceImplTest {
protected WxMpService wxService; protected WxMpService wxService;
public void testSendKefuMpNewsMessage() throws WxErrorException { public void testSendKefuMpNewsMessage() throws WxErrorException {
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService TestConfigStorage configStorage = (TestConfigStorage) this.wxService
.getWxMpConfigStorage(); .getWxMpConfigStorage();
WxMpKefuMessage message = new WxMpKefuMessage(); WxMpKefuMessage message = new WxMpKefuMessage();
message.setMsgType(WxConsts.CUSTOM_MSG_MPNEWS); message.setMsgType(WxConsts.CUSTOM_MSG_MPNEWS);
@ -42,7 +42,7 @@ public class WxMpKefuServiceImplTest {
} }
public void testSendKefuMessage() throws WxErrorException { public void testSendKefuMessage() throws WxErrorException {
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService TestConfigStorage configStorage = (TestConfigStorage) this.wxService
.getWxMpConfigStorage(); .getWxMpConfigStorage();
WxMpKefuMessage message = new WxMpKefuMessage(); WxMpKefuMessage message = new WxMpKefuMessage();
message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
@ -54,7 +54,7 @@ public class WxMpKefuServiceImplTest {
} }
public void testSendKefuMessageWithKfAccount() throws WxErrorException { public void testSendKefuMessageWithKfAccount() throws WxErrorException {
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService TestConfigStorage configStorage = (TestConfigStorage) this.wxService
.getWxMpConfigStorage(); .getWxMpConfigStorage();
WxMpKefuMessage message = new WxMpKefuMessage(); WxMpKefuMessage message = new WxMpKefuMessage();
message.setMsgType(WxConsts.CUSTOM_MSG_TEXT); message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
@ -85,7 +85,7 @@ public class WxMpKefuServiceImplTest {
@DataProvider @DataProvider
public Object[][] getKfAccount() { public Object[][] getKfAccount() {
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService TestConfigStorage configStorage = (TestConfigStorage) this.wxService
.getWxMpConfigStorage(); .getWxMpConfigStorage();
return new Object[][] { { configStorage.getKfAccount() } }; return new Object[][] { { configStorage.getKfAccount() } };
} }
@ -131,7 +131,7 @@ public class WxMpKefuServiceImplTest {
@DataProvider @DataProvider
public Object[][] getKfAccountAndOpenid() { public Object[][] getKfAccountAndOpenid() {
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService TestConfigStorage configStorage = (TestConfigStorage) this.wxService
.getWxMpConfigStorage(); .getWxMpConfigStorage();
return new Object[][] { return new Object[][] {
{ configStorage.getKfAccount(), configStorage.getOpenid() } }; { configStorage.getKfAccount(), configStorage.getOpenid() } };

View File

@ -5,7 +5,7 @@ import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.material.WxMpMaterial; import me.chanjar.weixin.mp.bean.material.WxMpMaterial;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate; import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate;

View File

@ -5,7 +5,7 @@ import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.menu.WxMenu; import me.chanjar.weixin.common.bean.menu.WxMenu;
import me.chanjar.weixin.common.bean.menu.WxMenuButton; import me.chanjar.weixin.common.bean.menu.WxMenuButton;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult; import me.chanjar.weixin.mp.bean.menu.WxMpGetSelfMenuInfoResult;
import me.chanjar.weixin.mp.bean.menu.WxMpMenu; import me.chanjar.weixin.mp.bean.menu.WxMpMenu;

View File

@ -3,9 +3,9 @@ package me.chanjar.weixin.mp.api.impl;
import com.github.binarywang.utils.qrcode.QrcodeUtils; import com.github.binarywang.utils.qrcode.QrcodeUtils;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.api.test.TestConfigStorage;
import me.chanjar.weixin.mp.bean.pay.request.*; import me.chanjar.weixin.mp.bean.pay.request.*;
import me.chanjar.weixin.mp.bean.pay.result.*; import me.chanjar.weixin.mp.bean.pay.result.*;
import org.testng.annotations.*; import org.testng.annotations.*;
@ -59,7 +59,7 @@ public class WxMpPayServiceImplTest {
*/ */
@Test @Test
public void setSSLKey(){ public void setSSLKey(){
WxXmlMpInMemoryConfigStorage config = (WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); TestConfigStorage config = (TestConfigStorage) this.wxService.getWxMpConfigStorage();
config.setSslContextFilePath(config.getKeyPath()); config.setSslContextFilePath(config.getKeyPath());
} }
@ -107,7 +107,7 @@ public class WxMpPayServiceImplTest {
request.setClientIp("aaa"); request.setClientIp("aaa");
request.setMchBillNo("aaaa"); request.setMchBillNo("aaaa");
request request
.setReOpenid(((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); .setReOpenid(((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid());
WxPaySendRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request); WxPaySendRedpackResult redpackResult = this.wxService.getPayService().sendRedpack(request);
System.err.println(redpackResult); System.err.println(redpackResult);
} }

View File

@ -2,7 +2,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import org.testng.Assert; import org.testng.Assert;

View File

@ -2,9 +2,9 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.api.test.TestConfigStorage;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -103,7 +103,7 @@ public class WxMpServiceImplTest {
@Test @Test
public void testBuildQrConnectUrl() { public void testBuildQrConnectUrl() {
String qrconnectRedirectUrl = ((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getQrconnectRedirectUrl(); String qrconnectRedirectUrl = ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getQrconnectRedirectUrl();
String qrConnectUrl = this.wxService.buildQrConnectUrl(qrconnectRedirectUrl, String qrConnectUrl = this.wxService.buildQrConnectUrl(qrconnectRedirectUrl,
WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, null); WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, null);
Assert.assertNotNull(qrConnectUrl); Assert.assertNotNull(qrConnectUrl);

View File

@ -2,7 +2,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo; import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo;
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo; import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo;

View File

@ -2,9 +2,9 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.api.test.TestConfigStorage;
import me.chanjar.weixin.mp.bean.template.WxMpTemplate; import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry; import me.chanjar.weixin.mp.bean.template.WxMpTemplateIndustry;
@ -33,7 +33,7 @@ public class WxMpTemplateMsgServiceImplTest {
public void testSendTemplateMsg() throws WxErrorException { public void testSendTemplateMsg() throws WxErrorException {
SimpleDateFormat dateFormat = new SimpleDateFormat( SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss.SSS"); "yyyy-MM-dd HH:mm:ss.SSS");
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService TestConfigStorage configStorage = (TestConfigStorage) this.wxService
.getWxMpConfigStorage(); .getWxMpConfigStorage();
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder() WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
.toUser(configStorage.getOpenid()) .toUser(configStorage.getOpenid())

View File

@ -1,8 +1,8 @@
package me.chanjar.weixin.mp.api.impl; package me.chanjar.weixin.mp.api.impl;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.api.test.TestConfigStorage;
import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
@ -23,7 +23,7 @@ public class WxMpUserBlacklistServiceImplTest {
@Test @Test
public void testGetBlacklist() throws Exception { public void testGetBlacklist() throws Exception {
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService TestConfigStorage configStorage = (TestConfigStorage) this.wxService
.getWxMpConfigStorage(); .getWxMpConfigStorage();
WxMpUserBlacklistGetResult wxMpUserBlacklistGetResult = this.wxService.getBlackListService().getBlacklist(configStorage.getOpenid()); WxMpUserBlacklistGetResult wxMpUserBlacklistGetResult = this.wxService.getBlackListService().getBlacklist(configStorage.getOpenid());
Assert.assertNotNull(wxMpUserBlacklistGetResult); Assert.assertNotNull(wxMpUserBlacklistGetResult);
@ -35,7 +35,7 @@ public class WxMpUserBlacklistServiceImplTest {
@Test @Test
public void testPushToBlacklist() throws Exception { public void testPushToBlacklist() throws Exception {
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService TestConfigStorage configStorage = (TestConfigStorage) this.wxService
.getWxMpConfigStorage(); .getWxMpConfigStorage();
List<String> openidList = new ArrayList<>(); List<String> openidList = new ArrayList<>();
openidList.add(configStorage.getOpenid()); openidList.add(configStorage.getOpenid());
@ -44,7 +44,7 @@ public class WxMpUserBlacklistServiceImplTest {
@Test @Test
public void testPullFromBlacklist() throws Exception { public void testPullFromBlacklist() throws Exception {
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService TestConfigStorage configStorage = (TestConfigStorage) this.wxService
.getWxMpConfigStorage(); .getWxMpConfigStorage();
List<String> openidList = new ArrayList<>(); List<String> openidList = new ArrayList<>();
openidList.add(configStorage.getOpenid()); openidList.add(configStorage.getOpenid());

View File

@ -13,8 +13,8 @@ import org.testng.annotations.Test;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.api.test.TestConfigStorage;
import me.chanjar.weixin.mp.bean.WxMpUserQuery; import me.chanjar.weixin.mp.bean.WxMpUserQuery;
import me.chanjar.weixin.mp.bean.result.WxMpUser; import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.bean.result.WxMpUserList; import me.chanjar.weixin.mp.bean.result.WxMpUserList;
@ -32,11 +32,11 @@ public class WxMpUserServiceImplTest {
@Inject @Inject
private WxMpService wxService; private WxMpService wxService;
private WxXmlMpInMemoryConfigStorage configProvider; private TestConfigStorage configProvider;
@BeforeTest @BeforeTest
public void setup() { public void setup() {
this.configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService this.configProvider = (TestConfigStorage) this.wxService
.getWxMpConfigStorage(); .getWxMpConfigStorage();
} }

View File

@ -9,8 +9,8 @@ import org.testng.annotations.Test;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.test.ApiTestModule;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage; import me.chanjar.weixin.mp.api.test.TestConfigStorage;
import me.chanjar.weixin.mp.bean.tag.WxTagListUser; import me.chanjar.weixin.mp.bean.tag.WxTagListUser;
import me.chanjar.weixin.mp.bean.tag.WxUserTag; import me.chanjar.weixin.mp.bean.tag.WxUserTag;
@ -67,7 +67,7 @@ public class WxMpUserTagServiceImplTest {
@Test @Test
public void testBatchTagging() throws Exception { public void testBatchTagging() throws Exception {
String[] openids = new String[]{((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()}; String[] openids = new String[]{((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()};
boolean res = this.wxService.getUserTagService().batchTagging(this.tagId, openids); boolean res = this.wxService.getUserTagService().batchTagging(this.tagId, openids);
System.out.println(res); System.out.println(res);
Assert.assertTrue(res); Assert.assertTrue(res);
@ -75,7 +75,7 @@ public class WxMpUserTagServiceImplTest {
@Test @Test
public void testBatchUntagging() throws Exception { public void testBatchUntagging() throws Exception {
String[] openids = new String[]{((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()}; String[] openids = new String[]{((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()};
boolean res = this.wxService.getUserTagService().batchUntagging(this.tagId, openids); boolean res = this.wxService.getUserTagService().batchUntagging(this.tagId, openids);
System.out.println(res); System.out.println(res);
Assert.assertTrue(res); Assert.assertTrue(res);
@ -84,7 +84,7 @@ public class WxMpUserTagServiceImplTest {
@Test @Test
public void testUserTagList() throws Exception { public void testUserTagList() throws Exception {
List<Long> res = this.wxService.getUserTagService().userTagList( List<Long> res = this.wxService.getUserTagService().userTagList(
((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); ((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid());
System.out.println(res); System.out.println(res);
Assert.assertNotNull(res); Assert.assertNotNull(res);
} }

View File

@ -1,9 +1,11 @@
package me.chanjar.weixin.mp.api; package me.chanjar.weixin.mp.api.test;
import com.google.inject.Binder; import com.google.inject.Binder;
import com.google.inject.Module; import com.google.inject.Module;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.XStream;
import me.chanjar.weixin.common.util.xml.XStreamInitializer; import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import java.io.IOException; import java.io.IOException;
@ -14,10 +16,9 @@ public class ApiTestModule implements Module {
@Override @Override
public void configure(Binder binder) { public void configure(Binder binder) {
try (InputStream is1 = ClassLoader try (InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml")) {
.getSystemResourceAsStream("test-config.xml")) { TestConfigStorage config = this
WxXmlMpInMemoryConfigStorage config = this .fromXml(TestConfigStorage.class, is1);
.fromXml(WxXmlMpInMemoryConfigStorage.class, is1);
config.setAccessTokenLock(new ReentrantLock()); config.setAccessTokenLock(new ReentrantLock());
WxMpService wxService = new WxMpServiceImpl(); WxMpService wxService = new WxMpServiceImpl();
wxService.setWxMpConfigStorage(config); wxService.setWxMpConfigStorage(config);

View File

@ -1,18 +1,19 @@
package me.chanjar.weixin.mp.api; package me.chanjar.weixin.mp.api.test;
import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.annotations.XStreamAlias;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
@XStreamAlias("xml") @XStreamAlias("xml")
public class WxXmlMpInMemoryConfigStorage public class TestConfigStorage extends WxMpInMemoryConfigStorage {
extends WxMpInMemoryConfigStorage {
private String openid; private String openid;
private String kfAccount; private String kfAccount;
private String qrconnectRedirectUrl; private String qrconnectRedirectUrl;
private String templateId; private String templateId;
private String keyPath;
public String getKeyPath() { public String getKeyPath() {
return keyPath; return keyPath;
@ -22,8 +23,6 @@ public class WxXmlMpInMemoryConfigStorage
this.keyPath = keyPath; this.keyPath = keyPath;
} }
private String keyPath;
public String getOpenid() { public String getOpenid() {
return this.openid; return this.openid;
} }