final Map<String, Object> payloads = notification.getPayloads(); final Map<String, Object> translatedPayloads = translatePayloads(payloads, notifierMap); if (logger.isTraceEnabled()) {
final Map<String, Object> payloads = notification.getPayloads();
@Test public void twoBatchNotification() throws Exception { app.clear(); String payload = "Hello, World!"; Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getUuid().toString(), payload); app.put("payloads", payloads); app.put("queued", System.currentTimeMillis()); app.put("debug", true); Entity e = app.testRequest(ServiceAction.POST, 1, "devices", "notifications").getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals( notification.getPayloads().get(notifier.getUuid().toString()), payload); // reduce Batch size to 1 Field field = GCMAdapter.class.getDeclaredField("BATCH_SIZE"); field.setAccessible(true); int multicastSize = field.getInt(GCMAdapter.class); try { field.setInt(GCMAdapter.class, 1); // perform push // notification = notificationWaitForComplete(notification); checkReceipts(notification, 2); } finally { field.setInt(GCMAdapter.class, multicastSize); } }
@Test public void singlePushNotificationMultipleDevices() throws Exception { app.clear(); String payload = "Hello, World!"; Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getUuid().toString(), payload); app.put("payloads", payloads); app.put("queued", System.currentTimeMillis()); app.put("debug", true); app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time Entity e = app.testRequest(ServiceAction.POST, 1, "devices", "*", "notifications").getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals( notification.getPayloads().get(notifier.getUuid().toString()), payload); // perform push // notification = notificationWaitForComplete(notification); checkReceipts(notification, 2); }
@Test public void singlePushNotificationWithMapPayload() throws Exception { app.clear(); String payload = "{\"message\":\"Hello, World!\", \"campaign\":\"Hello Campaign\"}"; Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getUuid().toString(), payload); app.put("payloads", payloads); app.put("queued", System.currentTimeMillis()); app.put("debug", true); app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications").getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals( notification.getPayloads().get(notifier.getUuid().toString()), payload); // perform push // notification = notificationWaitForComplete(notification); checkReceipts(notification, 1); }
@Test public void singlePushNotificationNoReceipts() throws Exception { app.clear(); String payload = "Hello, World!"; Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getUuid().toString(), payload); app.put("payloads", payloads); app.put("queued", System.currentTimeMillis()); app.put("debug", true); app.put("saveReceipts",false ); app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications").getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals( notification.getPayloads().get(notifier.getUuid().toString()), payload); // perform push // notification = notificationWaitForComplete(notification); checkReceipts(notification, 0); }
@Test public void singlePushNotification() throws Exception { app.clear(); String payload = "Hello, World!"; Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getUuid().toString(), payload); app.put("payloads", payloads); app.put("queued", System.currentTimeMillis()); app.put("debug", true); app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications").getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals( notification.getPayloads().get(notifier.getUuid().toString()), payload); // perform push // notification = notificationWaitForComplete(notification); checkReceipts(notification, 1); }
@Test public void singlePushNotificationNoReceipts() throws Exception { app.clear(); String payload = "Hello, World!"; Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getUuid().toString(), payload); app.put("payloads", payloads); app.put("queued", System.currentTimeMillis()); app.put("debug", true); app.put("saveReceipts",false ); app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications").getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals( notification.getPayloads().get(notifier.getUuid().toString()), payload); // perform push // notification = notificationWaitForComplete(notification); checkReceipts(notification, 0); }
@Ignore("turn this on and run individually when you want to verify. there is an issue with the aggregate counter, because of all the other tests" + "AND, there is an issue with the batcher where we have to turn it up/down to see the results in time. ") @Test public void singlePushNotificationWithCounters() throws Exception { long ts = System.currentTimeMillis() - ( 24 * 60 * 60 * 1000 ); app.clear(); String payload = "Hello, World!"; Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getUuid().toString(), payload); app.put("payloads", payloads); app.put("queued", System.currentTimeMillis()); app.put("debug", false); app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications").getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals( notification.getPayloads().get(notifier.getUuid().toString()), payload); // perform push // notification = notificationWaitForComplete(notification); // checkReceipts(notification, 1); verifyNotificationCounter( notification,"completed",ts,1 ); verifyNotificationCounter( notification,"failed",ts, 0 ); }
@Test public void scheduledNotificationAndEnsureSend() throws Exception { // create push notification // app.clear(); String payload = getPayload(); Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getUuid().toString(), payload); app.put("payloads", payloads); app.put("deliver", System.currentTimeMillis() + 2000); app.put("debug",true); Entity e = app.testRequest(ServiceAction.POST, 1,"devices",device1.getUuid(), "notifications") .getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals( notification.getPayloads().get(notifier.getUuid().toString()), payload); // delay until the scheduler has time to run Notification.State notificationState = Notification.State.SCHEDULED; int retry = 60; do { logger.info("Sleeping while the scheduler does its work " + retry); Thread.sleep(1000); notificationState = app.getEntityManager().get(e.getUuid(), Notification.class).getState(); } while (Notification.State.FINISHED != notificationState && --retry >= 0 ); assertEquals(Notification.State.FINISHED, notificationState); }
@Test public void singlePushNotificationHighPriority() throws Exception { app.clear(); String payload = "Hello, World!"; Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getUuid().toString(), payload); app.put("payloads", payloads); app.put("queued", System.currentTimeMillis()); app.put("debug", true); app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time app.put("priority", "high"); Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications").getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals( notification.getPayloads().get(notifier.getUuid().toString()), payload); // perform push // notification = notificationWaitForComplete(notification); assertEquals("high", notification.getPriority()); checkReceipts(notification, 1); }
@Test public void singlePushNotification() throws Exception { app.clear(); String payload = getPayload(); Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getName(), payload); app.put("payloads", payloads); app.put("queued", System.currentTimeMillis()); app.put("debug",true); app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time // post notification to service manager Entity e = app.testRequest(ServiceAction.POST, 1,"devices",device1.getUuid(), "notifications").getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); // ensure notification has expected name Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals( notification.getPayloads().get(notifier.getName().toString()), payload); // perform push // notification = notificationWaitForComplete(notification); checkReceipts(notification, 1); }
@Test public void scheduledNotification() throws Exception { // create push notification // app.clear(); String payload = getPayload(); Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getUuid().toString(), payload); app.put("payloads", payloads); app.put("deliver", System.currentTimeMillis() + 240000); app.put("debug",true); Entity e = app.testRequest(ServiceAction.POST, 1,"devices",device1.getUuid(), "notifications") .getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals( notification.getPayloads().get(notifier.getUuid().toString()), payload); // delay until the scheduler has time to run Thread.sleep(500); notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals(Notification.State.SCHEDULED, notification.getState()); }
@Test public void singlePushNotificationWithInvalidPriority() throws Exception { app.clear(); String payload = "Hello, World!"; Map<String, String> payloads = new HashMap<String, String>(1); payloads.put(notifier.getUuid().toString(), payload); app.put("payloads", payloads); app.put("queued", System.currentTimeMillis()); app.put("debug", true); app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current time app.put("priority", "not_a_priority"); Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications").getEntity(); app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid()); Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals( notification.getPayloads().get(notifier.getUuid().toString()), payload); // perform push // notification = notificationWaitForComplete(notification); // if priority is invalid, it should default to normal assertEquals("normal", notification.getPriority()); checkReceipts(notification, 1); }
Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class); assertEquals( notification.getPayloads().get(notifier.getUuid().toString()), payload);
notification.getPayloads().get(notifier.getUuid().toString()), payload);
assertEquals(payload, notification.getPayloads().get(notifierName));
assertEquals(notification.getPayloads().get(notifierName), payload);
notification.getPayloads().get(notifier.getName()), payload);
notification.getPayloads().get(notifier.getUuid().toString()), payload );