55
66import cn .jiguang .common .ClientConfig ;
77import cn .jpush .api .JPushClient ;
8- import cn .jpush .api .push .model .Message ;
9- import cn .jpush .api .push .model .Options ;
108import cn .jpush .api .push .model .Platform ;
119import cn .jpush .api .push .model .audience .Audience ;
12- import cn .jpush .api .push .model .notification .InterfaceAdapter ;
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 .PlatformNotification ;
16- import com .google .gson .Gson ;
17- import com .google .gson .GsonBuilder ;
10+ import cn .jpush .api .push .model .notification .*;
1811import org .junit .Test ;
1912
2013import cn .jiguang .common .connection .HttpProxy ;
@@ -33,14 +26,9 @@ public class PushClientTest extends BaseTest {
3326 public void testSendPush () {
3427 ClientConfig clientConfig = ClientConfig .getInstance ();
3528 JPushClient jpushClient = new JPushClient (MASTER_SECRET , APP_KEY , null , clientConfig );
36- PushPayload payload = buildPushObject_ios_tagAnd_alertWithExtrasAndMessage ();
37- Gson gson = new GsonBuilder ()
38- .registerTypeAdapter (PlatformNotification .class , new InterfaceAdapter <PlatformNotification >())
39- .create ();
40- String payloadJson = gson .toJson (payload );
41- PushPayload newPayload = gson .fromJson (payloadJson , PushPayload .class );
29+ PushPayload payload = buildPushObject_android_and_ios ();
4230 try {
43- PushResult result = jpushClient .sendPush (newPayload );
31+ PushResult result = jpushClient .sendPush (payload );
4432 LOG .info ("Got result - " + result );
4533
4634 } catch (APIConnectionException e ) {
@@ -55,21 +43,17 @@ public void testSendPush() {
5543 }
5644 }
5745
58- private static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage () {
46+ private static PushPayload buildPushObject_android_and_ios () {
5947 return PushPayload .newBuilder ()
60- .setPlatform (Platform .ios ())
61- .setAudience (Audience .tag_and ("tag1" , "tag_all " ))
48+ .setPlatform (Platform .android_ios ())
49+ .setAudience (Audience .tag ("tag1" ))
6250 .setNotification (Notification .newBuilder ()
51+ .setAlert ("alert content" )
52+ .addPlatformNotification (AndroidNotification .newBuilder ()
53+ .setTitle ("Android Title" ).build ())
6354 .addPlatformNotification (IosNotification .newBuilder ()
64- .setAlert (ALERT )
65- .setBadge (5 )
66- .setSound ("happy" )
67- .addExtra ("from" , "JPush" )
68- .build ())
69- .build ())
70- .setMessage (Message .content (MSG_CONTENT ))
71- .setOptions (Options .newBuilder ()
72- .setApnsProduction (true )
55+ .incrBadge (1 )
56+ .addExtra ("extra_key" , "extra_value" ).build ())
7357 .build ())
7458 .build ();
7559 }
0 commit comments