From c9e28aefb46aaee3351859e17f108ad7a82d6046 Mon Sep 17 00:00:00 2001 From: Junling Bu Date: Sun, 15 Jul 2018 16:47:24 +0800 Subject: [PATCH] =?UTF-8?q?chore[litemall-core]=EF=BC=9A=E6=8F=90=E9=86=92?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E9=87=8D=E6=96=B0=E5=91=BD=E5=90=8D=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../linlinjava/litemall/core/MailTest.java | 41 +++++++++++ .../org/linlinjava/litemall/core/SmsTest.java | 73 +++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 litemall-core/src/test/java/org/linlinjava/litemall/core/MailTest.java create mode 100644 litemall-core/src/test/java/org/linlinjava/litemall/core/SmsTest.java diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/MailTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/MailTest.java new file mode 100644 index 00000000..3a3aee6e --- /dev/null +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/MailTest.java @@ -0,0 +1,41 @@ +package org.linlinjava.litemall.core; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.linlinjava.litemall.core.notify.LitemallNotifyService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +/** + * 测试邮件发送服务 + * + * 注意LitemallNotifyService采用异步线程操作 + * 因此测试的时候需要睡眠一会儿,保证任务执行 + * + * 开发者需要确保: + * 1. 在相应的邮件服务器设置正确notify.properties已经设置正确 + * 2. 在相应的邮件服务器设置正确 + */ +@WebAppConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest +public class MailTest { + + @Autowired + private LitemallNotifyService litemallNotifyService; + + @Test + public void testMail() { + litemallNotifyService.notifyMailMessage("订单信息", "订单1111111已付款,请发货"); + + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + +} diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/SmsTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/SmsTest.java new file mode 100644 index 00000000..f8b6d2ad --- /dev/null +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/SmsTest.java @@ -0,0 +1,73 @@ +package org.linlinjava.litemall.core; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.linlinjava.litemall.core.notify.LitemallNotifyService; +import org.linlinjava.litemall.core.notify.NotifyUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +/** + * 测试短信发送服务 + * + * 注意LitemallNotifyService采用异步线程操作 + * 因此测试的时候需要睡眠一会儿,保证任务执行 + * + * 开发者需要确保: + * 1. 在腾讯云短信平台设置短信签名和短信模板notify.properties已经设置正确 + * 2. 在腾讯云短信平台设置短信签名和短信模板 + * 3. 在当前测试类设置好正确的手机号码 + */ +@WebAppConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest +public class SmsTest { + + @Autowired + private LitemallNotifyService litemallNotifyService; + +// @Test + public void testSingle() { + String phone = "xxxxxxxxxxx"; + // 这里的短信签名必须在短信管理平台内设置正确并且相符合 + String msg = "【xxx】你的验证码为:123456,请与2分钟内填写,如非本人操作,请忽略本短信。"; + litemallNotifyService.notifySMSMessage(phone, msg); + + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + @Test + public void testCaptcha() { + String phone = "xxxxxxxxxxx"; + String[] params = new String[] {"123456"}; + + litemallNotifyService.notifySMSTemplate(phone, NotifyUtils.NotifyType.CAPTCHA, params); + + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + @Test + public void testPaySucceed() { + String phone = "xxxxxxxxxxx"; + String[] params = new String[] {"123456"}; + + litemallNotifyService.notifySMSTemplate(phone, NotifyUtils.NotifyType.PAY_SUCCEED, params); + + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + +}