@Test public void testNotifyFullFields() throws Exception { final String url = "http: final String sourceName = "Source Name"; final String sourceUniqueId = "Source Unique ID"; final EntityType sourceType = EntityType.GROUP; final String actorUniqueId = "Actor Unique ID"; final EntityType actorType = EntityType.PERSON; final Identifiable source = context.mock(Identifiable.class, "source"); final Identifiable actor = context.mock(Identifiable.class, "actor"); context.checking(new Expectations() { { oneOf(placeholderPersonMapper).execute(RECIPIENT1); will(returnValue(person1)); oneOf(velocityEngine).evaluate(with(any(VelocityContext.class)), with(any(StringWriter.class)), with(equal("InAppNotification-POST_TO_PERSONAL_STREAM")), with(equal(TEMPLATE))); will(new AppendRenderedAction()); oneOf(insertMapper).execute(with(new EasyMatcher<PersistenceRequest>() { @Override protected boolean isMatch(final PersistenceRequest testObject) { InAppNotificationEntity notif = (InAppNotificationEntity) testObject.getDomainEnity(); return person1 == notif.getRecipient() && RENDERED.equals(notif.getMessage()) && OK_TYPE == notif.getNotificationType() && url.equals(notif.getUrl()) && notif.isHighPriority() && notif.getSourceType() == EntityType.GROUP && sourceUniqueId.equals(notif.getSourceUniqueId()) && sourceName.equals(notif.getSourceName()) && notif.getAvatarOwnerType() == EntityType.PERSON && actorUniqueId.equals(notif.getAvatarOwnerUniqueId()); } })); oneOf(syncMapper).execute(RECIPIENT1); allowing(source).getDisplayName(); will(returnValue(sourceName)); allowing(source).getUniqueId(); will(returnValue(sourceUniqueId)); allowing(source).getEntityType(); will(returnValue(sourceType)); allowing(actor).getUniqueId(); will(returnValue(actorUniqueId)); allowing(actor).getEntityType(); will(returnValue(actorType)); oneOf(person1).getId(); will(returnValue(RECIPIENT1)); } }); Map<String, Object> properties = new HashMap<String, Object>(); properties.put(NotificationPropertyKeys.URL, url); properties.put(NotificationPropertyKeys.HIGH_PRIORITY, Boolean.TRUE); properties.put(NotificationPropertyKeys.SOURCE, source); properties.put(NotificationPropertyKeys.ACTOR, actor); Collection<UserActionRequest> result = sut.notify(NotificationType.POST_TO_PERSONAL_STREAM, Collections.singletonList(RECIPIENT1), properties, recipientIndex); context.assertIsSatisfied(); assertNull(result); }
@Override public Collection<UserActionRequest> notify(final NotificationType inType, final Collection<Long> inRecipients, final Map<String, Object> inProperties, final Map<Long, PersonModelView> inRecipientIndex) throws Exception { Context velocityContext = new VelocityContext(new VelocityContext(inProperties, velocityGlobalContext)); velocityContext.put("context", velocityContext); velocityContext.put("type", inType); for (long recipientId : inRecipients) { Person recipient = placeholderPersonMapper.execute(recipientId); if (recipient == null) { continue; } if (aggregateTemplates.containsKey(inType)) { updateAggregateNotification(recipient, inType, inProperties, velocityContext); } else { createNewNotification(recipient, inType, inProperties, velocityContext); } } return null; }
InAppNotificationNotifier implements Notifier { @Override public Collection<UserActionRequest> notify(final NotificationType inType, final Collection<Long> inRecipients, final Map<String, Object> inProperties, final Map<Long, PersonModelView> inRecipientIndex) throws Exception { Context velocityContext = new VelocityContext(new VelocityContext(inProperties, velocityGlobalContext)); velocityContext.put("context", velocityContext); velocityContext.put("type", inType); for (long recipientId : inRecipients) { Person recipient = placeholderPersonMapper.execute(recipientId); if (recipient == null) { continue; } if (aggregateTemplates.containsKey(inType)) { updateAggregateNotification(recipient, inType, inProperties, velocityContext); } else { createNewNotification(recipient, inType, inProperties, velocityContext); } } return null; } }
InAppNotificationNotifier implements Notifier { @Override public Collection<UserActionRequest> notify(final NotificationType inType, final Collection<Long> inRecipients, final Map<String, Object> inProperties, final Map<Long, PersonModelView> inRecipientIndex) throws Exception { Context velocityContext = new VelocityContext(new VelocityContext(inProperties, velocityGlobalContext)); velocityContext.put("context", velocityContext); velocityContext.put("type", inType); for (long recipientId : inRecipients) { Person recipient = placeholderPersonMapper.execute(recipientId); if (recipient == null) { continue; } if (aggregateTemplates.containsKey(inType)) { updateAggregateNotification(recipient, inType, inProperties, velocityContext); } else { createNewNotification(recipient, inType, inProperties, velocityContext); } } return null; } InAppNotificationNotifier(final VelocityEngine inVelocityEngine, final Context inVelocityGlobalContext,
            final Map<NotificationType, String> inTemplates, final Map<NotificationType, String> inAggregateTemplates,
            final DomainMapper<PersistenceRequest<InAppNotificationEntity>, Boolean> inInsertMapper,
            final DomainMapper<PersistenceRequest<InAppNotificationEntity>, Boolean> inUpdateMapper,
            final DomainMapper<Long, UnreadInAppNotificationCountDTO> inSyncMapper,
            final DomainMapper<Long, Person> inPlaceholderPersonMapper,
            final DomainMapper<InAppNotificationEntity, InAppNotificationEntity> inExistingNotificationMapper); }
InAppNotificationNotifier implements Notifier { @Override public Collection<UserActionRequest> notify(final NotificationType inType, final Collection<Long> inRecipients, final Map<String, Object> inProperties, final Map<Long, PersonModelView> inRecipientIndex) throws Exception { Context velocityContext = new VelocityContext(new VelocityContext(inProperties, velocityGlobalContext)); velocityContext.put("context", velocityContext); velocityContext.put("type", inType); for (long recipientId : inRecipients) { Person recipient = placeholderPersonMapper.execute(recipientId); if (recipient == null) { continue; } if (aggregateTemplates.containsKey(inType)) { updateAggregateNotification(recipient, inType, inProperties, velocityContext); } else { createNewNotification(recipient, inType, inProperties, velocityContext); } } return null; } InAppNotificationNotifier(final VelocityEngine inVelocityEngine, final Context inVelocityGlobalContext,
            final Map<NotificationType, String> inTemplates, final Map<NotificationType, String> inAggregateTemplates,
            final DomainMapper<PersistenceRequest<InAppNotificationEntity>, Boolean> inInsertMapper,
            final DomainMapper<PersistenceRequest<InAppNotificationEntity>, Boolean> inUpdateMapper,
            final DomainMapper<Long, UnreadInAppNotificationCountDTO> inSyncMapper,
            final DomainMapper<Long, Person> inPlaceholderPersonMapper,
            final DomainMapper<InAppNotificationEntity, InAppNotificationEntity> inExistingNotificationMapper); @Override Collection<UserActionRequest> notify(final NotificationType inType, final Collection<Long> inRecipients,
            final Map<String, Object> inProperties, final Map<Long, PersonModelView> inRecipientIndex); }
InAppNotificationNotifier implements Notifier { @Override public Collection<UserActionRequest> notify(final NotificationType inType, final Collection<Long> inRecipients, final Map<String, Object> inProperties, final Map<Long, PersonModelView> inRecipientIndex) throws Exception { Context velocityContext = new VelocityContext(new VelocityContext(inProperties, velocityGlobalContext)); velocityContext.put("context", velocityContext); velocityContext.put("type", inType); for (long recipientId : inRecipients) { Person recipient = placeholderPersonMapper.execute(recipientId); if (recipient == null) { continue; } if (aggregateTemplates.containsKey(inType)) { updateAggregateNotification(recipient, inType, inProperties, velocityContext); } else { createNewNotification(recipient, inType, inProperties, velocityContext); } } return null; } InAppNotificationNotifier(final VelocityEngine inVelocityEngine, final Context inVelocityGlobalContext,
            final Map<NotificationType, String> inTemplates, final Map<NotificationType, String> inAggregateTemplates,
            final DomainMapper<PersistenceRequest<InAppNotificationEntity>, Boolean> inInsertMapper,
            final DomainMapper<PersistenceRequest<InAppNotificationEntity>, Boolean> inUpdateMapper,
            final DomainMapper<Long, UnreadInAppNotificationCountDTO> inSyncMapper,
            final DomainMapper<Long, Person> inPlaceholderPersonMapper,
            final DomainMapper<InAppNotificationEntity, InAppNotificationEntity> inExistingNotificationMapper); @Override Collection<UserActionRequest> notify(final NotificationType inType, final Collection<Long> inRecipients,
            final Map<String, Object> inProperties, final Map<Long, PersonModelView> inRecipientIndex);  }