1 package com.foxinmy.weixin4j.qy.test;
2
3 import java.util.Arrays;
4 import java.util.List;
5
6 import org.junit.Assert;
7 import org.junit.Before;
8 import org.junit.Test;
9
10 import com.foxinmy.weixin4j.exception.WeixinException;
11 import com.foxinmy.weixin4j.http.weixin.ApiResult;
12 import com.foxinmy.weixin4j.qy.api.TagApi;
13 import com.foxinmy.weixin4j.qy.model.Contacts;
14 import com.foxinmy.weixin4j.qy.model.IdParameter;
15 import com.foxinmy.weixin4j.qy.model.Tag;
16
17
18
19
20
21
22
23
24
25
26 public class TagTest extends TokenTest {
27 public TagApi tagApi;
28
29 @Before
30 public void init() {
31 this.tagApi = new TagApi(tokenManager);
32 }
33
34 @Test
35 public void create() throws WeixinException {
36 int tagId = tagApi.createTag(new Tag("coder"));
37 Assert.assertTrue(tagId > 0);
38 }
39
40 @Test
41 public void update() throws WeixinException {
42 ApiResult result = tagApi.updateTag(new Tag(1, "coder456"));
43 Assert.assertEquals("updated", result.getReturnMsg());
44 }
45
46 @Test
47 public void getUsers() throws WeixinException {
48 Contacts contacts = tagApi.getTagUsers(1);
49 System.out.println(contacts);
50 }
51
52 @Test
53 public void addUsers() throws WeixinException {
54 IdParameter result = tagApi
55 .addTagUsers(1, Arrays.asList("jinyu"), null);
56 Assert.assertTrue(result.getUserIds().isEmpty());
57 }
58
59 @Test
60 public void deleteUsers() throws WeixinException {
61 IdParameter result = tagApi.deleteTagUsers(1, Arrays.asList("jinyu"),
62 null);
63 Assert.assertTrue(result.getUserIds().isEmpty());
64 System.out.println(result);
65 }
66
67 @Test
68 public void list() throws WeixinException {
69 List<Tag> tags = tagApi.listTag();
70 Assert.assertFalse(tags.isEmpty());
71 System.out.println(tags);
72 }
73
74 @Test
75 public void delete() throws WeixinException {
76 ApiResult result = tagApi.deleteTag(3);
77 Assert.assertEquals("deleted", result.getReturnMsg());
78 }
79 }