|
3 | 3 | import org.junit.Assert; |
4 | 4 | import org.junit.Test; |
5 | 5 |
|
| 6 | +import cn.jpush.api.common.ServiceHelper; |
6 | 7 | import cn.jpush.api.push.model.audience.Audience; |
7 | 8 | import cn.jpush.api.push.model.notification.Notification; |
8 | 9 |
|
@@ -45,61 +46,53 @@ public void testIllegal_NoPlatform() { |
45 | 46 | .setAudience(audience) |
46 | 47 | .setNotification(notifcation).build(); |
47 | 48 | } |
48 | | - |
49 | | - @Test |
50 | | - public void testQuickNotification() { |
51 | | - PushPayload payload = PushPayload.notificationAlertAll("alert"); |
52 | | - JsonObject json = new JsonObject(); |
53 | | - JsonObject noti = new JsonObject(); |
54 | | - noti.add("alert", new JsonPrimitive("alert")); |
55 | | - json.add("notification", noti); |
56 | | - json.add("audience", new JsonPrimitive("all")); |
57 | | - json.add("platform", new JsonPrimitive("all")); |
58 | | - Assert.assertEquals("", json, payload.toJSON()); |
59 | | - } |
60 | | - |
61 | | - @Test |
62 | | - public void testQuickMessage() { |
63 | | - PushPayload payload = PushPayload.simpleMessageAll("message"); |
64 | | - JsonObject json = new JsonObject(); |
65 | | - JsonObject msg = new JsonObject(); |
66 | | - msg.add("content", new JsonPrimitive("message")); |
67 | | - json.add("message", msg); |
68 | | - json.add("audience", new JsonPrimitive("all")); |
69 | | - json.add("platform", new JsonPrimitive("all")); |
70 | | - Assert.assertEquals("", json, payload.toJSON()); |
71 | | - } |
72 | | - |
| 49 | + |
73 | 50 | @Test |
74 | 51 | public void testNotification() { |
| 52 | + int sendno = ServiceHelper.generateSendno(); |
75 | 53 | Notification notifcation = Notification.alert("alert"); |
76 | 54 | PushPayload payload = PushPayload.newBuilder() |
77 | 55 | .setPlatform(Platform.all()) |
78 | 56 | .setAudience(Audience.all()) |
| 57 | + .setOptions(Options.sendno(sendno)) |
79 | 58 | .setNotification(notifcation).build(); |
80 | 59 |
|
81 | 60 | JsonObject json = new JsonObject(); |
| 61 | + json.add("audience", new JsonPrimitive("all")); |
| 62 | + json.add("platform", new JsonPrimitive("all")); |
| 63 | + |
82 | 64 | JsonObject noti = new JsonObject(); |
83 | 65 | noti.add("alert", new JsonPrimitive("alert")); |
84 | 66 | json.add("notification", noti); |
85 | | - json.add("audience", new JsonPrimitive("all")); |
86 | | - json.add("platform", new JsonPrimitive("all")); |
| 67 | + |
| 68 | + JsonObject options = new JsonObject(); |
| 69 | + options.add("sendno", new JsonPrimitive(sendno)); |
| 70 | + json.add("options", options); |
| 71 | + |
87 | 72 | Assert.assertEquals("", json, payload.toJSON()); |
88 | 73 | } |
89 | 74 |
|
90 | 75 | @Test |
91 | 76 | public void testMessage() { |
| 77 | + int sendno = ServiceHelper.generateSendno(); |
92 | 78 | PushPayload payload = PushPayload.newBuilder() |
93 | 79 | .setPlatform(Platform.all()) |
94 | 80 | .setAudience(Audience.all()) |
| 81 | + .setOptions(Options.sendno(sendno)) |
95 | 82 | .setMessage(Message.content("message")).build(); |
96 | 83 |
|
97 | 84 | JsonObject json = new JsonObject(); |
98 | | - JsonObject msg = new JsonObject(); |
99 | | - msg.add("content", new JsonPrimitive("message")); |
100 | | - json.add("message", msg); |
101 | 85 | json.add("audience", new JsonPrimitive("all")); |
102 | 86 | json.add("platform", new JsonPrimitive("all")); |
| 87 | + |
| 88 | + JsonObject msg = new JsonObject(); |
| 89 | + msg.add("msg_content", new JsonPrimitive("message")); |
| 90 | + json.add("message", msg); |
| 91 | + |
| 92 | + JsonObject options = new JsonObject(); |
| 93 | + options.add("sendno", new JsonPrimitive(sendno)); |
| 94 | + json.add("options", options); |
| 95 | + |
103 | 96 | Assert.assertEquals("", json, payload.toJSON()); |
104 | 97 | } |
105 | 98 |
|
|
0 commit comments