Skip to content

Commit d55e125

Browse files
author
Javen
committed
Adding tests.
1 parent bc5f249 commit d55e125

File tree

6 files changed

+288
-24
lines changed

6 files changed

+288
-24
lines changed

src/cn/jpush/api/push/model/audience/Audience.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ public static Audience tag(Collection<String> tagValues) {
5050
return newBuilder().addAudienceTarget(target).build();
5151
}
5252

53-
public static Audience tagAnd(String... tagValue) {
53+
public static Audience tag_and(String... tagValue) {
5454
AudienceTarget target = AudienceTarget.newBuilder()
5555
.setAudienceType(AudienceType.TAG_AND)
5656
.addAudienceTargetValues(tagValue).build();
5757
return newBuilder().addAudienceTarget(target).build();
5858
}
5959

60-
public static Audience tagAnd(Collection<String> tagValues) {
60+
public static Audience tag_and(Collection<String> tagValues) {
6161
AudienceTarget target = AudienceTarget.newBuilder()
6262
.setAudienceType(AudienceType.TAG_AND)
6363
.addAudienceTargetValues(tagValues).build();
@@ -94,7 +94,7 @@ public static Audience segment(Collection<String> segments) {
9494

9595
public static Audience registrationId(String... registrationId) {
9696
AudienceTarget target = AudienceTarget.newBuilder()
97-
.setAudienceType(AudienceType.ALIAS)
97+
.setAudienceType(AudienceType.REGISTRATION_ID)
9898
.addAudienceTargetValues(registrationId).build();
9999
return newBuilder().addAudienceTarget(target).build();
100100
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package cn.jpush.api.push;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
8+
import cn.jpush.api.JPushClient;
9+
import cn.jpush.api.push.model.Platform;
10+
import cn.jpush.api.push.model.PushPayload;
11+
import cn.jpush.api.push.model.audience.Audience;
12+
import cn.jpush.api.push.model.notification.AndroidNotification;
13+
import cn.jpush.api.push.model.notification.IosNotification;
14+
import cn.jpush.api.push.model.notification.Notification;
15+
import cn.jpush.api.push.model.notification.WinphoneNotification;
16+
17+
public class AlertOverrideTests {
18+
private static final String appKey ="dd1066407b044738b6479275";
19+
private static final String masterSecret = "2b38ce69b1de2a7fa95706ea";
20+
21+
private static final int SUCCEED_RESULT_CODE = 0;
22+
23+
private JPushClient _client = null;
24+
25+
@Before
26+
public void before() {
27+
_client = new JPushClient(masterSecret, appKey);
28+
}
29+
30+
@Test
31+
public void sendAlert_all() {
32+
PushPayload payload = PushPayload.newBuilder()
33+
.setPlatform(Platform.all())
34+
.setAudience(Audience.all())
35+
.setNotification(Notification.newBuilder()
36+
.setAlert("alert")
37+
.addPlatformNotification(AndroidNotification.alert("android alert"))
38+
.addPlatformNotification(IosNotification.alert("ios alert"))
39+
.addPlatformNotification(WinphoneNotification.alert("winphone alert"))
40+
.build())
41+
.build();
42+
PushResult result = _client.sendPush(payload);
43+
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
44+
}
45+
46+
@Test
47+
public void sendAlert_android() {
48+
PushPayload payload = PushPayload.newBuilder()
49+
.setPlatform(Platform.android())
50+
.setAudience(Audience.all())
51+
.setNotification(Notification.newBuilder()
52+
.setAlert("alert")
53+
.addPlatformNotification(AndroidNotification.alert("android alert"))
54+
.build())
55+
.build();
56+
PushResult result = _client.sendPush(payload);
57+
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
58+
}
59+
60+
@Test
61+
public void sendAlert_ios() {
62+
PushPayload payload = PushPayload.newBuilder()
63+
.setPlatform(Platform.ios())
64+
.setAudience(Audience.all())
65+
.setNotification(Notification.newBuilder()
66+
.setAlert("alert")
67+
.addPlatformNotification(IosNotification.alert("ios alert"))
68+
.build())
69+
.build();
70+
PushResult result = _client.sendPush(payload);
71+
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
72+
}
73+
74+
@Test
75+
public void sendAlert_wp() {
76+
PushPayload payload = PushPayload.newBuilder()
77+
.setPlatform(Platform.winphone())
78+
.setAudience(Audience.all())
79+
.setNotification(Notification.newBuilder()
80+
.setAlert("alert")
81+
.addPlatformNotification(WinphoneNotification.alert("winphone alert"))
82+
.build())
83+
.build();
84+
PushResult result = _client.sendPush(payload);
85+
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
86+
}
87+
88+
89+
}
90+
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package cn.jpush.api.push;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
8+
import cn.jpush.api.JPushClient;
9+
import cn.jpush.api.push.model.Platform;
10+
import cn.jpush.api.push.model.PushPayload;
11+
import cn.jpush.api.push.model.audience.Audience;
12+
import cn.jpush.api.push.model.audience.AudienceTarget;
13+
import cn.jpush.api.push.model.audience.AudienceType;
14+
import cn.jpush.api.push.model.notification.Notification;
15+
16+
public class AudienceTests {
17+
private static final String appKey ="dd1066407b044738b6479275";
18+
private static final String masterSecret = "2b38ce69b1de2a7fa95706ea";
19+
20+
private static final int SUCCEED_RESULT_CODE = 0;
21+
private static final String TAG = "tag1";
22+
private static final String TAG2 = "tag2";
23+
private static final String TAG3 = "tag3";
24+
private static final String ALIAS = "alias1";
25+
private static final String ALIAS2 = "alias2";
26+
private static final String ALIAS3 = "alias3";
27+
private static final String REGISTRATION = "0900e8d85ef";
28+
private static final String REGISTRATION2 = "0900e8d85ef";
29+
private static final String ALERT = "JPush Test - alert";
30+
private static final String MSG_CONTENT = "JPush Test - msgContent";
31+
32+
private JPushClient _client = null;
33+
34+
@Before
35+
public void before() {
36+
_client = new JPushClient(masterSecret, appKey);
37+
}
38+
39+
// one --------
40+
41+
@Test
42+
public void sendByTag() {
43+
PushPayload payload = PushPayload.newBuilder()
44+
.setPlatform(Platform.all())
45+
.setAudience(Audience.tag(TAG))
46+
.setNotification(Notification.alert(ALERT))
47+
.build();
48+
PushResult result = _client.sendPush(payload);
49+
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
50+
}
51+
52+
@Test
53+
public void sendByTagAnd() {
54+
PushPayload payload = PushPayload.newBuilder()
55+
.setPlatform(Platform.all())
56+
.setAudience(Audience.tag_and(TAG))
57+
.setNotification(Notification.alert(ALERT))
58+
.build();
59+
PushResult result = _client.sendPush(payload);
60+
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
61+
}
62+
63+
@Test
64+
public void sendByAlias() {
65+
PushPayload payload = PushPayload.newBuilder()
66+
.setPlatform(Platform.all())
67+
.setAudience(Audience.alias(ALIAS))
68+
.setNotification(Notification.alert(ALERT))
69+
.build();
70+
PushResult result = _client.sendPush(payload);
71+
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
72+
}
73+
74+
@Test
75+
public void sendByRegistrationID() {
76+
PushPayload payload = PushPayload.newBuilder()
77+
.setPlatform(Platform.all())
78+
.setAudience(Audience.registrationId(REGISTRATION))
79+
.setNotification(Notification.alert(ALERT))
80+
.build();
81+
PushResult result = _client.sendPush(payload);
82+
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
83+
}
84+
85+
// one more -------------------------
86+
87+
@Test
88+
public void sendByTagMore() {
89+
PushPayload payload = PushPayload.newBuilder()
90+
.setPlatform(Platform.all())
91+
.setAudience(Audience.tag(TAG, TAG2))
92+
.setNotification(Notification.alert(ALERT))
93+
.build();
94+
PushResult result = _client.sendPush(payload);
95+
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
96+
}
97+
98+
@Test
99+
public void sendByTagAndMore() {
100+
PushPayload payload = PushPayload.newBuilder()
101+
.setPlatform(Platform.all())
102+
.setAudience(Audience.tag_and(TAG, TAG3))
103+
.setNotification(Notification.alert(ALERT))
104+
.build();
105+
PushResult result = _client.sendPush(payload);
106+
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
107+
}
108+
109+
@Test
110+
public void sendByAliasMore() {
111+
PushPayload payload = PushPayload.newBuilder()
112+
.setPlatform(Platform.all())
113+
.setAudience(Audience.alias(ALIAS, ALIAS2))
114+
.setNotification(Notification.alert(ALERT))
115+
.build();
116+
PushResult result = _client.sendPush(payload);
117+
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
118+
}
119+
120+
121+
@Test
122+
public void sendByRegistrationIDMore() {
123+
PushPayload payload = PushPayload.newBuilder()
124+
.setPlatform(Platform.all())
125+
.setAudience(Audience.registrationId(REGISTRATION, REGISTRATION2))
126+
.setNotification(Notification.alert(ALERT))
127+
.build();
128+
PushResult result = _client.sendPush(payload);
129+
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
130+
}
131+
132+
133+
134+
// composite -------------------------
135+
136+
@Test
137+
public void sendByTagAlias() {
138+
PushPayload payload = PushPayload.newBuilder()
139+
.setPlatform(Platform.all())
140+
.setAudience(Audience.newBuilder()
141+
.addAudienceTarget(AudienceTarget.newBuilder()
142+
.setAudienceType(AudienceType.ALIAS)
143+
.addAudienceTargetValue(ALIAS).build())
144+
.addAudienceTarget(AudienceTarget.newBuilder()
145+
.setAudienceType(AudienceType.TAG)
146+
.addAudienceTargetValue(TAG).build())
147+
.build())
148+
.setNotification(Notification.alert(ALERT))
149+
.build();
150+
PushResult result = _client.sendPush(payload);
151+
assertEquals(SUCCEED_RESULT_CODE, result.getErrorCode());
152+
}
153+
154+
155+
}
156+

0 commit comments

Comments
 (0)