@Override protected boolean isDeleteAllowed(ServiceContext context, Entity entity) { Notification notification = (Notification) entity; Notification.State state = notification.getState(); return !(state.equals(Notification.State.CREATED) || state.equals(Notification.State.STARTED) || state.equals(Notification.State.SCHEDULED)); }
Map<String, Object> properties = new HashMap<String, Object>(2); properties.put("started", notification.getStarted()); properties.put("state", notification.getState()); notification.addProperties(properties); if (logger.isTraceEnabled()) {
properties.put("state", notification.getState()); if (errorMessages.size() > 0) { if (notification.getErrorMessage() == null) {
@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 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()); }
assertEquals(Notification.State.FINISHED, notification.getState());