优化重构代码,统一管理公众号接口地址
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
@@ -12,6 +13,7 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
@Test
|
||||
@Slf4j
|
||||
public class WxMpBusyRetryTest {
|
||||
|
||||
@DataProvider(name = "getService")
|
||||
@@ -22,7 +24,7 @@ public class WxMpBusyRetryTest {
|
||||
public synchronized <T, E> T executeInternal(
|
||||
RequestExecutor<T, E> executor, String uri, E data)
|
||||
throws WxErrorException {
|
||||
this.log.info("Executed");
|
||||
log.info("Executed");
|
||||
throw new WxErrorException(WxError.builder().errorCode(-1).build());
|
||||
}
|
||||
};
|
||||
@@ -34,7 +36,7 @@ public class WxMpBusyRetryTest {
|
||||
|
||||
@Test(dataProvider = "getService", expectedExceptions = RuntimeException.class)
|
||||
public void testRetry(WxMpService service) throws WxErrorException {
|
||||
service.execute(null, null, null);
|
||||
service.execute(null, (String)null, null);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "getService")
|
||||
@@ -47,7 +49,7 @@ public class WxMpBusyRetryTest {
|
||||
try {
|
||||
System.out.println("=====================");
|
||||
System.out.println(Thread.currentThread().getName() + ": testRetry");
|
||||
service.execute(null, null, null);
|
||||
service.execute(null, (String)null, null);
|
||||
} catch (WxErrorException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
@@ -3,24 +3,22 @@ package me.chanjar.weixin.mp.api;
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.util.crypto.SHA1;
|
||||
import me.chanjar.weixin.mp.api.test.ApiTestModule;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* 测试jsapi ticket接口
|
||||
*
|
||||
* @author chanjarster
|
||||
*/
|
||||
@Test(groups = "jsAPI", dependsOnGroups = "baseAPI")
|
||||
@Test
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpJsAPITest {
|
||||
|
||||
@Inject
|
||||
protected WxMpService wxService;
|
||||
|
||||
|
||||
|
||||
|
||||
public void test() {
|
||||
long timestamp = 1419835025L;
|
||||
String url = "http://omstest.vmall.com:23568/thirdparty/wechat/vcode/gotoshare?quantity=1&batchName=MATE7";
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import me.chanjar.weixin.mp.api.WxMpUserService;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpChangeOpenid;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
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.bean.WxMpUserQuery;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpChangeOpenid;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||
import me.chanjar.weixin.mp.enums.WxMpApiUrl;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static me.chanjar.weixin.mp.enums.WxMpApiUrl.User.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -86,8 +88,7 @@ public class WxMpUserServiceImplTest {
|
||||
public void testChangeOpenid() throws WxErrorException {
|
||||
List<String> openids = new ArrayList<>();
|
||||
openids.add(this.configProvider.getOpenid());
|
||||
List<WxMpChangeOpenid> wxMpChangeOpenidList = this.wxService.getUserService()
|
||||
.changeOpenid("原公众号appid", openids);
|
||||
List<WxMpChangeOpenid> wxMpChangeOpenidList = this.wxService.getUserService().changeOpenid("原公众号appid", openids);
|
||||
Assert.assertNotNull(wxMpChangeOpenidList);
|
||||
Assert.assertEquals(1, wxMpChangeOpenidList.size());
|
||||
WxMpChangeOpenid wxMpChangeOpenid = wxMpChangeOpenidList.get(0);
|
||||
@@ -98,6 +99,7 @@ public class WxMpUserServiceImplTest {
|
||||
|
||||
public static class MockTest {
|
||||
private WxMpService wxService = mock(WxMpService.class);
|
||||
|
||||
@Test
|
||||
public void testMockChangeOpenid() throws WxErrorException {
|
||||
List<String> openids = new ArrayList<>();
|
||||
@@ -109,9 +111,8 @@ public class WxMpUserServiceImplTest {
|
||||
map.put("openid_list", openids);
|
||||
|
||||
String returnJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"result_list\": [{\"ori_openid\": \"oEmYbwN-n24jxvk4Sox81qedINkQ\",\"new_openid\": \"o2FwqwI9xCsVadFah_HtpPfaR-X4\",\"err_msg\": \"ok\"},{\"ori_openid\": \"oEmYbwH9uVd4RKJk7ZZg6SzL6tTo\",\"err_msg\": \"ori_openid error\"}]}";
|
||||
when(wxService.post(WxMpUserService.USER_CHANGE_OPENID_URL, WxMpGsonBuilder.create().toJson(map))).thenReturn(returnJson);
|
||||
List<WxMpChangeOpenid> wxMpChangeOpenidList = this.wxService.getUserService()
|
||||
.changeOpenid(fromAppid, openids);
|
||||
when(wxService.post(USER_CHANGE_OPENID_URL, WxMpGsonBuilder.create().toJson(map))).thenReturn(returnJson);
|
||||
List<WxMpChangeOpenid> wxMpChangeOpenidList = this.wxService.getUserService().changeOpenid(fromAppid, openids);
|
||||
Assert.assertNotNull(wxMpChangeOpenidList);
|
||||
Assert.assertEquals(2, wxMpChangeOpenidList.size());
|
||||
WxMpChangeOpenid wxMpChangeOpenid = wxMpChangeOpenidList.get(0);
|
||||
|
||||
Reference in New Issue
Block a user