/**
  * 构建推送对象:所有平台,推送目标是别名为 "alias1",通知内容为 ALERT。
  *
  * @return
  */
 private static PushPayload buildPushObject_all_alias_alert(String title, String message) {
   return PushPayload.newBuilder()
       .setPlatform(Platform.all())
       .setAudience(Audience.alias(title))
       .setNotification(Notification.alert(message))
       .build();
 }
 /**
  * The shortcut of building a simple alert notification object to all platforms and all audiences
  */
 public static PushPayload alertAll(String alert) {
   return new Builder()
       .setPlatform(Platform.all())
       .setAudience(Audience.all())
       .setNotification(Notification.alert(alert))
       .build();
 }
  @Test
  public void lackOfParams_audience() {
    JsonObject payload = new JsonObject();
    payload.add("platform", Platform.all().toJSON());
    payload.add("notification", Notification.alert(ALERT).toJSON());
    System.out.println("json string: " + payload.toString());

    try {
      _client.sendPush(payload.toString());
    } catch (APIConnectionException e) {
      e.printStackTrace();
    } catch (APIRequestException e) {
      assertEquals(LACK_OF_PARAMS, e.getErrorCode());
    }
  }
  @Test
  public void invalidParams_platform() {
    JsonObject payload = new JsonObject();
    payload.add("platform", new JsonPrimitive("all_platform"));
    payload.add("audience", Audience.all().toJSON());
    payload.add("notification", Notification.alert(ALERT).toJSON());
    System.out.println("json string: " + payload.toString());

    try {
      _client.sendPush(payload.toString());
    } catch (APIConnectionException e) {
      e.printStackTrace();
    } catch (APIRequestException e) {
      assertEquals(INVALID_PARAMS, e.getErrorCode());
    }
  }
 @Override
 public boolean sendAll(String msg) {
   PushPayload payload =
       PushPayload.newBuilder()
           .setPlatform(Platform.all())
           .setAudience(Audience.all())
           .setNotification(Notification.alert(msg))
           .build();
   try {
     PushResult result = jpushClient.sendPush(payload);
     return result.isResultOK();
   } catch (Exception e1) {
     errorLogger.writeErrorLog(e1.getMessage());
     appLogger.error(e1.getMessage(), e1);
     debugLogger.error(e1.getMessage(), e1);
     return false;
   }
 }