@@ -4,14 +4,13 @@ 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 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.annotations.Guice; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
/** | /** | ||||
* 基础API测试 | * 基础API测试 | ||||
* @author chanjarster | |||||
* | * | ||||
* @author chanjarster | |||||
*/ | */ | ||||
@Test(groups = "baseAPI") | @Test(groups = "baseAPI") | ||||
@Guice(modules = ApiTestModule.class) | @Guice(modules = ApiTestModule.class) | ||||
@@ -4,8 +4,7 @@ import me.chanjar.weixin.common.bean.result.WxError; | |||||
import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||
import me.chanjar.weixin.common.util.http.RequestExecutor; | import me.chanjar.weixin.common.util.http.RequestExecutor; | ||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; | import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; | ||||
import org.testng.annotations.DataProvider; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.annotations.*; | |||||
import java.util.concurrent.ExecutionException; | import java.util.concurrent.ExecutionException; | ||||
import java.util.concurrent.ExecutorService; | import java.util.concurrent.ExecutorService; | ||||
@@ -15,14 +14,14 @@ import java.util.concurrent.Future; | |||||
@Test | @Test | ||||
public class WxMpBusyRetryTest { | public class WxMpBusyRetryTest { | ||||
@DataProvider(name="getService") | |||||
@DataProvider(name = "getService") | |||||
public Object[][] getService() { | public Object[][] getService() { | ||||
WxMpService service = new WxMpServiceImpl() { | WxMpService service = new WxMpServiceImpl() { | ||||
@Override | @Override | ||||
protected synchronized <T, E> T executeInternal( | protected synchronized <T, E> T executeInternal( | ||||
RequestExecutor<T, E> executor, String uri, E data) | |||||
throws WxErrorException { | |||||
RequestExecutor<T, E> executor, String uri, E data) | |||||
throws WxErrorException { | |||||
this.log.info("Executed"); | this.log.info("Executed"); | ||||
WxError error = new WxError(); | WxError error = new WxError(); | ||||
error.setErrorCode(-1); | error.setErrorCode(-1); | ||||
@@ -32,7 +31,7 @@ public class WxMpBusyRetryTest { | |||||
service.setMaxRetryTimes(3); | service.setMaxRetryTimes(3); | ||||
service.setRetrySleepMillis(500); | service.setRetrySleepMillis(500); | ||||
return new Object[][] { { service } }; | |||||
return new Object[][]{{service}}; | |||||
} | } | ||||
@Test(dataProvider = "getService", expectedExceptions = RuntimeException.class) | @Test(dataProvider = "getService", expectedExceptions = RuntimeException.class) | ||||
@@ -1,14 +1,11 @@ | |||||
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.annotations.Guice; | |||||
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.common.util.crypto.SHA1; | import me.chanjar.weixin.common.util.crypto.SHA1; | ||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
/** | /** | ||||
* 测试jsapi ticket接口 | * 测试jsapi ticket接口 | ||||
@@ -35,10 +32,10 @@ public class WxMpJsAPITest { | |||||
String noncestr = "82693e11-b9bc-448e-892f-f5289f46cd0f"; | String noncestr = "82693e11-b9bc-448e-892f-f5289f46cd0f"; | ||||
String jsapiTicket = "bxLdikRXVbTPdHSM05e5u4RbEYQn7pNQMPrfzl8lJNb1foLDa3HIwI3BRMkQmSO_5F64VFa75uURcq6Uz7QHgA"; | String jsapiTicket = "bxLdikRXVbTPdHSM05e5u4RbEYQn7pNQMPrfzl8lJNb1foLDa3HIwI3BRMkQmSO_5F64VFa75uURcq6Uz7QHgA"; | ||||
String result = SHA1.genWithAmple( | String result = SHA1.genWithAmple( | ||||
"jsapi_ticket=" + jsapiTicket, | |||||
"noncestr=" + noncestr, | |||||
"timestamp=" + timestamp, | |||||
"url=" + url | |||||
"jsapi_ticket=" + jsapiTicket, | |||||
"noncestr=" + noncestr, | |||||
"timestamp=" + timestamp, | |||||
"url=" + url | |||||
); | ); | ||||
Assert.assertEquals(result, "c6f04b64d6351d197b71bd23fb7dd2d44c0db486"); | Assert.assertEquals(result, "c6f04b64d6351d197b71bd23fb7dd2d44c0db486"); | ||||
@@ -12,10 +12,8 @@ import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; | |||||
import me.chanjar.weixin.mp.bean.WxMpMassVideo; | import me.chanjar.weixin.mp.bean.WxMpMassVideo; | ||||
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; | import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; | ||||
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.DataProvider; | |||||
import org.testng.annotations.Guice; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
@@ -5,16 +5,15 @@ import me.chanjar.weixin.common.session.StandardSessionManager; | |||||
import me.chanjar.weixin.common.session.WxSessionManager; | import me.chanjar.weixin.common.session.WxSessionManager; | ||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; | import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; | ||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; | import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.DataProvider; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
import java.util.Map; | import java.util.Map; | ||||
/** | /** | ||||
* 测试消息路由器 | * 测试消息路由器 | ||||
* @author chanjarster | |||||
* | * | ||||
* @author chanjarster | |||||
*/ | */ | ||||
@Test | @Test | ||||
public class WxMpMessageRouterTest { | public class WxMpMessageRouterTest { | ||||
@@ -23,19 +22,19 @@ public class WxMpMessageRouterTest { | |||||
public void prepare(boolean async, StringBuffer sb, WxMpMessageRouter router) { | public void prepare(boolean async, StringBuffer sb, WxMpMessageRouter router) { | ||||
router | router | ||||
.rule() | .rule() | ||||
.async(async) | |||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1") | |||||
.handler(new WxEchoMpMessageHandler(sb, "COMBINE_4")) | |||||
.async(async) | |||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1") | |||||
.handler(new WxEchoMpMessageHandler(sb, "COMBINE_4")) | |||||
.end() | .end() | ||||
.rule() | .rule() | ||||
.async(async) | |||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1") | |||||
.handler(new WxEchoMpMessageHandler(sb, "COMBINE_3")) | |||||
.async(async) | |||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1") | |||||
.handler(new WxEchoMpMessageHandler(sb, "COMBINE_3")) | |||||
.end() | .end() | ||||
.rule() | .rule() | ||||
.async(async) | |||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK) | |||||
.handler(new WxEchoMpMessageHandler(sb, "COMBINE_2")) | |||||
.async(async) | |||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK) | |||||
.handler(new WxEchoMpMessageHandler(sb, "COMBINE_2")) | |||||
.end() | .end() | ||||
.rule().async(async).msgType(WxConsts.XML_MSG_TEXT).handler(new WxEchoMpMessageHandler(sb, WxConsts.XML_MSG_TEXT)).end() | .rule().async(async).msgType(WxConsts.XML_MSG_TEXT).handler(new WxEchoMpMessageHandler(sb, WxConsts.XML_MSG_TEXT)).end() | ||||
.rule().async(async).event(WxConsts.EVT_CLICK).handler(new WxEchoMpMessageHandler(sb, WxConsts.EVT_CLICK)).end() | .rule().async(async).event(WxConsts.EVT_CLICK).handler(new WxEchoMpMessageHandler(sb, WxConsts.EVT_CLICK)).end() | ||||
@@ -43,15 +42,15 @@ public class WxMpMessageRouterTest { | |||||
.rule().async(async).content("CONTENT_1").handler(new WxEchoMpMessageHandler(sb, "CONTENT_1")).end() | .rule().async(async).content("CONTENT_1").handler(new WxEchoMpMessageHandler(sb, "CONTENT_1")).end() | ||||
.rule().async(async).rContent(".*bc.*").handler(new WxEchoMpMessageHandler(sb, "abcd")).end() | .rule().async(async).rContent(".*bc.*").handler(new WxEchoMpMessageHandler(sb, "abcd")).end() | ||||
.rule().async(async).matcher(new WxMpMessageMatcher() { | .rule().async(async).matcher(new WxMpMessageMatcher() { | ||||
@Override | |||||
public boolean match(WxMpXmlMessage message) { | |||||
return "strangeformat".equals(message.getFormat()); | |||||
} | |||||
}).handler(new WxEchoMpMessageHandler(sb, "matcher")).end() | |||||
@Override | |||||
public boolean match(WxMpXmlMessage message) { | |||||
return "strangeformat".equals(message.getFormat()); | |||||
} | |||||
}).handler(new WxEchoMpMessageHandler(sb, "matcher")).end() | |||||
.rule().async(async).handler(new WxEchoMpMessageHandler(sb, "ALL")).end(); | .rule().async(async).handler(new WxEchoMpMessageHandler(sb, "ALL")).end(); | ||||
} | } | ||||
@Test(dataProvider="messages-1") | |||||
@Test(dataProvider = "messages-1") | |||||
public void testSync(WxMpXmlMessage message, String expected) { | public void testSync(WxMpXmlMessage message, String expected) { | ||||
StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
WxMpMessageRouter router = new WxMpMessageRouter(null); | WxMpMessageRouter router = new WxMpMessageRouter(null); | ||||
@@ -60,11 +59,11 @@ public class WxMpMessageRouterTest { | |||||
Assert.assertEquals(sb.toString(), expected); | Assert.assertEquals(sb.toString(), expected); | ||||
} | } | ||||
@Test(dataProvider="messages-1") | |||||
@Test(dataProvider = "messages-1") | |||||
public void testAsync(WxMpXmlMessage message, String expected) throws InterruptedException { | public void testAsync(WxMpXmlMessage message, String expected) throws InterruptedException { | ||||
StringBuffer sb = new StringBuffer(); | StringBuffer sb = new StringBuffer(); | ||||
WxMpMessageRouter router = new WxMpMessageRouter(null); | WxMpMessageRouter router = new WxMpMessageRouter(null); | ||||
prepare(true, sb, router); | |||||
prepare(true, sb, router); | |||||
router.route(message); | router.route(message); | ||||
Thread.sleep(500l); | Thread.sleep(500l); | ||||
Assert.assertEquals(sb.toString(), expected); | Assert.assertEquals(sb.toString(), expected); | ||||
@@ -75,7 +74,7 @@ public class WxMpMessageRouterTest { | |||||
router.rule().handler(new WxMpMessageHandler() { | router.rule().handler(new WxMpMessageHandler() { | ||||
@Override | @Override | ||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, | public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, | ||||
WxSessionManager sessionManager) { | |||||
WxSessionManager sessionManager) { | |||||
return null; | return null; | ||||
} | } | ||||
}).end(); | }).end(); | ||||
@@ -97,7 +96,8 @@ public class WxMpMessageRouterTest { | |||||
Thread.sleep(1000l * 2); | Thread.sleep(1000l * 2); | ||||
} | } | ||||
@DataProvider(name="messages-1") | |||||
@DataProvider(name = "messages-1") | |||||
public Object[][] messages2() { | public Object[][] messages2() { | ||||
WxMpXmlMessage message1 = new WxMpXmlMessage(); | WxMpXmlMessage message1 = new WxMpXmlMessage(); | ||||
message1.setMsgType(WxConsts.XML_MSG_TEXT); | message1.setMsgType(WxConsts.XML_MSG_TEXT); | ||||
@@ -135,40 +135,21 @@ public class WxMpMessageRouterTest { | |||||
c4.setEventKey("KEY_1"); | c4.setEventKey("KEY_1"); | ||||
c4.setContent("CONTENT_1"); | c4.setContent("CONTENT_1"); | ||||
return new Object[][] { | |||||
new Object[] { message1, WxConsts.XML_MSG_TEXT + "," }, | |||||
new Object[] { message2, WxConsts.EVT_CLICK + "," }, | |||||
new Object[] { message3, "KEY_1," }, | |||||
new Object[] { message4, "CONTENT_1," }, | |||||
new Object[] { message5, "ALL," }, | |||||
new Object[] { message6, "abcd," }, | |||||
new Object[] { message7, "matcher," }, | |||||
new Object[] { c2, "COMBINE_2," }, | |||||
new Object[] { c3, "COMBINE_3," }, | |||||
new Object[] { c4, "COMBINE_4," } | |||||
return new Object[][]{ | |||||
new Object[]{message1, WxConsts.XML_MSG_TEXT + ","}, | |||||
new Object[]{message2, WxConsts.EVT_CLICK + ","}, | |||||
new Object[]{message3, "KEY_1,"}, | |||||
new Object[]{message4, "CONTENT_1,"}, | |||||
new Object[]{message5, "ALL,"}, | |||||
new Object[]{message6, "abcd,"}, | |||||
new Object[]{message7, "matcher,"}, | |||||
new Object[]{c2, "COMBINE_2,"}, | |||||
new Object[]{c3, "COMBINE_3,"}, | |||||
new Object[]{c4, "COMBINE_4,"} | |||||
}; | }; | ||||
} | } | ||||
public static class WxEchoMpMessageHandler implements WxMpMessageHandler { | |||||
private StringBuffer sb; | |||||
private String echoStr; | |||||
public WxEchoMpMessageHandler(StringBuffer sb, String echoStr) { | |||||
this.sb = sb; | |||||
this.echoStr = echoStr; | |||||
} | |||||
@Override | |||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, | |||||
WxSessionManager sessionManager) { | |||||
this.sb.append(this.echoStr).append(','); | |||||
return null; | |||||
} | |||||
} | |||||
@DataProvider | @DataProvider | ||||
public Object[][] standardSessionManager() { | public Object[][] standardSessionManager() { | ||||
@@ -178,8 +159,8 @@ public class WxMpMessageRouterTest { | |||||
ism.setProcessExpiresFrequency(1); | ism.setProcessExpiresFrequency(1); | ||||
ism.setBackgroundProcessorDelay(1); | ism.setBackgroundProcessorDelay(1); | ||||
return new Object[][] { | |||||
new Object[] { ism } | |||||
return new Object[][]{ | |||||
new Object[]{ism} | |||||
}; | }; | ||||
} | } | ||||
@@ -191,8 +172,8 @@ public class WxMpMessageRouterTest { | |||||
final WxMpMessageRouter router = new WxMpMessageRouter(null); | final WxMpMessageRouter router = new WxMpMessageRouter(null); | ||||
router.setSessionManager(ism); | router.setSessionManager(ism); | ||||
router | router | ||||
.rule().async(false).handler(new WxSessionMessageHandler()).next() | |||||
.rule().async(false).handler(new WxSessionMessageHandler()).end(); | |||||
.rule().async(false).handler(new WxSessionMessageHandler()).next() | |||||
.rule().async(false).handler(new WxSessionMessageHandler()).end(); | |||||
WxMpXmlMessage msg = new WxMpXmlMessage(); | WxMpXmlMessage msg = new WxMpXmlMessage(); | ||||
msg.setFromUser("abc"); | msg.setFromUser("abc"); | ||||
@@ -211,8 +192,8 @@ public class WxMpMessageRouterTest { | |||||
final WxMpMessageRouter router = new WxMpMessageRouter(null); | final WxMpMessageRouter router = new WxMpMessageRouter(null); | ||||
router.setSessionManager(ism); | router.setSessionManager(ism); | ||||
router | router | ||||
.rule().async(false).handler(new WxSessionMessageHandler()).next() | |||||
.rule().async(true).handler(new WxSessionMessageHandler()).end(); | |||||
.rule().async(false).handler(new WxSessionMessageHandler()).next() | |||||
.rule().async(true).handler(new WxSessionMessageHandler()).end(); | |||||
WxMpXmlMessage msg = new WxMpXmlMessage(); | WxMpXmlMessage msg = new WxMpXmlMessage(); | ||||
msg.setFromUser("abc"); | msg.setFromUser("abc"); | ||||
@@ -225,8 +206,8 @@ public class WxMpMessageRouterTest { | |||||
final WxMpMessageRouter router = new WxMpMessageRouter(null); | final WxMpMessageRouter router = new WxMpMessageRouter(null); | ||||
router.setSessionManager(ism); | router.setSessionManager(ism); | ||||
router | router | ||||
.rule().async(true).handler(new WxSessionMessageHandler()).next() | |||||
.rule().async(false).handler(new WxSessionMessageHandler()).end(); | |||||
.rule().async(true).handler(new WxSessionMessageHandler()).next() | |||||
.rule().async(false).handler(new WxSessionMessageHandler()).end(); | |||||
WxMpXmlMessage msg = new WxMpXmlMessage(); | WxMpXmlMessage msg = new WxMpXmlMessage(); | ||||
msg.setFromUser("abc"); | msg.setFromUser("abc"); | ||||
@@ -245,8 +226,8 @@ public class WxMpMessageRouterTest { | |||||
final WxMpMessageRouter router = new WxMpMessageRouter(null); | final WxMpMessageRouter router = new WxMpMessageRouter(null); | ||||
router.setSessionManager(ism); | router.setSessionManager(ism); | ||||
router | router | ||||
.rule().async(true).handler(new WxSessionMessageHandler()).next() | |||||
.rule().async(true).handler(new WxSessionMessageHandler()).end(); | |||||
.rule().async(true).handler(new WxSessionMessageHandler()).next() | |||||
.rule().async(true).handler(new WxSessionMessageHandler()).end(); | |||||
WxMpXmlMessage msg = new WxMpXmlMessage(); | WxMpXmlMessage msg = new WxMpXmlMessage(); | ||||
msg.setFromUser("abc"); | msg.setFromUser("abc"); | ||||
@@ -265,7 +246,7 @@ public class WxMpMessageRouterTest { | |||||
final WxMpMessageRouter router = new WxMpMessageRouter(null); | final WxMpMessageRouter router = new WxMpMessageRouter(null); | ||||
router.setSessionManager(ism); | router.setSessionManager(ism); | ||||
router | router | ||||
.rule().async(false).handler(new WxSessionMessageHandler()).end(); | |||||
.rule().async(false).handler(new WxSessionMessageHandler()).end(); | |||||
WxMpXmlMessage msg = new WxMpXmlMessage(); | WxMpXmlMessage msg = new WxMpXmlMessage(); | ||||
msg.setFromUser("abc"); | msg.setFromUser("abc"); | ||||
@@ -279,7 +260,7 @@ public class WxMpMessageRouterTest { | |||||
final WxMpMessageRouter router = new WxMpMessageRouter(null); | final WxMpMessageRouter router = new WxMpMessageRouter(null); | ||||
router.setSessionManager(ism); | router.setSessionManager(ism); | ||||
router | router | ||||
.rule().async(true).handler(new WxSessionMessageHandler()).end(); | |||||
.rule().async(true).handler(new WxSessionMessageHandler()).end(); | |||||
WxMpXmlMessage msg = new WxMpXmlMessage(); | WxMpXmlMessage msg = new WxMpXmlMessage(); | ||||
msg.setFromUser("abc"); | msg.setFromUser("abc"); | ||||
@@ -290,11 +271,30 @@ public class WxMpMessageRouterTest { | |||||
} | } | ||||
} | } | ||||
public static class WxSessionMessageHandler implements WxMpMessageHandler { | |||||
public static class WxEchoMpMessageHandler implements WxMpMessageHandler { | |||||
private StringBuffer sb; | |||||
private String echoStr; | |||||
public WxEchoMpMessageHandler(StringBuffer sb, String echoStr) { | |||||
this.sb = sb; | |||||
this.echoStr = echoStr; | |||||
} | |||||
@Override | |||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, | |||||
WxSessionManager sessionManager) { | |||||
this.sb.append(this.echoStr).append(','); | |||||
return null; | |||||
} | |||||
} | |||||
public static class WxSessionMessageHandler implements WxMpMessageHandler { | |||||
@Override | @Override | ||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, | public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, | ||||
WxSessionManager sessionManager) { | |||||
WxSessionManager sessionManager) { | |||||
sessionManager.getSession(wxMessage.getFromUser()); | sessionManager.getSession(wxMessage.getFromUser()); | ||||
return null; | return null; | ||||
} | } | ||||
@@ -3,16 +3,13 @@ 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 me.chanjar.weixin.mp.api.test.ApiTestModule; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Guice; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
import java.util.Arrays; | import java.util.Arrays; | ||||
/** | /** | ||||
* | |||||
* @author chanjarster | * @author chanjarster | ||||
* | |||||
*/ | */ | ||||
@Test(groups = "miscAPI") | @Test(groups = "miscAPI") | ||||
@Guice(modules = ApiTestModule.class) | @Guice(modules = ApiTestModule.class) | ||||
@@ -3,9 +3,8 @@ 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 me.chanjar.weixin.mp.api.test.ApiTestModule; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Guice; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
/** | /** | ||||
* 测试短连接 | * 测试短连接 | ||||
@@ -2,17 +2,17 @@ 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.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | |||||
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.Test; | |||||
import org.testng.annotations.*; | |||||
import static org.testng.AssertJUnit.assertNotNull; | |||||
import static org.testng.AssertJUnit.*; | |||||
/** | /** | ||||
* 测试代码仅供参考,未做严格测试,因原接口作者并未提供单元测试代码 | * 测试代码仅供参考,未做严格测试,因原接口作者并未提供单元测试代码 | ||||
* Created by Binary Wang on 2016/7/27. | * Created by Binary Wang on 2016/7/27. | ||||
* | |||||
* @author binarywang (https://github.com/binarywang) | * @author binarywang (https://github.com/binarywang) | ||||
*/ | */ | ||||
@Test | @Test | ||||
@@ -1,83 +1,74 @@ | |||||
package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
import java.text.ParseException; | |||||
import java.util.Date; | |||||
import java.util.List; | |||||
import me.chanjar.weixin.mp.api.WxMpService; | |||||
import org.apache.commons.lang3.time.FastDateFormat; | |||||
import org.testng.Assert; | |||||
import org.testng.annotations.DataProvider; | |||||
import org.testng.annotations.Guice; | |||||
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.WxMpService; | |||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | import me.chanjar.weixin.mp.api.test.ApiTestModule; | ||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleResult; | |||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeArticleTotal; | |||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeInterfaceResult; | |||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeMsgResult; | |||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserCumulate; | |||||
import me.chanjar.weixin.mp.bean.datacube.WxDataCubeUserSummary; | |||||
import me.chanjar.weixin.mp.bean.datacube.*; | |||||
import org.apache.commons.lang3.time.FastDateFormat; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
import java.text.ParseException; | |||||
import java.util.Date; | |||||
import java.util.List; | |||||
/** | /** | ||||
* 测试统计分析相关的接口 | * 测试统计分析相关的接口 | ||||
* Created by Binary Wang on 2016/8/23. | |||||
* Created by Binary Wang on 2016/8/23. | |||||
* | |||||
* @author binarywang (https://github.com/binarywang) | * @author binarywang (https://github.com/binarywang) | ||||
*/ | */ | ||||
@Guice(modules = ApiTestModule.class) | @Guice(modules = ApiTestModule.class) | ||||
public class WxMpDataCubeServiceImplTest { | public class WxMpDataCubeServiceImplTest { | ||||
private FastDateFormat simpleDateFormat = FastDateFormat | |||||
.getInstance("yyyy-MM-dd"); | |||||
@Inject | @Inject | ||||
protected WxMpService wxService; | protected WxMpService wxService; | ||||
private FastDateFormat simpleDateFormat = FastDateFormat | |||||
.getInstance("yyyy-MM-dd"); | |||||
@DataProvider | @DataProvider | ||||
public Object[][] oneDay() throws ParseException { | public Object[][] oneDay() throws ParseException { | ||||
return new Object[][] { { this.simpleDateFormat.parse("2016-08-22") } }; | |||||
return new Object[][]{{this.simpleDateFormat.parse("2016-08-22")}}; | |||||
} | } | ||||
@DataProvider | @DataProvider | ||||
public Object[][] threeDays() throws ParseException { | public Object[][] threeDays() throws ParseException { | ||||
return new Object[][] { { this.simpleDateFormat.parse("2016-08-20"), | |||||
this.simpleDateFormat.parse("2016-08-22") } }; | |||||
return new Object[][]{{this.simpleDateFormat.parse("2016-08-20"), | |||||
this.simpleDateFormat.parse("2016-08-22")}}; | |||||
} | } | ||||
@DataProvider | @DataProvider | ||||
public Object[][] sevenDays() throws ParseException { | public Object[][] sevenDays() throws ParseException { | ||||
return new Object[][] { { this.simpleDateFormat.parse("2016-08-16"), | |||||
this.simpleDateFormat.parse("2016-08-22") } }; | |||||
return new Object[][]{{this.simpleDateFormat.parse("2016-08-16"), | |||||
this.simpleDateFormat.parse("2016-08-22")}}; | |||||
} | } | ||||
@DataProvider | @DataProvider | ||||
public Object[][] fifteenDays() throws ParseException { | public Object[][] fifteenDays() throws ParseException { | ||||
return new Object[][] { { this.simpleDateFormat.parse("2016-08-14"), | |||||
this.simpleDateFormat.parse("2016-08-27") } }; | |||||
return new Object[][]{{this.simpleDateFormat.parse("2016-08-14"), | |||||
this.simpleDateFormat.parse("2016-08-27")}}; | |||||
} | } | ||||
@DataProvider | @DataProvider | ||||
public Object[][] thirtyDays() throws ParseException { | public Object[][] thirtyDays() throws ParseException { | ||||
return new Object[][] { { this.simpleDateFormat.parse("2016-07-30"), | |||||
this.simpleDateFormat.parse("2016-08-27") } }; | |||||
return new Object[][]{{this.simpleDateFormat.parse("2016-07-30"), | |||||
this.simpleDateFormat.parse("2016-08-27")}}; | |||||
} | } | ||||
@Test(dataProvider = "sevenDays") | @Test(dataProvider = "sevenDays") | ||||
public void testGetUserSummary(Date beginDate, Date endDate) | public void testGetUserSummary(Date beginDate, Date endDate) | ||||
throws WxErrorException { | |||||
throws WxErrorException { | |||||
List<WxDataCubeUserSummary> summaries = this.wxService.getDataCubeService() | List<WxDataCubeUserSummary> summaries = this.wxService.getDataCubeService() | ||||
.getUserSummary(beginDate, endDate); | |||||
.getUserSummary(beginDate, endDate); | |||||
Assert.assertNotNull(summaries); | Assert.assertNotNull(summaries); | ||||
System.out.println(summaries); | System.out.println(summaries); | ||||
} | } | ||||
@Test(dataProvider = "sevenDays") | @Test(dataProvider = "sevenDays") | ||||
public void testGetUserCumulate(Date beginDate, Date endDate) | public void testGetUserCumulate(Date beginDate, Date endDate) | ||||
throws WxErrorException { | |||||
throws WxErrorException { | |||||
List<WxDataCubeUserCumulate> result = this.wxService.getDataCubeService() | List<WxDataCubeUserCumulate> result = this.wxService.getDataCubeService() | ||||
.getUserCumulate(beginDate, endDate); | |||||
.getUserCumulate(beginDate, endDate); | |||||
Assert.assertNotNull(result); | Assert.assertNotNull(result); | ||||
System.out.println(result); | System.out.println(result); | ||||
} | } | ||||
@@ -85,7 +76,7 @@ public class WxMpDataCubeServiceImplTest { | |||||
@Test(dataProvider = "oneDay") | @Test(dataProvider = "oneDay") | ||||
public void testGetArticleSummary(Date date) throws WxErrorException { | public void testGetArticleSummary(Date date) throws WxErrorException { | ||||
List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() | List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() | ||||
.getArticleSummary(date, date); | |||||
.getArticleSummary(date, date); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@@ -96,16 +87,16 @@ public class WxMpDataCubeServiceImplTest { | |||||
@Test(dataProvider = "oneDay") | @Test(dataProvider = "oneDay") | ||||
public void testGetArticleTotal(Date date) throws WxErrorException { | public void testGetArticleTotal(Date date) throws WxErrorException { | ||||
List<WxDataCubeArticleTotal> results = this.wxService.getDataCubeService() | List<WxDataCubeArticleTotal> results = this.wxService.getDataCubeService() | ||||
.getArticleTotal(date, date); | |||||
.getArticleTotal(date, date); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@Test(dataProvider = "threeDays") | @Test(dataProvider = "threeDays") | ||||
public void testGetUserRead(Date beginDate, Date endDate) | public void testGetUserRead(Date beginDate, Date endDate) | ||||
throws WxErrorException { | |||||
throws WxErrorException { | |||||
List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() | List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() | ||||
.getUserRead(beginDate, endDate); | |||||
.getUserRead(beginDate, endDate); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@@ -113,16 +104,16 @@ public class WxMpDataCubeServiceImplTest { | |||||
@Test(dataProvider = "oneDay") | @Test(dataProvider = "oneDay") | ||||
public void testGetUserReadHour(Date date) throws WxErrorException { | public void testGetUserReadHour(Date date) throws WxErrorException { | ||||
List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() | List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() | ||||
.getUserReadHour(date, date); | |||||
.getUserReadHour(date, date); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@Test(dataProvider = "sevenDays") | @Test(dataProvider = "sevenDays") | ||||
public void testGetUserShare(Date beginDate, Date endDate) | public void testGetUserShare(Date beginDate, Date endDate) | ||||
throws WxErrorException { | |||||
throws WxErrorException { | |||||
List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() | List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() | ||||
.getUserShare(beginDate, endDate); | |||||
.getUserShare(beginDate, endDate); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@@ -130,7 +121,7 @@ public class WxMpDataCubeServiceImplTest { | |||||
@Test(dataProvider = "oneDay") | @Test(dataProvider = "oneDay") | ||||
public void testGetUserShareHour(Date date) throws WxErrorException { | public void testGetUserShareHour(Date date) throws WxErrorException { | ||||
List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() | List<WxDataCubeArticleResult> results = this.wxService.getDataCubeService() | ||||
.getUserShareHour(date, date); | |||||
.getUserShareHour(date, date); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@@ -138,7 +129,7 @@ public class WxMpDataCubeServiceImplTest { | |||||
@Test(dataProvider = "sevenDays") | @Test(dataProvider = "sevenDays") | ||||
public void testGetUpstreamMsg(Date beginDate, Date endDate) throws WxErrorException { | public void testGetUpstreamMsg(Date beginDate, Date endDate) throws WxErrorException { | ||||
List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() | List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() | ||||
.getUpstreamMsg(beginDate, endDate); | |||||
.getUpstreamMsg(beginDate, endDate); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@@ -146,7 +137,7 @@ public class WxMpDataCubeServiceImplTest { | |||||
@Test(dataProvider = "oneDay") | @Test(dataProvider = "oneDay") | ||||
public void testGetUpstreamMsgHour(Date date) throws WxErrorException { | public void testGetUpstreamMsgHour(Date date) throws WxErrorException { | ||||
List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() | List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() | ||||
.getUpstreamMsgHour(date, date); | |||||
.getUpstreamMsgHour(date, date); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@@ -154,7 +145,7 @@ public class WxMpDataCubeServiceImplTest { | |||||
@Test(dataProvider = "thirtyDays") | @Test(dataProvider = "thirtyDays") | ||||
public void testGetUpstreamMsgWeek(Date beginDate, Date endDate) throws WxErrorException { | public void testGetUpstreamMsgWeek(Date beginDate, Date endDate) throws WxErrorException { | ||||
List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() | List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() | ||||
.getUpstreamMsgWeek(beginDate, endDate); | |||||
.getUpstreamMsgWeek(beginDate, endDate); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@@ -165,7 +156,7 @@ public class WxMpDataCubeServiceImplTest { | |||||
@Test(dataProvider = "thirtyDays") | @Test(dataProvider = "thirtyDays") | ||||
public void testGetUpstreamMsgMonth(Date beginDate, Date endDate) throws WxErrorException { | public void testGetUpstreamMsgMonth(Date beginDate, Date endDate) throws WxErrorException { | ||||
List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() | List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() | ||||
.getUpstreamMsgMonth(beginDate, endDate); | |||||
.getUpstreamMsgMonth(beginDate, endDate); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@@ -173,7 +164,7 @@ public class WxMpDataCubeServiceImplTest { | |||||
@Test(dataProvider = "fifteenDays") | @Test(dataProvider = "fifteenDays") | ||||
public void testGetUpstreamMsgDist(Date beginDate, Date endDate) throws WxErrorException { | public void testGetUpstreamMsgDist(Date beginDate, Date endDate) throws WxErrorException { | ||||
List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() | List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() | ||||
.getUpstreamMsgDist(beginDate, endDate); | |||||
.getUpstreamMsgDist(beginDate, endDate); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@@ -181,7 +172,7 @@ public class WxMpDataCubeServiceImplTest { | |||||
@Test(dataProvider = "thirtyDays") | @Test(dataProvider = "thirtyDays") | ||||
public void testGetUpstreamMsgDistWeek(Date beginDate, Date endDate) throws WxErrorException { | public void testGetUpstreamMsgDistWeek(Date beginDate, Date endDate) throws WxErrorException { | ||||
List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() | List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() | ||||
.getUpstreamMsgDistWeek(beginDate, endDate); | |||||
.getUpstreamMsgDistWeek(beginDate, endDate); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@@ -192,7 +183,7 @@ public class WxMpDataCubeServiceImplTest { | |||||
@Test(dataProvider = "thirtyDays") | @Test(dataProvider = "thirtyDays") | ||||
public void testGetUpstreamMsgDistMonth(Date beginDate, Date endDate) throws WxErrorException { | public void testGetUpstreamMsgDistMonth(Date beginDate, Date endDate) throws WxErrorException { | ||||
List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() | List<WxDataCubeMsgResult> results = this.wxService.getDataCubeService() | ||||
.getUpstreamMsgDistMonth(beginDate, endDate); | |||||
.getUpstreamMsgDistMonth(beginDate, endDate); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@@ -200,7 +191,7 @@ public class WxMpDataCubeServiceImplTest { | |||||
@Test(dataProvider = "thirtyDays") | @Test(dataProvider = "thirtyDays") | ||||
public void testGetInterfaceSummary(Date beginDate, Date endDate) throws WxErrorException { | public void testGetInterfaceSummary(Date beginDate, Date endDate) throws WxErrorException { | ||||
List<WxDataCubeInterfaceResult> results = this.wxService.getDataCubeService() | List<WxDataCubeInterfaceResult> results = this.wxService.getDataCubeService() | ||||
.getInterfaceSummary(beginDate, endDate); | |||||
.getInterfaceSummary(beginDate, endDate); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@@ -208,7 +199,7 @@ public class WxMpDataCubeServiceImplTest { | |||||
@Test(dataProvider = "oneDay") | @Test(dataProvider = "oneDay") | ||||
public void testGetInterfaceSummaryHour(Date date) throws WxErrorException { | public void testGetInterfaceSummaryHour(Date date) throws WxErrorException { | ||||
List<WxDataCubeInterfaceResult> results = this.wxService.getDataCubeService() | List<WxDataCubeInterfaceResult> results = this.wxService.getDataCubeService() | ||||
.getInterfaceSummaryHour(date, date); | |||||
.getInterfaceSummaryHour(date, date); | |||||
Assert.assertNotNull(results); | Assert.assertNotNull(results); | ||||
System.out.println(results); | System.out.println(results); | ||||
} | } | ||||
@@ -3,12 +3,10 @@ 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.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | |||||
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.Guice; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.annotations.*; | |||||
/** | /** | ||||
* Created by keungtung on 14/12/2016. | * Created by keungtung on 14/12/2016. | ||||
@@ -3,25 +3,23 @@ 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.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.api.test.TestConfigStorage; | 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.*; | ||||
import org.joda.time.DateTime; | import org.joda.time.DateTime; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.DataProvider; | |||||
import org.testng.annotations.Guice; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
import java.io.File; | import java.io.File; | ||||
import java.util.Date; | import java.util.Date; | ||||
/** | /** | ||||
* 测试客服相关接口 | * 测试客服相关接口 | ||||
* @author Binary Wang | |||||
* | * | ||||
* @author Binary Wang | |||||
*/ | */ | ||||
@Test | @Test | ||||
@Guice(modules = ApiTestModule.class) | @Guice(modules = ApiTestModule.class) | ||||
@@ -43,25 +41,25 @@ public class WxMpKefuServiceImplTest { | |||||
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.CUSTOM_MSG_TEXT); | message.setMsgType(WxConsts.CUSTOM_MSG_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); | this.wxService.getKefuService().sendKefuMessage(message); | ||||
} | } | ||||
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.CUSTOM_MSG_TEXT); | message.setMsgType(WxConsts.CUSTOM_MSG_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); | this.wxService.getKefuService().sendKefuMessage(message); | ||||
} | } | ||||
@@ -76,7 +74,7 @@ public class WxMpKefuServiceImplTest { | |||||
public void testKfOnlineList() throws WxErrorException { | public void testKfOnlineList() throws WxErrorException { | ||||
WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService() | WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService() | ||||
.kfOnlineList(); | |||||
.kfOnlineList(); | |||||
Assert.assertNotNull(kfOnlineList); | Assert.assertNotNull(kfOnlineList); | ||||
for (WxMpKfInfo k : kfOnlineList.getKfOnlineList()) { | for (WxMpKfInfo k : kfOnlineList.getKfOnlineList()) { | ||||
System.err.println(k); | System.err.println(k); | ||||
@@ -86,40 +84,40 @@ public class WxMpKefuServiceImplTest { | |||||
@DataProvider | @DataProvider | ||||
public Object[][] getKfAccount() { | public Object[][] getKfAccount() { | ||||
TestConfigStorage configStorage = (TestConfigStorage) this.wxService | TestConfigStorage configStorage = (TestConfigStorage) this.wxService | ||||
.getWxMpConfigStorage(); | |||||
return new Object[][] { { configStorage.getKfAccount() } }; | |||||
.getWxMpConfigStorage(); | |||||
return new Object[][]{{configStorage.getKfAccount()}}; | |||||
} | } | ||||
@Test(dataProvider = "getKfAccount") | @Test(dataProvider = "getKfAccount") | ||||
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)); | Assert.assertTrue(this.wxService.getKefuService().kfAccountAdd(request)); | ||||
} | } | ||||
@Test(dependsOnMethods = { | @Test(dependsOnMethods = { | ||||
"testKfAccountAdd" }, dataProvider = "getKfAccount") | |||||
"testKfAccountAdd"}, dataProvider = "getKfAccount") | |||||
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)); | Assert.assertTrue(this.wxService.getKefuService().kfAccountUpdate(request)); | ||||
} | } | ||||
@Test(dependsOnMethods = { | @Test(dependsOnMethods = { | ||||
"testKfAccountAdd" }, dataProvider = "getKfAccount") | |||||
"testKfAccountAdd"}, dataProvider = "getKfAccount") | |||||
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)); | Assert.assertTrue(this.wxService.getKefuService().kfAccountInviteWorker(request)); | ||||
} | } | ||||
@Test(dependsOnMethods = { | @Test(dependsOnMethods = { | ||||
"testKfAccountUpdate" }, dataProvider = "getKfAccount") | |||||
"testKfAccountUpdate"}, dataProvider = "getKfAccount") | |||||
public void testKfAccountUploadHeadImg(String kfAccount) | public void testKfAccountUploadHeadImg(String kfAccount) | ||||
throws WxErrorException { | |||||
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); | |||||
Assert.assertTrue(result); | Assert.assertTrue(result); | ||||
} | } | ||||
@@ -132,32 +130,32 @@ public class WxMpKefuServiceImplTest { | |||||
@DataProvider | @DataProvider | ||||
public Object[][] getKfAccountAndOpenid() { | public Object[][] getKfAccountAndOpenid() { | ||||
TestConfigStorage configStorage = (TestConfigStorage) this.wxService | TestConfigStorage configStorage = (TestConfigStorage) this.wxService | ||||
.getWxMpConfigStorage(); | |||||
return new Object[][] { | |||||
{ configStorage.getKfAccount(), configStorage.getOpenid() } }; | |||||
.getWxMpConfigStorage(); | |||||
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, | boolean result = this.wxService.getKefuService().kfSessionCreate(openid, | ||||
kfAccount); | |||||
kfAccount); | |||||
Assert.assertTrue(result); | 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); | |||||
Assert.assertTrue(result); | 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() | WxMpKfSessionGetResult result = this.wxService.getKefuService() | ||||
.kfSessionGet(openid); | |||||
.kfSessionGet(openid); | |||||
Assert.assertNotNull(result); | Assert.assertNotNull(result); | ||||
System.err.println(result); | System.err.println(result); | ||||
} | } | ||||
@@ -165,7 +163,7 @@ public class WxMpKefuServiceImplTest { | |||||
@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); | |||||
Assert.assertNotNull(result); | Assert.assertNotNull(result); | ||||
System.err.println(result); | System.err.println(result); | ||||
} | } | ||||
@@ -173,7 +171,7 @@ public class WxMpKefuServiceImplTest { | |||||
@Test | @Test | ||||
public void testKfSessionGetWaitCase() throws WxErrorException { | public void testKfSessionGetWaitCase() throws WxErrorException { | ||||
WxMpKfSessionWaitCaseList result = this.wxService.getKefuService() | WxMpKfSessionWaitCaseList result = this.wxService.getKefuService() | ||||
.kfSessionGetWaitCase(); | |||||
.kfSessionGetWaitCase(); | |||||
Assert.assertNotNull(result); | Assert.assertNotNull(result); | ||||
System.err.println(result); | System.err.println(result); | ||||
} | } | ||||
@@ -182,7 +180,7 @@ public class WxMpKefuServiceImplTest { | |||||
public void testKfMsgList() throws WxErrorException { | public void testKfMsgList() throws WxErrorException { | ||||
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); | Assert.assertNotNull(result); | ||||
System.err.println(result); | System.err.println(result); | ||||
} | } | ||||
@@ -191,7 +189,7 @@ public class WxMpKefuServiceImplTest { | |||||
public void testKfMsgListAll() throws WxErrorException { | public void testKfMsgListAll() throws WxErrorException { | ||||
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); | Assert.assertNotNull(result); | ||||
System.err.println(result); | System.err.println(result); | ||||
} | } | ||||
@@ -5,15 +5,10 @@ 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.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.WxMpMaterialArticleUpdate; | |||||
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; | |||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.bean.material.*; | import me.chanjar.weixin.mp.bean.material.*; | ||||
import org.testng.annotations.DataProvider; | |||||
import org.testng.annotations.Guice; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.annotations.*; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
@@ -44,14 +39,16 @@ public class WxMpMaterialServiceImplTest { | |||||
private String multiNewsMediaId = ""; | private String multiNewsMediaId = ""; | ||||
// 先查询保存测试开始前永久素材数据 | // 先查询保存测试开始前永久素材数据 | ||||
private WxMpMaterialCountResult wxMaterialCountResultBeforeTest; | private WxMpMaterialCountResult wxMaterialCountResultBeforeTest; | ||||
// 以下为media接口的测试 | |||||
private List<String> mediaIdsToDownload = new ArrayList<>(); | |||||
@DataProvider | @DataProvider | ||||
public Object[][] mediaFiles() { | public Object[][] mediaFiles() { | ||||
return new Object[][] { | |||||
new Object[] { WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, "mm.jpeg" }, | |||||
new Object[] { WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, "mm.mp3" }, | |||||
new Object[] { WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, "mm.mp4" }, | |||||
new Object[] { WxConsts.MEDIA_THUMB, WxConsts.FILE_JPG, "mm.jpeg" } | |||||
return new Object[][]{ | |||||
new Object[]{WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, "mm.jpeg"}, | |||||
new Object[]{WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, "mm.mp3"}, | |||||
new Object[]{WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, "mm.mp4"}, | |||||
new Object[]{WxConsts.MEDIA_THUMB, WxConsts.FILE_JPG, "mm.jpeg"} | |||||
}; | }; | ||||
} | } | ||||
@@ -59,13 +56,13 @@ public class WxMpMaterialServiceImplTest { | |||||
public void testUploadMaterial(String mediaType, String fileType, String fileName) throws WxErrorException, IOException { | public void testUploadMaterial(String mediaType, String fileType, String fileName) throws WxErrorException, IOException { | ||||
if (this.wxMaterialCountResultBeforeTest == null) { | if (this.wxMaterialCountResultBeforeTest == null) { | ||||
this.wxMaterialCountResultBeforeTest = this.wxService.getMaterialService() | this.wxMaterialCountResultBeforeTest = this.wxService.getMaterialService() | ||||
.materialCount(); | |||||
.materialCount(); | |||||
} | } | ||||
try (InputStream inputStream = ClassLoader | try (InputStream inputStream = ClassLoader | ||||
.getSystemResourceAsStream(fileName)) { | |||||
.getSystemResourceAsStream(fileName)) { | |||||
File tempFile = FileUtils.createTmpFile(inputStream, | File tempFile = FileUtils.createTmpFile(inputStream, | ||||
UUID.randomUUID().toString(), fileType); | |||||
UUID.randomUUID().toString(), fileType); | |||||
WxMpMaterial wxMaterial = new WxMpMaterial(); | WxMpMaterial wxMaterial = new WxMpMaterial(); | ||||
wxMaterial.setFile(tempFile); | wxMaterial.setFile(tempFile); | ||||
wxMaterial.setName(fileName); | wxMaterial.setName(fileName); | ||||
@@ -75,11 +72,11 @@ public class WxMpMaterialServiceImplTest { | |||||
} | } | ||||
WxMpMaterialUploadResult res = this.wxService.getMaterialService() | WxMpMaterialUploadResult res = this.wxService.getMaterialService() | ||||
.materialFileUpload(mediaType, wxMaterial); | |||||
.materialFileUpload(mediaType, wxMaterial); | |||||
assertNotNull(res.getMediaId()); | assertNotNull(res.getMediaId()); | ||||
if (WxConsts.MEDIA_IMAGE.equals(mediaType) | if (WxConsts.MEDIA_IMAGE.equals(mediaType) | ||||
|| WxConsts.MEDIA_THUMB.equals(mediaType)) { | |||||
|| WxConsts.MEDIA_THUMB.equals(mediaType)) { | |||||
assertNotNull(res.getUrl()); | assertNotNull(res.getUrl()); | ||||
} | } | ||||
@@ -145,16 +142,16 @@ public class WxMpMaterialServiceImplTest { | |||||
WxMpMaterialCountResult wxMaterialCountResult = this.wxService.getMaterialService().materialCount(); | WxMpMaterialCountResult wxMaterialCountResult = this.wxService.getMaterialService().materialCount(); | ||||
// 测试上传过程中添加了一个音频,一个视频,两个图片,两个图文消息 | // 测试上传过程中添加了一个音频,一个视频,两个图片,两个图文消息 | ||||
assertEquals( | assertEquals( | ||||
this.wxMaterialCountResultBeforeTest.getVoiceCount() + 1, | |||||
wxMaterialCountResult.getVoiceCount()); | |||||
this.wxMaterialCountResultBeforeTest.getVoiceCount() + 1, | |||||
wxMaterialCountResult.getVoiceCount()); | |||||
assertEquals( | assertEquals( | ||||
this.wxMaterialCountResultBeforeTest.getVideoCount() + 1, | |||||
wxMaterialCountResult.getVideoCount()); | |||||
this.wxMaterialCountResultBeforeTest.getVideoCount() + 1, | |||||
wxMaterialCountResult.getVideoCount()); | |||||
assertEquals( | assertEquals( | ||||
this.wxMaterialCountResultBeforeTest.getImageCount() + 2, | |||||
wxMaterialCountResult.getImageCount()); | |||||
this.wxMaterialCountResultBeforeTest.getImageCount() + 2, | |||||
wxMaterialCountResult.getImageCount()); | |||||
assertEquals(this.wxMaterialCountResultBeforeTest.getNewsCount() + 2, | assertEquals(this.wxMaterialCountResultBeforeTest.getNewsCount() + 2, | ||||
wxMaterialCountResult.getNewsCount()); | |||||
wxMaterialCountResult.getNewsCount()); | |||||
} | } | ||||
@Test(dependsOnMethods = {"testMaterialCount"}, dataProvider = "downloadMaterial") | @Test(dependsOnMethods = {"testMaterialCount"}, dataProvider = "downloadMaterial") | ||||
@@ -164,7 +161,7 @@ public class WxMpMaterialServiceImplTest { | |||||
String filename = materialInfo.get("filename").toString(); | String filename = materialInfo.get("filename").toString(); | ||||
if (filename.endsWith(".mp3") || filename.endsWith(".jpeg")) { | if (filename.endsWith(".mp3") || filename.endsWith(".jpeg")) { | ||||
try (InputStream inputStream = this.wxService.getMaterialService() | try (InputStream inputStream = this.wxService.getMaterialService() | ||||
.materialImageOrVoiceDownload(mediaId)) { | |||||
.materialImageOrVoiceDownload(mediaId)) { | |||||
assertNotNull(inputStream); | assertNotNull(inputStream); | ||||
} | } | ||||
} | } | ||||
@@ -178,9 +175,9 @@ public class WxMpMaterialServiceImplTest { | |||||
@Test(dependsOnMethods = {"testAddNews"}) | @Test(dependsOnMethods = {"testAddNews"}) | ||||
public void testGetNewsInfo() throws WxErrorException { | public void testGetNewsInfo() throws WxErrorException { | ||||
WxMpMaterialNews wxMpMaterialNewsSingle = this.wxService | WxMpMaterialNews wxMpMaterialNewsSingle = this.wxService | ||||
.getMaterialService().materialNewsInfo(this.singleNewsMediaId); | |||||
.getMaterialService().materialNewsInfo(this.singleNewsMediaId); | |||||
WxMpMaterialNews wxMpMaterialNewsMultiple = this.wxService | WxMpMaterialNews wxMpMaterialNewsMultiple = this.wxService | ||||
.getMaterialService().materialNewsInfo(this.multiNewsMediaId); | |||||
.getMaterialService().materialNewsInfo(this.multiNewsMediaId); | |||||
assertNotNull(wxMpMaterialNewsSingle); | assertNotNull(wxMpMaterialNewsSingle); | ||||
assertNotNull(wxMpMaterialNewsMultiple); | assertNotNull(wxMpMaterialNewsMultiple); | ||||
} | } | ||||
@@ -188,7 +185,7 @@ public class WxMpMaterialServiceImplTest { | |||||
@Test(dependsOnMethods = {"testGetNewsInfo"}) | @Test(dependsOnMethods = {"testGetNewsInfo"}) | ||||
public void testUpdateNewsInfo() throws WxErrorException { | public void testUpdateNewsInfo() throws WxErrorException { | ||||
WxMpMaterialNews wxMpMaterialNewsSingle = this.wxService | WxMpMaterialNews wxMpMaterialNewsSingle = this.wxService | ||||
.getMaterialService().materialNewsInfo(this.singleNewsMediaId); | |||||
.getMaterialService().materialNewsInfo(this.singleNewsMediaId); | |||||
assertNotNull(wxMpMaterialNewsSingle); | assertNotNull(wxMpMaterialNewsSingle); | ||||
WxMpMaterialArticleUpdate wxMpMaterialArticleUpdateSingle = new WxMpMaterialArticleUpdate(); | WxMpMaterialArticleUpdate wxMpMaterialArticleUpdateSingle = new WxMpMaterialArticleUpdate(); | ||||
WxMpMaterialNews.WxMpMaterialNewsArticle articleSingle = wxMpMaterialNewsSingle.getArticles().get(0); | WxMpMaterialNews.WxMpMaterialNewsArticle articleSingle = wxMpMaterialNewsSingle.getArticles().get(0); | ||||
@@ -199,13 +196,13 @@ public class WxMpMaterialServiceImplTest { | |||||
boolean resultSingle = this.wxService.getMaterialService().materialNewsUpdate(wxMpMaterialArticleUpdateSingle); | boolean resultSingle = this.wxService.getMaterialService().materialNewsUpdate(wxMpMaterialArticleUpdateSingle); | ||||
assertTrue(resultSingle); | assertTrue(resultSingle); | ||||
wxMpMaterialNewsSingle = this.wxService.getMaterialService() | wxMpMaterialNewsSingle = this.wxService.getMaterialService() | ||||
.materialNewsInfo(this.singleNewsMediaId); | |||||
.materialNewsInfo(this.singleNewsMediaId); | |||||
assertNotNull(wxMpMaterialNewsSingle); | assertNotNull(wxMpMaterialNewsSingle); | ||||
assertEquals("content single update", | assertEquals("content single update", | ||||
wxMpMaterialNewsSingle.getArticles().get(0).getContent()); | |||||
wxMpMaterialNewsSingle.getArticles().get(0).getContent()); | |||||
WxMpMaterialNews wxMpMaterialNewsMultiple = this.wxService | WxMpMaterialNews wxMpMaterialNewsMultiple = this.wxService | ||||
.getMaterialService().materialNewsInfo(this.multiNewsMediaId); | |||||
.getMaterialService().materialNewsInfo(this.multiNewsMediaId); | |||||
assertNotNull(wxMpMaterialNewsMultiple); | assertNotNull(wxMpMaterialNewsMultiple); | ||||
WxMpMaterialArticleUpdate wxMpMaterialArticleUpdateMulti = new WxMpMaterialArticleUpdate(); | WxMpMaterialArticleUpdate wxMpMaterialArticleUpdateMulti = new WxMpMaterialArticleUpdate(); | ||||
WxMpMaterialNews.WxMpMaterialNewsArticle articleMulti = wxMpMaterialNewsMultiple.getArticles().get(1); | WxMpMaterialNews.WxMpMaterialNewsArticle articleMulti = wxMpMaterialNewsMultiple.getArticles().get(1); | ||||
@@ -216,10 +213,10 @@ public class WxMpMaterialServiceImplTest { | |||||
boolean resultMulti = this.wxService.getMaterialService().materialNewsUpdate(wxMpMaterialArticleUpdateMulti); | boolean resultMulti = this.wxService.getMaterialService().materialNewsUpdate(wxMpMaterialArticleUpdateMulti); | ||||
assertTrue(resultMulti); | assertTrue(resultMulti); | ||||
wxMpMaterialNewsMultiple = this.wxService.getMaterialService() | wxMpMaterialNewsMultiple = this.wxService.getMaterialService() | ||||
.materialNewsInfo(this.multiNewsMediaId); | |||||
.materialNewsInfo(this.multiNewsMediaId); | |||||
assertNotNull(wxMpMaterialNewsMultiple); | assertNotNull(wxMpMaterialNewsMultiple); | ||||
assertEquals("content 2 update", | assertEquals("content 2 update", | ||||
wxMpMaterialNewsMultiple.getArticles().get(1).getContent()); | |||||
wxMpMaterialNewsMultiple.getArticles().get(1).getContent()); | |||||
} | } | ||||
@Test(dependsOnMethods = {"testUpdateNewsInfo"}) | @Test(dependsOnMethods = {"testUpdateNewsInfo"}) | ||||
@@ -266,12 +263,9 @@ public class WxMpMaterialServiceImplTest { | |||||
return params.iterator(); | return params.iterator(); | ||||
} | } | ||||
// 以下为media接口的测试 | |||||
private List<String> mediaIdsToDownload = new ArrayList<>(); | |||||
@Test(dataProvider="mediaFiles") | |||||
@Test(dataProvider = "mediaFiles") | |||||
public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException { | public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException { | ||||
try(InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName)){ | |||||
try (InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName)) { | |||||
WxMediaUploadResult res = this.wxService.getMaterialService().mediaUpload(mediaType, fileType, inputStream); | WxMediaUploadResult res = this.wxService.getMaterialService().mediaUpload(mediaType, fileType, inputStream); | ||||
assertNotNull(res.getType()); | assertNotNull(res.getType()); | ||||
assertNotNull(res.getCreatedAt()); | assertNotNull(res.getCreatedAt()); | ||||
@@ -294,12 +288,12 @@ public class WxMpMaterialServiceImplTest { | |||||
public Object[][] downloadMedia() { | public Object[][] downloadMedia() { | ||||
Object[][] params = new Object[this.mediaIdsToDownload.size()][]; | Object[][] params = new Object[this.mediaIdsToDownload.size()][]; | ||||
for (int i = 0; i < this.mediaIdsToDownload.size(); i++) { | for (int i = 0; i < this.mediaIdsToDownload.size(); i++) { | ||||
params[i] = new Object[] { this.mediaIdsToDownload.get(i) }; | |||||
params[i] = new Object[]{this.mediaIdsToDownload.get(i)}; | |||||
} | } | ||||
return params; | return params; | ||||
} | } | ||||
@Test(dependsOnMethods = { "testUploadMedia" }, dataProvider="downloadMedia") | |||||
@Test(dependsOnMethods = {"testUploadMedia"}, dataProvider = "downloadMedia") | |||||
public void testDownloadMedia(String mediaId) throws WxErrorException { | public void testDownloadMedia(String mediaId) throws WxErrorException { | ||||
File file = this.wxService.getMaterialService().mediaDownload(mediaId); | File file = this.wxService.getMaterialService().mediaDownload(mediaId); | ||||
assertNotNull(file); | assertNotNull(file); | ||||
@@ -5,8 +5,8 @@ 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.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | |||||
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; | ||||
import org.testng.*; | import org.testng.*; | ||||
@@ -3,8 +3,8 @@ 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.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.api.test.TestConfigStorage; | 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.*; | ||||
@@ -36,10 +36,10 @@ public class WxMpPayServiceImplTest { | |||||
@Test | @Test | ||||
public void testDownloadBill() throws Exception { | public void testDownloadBill() throws Exception { | ||||
File file = this.wxService.getPayService().downloadBill("20170101","ALL","GZIP","1111111"); | |||||
File file = this.wxService.getPayService().downloadBill("20170101", "ALL", "GZIP", "1111111"); | |||||
assertNotNull(file); | assertNotNull(file); | ||||
//必填字段为空时,抛出异常 | //必填字段为空时,抛出异常 | ||||
this.wxService.getPayService().downloadBill("","","",null); | |||||
this.wxService.getPayService().downloadBill("", "", "", null); | |||||
} | } | ||||
@Test | @Test | ||||
@@ -58,7 +58,7 @@ public class WxMpPayServiceImplTest { | |||||
* 需要证书的接口需要先执行该方法 | * 需要证书的接口需要先执行该方法 | ||||
*/ | */ | ||||
@Test | @Test | ||||
public void setSSLKey(){ | |||||
public void setSSLKey() { | |||||
TestConfigStorage config = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); | TestConfigStorage config = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); | ||||
config.setSslContextFilePath(config.getKeyPath()); | config.setSslContextFilePath(config.getKeyPath()); | ||||
} | } | ||||
@@ -2,13 +2,11 @@ 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.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; | import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.DataProvider; | |||||
import org.testng.annotations.Guice; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
import java.io.File; | import java.io.File; | ||||
@@ -2,12 +2,11 @@ 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.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.api.test.TestConfigStorage; | import me.chanjar.weixin.mp.api.test.TestConfigStorage; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Guice; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
@Test | @Test | ||||
@Guice(modules = ApiTestModule.class) | @Guice(modules = ApiTestModule.class) | ||||
@@ -105,7 +104,7 @@ public class WxMpServiceImplTest { | |||||
public void testBuildQrConnectUrl() { | public void testBuildQrConnectUrl() { | ||||
String qrconnectRedirectUrl = ((TestConfigStorage) 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); | ||||
System.out.println(qrConnectUrl); | System.out.println(qrConnectUrl); | ||||
} | } | ||||
@@ -2,13 +2,12 @@ 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.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | |||||
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; | ||||
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult; | import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult; | ||||
import org.testng.annotations.Guice; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.annotations.*; | |||||
import java.math.BigDecimal; | import java.math.BigDecimal; | ||||
import java.util.List; | import java.util.List; | ||||
@@ -18,7 +17,6 @@ import static org.junit.Assert.assertNotNull; | |||||
/** | /** | ||||
* @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a> | * @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a> | ||||
* Created by Binary Wang on 2016-09-23. | * Created by Binary Wang on 2016-09-23. | ||||
* | |||||
*/ | */ | ||||
@Test | @Test | ||||
@Guice(modules = ApiTestModule.class) | @Guice(modules = ApiTestModule.class) | ||||
@@ -28,16 +26,17 @@ public class WxMpStoreServiceImplTest { | |||||
/** | /** | ||||
* Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpStoreServiceImpl#add(me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo)}. | * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpStoreServiceImpl#add(me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo)}. | ||||
* | |||||
* @throws WxErrorException | * @throws WxErrorException | ||||
*/ | */ | ||||
public void testAdd() throws WxErrorException { | public void testAdd() throws WxErrorException { | ||||
this.wxMpService.getStoreService().add(WxMpStoreBaseInfo.builder().build()); | this.wxMpService.getStoreService().add(WxMpStoreBaseInfo.builder().build()); | ||||
this.wxMpService.getStoreService() | this.wxMpService.getStoreService() | ||||
.add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc") | |||||
.province("aaa").district("aaa").telephone("122").address("abc").categories(new String[] { "美食,江浙菜" }) | |||||
.longitude(new BigDecimal("115.32375")) | |||||
.latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1) | |||||
.build()); | |||||
.add(WxMpStoreBaseInfo.builder().businessName("haha").branchName("abc") | |||||
.province("aaa").district("aaa").telephone("122").address("abc").categories(new String[]{"美食,江浙菜"}) | |||||
.longitude(new BigDecimal("115.32375")) | |||||
.latitude(new BigDecimal("25.097486")).city("aaa").offsetType(1) | |||||
.build()); | |||||
} | } | ||||
public void testUpdate() throws WxErrorException { | public void testUpdate() throws WxErrorException { | ||||
@@ -2,17 +2,16 @@ 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.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.api.test.TestConfigStorage; | 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; | ||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; | import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage; | ||||
import org.apache.commons.lang3.RandomStringUtils; | import org.apache.commons.lang3.RandomStringUtils; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Guice; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
import java.util.Date; | import java.util.Date; | ||||
@@ -39,7 +38,7 @@ public class WxMpTemplateMsgServiceImplTest { | |||||
.toUser(configStorage.getOpenid()) | .toUser(configStorage.getOpenid()) | ||||
.templateId(configStorage.getTemplateId()).build(); | .templateId(configStorage.getTemplateId()).build(); | ||||
templateMessage.addWxMpTemplateData( | templateMessage.addWxMpTemplateData( | ||||
new WxMpTemplateData("first", dateFormat.format(new Date()),"#FF00FF")); | |||||
new WxMpTemplateData("first", dateFormat.format(new Date()), "#FF00FF")); | |||||
templateMessage.addWxMpTemplateData( | templateMessage.addWxMpTemplateData( | ||||
new WxMpTemplateData("remark", RandomStringUtils.randomAlphanumeric(100), "#FF00FF")); | new WxMpTemplateData("remark", RandomStringUtils.randomAlphanumeric(100), "#FF00FF")); | ||||
templateMessage.setUrl(" "); | templateMessage.setUrl(" "); | ||||
@@ -58,7 +57,7 @@ public class WxMpTemplateMsgServiceImplTest { | |||||
@Test | @Test | ||||
public void testSetIndustry() throws Exception { | public void testSetIndustry() throws Exception { | ||||
WxMpTemplateIndustry industry = new WxMpTemplateIndustry(new WxMpTemplateIndustry.Industry("1"), | WxMpTemplateIndustry industry = new WxMpTemplateIndustry(new WxMpTemplateIndustry.Industry("1"), | ||||
new WxMpTemplateIndustry.Industry("04")); | |||||
new WxMpTemplateIndustry.Industry("04")); | |||||
boolean result = this.wxService.getTemplateMsgService().setIndustry(industry); | boolean result = this.wxService.getTemplateMsgService().setIndustry(industry); | ||||
Assert.assertTrue(result); | Assert.assertTrue(result); | ||||
} | } | ||||
@@ -1,12 +1,11 @@ | |||||
package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
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.test.ApiTestModule; | |||||
import me.chanjar.weixin.mp.api.test.TestConfigStorage; | 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.annotations.Guice; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
import javax.inject.Inject; | import javax.inject.Inject; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
@@ -1,23 +1,18 @@ | |||||
package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import me.chanjar.weixin.mp.api.WxMpService; | |||||
import org.testng.Assert; | |||||
import org.testng.annotations.BeforeTest; | |||||
import org.testng.annotations.Guice; | |||||
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.WxMpService; | |||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | import me.chanjar.weixin.mp.api.test.ApiTestModule; | ||||
import me.chanjar.weixin.mp.api.test.TestConfigStorage; | 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; | ||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
/** | /** | ||||
* 测试用户相关的接口 | * 测试用户相关的接口 | ||||
@@ -37,17 +32,17 @@ public class WxMpUserServiceImplTest { | |||||
@BeforeTest | @BeforeTest | ||||
public void setup() { | public void setup() { | ||||
this.configProvider = (TestConfigStorage) this.wxService | this.configProvider = (TestConfigStorage) this.wxService | ||||
.getWxMpConfigStorage(); | |||||
.getWxMpConfigStorage(); | |||||
} | } | ||||
public void testUserUpdateRemark() throws WxErrorException { | public void testUserUpdateRemark() throws WxErrorException { | ||||
this.wxService.getUserService() | this.wxService.getUserService() | ||||
.userUpdateRemark(this.configProvider.getOpenid(), "测试备注名"); | |||||
.userUpdateRemark(this.configProvider.getOpenid(), "测试备注名"); | |||||
} | } | ||||
public void testUserInfo() throws WxErrorException { | public void testUserInfo() throws WxErrorException { | ||||
WxMpUser user = this.wxService.getUserService() | WxMpUser user = this.wxService.getUserService() | ||||
.userInfo(this.configProvider.getOpenid(), null); | |||||
.userInfo(this.configProvider.getOpenid(), null); | |||||
Assert.assertNotNull(user); | Assert.assertNotNull(user); | ||||
System.out.println(user); | System.out.println(user); | ||||
} | } | ||||
@@ -56,7 +51,7 @@ public class WxMpUserServiceImplTest { | |||||
List<String> openids = new ArrayList<>(); | List<String> openids = new ArrayList<>(); | ||||
openids.add(this.configProvider.getOpenid()); | openids.add(this.configProvider.getOpenid()); | ||||
List<WxMpUser> userList = this.wxService.getUserService() | List<WxMpUser> userList = this.wxService.getUserService() | ||||
.userInfoList(openids); | |||||
.userInfoList(openids); | |||||
Assert.assertEquals(userList.size(), 1); | Assert.assertEquals(userList.size(), 1); | ||||
System.out.println(userList); | System.out.println(userList); | ||||
} | } | ||||
@@ -65,7 +60,7 @@ public class WxMpUserServiceImplTest { | |||||
WxMpUserQuery query = new WxMpUserQuery(); | WxMpUserQuery query = new WxMpUserQuery(); | ||||
query.add(this.configProvider.getOpenid(), "zh_CN"); | query.add(this.configProvider.getOpenid(), "zh_CN"); | ||||
List<WxMpUser> userList = this.wxService.getUserService() | List<WxMpUser> userList = this.wxService.getUserService() | ||||
.userInfoList(query); | |||||
.userInfoList(query); | |||||
Assert.assertEquals(userList.size(), 1); | Assert.assertEquals(userList.size(), 1); | ||||
System.out.println(userList); | System.out.println(userList); | ||||
} | } | ||||
@@ -1,21 +1,17 @@ | |||||
package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
import java.util.List; | |||||
import me.chanjar.weixin.mp.api.WxMpService; | |||||
import org.testng.Assert; | |||||
import org.testng.annotations.Guice; | |||||
import org.testng.annotations.Test; | |||||
import com.google.inject.Inject; | import com.google.inject.Inject; | ||||
import me.chanjar.weixin.mp.api.WxMpService; | |||||
import me.chanjar.weixin.mp.api.test.ApiTestModule; | import me.chanjar.weixin.mp.api.test.ApiTestModule; | ||||
import me.chanjar.weixin.mp.api.test.TestConfigStorage; | 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; | ||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
import java.util.List; | |||||
/** | /** | ||||
* | |||||
* @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a> | * @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a> | ||||
* Created by Binary Wang on 2016/9/2. | * Created by Binary Wang on 2016/9/2. | ||||
*/ | */ | ||||
@@ -43,7 +39,7 @@ public class WxMpUserTagServiceImplTest { | |||||
Assert.assertNotNull(res); | Assert.assertNotNull(res); | ||||
} | } | ||||
@Test(dependsOnMethods = { "testTagCreate" }) | |||||
@Test(dependsOnMethods = {"testTagCreate"}) | |||||
public void testTagUpdate() throws Exception { | public void testTagUpdate() throws Exception { | ||||
String tagName = "修改标签" + System.currentTimeMillis(); | String tagName = "修改标签" + System.currentTimeMillis(); | ||||
Boolean res = this.wxService.getUserTagService().tagUpdate(this.tagId, tagName); | Boolean res = this.wxService.getUserTagService().tagUpdate(this.tagId, tagName); | ||||
@@ -51,7 +47,7 @@ public class WxMpUserTagServiceImplTest { | |||||
Assert.assertTrue(res); | Assert.assertTrue(res); | ||||
} | } | ||||
@Test(dependsOnMethods = { "testTagCreate" }) | |||||
@Test(dependsOnMethods = {"testTagCreate"}) | |||||
public void testTagDelete() throws Exception { | public void testTagDelete() throws Exception { | ||||
Boolean res = this.wxService.getUserTagService().tagDelete(this.tagId); | Boolean res = this.wxService.getUserTagService().tagDelete(this.tagId); | ||||
System.out.println(res); | System.out.println(res); | ||||
@@ -84,7 +80,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( | ||||
((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); | |||||
((TestConfigStorage) this.wxService.getWxMpConfigStorage()).getOpenid()); | |||||
System.out.println(res); | System.out.println(res); | ||||
Assert.assertNotNull(res); | Assert.assertNotNull(res); | ||||
} | } | ||||
@@ -2,8 +2,8 @@ package me.chanjar.weixin.mp.bean.kefu; | |||||
import me.chanjar.weixin.common.api.WxConsts; | import me.chanjar.weixin.common.api.WxConsts; | ||||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage.WxArticle; | import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage.WxArticle; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
@Test | @Test | ||||
public class WxMpKefuMessageTest { | public class WxMpKefuMessageTest { | ||||
@@ -77,13 +77,13 @@ public class WxMpKefuMessageTest { | |||||
public void testMusicBuild() { | public void testMusicBuild() { | ||||
WxMpKefuMessage reply = WxMpKefuMessage.MUSIC() | WxMpKefuMessage reply = WxMpKefuMessage.MUSIC() | ||||
.toUser("OPENID") | |||||
.title("TITLE") | |||||
.thumbMediaId("MEDIA_ID") | |||||
.description("DESCRIPTION") | |||||
.musicUrl("MUSIC_URL") | |||||
.hqMusicUrl("HQ_MUSIC_URL") | |||||
.build(); | |||||
.toUser("OPENID") | |||||
.title("TITLE") | |||||
.thumbMediaId("MEDIA_ID") | |||||
.description("DESCRIPTION") | |||||
.musicUrl("MUSIC_URL") | |||||
.hqMusicUrl("HQ_MUSIC_URL") | |||||
.build(); | |||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}"); | Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}"); | ||||
} | } | ||||
@@ -1,36 +1,36 @@ | |||||
package me.chanjar.weixin.mp.bean.kefu.result; | package me.chanjar.weixin.mp.bean.kefu.result; | ||||
import org.apache.commons.lang3.builder.ToStringBuilder; | import org.apache.commons.lang3.builder.ToStringBuilder; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
@Test | @Test | ||||
public class WxMpKfListTest { | public class WxMpKfListTest { | ||||
public void testFromJson() { | public void testFromJson() { | ||||
String json=" {\r\n" + | |||||
" \"kf_list\" : [\r\n" + | |||||
" {\r\n" + | |||||
" \"kf_account\" : \"test1@test\",\r\n" + | |||||
" \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + | |||||
" \"kf_id\" : \"1001\",\r\n" + | |||||
" \"kf_nick\" : \"ntest1\"\r\n" + | |||||
" },\r\n" + | |||||
" {\r\n" + | |||||
" \"kf_account\" : \"test2@test\",\r\n" + | |||||
" \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + | |||||
" \"kf_id\" : \"1002\",\r\n" + | |||||
" \"kf_nick\" : \"ntest2\"\r\n" + | |||||
" },\r\n" + | |||||
" {\r\n" + | |||||
" \"kf_account\" : \"test3@test\",\r\n" + | |||||
" \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + | |||||
" \"kf_id\" : \"1003\",\r\n" + | |||||
" \"kf_nick\" : \"ntest3\"\r\n" + | |||||
" }\r\n" + | |||||
" ]\r\n" + | |||||
" }"; | |||||
String json = " {\r\n" + | |||||
" \"kf_list\" : [\r\n" + | |||||
" {\r\n" + | |||||
" \"kf_account\" : \"test1@test\",\r\n" + | |||||
" \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + | |||||
" \"kf_id\" : \"1001\",\r\n" + | |||||
" \"kf_nick\" : \"ntest1\"\r\n" + | |||||
" },\r\n" + | |||||
" {\r\n" + | |||||
" \"kf_account\" : \"test2@test\",\r\n" + | |||||
" \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + | |||||
" \"kf_id\" : \"1002\",\r\n" + | |||||
" \"kf_nick\" : \"ntest2\"\r\n" + | |||||
" },\r\n" + | |||||
" {\r\n" + | |||||
" \"kf_account\" : \"test3@test\",\r\n" + | |||||
" \"kf_headimgurl\" : \"http://mmbiz.qpic.cn/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjfUS8Ym0GSaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\",\r\n" + | |||||
" \"kf_id\" : \"1003\",\r\n" + | |||||
" \"kf_nick\" : \"ntest3\"\r\n" + | |||||
" }\r\n" + | |||||
" ]\r\n" + | |||||
" }"; | |||||
WxMpKfList wxMpKfList = WxMpKfList.fromJson(json); | WxMpKfList wxMpKfList = WxMpKfList.fromJson(json); | ||||
Assert.assertNotNull(wxMpKfList); | Assert.assertNotNull(wxMpKfList); | ||||
System.err.println(ToStringBuilder.reflectionToString(wxMpKfList)); | System.err.println(ToStringBuilder.reflectionToString(wxMpKfList)); | ||||
@@ -1,34 +1,32 @@ | |||||
package me.chanjar.weixin.mp.bean.kefu.result; | package me.chanjar.weixin.mp.bean.kefu.result; | ||||
import org.apache.commons.lang3.builder.ToStringBuilder; | import org.apache.commons.lang3.builder.ToStringBuilder; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
import me.chanjar.weixin.mp.bean.kefu.result.WxMpKfOnlineList; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
@Test | @Test | ||||
public class WxMpKfOnlineListTest { | public class WxMpKfOnlineListTest { | ||||
@Test | @Test | ||||
public void testFromJson() { | public void testFromJson() { | ||||
String json = "{\r\n" + | |||||
" \"kf_online_list\": [\r\n" + | |||||
" {\r\n" + | |||||
" \"kf_account\": \"test1@test\", \r\n" + | |||||
" \"status\": 1, \r\n" + | |||||
" \"kf_id\": \"1001\", \r\n" + | |||||
" \"auto_accept\": 0, \r\n" + | |||||
" \"accepted_case\": 1\r\n" + | |||||
" },\r\n" + | |||||
" {\r\n" + | |||||
" \"kf_account\": \"test2@test\", \r\n" + | |||||
" \"status\": 1, \r\n" + | |||||
" \"kf_id\": \"1002\", \r\n" + | |||||
" \"auto_accept\": 0, \r\n" + | |||||
" \"accepted_case\": 2\r\n" + | |||||
" }\r\n" + | |||||
" ]\r\n" + | |||||
"}"; | |||||
String json = "{\r\n" + | |||||
" \"kf_online_list\": [\r\n" + | |||||
" {\r\n" + | |||||
" \"kf_account\": \"test1@test\", \r\n" + | |||||
" \"status\": 1, \r\n" + | |||||
" \"kf_id\": \"1001\", \r\n" + | |||||
" \"auto_accept\": 0, \r\n" + | |||||
" \"accepted_case\": 1\r\n" + | |||||
" },\r\n" + | |||||
" {\r\n" + | |||||
" \"kf_account\": \"test2@test\", \r\n" + | |||||
" \"status\": 1, \r\n" + | |||||
" \"kf_id\": \"1002\", \r\n" + | |||||
" \"auto_accept\": 0, \r\n" + | |||||
" \"accepted_case\": 2\r\n" + | |||||
" }\r\n" + | |||||
" ]\r\n" + | |||||
"}"; | |||||
WxMpKfOnlineList wxMpKfOnlineList = WxMpKfOnlineList.fromJson(json); | WxMpKfOnlineList wxMpKfOnlineList = WxMpKfOnlineList.fromJson(json); | ||||
Assert.assertNotNull(wxMpKfOnlineList); | Assert.assertNotNull(wxMpKfOnlineList); | ||||
@@ -1,8 +1,8 @@ | |||||
package me.chanjar.weixin.mp.bean.message; | package me.chanjar.weixin.mp.bean.message; | ||||
import me.chanjar.weixin.common.api.WxConsts; | import me.chanjar.weixin.common.api.WxConsts; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
@Test | @Test | ||||
public class WxMpXmlMessageTest { | public class WxMpXmlMessageTest { | ||||
@@ -1,7 +1,7 @@ | |||||
package me.chanjar.weixin.mp.bean.message; | package me.chanjar.weixin.mp.bean.message; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
@Test | @Test | ||||
public class WxMpXmlOutImageMessageTest { | public class WxMpXmlOutImageMessageTest { | ||||
@@ -14,12 +14,12 @@ public class WxMpXmlOutImageMessageTest { | |||||
m.setToUserName("to"); | m.setToUserName("to"); | ||||
String expected = "<xml>" | String expected = "<xml>" | ||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[image]]></MsgType>" | |||||
+ "<Image><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Image>" | |||||
+ "</xml>"; | |||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[image]]></MsgType>" | |||||
+ "<Image><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Image>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | System.out.println(m.toXml()); | ||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | ||||
} | } | ||||
@@ -27,22 +27,22 @@ public class WxMpXmlOutImageMessageTest { | |||||
public void testBuild() { | public void testBuild() { | ||||
WxMpXmlOutImageMessage m = WxMpXmlOutMessage.IMAGE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build(); | WxMpXmlOutImageMessage m = WxMpXmlOutMessage.IMAGE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build(); | ||||
String expected = "<xml>" | String expected = "<xml>" | ||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[image]]></MsgType>" | |||||
+ "<Image><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Image>" | |||||
+ "</xml>"; | |||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[image]]></MsgType>" | |||||
+ "<Image><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Image>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | System.out.println(m.toXml()); | ||||
Assert.assertEquals( | Assert.assertEquals( | ||||
m | |||||
.toXml() | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""), | |||||
expected | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", "") | |||||
); | |||||
m | |||||
.toXml() | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""), | |||||
expected | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", "") | |||||
); | |||||
} | } | ||||
} | } |
@@ -1,7 +1,7 @@ | |||||
package me.chanjar.weixin.mp.bean.message; | package me.chanjar.weixin.mp.bean.message; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
@Test | @Test | ||||
public class WxMpXmlOutMusicMessageTest { | public class WxMpXmlOutMusicMessageTest { | ||||
@@ -18,55 +18,55 @@ public class WxMpXmlOutMusicMessageTest { | |||||
m.setToUserName("toUser"); | m.setToUserName("toUser"); | ||||
String expected = "<xml>" | String expected = "<xml>" | ||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[music]]></MsgType>" | |||||
+ "<Music>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[ddfff]]></Description>" | |||||
+ " <ThumbMediaId><![CDATA[thumbMediaId]]></ThumbMediaId>" | |||||
+ " <MusicUrl><![CDATA[musicUrl]]></MusicUrl>" | |||||
+ " <HQMusicUrl><![CDATA[hQMusicUrl]]></HQMusicUrl>" | |||||
+ " </Music>" | |||||
+ "</xml>"; | |||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[music]]></MsgType>" | |||||
+ "<Music>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[ddfff]]></Description>" | |||||
+ " <ThumbMediaId><![CDATA[thumbMediaId]]></ThumbMediaId>" | |||||
+ " <MusicUrl><![CDATA[musicUrl]]></MusicUrl>" | |||||
+ " <HQMusicUrl><![CDATA[hQMusicUrl]]></HQMusicUrl>" | |||||
+ " </Music>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | System.out.println(m.toXml()); | ||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | ||||
} | } | ||||
public void testBuild() { | public void testBuild() { | ||||
WxMpXmlOutMusicMessage m = WxMpXmlOutMessage.MUSIC() | WxMpXmlOutMusicMessage m = WxMpXmlOutMessage.MUSIC() | ||||
.fromUser("fromUser") | |||||
.toUser("toUser") | |||||
.title("title") | |||||
.description("ddfff") | |||||
.hqMusicUrl("hQMusicUrl") | |||||
.musicUrl("musicUrl") | |||||
.thumbMediaId("thumbMediaId") | |||||
.build(); | |||||
.fromUser("fromUser") | |||||
.toUser("toUser") | |||||
.title("title") | |||||
.description("ddfff") | |||||
.hqMusicUrl("hQMusicUrl") | |||||
.musicUrl("musicUrl") | |||||
.thumbMediaId("thumbMediaId") | |||||
.build(); | |||||
String expected = "<xml>" | String expected = "<xml>" | ||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[music]]></MsgType>" | |||||
+ "<Music>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[ddfff]]></Description>" | |||||
+ " <ThumbMediaId><![CDATA[thumbMediaId]]></ThumbMediaId>" | |||||
+ " <MusicUrl><![CDATA[musicUrl]]></MusicUrl>" | |||||
+ " <HQMusicUrl><![CDATA[hQMusicUrl]]></HQMusicUrl>" | |||||
+ " </Music>" | |||||
+ "</xml>"; | |||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[music]]></MsgType>" | |||||
+ "<Music>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[ddfff]]></Description>" | |||||
+ " <ThumbMediaId><![CDATA[thumbMediaId]]></ThumbMediaId>" | |||||
+ " <MusicUrl><![CDATA[musicUrl]]></MusicUrl>" | |||||
+ " <HQMusicUrl><![CDATA[hQMusicUrl]]></HQMusicUrl>" | |||||
+ " </Music>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | System.out.println(m.toXml()); | ||||
Assert.assertEquals( | Assert.assertEquals( | ||||
m | |||||
m | |||||
.toXml() | .toXml() | ||||
.replaceAll("\\s", "") | .replaceAll("\\s", "") | ||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""), | .replaceAll("<CreateTime>.*?</CreateTime>", ""), | ||||
expected | |||||
expected | |||||
.replaceAll("\\s", "") | .replaceAll("\\s", "") | ||||
.replaceAll("<CreateTime>.*?</CreateTime>", "") | .replaceAll("<CreateTime>.*?</CreateTime>", "") | ||||
); | |||||
); | |||||
} | } | ||||
} | } |
@@ -1,7 +1,7 @@ | |||||
package me.chanjar.weixin.mp.bean.message; | package me.chanjar.weixin.mp.bean.message; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
@Test | @Test | ||||
public class WxMpXmlOutNewsMessageTest { | public class WxMpXmlOutNewsMessageTest { | ||||
@@ -20,26 +20,26 @@ public class WxMpXmlOutNewsMessageTest { | |||||
m.addArticle(item); | m.addArticle(item); | ||||
m.addArticle(item); | m.addArticle(item); | ||||
String expected = "<xml>" | String expected = "<xml>" | ||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[news]]></MsgType>" | |||||
+ " <ArticleCount>2</ArticleCount>" | |||||
+ " <Articles>" | |||||
+ " <item>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[description]]></Description>" | |||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>" | |||||
+ " <Url><![CDATA[url]]></Url>" | |||||
+ " </item>" | |||||
+ " <item>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[description]]></Description>" | |||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>" | |||||
+ " <Url><![CDATA[url]]></Url>" | |||||
+ " </item>" | |||||
+ " </Articles>" | |||||
+ "</xml>"; | |||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[news]]></MsgType>" | |||||
+ " <ArticleCount>2</ArticleCount>" | |||||
+ " <Articles>" | |||||
+ " <item>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[description]]></Description>" | |||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>" | |||||
+ " <Url><![CDATA[url]]></Url>" | |||||
+ " </item>" | |||||
+ " <item>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[description]]></Description>" | |||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>" | |||||
+ " <Url><![CDATA[url]]></Url>" | |||||
+ " </item>" | |||||
+ " </Articles>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | System.out.println(m.toXml()); | ||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | ||||
} | } | ||||
@@ -52,42 +52,42 @@ public class WxMpXmlOutNewsMessageTest { | |||||
item.setUrl("url"); | item.setUrl("url"); | ||||
WxMpXmlOutNewsMessage m = WxMpXmlOutMessage.NEWS() | WxMpXmlOutNewsMessage m = WxMpXmlOutMessage.NEWS() | ||||
.fromUser("fromUser") | |||||
.toUser("toUser") | |||||
.addArticle(item) | |||||
.addArticle(item) | |||||
.build(); | |||||
.fromUser("fromUser") | |||||
.toUser("toUser") | |||||
.addArticle(item) | |||||
.addArticle(item) | |||||
.build(); | |||||
String expected = "<xml>" | String expected = "<xml>" | ||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[news]]></MsgType>" | |||||
+ " <ArticleCount>2</ArticleCount>" | |||||
+ " <Articles>" | |||||
+ " <item>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[description]]></Description>" | |||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>" | |||||
+ " <Url><![CDATA[url]]></Url>" | |||||
+ " </item>" | |||||
+ " <item>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[description]]></Description>" | |||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>" | |||||
+ " <Url><![CDATA[url]]></Url>" | |||||
+ " </item>" | |||||
+ " </Articles>" | |||||
+ "</xml>"; | |||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[news]]></MsgType>" | |||||
+ " <ArticleCount>2</ArticleCount>" | |||||
+ " <Articles>" | |||||
+ " <item>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[description]]></Description>" | |||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>" | |||||
+ " <Url><![CDATA[url]]></Url>" | |||||
+ " </item>" | |||||
+ " <item>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[description]]></Description>" | |||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>" | |||||
+ " <Url><![CDATA[url]]></Url>" | |||||
+ " </item>" | |||||
+ " </Articles>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | System.out.println(m.toXml()); | ||||
Assert.assertEquals( | Assert.assertEquals( | ||||
m | |||||
m | |||||
.toXml() | .toXml() | ||||
.replaceAll("\\s", "") | .replaceAll("\\s", "") | ||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""), | .replaceAll("<CreateTime>.*?</CreateTime>", ""), | ||||
expected | |||||
expected | |||||
.replaceAll("\\s", "") | .replaceAll("\\s", "") | ||||
.replaceAll("<CreateTime>.*?</CreateTime>", "") | .replaceAll("<CreateTime>.*?</CreateTime>", "") | ||||
); | |||||
); | |||||
} | } | ||||
} | } |
@@ -1,7 +1,7 @@ | |||||
package me.chanjar.weixin.mp.bean.message; | package me.chanjar.weixin.mp.bean.message; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
@Test | @Test | ||||
public class WxMpXmlOutTextMessageTest { | public class WxMpXmlOutTextMessageTest { | ||||
@@ -14,12 +14,12 @@ public class WxMpXmlOutTextMessageTest { | |||||
m.setToUserName("to"); | m.setToUserName("to"); | ||||
String expected = "<xml>" | String expected = "<xml>" | ||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[text]]></MsgType>" | |||||
+ "<Content><![CDATA[content]]></Content>" | |||||
+ "</xml>"; | |||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[text]]></MsgType>" | |||||
+ "<Content><![CDATA[content]]></Content>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | System.out.println(m.toXml()); | ||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | ||||
} | } | ||||
@@ -27,22 +27,22 @@ public class WxMpXmlOutTextMessageTest { | |||||
public void testBuild() { | public void testBuild() { | ||||
WxMpXmlOutTextMessage m = WxMpXmlOutMessage.TEXT().content("content").fromUser("from").toUser("to").build(); | WxMpXmlOutTextMessage m = WxMpXmlOutMessage.TEXT().content("content").fromUser("from").toUser("to").build(); | ||||
String expected = "<xml>" | String expected = "<xml>" | ||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[text]]></MsgType>" | |||||
+ "<Content><![CDATA[content]]></Content>" | |||||
+ "</xml>"; | |||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[text]]></MsgType>" | |||||
+ "<Content><![CDATA[content]]></Content>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | System.out.println(m.toXml()); | ||||
Assert.assertEquals( | Assert.assertEquals( | ||||
m | |||||
m | |||||
.toXml() | .toXml() | ||||
.replaceAll("\\s", "") | .replaceAll("\\s", "") | ||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""), | .replaceAll("<CreateTime>.*?</CreateTime>", ""), | ||||
expected | |||||
expected | |||||
.replaceAll("\\s", "") | .replaceAll("\\s", "") | ||||
.replaceAll("<CreateTime>.*?</CreateTime>", "") | .replaceAll("<CreateTime>.*?</CreateTime>", "") | ||||
); | |||||
); | |||||
} | } | ||||
@@ -1,7 +1,7 @@ | |||||
package me.chanjar.weixin.mp.bean.message; | package me.chanjar.weixin.mp.bean.message; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
/** | /** | ||||
* Created by ben on 2015/12/29. | * Created by ben on 2015/12/29. | ||||
@@ -1,7 +1,7 @@ | |||||
package me.chanjar.weixin.mp.bean.message; | package me.chanjar.weixin.mp.bean.message; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
@Test | @Test | ||||
public class WxMpXmlOutVideoMessageTest { | public class WxMpXmlOutVideoMessageTest { | ||||
@@ -16,49 +16,49 @@ public class WxMpXmlOutVideoMessageTest { | |||||
m.setToUserName("toUser"); | m.setToUserName("toUser"); | ||||
String expected = "<xml>" | String expected = "<xml>" | ||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[video]]></MsgType>" | |||||
+ "<Video>" | |||||
+ "<MediaId><![CDATA[media_id]]></MediaId>" | |||||
+ "<Title><![CDATA[title]]></Title>" | |||||
+ "<Description><![CDATA[ddfff]]></Description>" | |||||
+ "</Video> " | |||||
+ "</xml>"; | |||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[video]]></MsgType>" | |||||
+ "<Video>" | |||||
+ "<MediaId><![CDATA[media_id]]></MediaId>" | |||||
+ "<Title><![CDATA[title]]></Title>" | |||||
+ "<Description><![CDATA[ddfff]]></Description>" | |||||
+ "</Video> " | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | System.out.println(m.toXml()); | ||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | ||||
} | } | ||||
public void testBuild() { | public void testBuild() { | ||||
WxMpXmlOutVideoMessage m = WxMpXmlOutMessage.VIDEO() | WxMpXmlOutVideoMessage m = WxMpXmlOutMessage.VIDEO() | ||||
.mediaId("media_id") | |||||
.fromUser("fromUser") | |||||
.toUser("toUser") | |||||
.title("title") | |||||
.description("ddfff") | |||||
.build(); | |||||
.mediaId("media_id") | |||||
.fromUser("fromUser") | |||||
.toUser("toUser") | |||||
.title("title") | |||||
.description("ddfff") | |||||
.build(); | |||||
String expected = "<xml>" | String expected = "<xml>" | ||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[video]]></MsgType>" | |||||
+ "<Video>" | |||||
+ "<MediaId><![CDATA[media_id]]></MediaId>" | |||||
+ "<Title><![CDATA[title]]></Title>" | |||||
+ "<Description><![CDATA[ddfff]]></Description>" | |||||
+ "</Video> " | |||||
+ "</xml>"; | |||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[video]]></MsgType>" | |||||
+ "<Video>" | |||||
+ "<MediaId><![CDATA[media_id]]></MediaId>" | |||||
+ "<Title><![CDATA[title]]></Title>" | |||||
+ "<Description><![CDATA[ddfff]]></Description>" | |||||
+ "</Video> " | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | System.out.println(m.toXml()); | ||||
Assert.assertEquals( | Assert.assertEquals( | ||||
m | |||||
m | |||||
.toXml() | .toXml() | ||||
.replaceAll("\\s", "") | .replaceAll("\\s", "") | ||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""), | .replaceAll("<CreateTime>.*?</CreateTime>", ""), | ||||
expected | |||||
expected | |||||
.replaceAll("\\s", "") | .replaceAll("\\s", "") | ||||
.replaceAll("<CreateTime>.*?</CreateTime>", "") | .replaceAll("<CreateTime>.*?</CreateTime>", "") | ||||
); | |||||
); | |||||
} | } | ||||
} | } |
@@ -1,7 +1,7 @@ | |||||
package me.chanjar.weixin.mp.bean.message; | package me.chanjar.weixin.mp.bean.message; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
@Test | @Test | ||||
public class WxMpXmlOutVoiceMessageTest { | public class WxMpXmlOutVoiceMessageTest { | ||||
@@ -14,12 +14,12 @@ public class WxMpXmlOutVoiceMessageTest { | |||||
m.setToUserName("to"); | m.setToUserName("to"); | ||||
String expected = "<xml>" | String expected = "<xml>" | ||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[voice]]></MsgType>" | |||||
+ "<Voice><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Voice>" | |||||
+ "</xml>"; | |||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[voice]]></MsgType>" | |||||
+ "<Voice><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Voice>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | System.out.println(m.toXml()); | ||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | ||||
} | } | ||||
@@ -27,22 +27,22 @@ public class WxMpXmlOutVoiceMessageTest { | |||||
public void testBuild() { | public void testBuild() { | ||||
WxMpXmlOutVoiceMessage m = WxMpXmlOutMessage.VOICE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build(); | WxMpXmlOutVoiceMessage m = WxMpXmlOutMessage.VOICE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build(); | ||||
String expected = "<xml>" | String expected = "<xml>" | ||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[voice]]></MsgType>" | |||||
+ "<Voice><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Voice>" | |||||
+ "</xml>"; | |||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[voice]]></MsgType>" | |||||
+ "<Voice><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Voice>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | System.out.println(m.toXml()); | ||||
Assert.assertEquals( | Assert.assertEquals( | ||||
m | |||||
m | |||||
.toXml() | .toXml() | ||||
.replaceAll("\\s", "") | .replaceAll("\\s", "") | ||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""), | .replaceAll("<CreateTime>.*?</CreateTime>", ""), | ||||
expected | |||||
expected | |||||
.replaceAll("\\s", "") | .replaceAll("\\s", "") | ||||
.replaceAll("<CreateTime>.*?</CreateTime>", "") | .replaceAll("<CreateTime>.*?</CreateTime>", "") | ||||
); | |||||
); | |||||
} | } | ||||
} | } |
@@ -1,7 +1,7 @@ | |||||
package me.chanjar.weixin.mp.bean.pay.result; | package me.chanjar.weixin.mp.bean.pay.result; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
import java.util.Map; | import java.util.Map; | ||||
@@ -1,7 +1,7 @@ | |||||
package me.chanjar.weixin.mp.bean.pay.result; | package me.chanjar.weixin.mp.bean.pay.result; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
@@ -1,8 +1,8 @@ | |||||
package me.chanjar.weixin.mp.bean.pay.result; | package me.chanjar.weixin.mp.bean.pay.result; | ||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
/** | /** | ||||
* <pre> | * <pre> | ||||
@@ -2,9 +2,8 @@ package me.chanjar.weixin.mp.bean.pay.result; | |||||
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 org.testng.Assert; | |||||
import org.testng.annotations.BeforeTest; | |||||
import org.testng.annotations.Test; | |||||
import org.testng.*; | |||||
import org.testng.annotations.*; | |||||
public class WxPaySendRedpackResultTest { | public class WxPaySendRedpackResultTest { | ||||
@@ -12,26 +11,26 @@ public class WxPaySendRedpackResultTest { | |||||
@BeforeTest | @BeforeTest | ||||
public void setup() { | public void setup() { | ||||
this.xstream = XStreamInitializer.getInstance(); | |||||
this.xstream.processAnnotations(WxPaySendRedpackResult.class); | |||||
this.xstream = XStreamInitializer.getInstance(); | |||||
this.xstream.processAnnotations(WxPaySendRedpackResult.class); | |||||
} | } | ||||
@Test | @Test | ||||
public void loadSuccessResult() { | public void loadSuccessResult() { | ||||
final String successSample = "<xml>\n" + | final String successSample = "<xml>\n" + | ||||
"<return_code><![CDATA[SUCCESS]]></return_code>\n" + | |||||
"<return_msg><![CDATA[发放成功.]]></return_msg>\n" + | |||||
"<result_code><![CDATA[SUCCESS]]></result_code>\n" + | |||||
"<err_code><![CDATA[0]]></err_code>\n" + | |||||
"<err_code_des><![CDATA[发放成功.]]></err_code_des>\n" + | |||||
"<mch_billno><![CDATA[0010010404201411170000046545]]></mch_billno>\n" + | |||||
"<mch_id>10010404</mch_id>\n" + | |||||
"<wxappid><![CDATA[wx6fa7e3bab7e15415]]></wxappid>\n" + | |||||
"<re_openid><![CDATA[onqOjjmM1tad-3ROpncN-yUfa6uI]]></re_openid>\n" + | |||||
"<total_amount>1</total_amount>\n" + | |||||
"<send_listid>100000000020150520314766074200</send_listid>\n" + | |||||
"<send_time>20150520102602</send_time>\n" + | |||||
"</xml>"; | |||||
"<return_code><![CDATA[SUCCESS]]></return_code>\n" + | |||||
"<return_msg><![CDATA[发放成功.]]></return_msg>\n" + | |||||
"<result_code><![CDATA[SUCCESS]]></result_code>\n" + | |||||
"<err_code><![CDATA[0]]></err_code>\n" + | |||||
"<err_code_des><![CDATA[发放成功.]]></err_code_des>\n" + | |||||
"<mch_billno><![CDATA[0010010404201411170000046545]]></mch_billno>\n" + | |||||
"<mch_id>10010404</mch_id>\n" + | |||||
"<wxappid><![CDATA[wx6fa7e3bab7e15415]]></wxappid>\n" + | |||||
"<re_openid><![CDATA[onqOjjmM1tad-3ROpncN-yUfa6uI]]></re_openid>\n" + | |||||
"<total_amount>1</total_amount>\n" + | |||||
"<send_listid>100000000020150520314766074200</send_listid>\n" + | |||||
"<send_time>20150520102602</send_time>\n" + | |||||
"</xml>"; | |||||
WxPaySendRedpackResult wxMpRedpackResult = (WxPaySendRedpackResult) this.xstream.fromXML(successSample); | WxPaySendRedpackResult wxMpRedpackResult = (WxPaySendRedpackResult) this.xstream.fromXML(successSample); | ||||
Assert.assertEquals("SUCCESS", wxMpRedpackResult.getReturnCode()); | Assert.assertEquals("SUCCESS", wxMpRedpackResult.getReturnCode()); | ||||
Assert.assertEquals("SUCCESS", wxMpRedpackResult.getResultCode()); | Assert.assertEquals("SUCCESS", wxMpRedpackResult.getResultCode()); | ||||
@@ -41,17 +40,17 @@ public class WxPaySendRedpackResultTest { | |||||
@Test | @Test | ||||
public void loadFailureResult() { | public void loadFailureResult() { | ||||
final String failureSample = "<xml>\n" + | final String failureSample = "<xml>\n" + | ||||
"<return_code><![CDATA[FAIL]]></return_code>\n" + | |||||
"<return_msg><![CDATA[系统繁忙,请稍后再试.]]></return_msg>\n" + | |||||
"<result_code><![CDATA[FAIL]]></result_code>\n" + | |||||
"<err_code><![CDATA[268458547]]></err_code>\n" + | |||||
"<err_code_des><![CDATA[系统繁忙,请稍后再试.]]></err_code_des>\n" + | |||||
"<mch_billno><![CDATA[0010010404201411170000046542]]></mch_billno>\n" + | |||||
"<mch_id>10010404</mch_id>\n" + | |||||
"<wxappid><![CDATA[wx6fa7e3bab7e15415]]></wxappid>\n" + | |||||
"<re_openid><![CDATA[onqOjjmM1tad-3ROpncN-yUfa6uI]]></re_openid>\n" + | |||||
"<total_amount>1</total_amount>\n" + | |||||
"</xml>"; | |||||
"<return_code><![CDATA[FAIL]]></return_code>\n" + | |||||
"<return_msg><![CDATA[系统繁忙,请稍后再试.]]></return_msg>\n" + | |||||
"<result_code><![CDATA[FAIL]]></result_code>\n" + | |||||
"<err_code><![CDATA[268458547]]></err_code>\n" + | |||||
"<err_code_des><![CDATA[系统繁忙,请稍后再试.]]></err_code_des>\n" + | |||||
"<mch_billno><![CDATA[0010010404201411170000046542]]></mch_billno>\n" + | |||||
"<mch_id>10010404</mch_id>\n" + | |||||
"<wxappid><![CDATA[wx6fa7e3bab7e15415]]></wxappid>\n" + | |||||
"<re_openid><![CDATA[onqOjjmM1tad-3ROpncN-yUfa6uI]]></re_openid>\n" + | |||||
"<total_amount>1</total_amount>\n" + | |||||
"</xml>"; | |||||
WxPaySendRedpackResult wxMpRedpackResult = (WxPaySendRedpackResult) this.xstream.fromXML(failureSample); | WxPaySendRedpackResult wxMpRedpackResult = (WxPaySendRedpackResult) this.xstream.fromXML(failureSample); | ||||
Assert.assertEquals("FAIL", wxMpRedpackResult.getReturnCode()); | Assert.assertEquals("FAIL", wxMpRedpackResult.getReturnCode()); | ||||
Assert.assertEquals("FAIL", wxMpRedpackResult.getResultCode()); | Assert.assertEquals("FAIL", wxMpRedpackResult.getResultCode()); | ||||
@@ -1,9 +1,5 @@ | |||||
package me.chanjar.weixin.mp.demo; | package me.chanjar.weixin.mp.demo; | ||||
import java.util.Map; | |||||
import java.util.Random; | |||||
import java.util.regex.Pattern; | |||||
import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||
import me.chanjar.weixin.common.session.WxSession; | import me.chanjar.weixin.common.session.WxSession; | ||||
import me.chanjar.weixin.common.session.WxSessionManager; | import me.chanjar.weixin.common.session.WxSessionManager; | ||||
@@ -14,6 +10,10 @@ import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | |||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; | import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; | ||||
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; | import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; | ||||
import java.util.Map; | |||||
import java.util.Random; | |||||
import java.util.regex.Pattern; | |||||
public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMatcher { | public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMatcher { | ||||
private Random random = new Random(); | private Random random = new Random(); | ||||
@@ -35,7 +35,7 @@ public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMa | |||||
@Override | @Override | ||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, | public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, | ||||
WxSessionManager sessionManager) throws WxErrorException { | |||||
WxSessionManager sessionManager) throws WxErrorException { | |||||
if (isUserWantGuess(wxMessage)) { | if (isUserWantGuess(wxMessage)) { | ||||
letsGo(wxMessage, wxMpService, sessionManager); | letsGo(wxMessage, wxMpService, sessionManager); | ||||
@@ -53,17 +53,17 @@ public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMa | |||||
WxSession session = sessionManager.getSession(wxMessage.getFromUser()); | WxSession session = sessionManager.getSession(wxMessage.getFromUser()); | ||||
if (session.getAttribute("guessing") == null) { | if (session.getAttribute("guessing") == null) { | ||||
WxMpKefuMessage m = WxMpKefuMessage | WxMpKefuMessage m = WxMpKefuMessage | ||||
.TEXT() | |||||
.toUser(wxMessage.getFromUser()) | |||||
.content("请猜一个100以内的数字") | |||||
.build(); | |||||
.TEXT() | |||||
.toUser(wxMessage.getFromUser()) | |||||
.content("请猜一个100以内的数字") | |||||
.build(); | |||||
wxMpService.getKefuService().sendKefuMessage(m); | wxMpService.getKefuService().sendKefuMessage(m); | ||||
} else { | } else { | ||||
WxMpKefuMessage m = WxMpKefuMessage | WxMpKefuMessage m = WxMpKefuMessage | ||||
.TEXT() | |||||
.toUser(wxMessage.getFromUser()) | |||||
.content("放弃了吗?那请重新猜一个100以内的数字") | |||||
.build(); | |||||
.TEXT() | |||||
.toUser(wxMessage.getFromUser()) | |||||
.content("放弃了吗?那请重新猜一个100以内的数字") | |||||
.build(); | |||||
wxMpService.getKefuService().sendKefuMessage(m); | wxMpService.getKefuService().sendKefuMessage(m); | ||||
} | } | ||||
@@ -88,25 +88,25 @@ public class DemoGuessNumberHandler implements WxMpMessageHandler, WxMpMessageMa | |||||
int guessNumber = Integer.valueOf(wxMessage.getContent()); | int guessNumber = Integer.valueOf(wxMessage.getContent()); | ||||
if (guessNumber < answer) { | if (guessNumber < answer) { | ||||
WxMpKefuMessage m = WxMpKefuMessage | WxMpKefuMessage m = WxMpKefuMessage | ||||
.TEXT() | |||||
.toUser(wxMessage.getFromUser()) | |||||
.content("小了") | |||||
.build(); | |||||
.TEXT() | |||||
.toUser(wxMessage.getFromUser()) | |||||
.content("小了") | |||||
.build(); | |||||
wxMpService.getKefuService().sendKefuMessage(m); | wxMpService.getKefuService().sendKefuMessage(m); | ||||
} else if (guessNumber > answer) { | } else if (guessNumber > answer) { | ||||
WxMpKefuMessage m = WxMpKefuMessage | WxMpKefuMessage m = WxMpKefuMessage | ||||
.TEXT() | |||||
.toUser(wxMessage.getFromUser()) | |||||
.content("大了") | |||||
.build(); | |||||
.TEXT() | |||||
.toUser(wxMessage.getFromUser()) | |||||
.content("大了") | |||||
.build(); | |||||
wxMpService.getKefuService().sendKefuMessage(m); | wxMpService.getKefuService().sendKefuMessage(m); | ||||
} else { | } else { | ||||
WxMpKefuMessage m = WxMpKefuMessage | WxMpKefuMessage m = WxMpKefuMessage | ||||
.TEXT() | |||||
.toUser(wxMessage.getFromUser()) | |||||
.content("Bingo!") | |||||
.build(); | |||||
.TEXT() | |||||
.toUser(wxMessage.getFromUser()) | |||||
.content("Bingo!") | |||||
.build(); | |||||
session.removeAttribute("guessing"); | session.removeAttribute("guessing"); | ||||
wxMpService.getKefuService().sendKefuMessage(m); | wxMpService.getKefuService().sendKefuMessage(m); | ||||
} | } | ||||
@@ -15,17 +15,17 @@ import java.util.Map; | |||||
public class DemoImageHandler implements WxMpMessageHandler { | public class DemoImageHandler implements WxMpMessageHandler { | ||||
@Override | @Override | ||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, | public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, | ||||
WxMpService wxMpService, WxSessionManager sessionManager) { | |||||
WxMpService wxMpService, WxSessionManager sessionManager) { | |||||
try { | try { | ||||
WxMediaUploadResult wxMediaUploadResult = wxMpService.getMaterialService() | WxMediaUploadResult wxMediaUploadResult = wxMpService.getMaterialService() | ||||
.mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, ClassLoader.getSystemResourceAsStream("mm.jpeg")); | |||||
.mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, ClassLoader.getSystemResourceAsStream("mm.jpeg")); | |||||
WxMpXmlOutImageMessage m | WxMpXmlOutImageMessage m | ||||
= WxMpXmlOutMessage | |||||
.IMAGE() | |||||
.mediaId(wxMediaUploadResult.getMediaId()) | |||||
.fromUser(wxMessage.getToUser()) | |||||
.toUser(wxMessage.getFromUser()) | |||||
.build(); | |||||
= WxMpXmlOutMessage | |||||
.IMAGE() | |||||
.mediaId(wxMediaUploadResult.getMediaId()) | |||||
.fromUser(wxMessage.getToUser()) | |||||
.toUser(wxMessage.getFromUser()) | |||||
.build(); | |||||
return m; | return m; | ||||
} catch (WxErrorException e) { | } catch (WxErrorException e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
@@ -14,7 +14,7 @@ import java.util.Map; | |||||
public class DemoLogHandler implements WxMpMessageHandler { | public class DemoLogHandler implements WxMpMessageHandler { | ||||
@Override | @Override | ||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, | public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService, | ||||
WxSessionManager sessionManager) { | |||||
WxSessionManager sessionManager) { | |||||
System.out.println(wxMessage.toString()); | System.out.println(wxMessage.toString()); | ||||
return null; | return null; | ||||
} | } | ||||
@@ -15,13 +15,13 @@ import java.util.Map; | |||||
public class DemoOAuth2Handler implements WxMpMessageHandler { | public class DemoOAuth2Handler implements WxMpMessageHandler { | ||||
@Override | @Override | ||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, | public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, | ||||
Map<String, Object> context, WxMpService wxMpService, | |||||
WxSessionManager sessionManager) { | |||||
Map<String, Object> context, WxMpService wxMpService, | |||||
WxSessionManager sessionManager) { | |||||
String href = "<a href=\"" + wxMpService.oauth2buildAuthorizationUrl( | String href = "<a href=\"" + wxMpService.oauth2buildAuthorizationUrl( | ||||
wxMpService.getWxMpConfigStorage().getOauth2redirectUri(), | |||||
WxConsts.OAUTH2_SCOPE_USER_INFO, null) + "\">测试oauth2</a>"; | |||||
wxMpService.getWxMpConfigStorage().getOauth2redirectUri(), | |||||
WxConsts.OAUTH2_SCOPE_USER_INFO, null) + "\">测试oauth2</a>"; | |||||
return WxMpXmlOutMessage.TEXT().content(href) | return WxMpXmlOutMessage.TEXT().content(href) | ||||
.fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()) | |||||
.build(); | |||||
.fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()) | |||||
.build(); | |||||
} | } | ||||
} | } |
@@ -15,10 +15,10 @@ import java.util.Map; | |||||
public class DemoTextHandler implements WxMpMessageHandler { | public class DemoTextHandler implements WxMpMessageHandler { | ||||
@Override | @Override | ||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, | public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, | ||||
WxMpService wxMpService, WxSessionManager sessionManager) { | |||||
WxMpService wxMpService, WxSessionManager sessionManager) { | |||||
WxMpXmlOutTextMessage m | WxMpXmlOutTextMessage m | ||||
= WxMpXmlOutMessage.TEXT().content("测试加密消息").fromUser(wxMessage.getToUser()) | |||||
.toUser(wxMessage.getFromUser()).build(); | |||||
= WxMpXmlOutMessage.TEXT().content("测试加密消息").fromUser(wxMessage.getToUser()) | |||||
.toUser(wxMessage.getFromUser()).build(); | |||||
return m; | return m; | ||||
} | } | ||||
@@ -13,17 +13,16 @@ import java.io.InputStream; | |||||
@XStreamAlias("xml") | @XStreamAlias("xml") | ||||
class WxMpDemoInMemoryConfigStorage extends WxMpInMemoryConfigStorage { | class WxMpDemoInMemoryConfigStorage extends WxMpInMemoryConfigStorage { | ||||
@Override | |||||
public String toString() { | |||||
return "SimpleWxConfigProvider [appId=" + this.appId + ", secret=" + this.secret + ", accessToken=" + this.accessToken | |||||
+ ", expiresTime=" + this.expiresTime + ", token=" + this.token + ", aesKey=" + this.aesKey + "]"; | |||||
} | |||||
public static WxMpDemoInMemoryConfigStorage fromXml(InputStream is) { | public static WxMpDemoInMemoryConfigStorage fromXml(InputStream is) { | ||||
XStream xstream = XStreamInitializer.getInstance(); | XStream xstream = XStreamInitializer.getInstance(); | ||||
xstream.processAnnotations(WxMpDemoInMemoryConfigStorage.class); | xstream.processAnnotations(WxMpDemoInMemoryConfigStorage.class); | ||||
return (WxMpDemoInMemoryConfigStorage) xstream.fromXML(is); | return (WxMpDemoInMemoryConfigStorage) xstream.fromXML(is); | ||||
} | } | ||||
@Override | |||||
public String toString() { | |||||
return "SimpleWxConfigProvider [appId=" + this.appId + ", secret=" + this.secret + ", accessToken=" + this.accessToken | |||||
+ ", expiresTime=" + this.expiresTime + ", token=" + this.token + ", aesKey=" + this.aesKey + "]"; | |||||
} | |||||
} | } |
@@ -1,18 +1,17 @@ | |||||
package me.chanjar.weixin.mp.demo; | package me.chanjar.weixin.mp.demo; | ||||
import java.io.IOException; | |||||
import java.io.InputStream; | |||||
import org.eclipse.jetty.server.Server; | |||||
import org.eclipse.jetty.servlet.ServletHandler; | |||||
import org.eclipse.jetty.servlet.ServletHolder; | |||||
import me.chanjar.weixin.common.api.WxConsts; | import me.chanjar.weixin.common.api.WxConsts; | ||||
import me.chanjar.weixin.mp.api.WxMpConfigStorage; | import me.chanjar.weixin.mp.api.WxMpConfigStorage; | ||||
import me.chanjar.weixin.mp.api.WxMpMessageHandler; | import me.chanjar.weixin.mp.api.WxMpMessageHandler; | ||||
import me.chanjar.weixin.mp.api.WxMpMessageRouter; | import me.chanjar.weixin.mp.api.WxMpMessageRouter; | ||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; | import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; | ||||
import org.eclipse.jetty.server.Server; | |||||
import org.eclipse.jetty.servlet.ServletHandler; | |||||
import org.eclipse.jetty.servlet.ServletHolder; | |||||
import java.io.IOException; | |||||
import java.io.InputStream; | |||||
public class WxMpDemoServer { | public class WxMpDemoServer { | ||||
@@ -29,12 +28,12 @@ public class WxMpDemoServer { | |||||
server.setHandler(servletHandler); | server.setHandler(servletHandler); | ||||
ServletHolder endpointServletHolder = new ServletHolder( | ServletHolder endpointServletHolder = new ServletHolder( | ||||
new WxMpEndpointServlet(wxMpConfigStorage, wxMpService, | |||||
wxMpMessageRouter)); | |||||
new WxMpEndpointServlet(wxMpConfigStorage, wxMpService, | |||||
wxMpMessageRouter)); | |||||
servletHandler.addServletWithMapping(endpointServletHolder, "/*"); | servletHandler.addServletWithMapping(endpointServletHolder, "/*"); | ||||
ServletHolder oauthServletHolder = new ServletHolder( | ServletHolder oauthServletHolder = new ServletHolder( | ||||
new WxMpOAuth2Servlet(wxMpService)); | |||||
new WxMpOAuth2Servlet(wxMpService)); | |||||
servletHandler.addServletWithMapping(oauthServletHolder, "/oauth2/*"); | servletHandler.addServletWithMapping(oauthServletHolder, "/oauth2/*"); | ||||
server.start(); | server.start(); | ||||
@@ -43,9 +42,9 @@ public class WxMpDemoServer { | |||||
private static void initWeixin() { | private static void initWeixin() { | ||||
try (InputStream is1 = ClassLoader | try (InputStream is1 = ClassLoader | ||||
.getSystemResourceAsStream("test-config.xml")) { | |||||
.getSystemResourceAsStream("test-config.xml")) { | |||||
WxMpDemoInMemoryConfigStorage config = WxMpDemoInMemoryConfigStorage | WxMpDemoInMemoryConfigStorage config = WxMpDemoInMemoryConfigStorage | ||||
.fromXml(is1); | |||||
.fromXml(is1); | |||||
wxMpConfigStorage = config; | wxMpConfigStorage = config; | ||||
wxMpService = new WxMpServiceImpl(); | wxMpService = new WxMpServiceImpl(); | ||||
@@ -59,11 +58,11 @@ public class WxMpDemoServer { | |||||
wxMpMessageRouter = new WxMpMessageRouter(wxMpService); | wxMpMessageRouter = new WxMpMessageRouter(wxMpService); | ||||
wxMpMessageRouter.rule().handler(logHandler).next().rule() | wxMpMessageRouter.rule().handler(logHandler).next().rule() | ||||
.msgType(WxConsts.XML_MSG_TEXT).matcher(guessNumberHandler) | |||||
.handler(guessNumberHandler).end().rule().async(false).content("哈哈") | |||||
.handler(textHandler).end().rule().async(false).content("图片") | |||||
.handler(imageHandler).end().rule().async(false).content("oauth") | |||||
.handler(oauth2handler).end(); | |||||
.msgType(WxConsts.XML_MSG_TEXT).matcher(guessNumberHandler) | |||||
.handler(guessNumberHandler).end().rule().async(false).content("哈哈") | |||||
.handler(textHandler).end().rule().async(false).content("图片") | |||||
.handler(imageHandler).end().rule().async(false).content("oauth") | |||||
.handler(oauth2handler).end(); | |||||
} catch (IOException e) { | } catch (IOException e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
@@ -23,7 +23,7 @@ public class WxMpEndpointServlet extends HttpServlet { | |||||
protected WxMpMessageRouter wxMpMessageRouter; | protected WxMpMessageRouter wxMpMessageRouter; | ||||
public WxMpEndpointServlet(WxMpConfigStorage wxMpConfigStorage, WxMpService wxMpService, | public WxMpEndpointServlet(WxMpConfigStorage wxMpConfigStorage, WxMpService wxMpService, | ||||
WxMpMessageRouter wxMpMessageRouter) { | |||||
WxMpMessageRouter wxMpMessageRouter) { | |||||
this.wxMpConfigStorage = wxMpConfigStorage; | this.wxMpConfigStorage = wxMpConfigStorage; | ||||
this.wxMpService = wxMpService; | this.wxMpService = wxMpService; | ||||
this.wxMpMessageRouter = wxMpMessageRouter; | this.wxMpMessageRouter = wxMpMessageRouter; | ||||
@@ -31,7 +31,7 @@ public class WxMpEndpointServlet extends HttpServlet { | |||||
@Override | @Override | ||||
protected void service(HttpServletRequest request, HttpServletResponse response) | protected void service(HttpServletRequest request, HttpServletResponse response) | ||||
throws IOException { | |||||
throws IOException { | |||||
response.setContentType("text/html;charset=utf-8"); | response.setContentType("text/html;charset=utf-8"); | ||||
response.setStatus(HttpServletResponse.SC_OK); | response.setStatus(HttpServletResponse.SC_OK); | ||||
@@ -54,8 +54,8 @@ public class WxMpEndpointServlet extends HttpServlet { | |||||
} | } | ||||
String encryptType = StringUtils.isBlank(request.getParameter("encrypt_type")) ? | String encryptType = StringUtils.isBlank(request.getParameter("encrypt_type")) ? | ||||
"raw" : | |||||
request.getParameter("encrypt_type"); | |||||
"raw" : | |||||
request.getParameter("encrypt_type"); | |||||
if ("raw".equals(encryptType)) { | if ("raw".equals(encryptType)) { | ||||
// 明文传输的消息 | // 明文传输的消息 | ||||
@@ -1,16 +1,15 @@ | |||||
package me.chanjar.weixin.mp.demo; | package me.chanjar.weixin.mp.demo; | ||||
import java.io.IOException; | |||||
import javax.servlet.http.HttpServlet; | |||||
import javax.servlet.http.HttpServletRequest; | |||||
import javax.servlet.http.HttpServletResponse; | |||||
import me.chanjar.weixin.common.exception.WxErrorException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||
import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | ||||
import me.chanjar.weixin.mp.bean.result.WxMpUser; | import me.chanjar.weixin.mp.bean.result.WxMpUser; | ||||
import javax.servlet.http.HttpServlet; | |||||
import javax.servlet.http.HttpServletRequest; | |||||
import javax.servlet.http.HttpServletResponse; | |||||
import java.io.IOException; | |||||
public class WxMpOAuth2Servlet extends HttpServlet { | public class WxMpOAuth2Servlet extends HttpServlet { | ||||
private static final long serialVersionUID = 1L; | private static final long serialVersionUID = 1L; | ||||
@@ -22,7 +21,7 @@ public class WxMpOAuth2Servlet extends HttpServlet { | |||||
@Override | @Override | ||||
protected void service(HttpServletRequest request, HttpServletResponse response) | protected void service(HttpServletRequest request, HttpServletResponse response) | ||||
throws IOException { | |||||
throws IOException { | |||||
response.setContentType("text/html;charset=utf-8"); | response.setContentType("text/html;charset=utf-8"); | ||||
response.setStatus(HttpServletResponse.SC_OK); | response.setStatus(HttpServletResponse.SC_OK); | ||||