mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
🎨 修复部分单元测试
This commit is contained in:
parent
33b13b1bcd
commit
daf0b23328
@ -1,69 +0,0 @@
|
||||
package cn.binarywang.wx.miniapp.api.impl;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateAddResult;
|
||||
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryGetResult;
|
||||
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryListResult;
|
||||
import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateListResult;
|
||||
import cn.binarywang.wx.miniapp.test.ApiTestModule;
|
||||
import com.google.inject.Inject;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Test
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMaTemplateServiceImplTest {
|
||||
@Inject
|
||||
protected WxMaService wxService;
|
||||
|
||||
@Test
|
||||
public void testFindTemplateLibraryList() throws Exception {
|
||||
WxMaTemplateLibraryListResult result = this.wxService.getTemplateService().findTemplateLibraryList(0, 20);
|
||||
Assert.assertEquals(20, result.getList().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindTemplateLibraryKeywordList() throws Exception {
|
||||
WxMaTemplateLibraryGetResult result = this.wxService.getTemplateService().findTemplateLibraryKeywordList("AT0004");
|
||||
Assert.assertEquals("AT0004", result.getId());
|
||||
Assert.assertEquals("交易提醒", result.getTitle());
|
||||
Assert.assertEquals(100, result.getKeywordList().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddTemplate() throws Exception {
|
||||
List<Integer> list = Lists.newArrayList();
|
||||
list.add(1);
|
||||
list.add(20);
|
||||
list.add(84);
|
||||
|
||||
WxMaTemplateAddResult result = this.wxService.getTemplateService().addTemplate("AT0004", list);
|
||||
Assert.assertNotNull(result.getTemplateId());
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindTemplateList() throws Exception {
|
||||
WxMaTemplateListResult result = this.wxService.getTemplateService().findTemplateList(0, 20);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelTemplate() throws Exception {
|
||||
|
||||
//add
|
||||
List<Integer> list = Lists.newArrayList();
|
||||
list.add(1);
|
||||
list.add(20);
|
||||
list.add(84);
|
||||
|
||||
WxMaTemplateAddResult result = this.wxService.getTemplateService().addTemplate("AT0004", list);
|
||||
|
||||
//delete
|
||||
this.wxService.getTemplateService().delTemplate(result.getTemplateId());
|
||||
}
|
||||
}
|
@ -221,28 +221,12 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
|
||||
return WxMpSemanticQueryResult.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) {
|
||||
return String.format(CONNECT_OAUTH2_AUTHORIZE_URL.getUrl(this.getWxMpConfigStorage()),
|
||||
this.getWxMpConfigStorage().getAppId(), URIUtil.encodeURIComponent(redirectURI), scope, StringUtils.trimToEmpty(state));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildQrConnectUrl(String redirectUri, String scope, String state) {
|
||||
return String.format(QRCONNECT_URL.getUrl(this.getWxMpConfigStorage()), this.getWxMpConfigStorage().getAppId(),
|
||||
URIUtil.encodeURIComponent(redirectUri), scope, StringUtils.trimToEmpty(state));
|
||||
}
|
||||
|
||||
private WxMpOAuth2AccessToken getOAuth2AccessToken(String url) throws WxErrorException {
|
||||
try {
|
||||
RequestExecutor<String, String> executor = SimpleGetRequestExecutor.create(this);
|
||||
String responseText = executor.execute(url, null, WxType.MP);
|
||||
return WxMpOAuth2AccessToken.fromJson(responseText);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getCallbackIP() throws WxErrorException {
|
||||
String responseContent = this.get(GET_CALLBACK_IP_URL, null);
|
||||
|
@ -17,7 +17,7 @@ public class DemoOAuth2Handler implements WxMpMessageHandler {
|
||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
|
||||
Map<String, Object> context, WxMpService wxMpService,
|
||||
WxSessionManager sessionManager) {
|
||||
String href = "<a href=\"" + wxMpService.oauth2buildAuthorizationUrl(
|
||||
String href = "<a href=\"" + wxMpService.getOAuth2Service().buildAuthorizationUrl(
|
||||
wxMpService.getWxMpConfigStorage().getOauth2redirectUri(),
|
||||
WxConsts.OAuth2Scope.SNSAPI_USERINFO, null) + "\">测试oauth2</a>";
|
||||
return WxMpXmlOutMessage.TEXT().content(href)
|
||||
|
@ -31,15 +31,15 @@ public class WxMpOAuth2Servlet extends HttpServlet {
|
||||
response.getWriter().println("<h1>code</h1>");
|
||||
response.getWriter().println(code);
|
||||
|
||||
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = this.wxMpService.oauth2getAccessToken(code);
|
||||
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = this.wxMpService.getOAuth2Service().getAccessToken(code);
|
||||
response.getWriter().println("<h1>access token</h1>");
|
||||
response.getWriter().println(wxMpOAuth2AccessToken.toString());
|
||||
|
||||
WxMpUser wxMpUser = this.wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
|
||||
WxMpUser wxMpUser = this.wxMpService.getOAuth2Service().getUserInfo(wxMpOAuth2AccessToken, null);
|
||||
response.getWriter().println("<h1>user info</h1>");
|
||||
response.getWriter().println(wxMpUser.toString());
|
||||
|
||||
wxMpOAuth2AccessToken = this.wxMpService.oauth2refreshAccessToken(wxMpOAuth2AccessToken.getRefreshToken());
|
||||
wxMpOAuth2AccessToken = this.wxMpService.getOAuth2Service().refreshAccessToken(wxMpOAuth2AccessToken.getRefreshToken());
|
||||
response.getWriter().println("<h1>after refresh</h1>");
|
||||
response.getWriter().println(wxMpOAuth2AccessToken.toString());
|
||||
|
||||
|
@ -31,18 +31,4 @@ public class WxOpenMpServiceImpl extends WxMpServiceImpl {
|
||||
return wxOpenComponentService.getAuthorizerAccessToken(appId, forceRefresh);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException {
|
||||
return wxOpenComponentService.oauth2getAccessToken(appId, code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException {
|
||||
return wxOpenComponentService.oauth2refreshAccessToken(appId, refreshToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) {
|
||||
return wxOpenComponentService.oauth2buildAuthorizationUrl(appId, redirectURI, scope, state);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user