forked from jpush/jpush-api-java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPushFunctionTests.java
More file actions
108 lines (81 loc) · 3.58 KB
/
PushFunctionTests.java
File metadata and controls
108 lines (81 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package cn.jpush.api;
import static org.junit.Assert.*;
import java.util.HashMap;
import org.junit.Before;
import org.junit.Test;
import cn.jpush.api.common.DeviceEnum;
import cn.jpush.api.push.IosExtras;
import cn.jpush.api.push.MessageResult;
import cn.jpush.api.push.NotificationParams;
import cn.jpush.api.push.ReceiverTypeEnum;
public class PushFunctionTests {
private static final String appKey ="dd1066407b044738b6479275";
private static final String masterSecret = "2b38ce69b1de2a7fa95706ea";
private static final String TAG = "tag_api";
private static final String ALIAS = "alias_api";
private static final String MSG_CONTENT = "JPush Test - error tests";
private static final int SUCCEED_RESULT_CODE = 0;
private JPushClient jpushAndroid = null;
private JPushClient jpushIos = null;
@Before
public void before() {
jpushAndroid = new JPushClient(masterSecret, appKey, 0, DeviceEnum.Android, false);
jpushIos = new JPushClient(masterSecret, appKey, 0, DeviceEnum.IOS, false);
}
@Test
public void sendNotificationAll_android(){
MessageResult result = jpushAndroid.sendNotificationAll(MSG_CONTENT);
assertEquals(0, result.getErrorCode());
}
@Test
public void sendNotificationAll_ios(){
HashMap<String, Object> extra = new HashMap<String, Object>();
extra.put("jpush-key","jpush-value");
IosExtras iosExtra = new IosExtras(1,"test.mp3");
extra.put("ios", iosExtra);
NotificationParams params = new NotificationParams();
params.setReceiverType(ReceiverTypeEnum.APP_KEY);
MessageResult result = jpushIos.sendNotification(MSG_CONTENT, params, extra);
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
}
@Test
public void sendNotificationWithAlias() {
NotificationParams params = new NotificationParams();
params.setReceiverType(ReceiverTypeEnum.ALIAS);
params.setReceiverValue(ALIAS);
MessageResult result = jpushAndroid.sendNotification(MSG_CONTENT, params, null);
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
}
@Test
public void sendNotificationWithAlias_ios(){
HashMap<String, Object> extra = new HashMap<String, Object>();
extra.put("jpush-key","jpush-value");
IosExtras iosExtra = new IosExtras(1,"test.mp3", true);
extra.put("ios", iosExtra);
NotificationParams params = new NotificationParams();
params.setReceiverType(ReceiverTypeEnum.ALIAS);
params.setReceiverValue(ALIAS);
MessageResult result = jpushIos.sendNotification(MSG_CONTENT, params, extra);
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
}
@Test
public void sendNotificationWithTag(){
NotificationParams params = new NotificationParams();
params.setReceiverType(ReceiverTypeEnum.TAG);
params.setReceiverValue(TAG);
MessageResult result = jpushAndroid.sendNotification(MSG_CONTENT, params, null);
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
}
@Test
public void sendNotificationWithTagByExtra(){
HashMap<String, Object> extra = new HashMap<String, Object>();
extra.put("jpush-key","jpush-value");
IosExtras iosExtra = new IosExtras(1,"test.mp3");
extra.put("ios", iosExtra);
NotificationParams params = new NotificationParams();
params.setReceiverType(ReceiverTypeEnum.ALIAS);
params.setReceiverValue(ALIAS);
MessageResult result = jpushAndroid.sendNotification(MSG_CONTENT, params, null);
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
}
}