Skip to content

Commit c6ebb9a

Browse files
victiniJaven
authored andcommitted
update device test and fix bugs after test
1 parent fe93624 commit c6ebb9a

File tree

6 files changed

+117
-27
lines changed

6 files changed

+117
-27
lines changed

src/cn/jpush/api/JPushClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ public DefaultResult updateDeviceTagAlias(String registrationId, String alias, b
316316
return _deviceClient.updateDeviceTagAlias(registrationId, alias, clearTag, tagsToAdd, tagsToRemove);
317317
}
318318

319-
public TagListResult getTagList(String platform)
319+
public TagListResult getTagList()
320320
throws APIConnectionException, APIRequestException {
321-
return _deviceClient.getTagList(platform);
321+
return _deviceClient.getTagList();
322322
}
323323

324324
public BooleanResult isDeviceInTag(String theTag, String registrationID)
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
package cn.jpush.api.common.resp;
22

33
public class DefaultResult extends BaseResult {
4-
4+
5+
public static DefaultResult fromResponse(ResponseWrapper responseWrapper, Class<DefaultResult> clazz) {
6+
DefaultResult result = null;
7+
8+
if (responseWrapper.isServerResponse()) {
9+
result = new DefaultResult();
10+
} else {
11+
try {
12+
result = clazz.newInstance();
13+
} catch (InstantiationException e) {
14+
e.printStackTrace();
15+
} catch (IllegalAccessException e) {
16+
e.printStackTrace();
17+
}
18+
}
19+
20+
result.setResponseWrapper(responseWrapper);
21+
22+
return result;
23+
}
524

625
}

src/cn/jpush/api/device/AliasDeviceListResult.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
import com.google.gson.annotations.Expose;
99

1010
public class AliasDeviceListResult extends BaseResult {
11-
@Expose public List<RegistrationId> registration_ids = new ArrayList<RegistrationId>();
12-
13-
public static class RegistrationId {
14-
@Expose public String id;
15-
}
16-
11+
12+
@Expose public List<String> registration_ids = new ArrayList<String>();
13+
1714
}
1815

src/cn/jpush/api/device/DeviceClient.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,18 @@ public DefaultResult updateDeviceTagAlias(String registrationId, String alias, b
8181

8282
ResponseWrapper response = _httpClient.sendPost(url, top.toString());
8383

84-
return BaseResult.fromResponse(response, DefaultResult.class);
84+
return DefaultResult.fromResponse(response, DefaultResult.class);
8585
}
8686

8787

8888
// ------------- tags
8989

90-
public TagListResult getTagList(String platform) throws APIConnectionException, APIRequestException {
90+
public TagListResult getTagList() throws APIConnectionException, APIRequestException {
9191
String url = HOST_NAME_SSL + TAG_PATH + "/list";
92-
if (!StringUtils.isEmpty(platform)) {
93-
url += "?platform=" + platform;
94-
}
9592

9693
ResponseWrapper response = _httpClient.sendGet(url);
9794

98-
return BaseResult.fromResponse(response, TagListResult.class);
95+
return TagListResult.fromResponse(response, TagListResult.class);
9996
}
10097

10198
public BooleanResult isDeviceInTag(String theTag, String registrationID) throws APIConnectionException, APIRequestException {
@@ -131,18 +128,18 @@ public DefaultResult addRemoveDevicesFromTag(String theTag, Set<String> toAddUse
131128

132129
ResponseWrapper response = _httpClient.sendPost(url, top.toString());
133130

134-
return BaseResult.fromResponse(response, DefaultResult.class);
131+
return DefaultResult.fromResponse(response, DefaultResult.class);
135132
}
136133

137134
public DefaultResult deleteTag(String theTag, String platform) throws APIConnectionException, APIRequestException {
138135
String url = HOST_NAME_SSL + TAG_PATH + "/" + theTag;
139136
if (null != platform) {
140-
url += "?platform=" + platform;
137+
url += "/?platform=" + platform;
141138
}
142139

143140
ResponseWrapper response = _httpClient.sendDelete(url);
144141

145-
return BaseResult.fromResponse(response, DefaultResult.class);
142+
return DefaultResult.fromResponse(response, DefaultResult.class);
146143
}
147144

148145

@@ -151,23 +148,23 @@ public DefaultResult deleteTag(String theTag, String platform) throws APIConnect
151148
public AliasDeviceListResult getAliasDeviceList(String alias, String platform) throws APIConnectionException, APIRequestException {
152149
String url = HOST_NAME_SSL + ALIAS_PATH + "/" + alias;
153150
if (null != platform) {
154-
url += "?platform=" + platform;
151+
url += "/?platform=" + platform;
155152
}
156153

157154
ResponseWrapper response = _httpClient.sendGet(url);
158155

159-
return BaseResult.fromResponse(response, AliasDeviceListResult.class);
156+
return DefaultResult.fromResponse(response, AliasDeviceListResult.class);
160157
}
161158

162159
public DefaultResult deleteAlias(String alias, String platform) throws APIConnectionException, APIRequestException {
163160
String url = HOST_NAME_SSL + ALIAS_PATH + "/" + alias;
164161
if (null != platform) {
165-
url += "?platform=" + platform;
162+
url += "/?platform=" + platform;
166163
}
167164

168165
ResponseWrapper response = _httpClient.sendDelete(url);
169166

170-
return BaseResult.fromResponse(response, DefaultResult.class);
167+
return DefaultResult.fromResponse(response, DefaultResult.class);
171168
}
172169

173170
}

src/cn/jpush/api/device/TagListResult.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99

1010
public class TagListResult extends BaseResult {
1111

12-
@Expose public List<Tag> tags = new ArrayList<Tag>();
12+
@Expose public List<String> tags = new ArrayList<String>();
1313

14-
public static class Tag {
15-
@Expose public String tag;
16-
}
17-
1814
}
1915

test/cn/jpush/api/device/DeviceNormalRemoteTest.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
import static org.junit.Assert.assertTrue;
44

5+
import java.util.HashSet;
6+
import java.util.Set;
7+
58
import org.junit.Test;
69

710
import cn.jpush.api.BaseTest;
11+
import cn.jpush.api.common.resp.APIConnectionException;
12+
import cn.jpush.api.common.resp.APIRequestException;
13+
import cn.jpush.api.common.resp.BooleanResult;
14+
import cn.jpush.api.common.resp.DefaultResult;
815

916
public class DeviceNormalRemoteTest extends BaseTest {
1017

@@ -14,6 +21,80 @@ public void testGetDeviceTagAlias_1() throws Exception {
1421
TagAliasResult result = jpushClient.getDeviceTagAlias(REGISTRATION_ID1);
1522
assertTrue(result.isResultOK());
1623
}
24+
25+
@Test
26+
public void testUpdateDeviceTagAlias_1() throws APIConnectionException, APIRequestException {
27+
Set<String> tagsToAdd = new HashSet<String>();
28+
tagsToAdd.add("tag2");
29+
tagsToAdd.add("tag2");
30+
Set<String> tagsToRemove = new HashSet<String>();
31+
tagsToRemove.add("tag4");
32+
tagsToRemove.add("tag3");
33+
DefaultResult result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID1, ALIAS1, false, tagsToAdd, tagsToRemove);
34+
assertTrue(result.isResultOK());
35+
}
1736

37+
@Test
38+
public void testUpdateDeviceTagAlias_2() throws APIConnectionException, APIRequestException {
39+
DefaultResult result = jpushClient.updateDeviceTagAlias(REGISTRATION_ID1, ALIAS1, true, null, null);
40+
assertTrue(result.isResultOK());
41+
}
42+
43+
@Test
44+
public void testGetTagList_1() throws APIConnectionException, APIRequestException {
45+
TagListResult result = jpushClient.getTagList();
46+
assertTrue(result.isResultOK());
47+
}
48+
49+
@Test
50+
public void testIsDeviceInTag() throws APIConnectionException, APIRequestException {
51+
BooleanResult result = jpushClient.isDeviceInTag(TAG1, REGISTRATION_ID1);
52+
assertTrue(result.isResultOK());
53+
}
1854

55+
@Test
56+
public void testAddRemoveDevicesFromTag() throws APIConnectionException, APIRequestException {
57+
Set<String> toAddUsers = new HashSet<String>();
58+
toAddUsers.add(REGISTRATION_ID1);
59+
Set<String> toRemoveUsers = new HashSet<String>();
60+
toRemoveUsers.add(REGISTRATION_ID2);
61+
DefaultResult result = jpushClient.addRemoveDevicesFromTag(TAG1, toAddUsers, toRemoveUsers);
62+
assertTrue(result.isResultOK());
63+
}
64+
65+
@Test
66+
public void testDeleteTag() throws APIConnectionException, APIRequestException {
67+
DefaultResult result = jpushClient.deleteTag(TAG1, "ios");
68+
assertTrue(result.isResultOK());
69+
}
70+
71+
@Test
72+
public void testDeleteTag_2() throws APIConnectionException, APIRequestException {
73+
DefaultResult result = jpushClient.deleteTag(TAG1, null);
74+
assertTrue(result.isResultOK());
75+
}
76+
77+
@Test
78+
public void testGetAliasDeviceList() throws APIConnectionException, APIRequestException {
79+
AliasDeviceListResult result = jpushClient.getAliasDeviceList(ALIAS1, "android");
80+
assertTrue(result.isResultOK());
81+
}
82+
83+
@Test
84+
public void testGetAliasDeviceList_2() throws APIConnectionException, APIRequestException {
85+
AliasDeviceListResult result = jpushClient.getAliasDeviceList(ALIAS1, null);
86+
assertTrue(result.isResultOK());
87+
}
88+
89+
@Test
90+
public void testDeleteAlias() throws APIConnectionException, APIRequestException {
91+
DefaultResult result = jpushClient.deleteAlias(ALIAS2, "android");
92+
assertTrue(result.isResultOK());
93+
}
94+
95+
@Test
96+
public void testDeleteAlias_2() throws APIConnectionException, APIRequestException {
97+
DefaultResult result = jpushClient.deleteAlias(ALIAS2, null);
98+
assertTrue(result.isResultOK());
99+
}
19100
}

0 commit comments

Comments
 (0)