1
0
mirror of synced 2025-12-22 09:58:07 +08:00

将模板消息相关接口代码移到单独的service,并作相应重构调整,增加单元测试 for issue #63

This commit is contained in:
Binary Wang
2016-10-14 19:33:34 +08:00
parent 6682f5ff28
commit 77db3c2dae
9 changed files with 274 additions and 165 deletions

View File

@@ -1,21 +1,13 @@
package me.chanjar.weixin.mp.api.impl;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.api.ApiTestModule;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.bean.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.WxMpTemplateMessage;
@Test
@Guice(modules = ApiTestModule.class)
public class WxMpServiceImplTest {
@@ -88,20 +80,6 @@ public class WxMpServiceImplTest {
Assert.fail("Not yet implemented");
}
@Test(invocationCount = 100, threadPoolSize = 30)
public void testTemplateSend() throws WxErrorException {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss.SSS");
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService
.getWxMpConfigStorage();
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
.toUser(configStorage.getOpenid())
.templateId(configStorage.getTemplateId()).build();
templateMessage.addWxMpTemplateData(
new WxMpTemplateData("first", dateFormat.format(new Date())));
this.wxService.templateSend(templateMessage);
}
@Test
public void testSetIndustry() {
Assert.fail("Not yet implemented");

View File

@@ -0,0 +1,59 @@
package me.chanjar.weixin.mp.api.impl;
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.WxXmlMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.bean.WxMpIndustry;
import me.chanjar.weixin.mp.bean.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.WxMpTemplateMessage;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* <pre>
* Created by Binary Wang on 2016-10-14.
* @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a>
* </pre>
*/
@Guice(modules = ApiTestModule.class)
public class WxMpTemplateMsgServiceImplTest {
@Inject
protected WxMpServiceImpl wxService;
@Test(invocationCount = 10, threadPoolSize = 10)
public void testSendTemplateMsg() throws WxErrorException {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss.SSS");
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService
.getWxMpConfigStorage();
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
.toUser(configStorage.getOpenid())
.templateId(configStorage.getTemplateId()).build();
templateMessage.addWxMpTemplateData(
new WxMpTemplateData("first", dateFormat.format(new Date())));
String msgId = this.wxService.getTemplateMsgService().sendTemplateMsg(templateMessage);
Assert.assertNotNull(msgId);
System.out.println(msgId);
}
@Test
public void testGetIndustry() throws Exception {
final WxMpIndustry industry = this.wxService.getTemplateMsgService().getIndustry();
Assert.assertNotNull(industry);
System.out.println(industry);
}
@Test
public void testSetIndustry() throws Exception {
WxMpIndustry industry = new WxMpIndustry(new WxMpIndustry.Industry("1"),
new WxMpIndustry.Industry("04"));
boolean result = this.wxService.getTemplateMsgService().setIndustry(industry);
Assert.assertTrue(result);
}
}