|
| 1 | +package me.chanjar.weixin.cp.api.impl; |
| 2 | + |
| 3 | +import com.google.inject.Inject; |
| 4 | +import me.chanjar.weixin.common.api.WxConsts; |
| 5 | +import me.chanjar.weixin.common.bean.menu.WxMenu; |
| 6 | +import me.chanjar.weixin.common.bean.menu.WxMenuButton; |
| 7 | +import me.chanjar.weixin.cp.api.ApiTestModule; |
| 8 | +import me.chanjar.weixin.cp.api.WxCpAgentService; |
| 9 | +import me.chanjar.weixin.cp.api.WxCpService; |
| 10 | +import me.chanjar.weixin.cp.bean.WxCpAgent; |
| 11 | +import me.chanjar.weixin.cp.config.WxCpInMemoryConfigStorage; |
| 12 | +import org.mockito.Mock; |
| 13 | +import org.testng.Assert; |
| 14 | +import org.testng.annotations.DataProvider; |
| 15 | +import org.testng.annotations.Guice; |
| 16 | +import org.testng.annotations.Test; |
| 17 | + |
| 18 | +import static org.testng.Assert.assertEquals; |
| 19 | +import static org.testng.Assert.assertNotNull; |
| 20 | +import static org.mockito.Mockito.*; |
| 21 | + |
| 22 | + |
| 23 | +/** |
| 24 | + * <pre> |
| 25 | + * 管理企业号应用-测试 |
| 26 | + * Created by huansinho on 2018/4/13. |
| 27 | + * </pre> |
| 28 | + * |
| 29 | + * @author <a href="https://github.com/huansinho">huansinho</a> |
| 30 | + */ |
| 31 | +public class WxCpAgentServiceImplTest { |
| 32 | + |
| 33 | + protected WxCpService wxService = mock(WxCpService.class); |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testGet() throws Exception { |
| 37 | + String returnJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"agentid\": 9,\"name\": \"测试应用\",\"square_logo_url\": \"http://wx.qlogo.cn/mmhead/alksjf;lasdjf;lasjfuodiuj3rj2o34j/0\",\"description\": \"这是一个企业号应用\",\"allow_userinfos\": {\"user\": [{\"userid\": \"0009854\"}, {\"userid\": \"1723\"}, {\"userid\": \"5625\"}]},\"allow_partys\": {\"partyid\": [42762742]},\"allow_tags\": {\"tagid\": [23, 22, 35, 19, 32, 125, 133, 46, 150, 38, 183, 9, 7]},\"close\": 0,\"redirect_domain\": \"weixin.com.cn\",\"report_location_flag\": 0,\"isreportenter\": 0,\"home_url\": \"\"}"; |
| 38 | + when(wxService.get("https://qyapi.weixin.qq.com/cgi-bin/agent/get?agentid=9", null)).thenReturn(returnJson); |
| 39 | + when(wxService.getAgentService()).thenReturn(new WxCpAgentServiceImpl(wxService)); |
| 40 | + |
| 41 | + WxCpAgentService wxAgentService = this.wxService.getAgentService(); |
| 42 | + WxCpAgent wxCpAgent = wxAgentService.get(9); |
| 43 | + |
| 44 | + Assert.assertEquals(9, wxCpAgent.getAgentid().intValue()); |
| 45 | + |
| 46 | + Assert.assertEquals(new Integer[]{42762742}, wxCpAgent.getAllowPartys().getPartyids().toArray()); |
| 47 | + |
| 48 | + Assert.assertEquals(new Integer[]{23, 22, 35, 19, 32, 125, 133, 46, 150, 38, 183, 9, 7}, wxCpAgent.getAllowTags().getTagids().toArray()); |
| 49 | + |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments