|
1 | 1 | package me.chanjar.weixin.cp.api.impl; |
2 | 2 |
|
| 3 | +import com.google.gson.JsonArray; |
| 4 | +import com.google.gson.JsonObject; |
3 | 5 | import com.google.inject.Inject; |
4 | 6 | import me.chanjar.weixin.common.error.WxErrorException; |
5 | 7 | import me.chanjar.weixin.cp.api.ApiTestModule; |
6 | 8 | import me.chanjar.weixin.cp.api.WxCpAgentService; |
7 | 9 | import me.chanjar.weixin.cp.api.WxCpService; |
8 | 10 | import me.chanjar.weixin.cp.bean.WxCpAgent; |
| 11 | +import me.chanjar.weixin.cp.bean.WxCpTpAdmin; |
9 | 12 | import me.chanjar.weixin.cp.config.WxCpConfigStorage; |
10 | 13 | import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl; |
11 | 14 | import me.chanjar.weixin.cp.constant.WxCpApiPathConsts; |
@@ -82,6 +85,20 @@ public void testList() throws WxErrorException { |
82 | 85 | assertThat(list.get(0).getSquareLogoUrl()).isNotEmpty(); |
83 | 86 | } |
84 | 87 |
|
| 88 | + /** |
| 89 | + * Test get admin list. |
| 90 | + * |
| 91 | + * @throws WxErrorException the wx error exception |
| 92 | + */ |
| 93 | + @Test |
| 94 | + public void testGetAdminList() throws WxErrorException { |
| 95 | + final Integer agentId = this.wxCpService.getWxCpConfigStorage().getAgentId(); |
| 96 | + WxCpTpAdmin adminList = this.wxCpService.getAgentService().getAdminList(agentId); |
| 97 | + |
| 98 | + assertThat(adminList).isNotNull(); |
| 99 | + assertThat(adminList.getErrcode()).isEqualTo(0L); |
| 100 | + } |
| 101 | + |
85 | 102 | /** |
86 | 103 | * The type Mock test. |
87 | 104 | */ |
@@ -118,6 +135,51 @@ public void testGet() throws Exception { |
118 | 135 |
|
119 | 136 | } |
120 | 137 |
|
| 138 | + /** |
| 139 | + * Test get admin list. |
| 140 | + * |
| 141 | + * @throws Exception the exception |
| 142 | + */ |
| 143 | + @Test |
| 144 | + public void testGetAdminList() throws Exception { |
| 145 | + // 构建响应JSON |
| 146 | + JsonObject admin1 = new JsonObject(); |
| 147 | + admin1.addProperty("userid", "zhangsan"); |
| 148 | + admin1.addProperty("open_userid", "woAJ2GCAAAXtWyujaWJHDDGi0mACH71w"); |
| 149 | + admin1.addProperty("auth_type", 1); |
| 150 | + |
| 151 | + JsonObject admin2 = new JsonObject(); |
| 152 | + admin2.addProperty("userid", "lisi"); |
| 153 | + admin2.addProperty("open_userid", "woAJ2GCAAAXtWyujaWJHDDGi0mACH72w"); |
| 154 | + admin2.addProperty("auth_type", 2); |
| 155 | + |
| 156 | + JsonArray adminArray = new JsonArray(); |
| 157 | + adminArray.add(admin1); |
| 158 | + adminArray.add(admin2); |
| 159 | + |
| 160 | + JsonObject returnJsonObj = new JsonObject(); |
| 161 | + returnJsonObj.addProperty("errcode", 0); |
| 162 | + returnJsonObj.addProperty("errmsg", "ok"); |
| 163 | + returnJsonObj.add("admin", adminArray); |
| 164 | + String returnJson = returnJsonObj.toString(); |
| 165 | + |
| 166 | + JsonObject requestJson = new JsonObject(); |
| 167 | + requestJson.addProperty("agentid", 9); |
| 168 | + final WxCpConfigStorage configStorage = new WxCpDefaultConfigImpl(); |
| 169 | + when(wxService.getWxCpConfigStorage()).thenReturn(configStorage); |
| 170 | + when(wxService.post(configStorage.getApiUrl(WxCpApiPathConsts.Agent.AGENT_GET_ADMIN_LIST), requestJson.toString())).thenReturn(returnJson); |
| 171 | + when(wxService.getAgentService()).thenReturn(new WxCpAgentServiceImpl(wxService)); |
| 172 | + |
| 173 | + WxCpAgentService wxAgentService = this.wxService.getAgentService(); |
| 174 | + WxCpTpAdmin adminList = wxAgentService.getAdminList(9); |
| 175 | + |
| 176 | + assertEquals(0, adminList.getErrcode().intValue()); |
| 177 | + assertEquals(2, adminList.getAdmin().size()); |
| 178 | + assertEquals("zhangsan", adminList.getAdmin().get(0).getUserId()); |
| 179 | + assertEquals("woAJ2GCAAAXtWyujaWJHDDGi0mACH71w", adminList.getAdmin().get(0).getOpenUserId()); |
| 180 | + assertEquals(1, adminList.getAdmin().get(0).getAuthType().intValue()); |
| 181 | + } |
| 182 | + |
121 | 183 | } |
122 | 184 |
|
123 | 185 | } |
0 commit comments