/** The shortcut of building a simple message object to all platforms and all audiences */ public static PushPayload messageAll(String msgContent) { return new Builder() .setPlatform(Platform.all()) .setAudience(Audience.all()) .setMessage(Message.content(msgContent)) .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_messageAndNotificaiton() { JsonObject payload = new JsonObject(); payload.add("platform", Platform.all().toJSON()); payload.add("audience", Audience.all().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; } }
@Test public void invalidParams_notification_winphone_empty() { JsonObject payload = new JsonObject(); payload.add("platform", Platform.all().toJSON()); payload.add("audience", Audience.all().toJSON()); JsonObject notification = new JsonObject(); JsonObject winphone = new JsonObject(); notification.add("winphone", winphone); payload.add("notification", notification); 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()); } }
@Test public void invalidParams_notification_android_builderidNotNumber() { JsonObject payload = new JsonObject(); payload.add("platform", Platform.all().toJSON()); payload.add("audience", Audience.all().toJSON()); JsonObject notification = new JsonObject(); JsonObject android = new JsonObject(); android.add("builder_id", new JsonPrimitive("builder_id_string")); notification.add("android", android); payload.add("notification", notification); 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()); } }