|
1 | 1 | package cn.jpush.api.examples; |
2 | 2 |
|
3 | | -import static org.junit.Assert.assertTrue; |
4 | | - |
5 | | -import java.util.HashSet; |
6 | | -import java.util.Set; |
7 | | - |
8 | 3 | import org.slf4j.Logger; |
9 | 4 | import org.slf4j.LoggerFactory; |
10 | 5 |
|
11 | 6 | import cn.jpush.api.JPushClient; |
12 | | -import cn.jpush.api.common.resp.APIConnectionException; |
13 | | -import cn.jpush.api.common.resp.APIRequestException; |
14 | | -import cn.jpush.api.common.resp.BooleanResult; |
15 | | -import cn.jpush.api.common.resp.DefaultResult; |
16 | | -import cn.jpush.api.device.AliasDeviceListResult; |
17 | | -import cn.jpush.api.device.TagAliasResult; |
18 | | -import cn.jpush.api.device.TagListResult; |
19 | 7 |
|
20 | 8 | public class DevcieExample { |
21 | 9 | protected static final Logger LOG = LoggerFactory.getLogger(DevcieExample.class); |
22 | 10 |
|
23 | 11 | private static final String appKey = "dd1066407b044738b6479275"; |
24 | 12 | private static final String masterSecret = "2b38ce69b1de2a7fa95706ea"; |
25 | | - private static JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3); |
26 | 13 | private static final String TAG1 = "tag1"; |
27 | 14 | private static final String ALIAS1 = "alias1"; |
28 | 15 | private static final String ALIAS2 = "alias2"; |
29 | 16 | private static final String REGISTRATION_ID1 = "0900e8d85ef"; |
30 | 17 | private static final String REGISTRATION_ID2 = "0a04ad7d8b4"; |
31 | 18 |
|
| 19 | + private static JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3); |
32 | 20 |
|
33 | | - public static void main(String[] args) throws Exception { |
34 | | - testGetDeviceTagAlias(); |
35 | | - testUpdateDeviceTagAlias(); |
36 | | - testGetTagList(); |
37 | | - testIsDeviceInTag(); |
38 | | - testAddRemoveDevicesFromTag(); |
39 | | - testDeleteTag(); |
40 | | - testGetAliasDeviceList(); |
41 | | - testDeleteAlias(); |
42 | | - } |
43 | | - public static void testGetDeviceTagAlias() throws Exception { |
44 | | - TagAliasResult result = jpushClient.getDeviceTagAlias(REGISTRATION_ID1); |
45 | | - assertTrue(result.isResultOK()); |
46 | | - } |
47 | | - |
48 | | - public static void testUpdateDeviceTagAlias() |
49 | | - throws APIConnectionException, APIRequestException { |
50 | | - Set<String> tagsToAdd = new HashSet<String>(); |
51 | | - tagsToAdd.add("tag2"); |
52 | | - tagsToAdd.add("tag2"); |
53 | | - Set<String> tagsToRemove = new HashSet<String>(); |
54 | | - tagsToRemove.add("tag4"); |
55 | | - tagsToRemove.add("tag3"); |
56 | | - DefaultResult result = jpushClient.updateDeviceTagAlias( |
57 | | - REGISTRATION_ID1, ALIAS1, tagsToAdd, tagsToRemove); |
58 | | - assertTrue(result.isResultOK()); |
59 | | - } |
60 | | - |
61 | | - public static void testGetTagList() throws APIConnectionException, |
62 | | - APIRequestException { |
63 | | - TagListResult result = jpushClient.getTagList(); |
64 | | - assertTrue(result.isResultOK()); |
65 | | - } |
66 | | - |
67 | | - public static void testIsDeviceInTag() throws APIConnectionException, |
68 | | - APIRequestException { |
69 | | - BooleanResult result = jpushClient |
70 | | - .isDeviceInTag(TAG1, REGISTRATION_ID1); |
71 | | - assertTrue(result.isResultOK()); |
72 | | - } |
73 | | - |
74 | | - public static void testAddRemoveDevicesFromTag() |
75 | | - throws APIConnectionException, APIRequestException { |
76 | | - Set<String> toAddUsers = new HashSet<String>(); |
77 | | - toAddUsers.add(REGISTRATION_ID1); |
78 | | - Set<String> toRemoveUsers = new HashSet<String>(); |
79 | | - toRemoveUsers.add(REGISTRATION_ID2); |
80 | | - DefaultResult result = jpushClient.addRemoveDevicesFromTag(TAG1, |
81 | | - toAddUsers, toRemoveUsers); |
82 | | - assertTrue(result.isResultOK()); |
83 | | - } |
84 | | - |
85 | | - public static void testDeleteTag() throws APIConnectionException, |
86 | | - APIRequestException { |
87 | | - DefaultResult result = jpushClient.deleteTag(TAG1, null); |
88 | | - assertTrue(result.isResultOK()); |
89 | | - } |
90 | | - |
91 | | - public static void testGetAliasDeviceList() throws APIConnectionException, |
92 | | - APIRequestException { |
93 | | - AliasDeviceListResult result = jpushClient.getAliasDeviceList(ALIAS1, |
94 | | - null); |
95 | | - assertTrue(result.isResultOK()); |
96 | | - } |
97 | | - |
98 | | - public static void testDeleteAlias() throws APIConnectionException, |
99 | | - APIRequestException { |
100 | | - DefaultResult result = jpushClient.deleteAlias(ALIAS2, null); |
101 | | - assertTrue(result.isResultOK()); |
| 21 | + public static void main(String[] args) { |
| 22 | + |
102 | 23 | } |
103 | 24 | } |
0 commit comments