EmailNotificationPublisher implements NotificationPublisher { @Override public void publish(String sender, String subject, Set<OrganizationalEntity> recipients, String body) { Email emailNotification = createEmail(sender, subject, recipients, body, connection); SendHtml.sendHtml(emailNotification, false); } EmailNotificationPublisher();  EmailNotificationPublisher(Connection connection, UserInfo userInfo); @Override void publish(String sender, String subject, Set<OrganizationalEntity> recipients, String body); @Override void publish(String sender, String subject, Set<OrganizationalEntity> recipients, String template, Map<String, Object> parameters); @Override boolean isActive();  }
@Test public void testEmailNotificationWithoutTemplate() throws Exception { EmailNotificationPublisher publisher = new EmailNotificationPublisher(connection, userInfo); Set<OrganizationalEntity> recipients = new HashSet<>(Arrays.asList(factory.newUser("john"))); publisher.publish("admin@jbpm.org", "Test notification", recipients, "Test body"); assertEquals( 1, wiser.getMessages().size() ); MimeMessage msg = (( WiserMessage ) wiser.getMessages().get( 0 )).getMimeMessage(); String content = ((String) msg.getContent()).replace("\r\n", ""); assertEquals( "Test body", content ); assertEquals( "Test notification", msg.getSubject() ); assertEquals( "admin@jbpm.org", ((InternetAddress)msg.getFrom()[0]).getAddress() ); assertEquals( "john@domain.com", ((InternetAddress)msg.getRecipients( RecipientType.TO )[0]).getAddress() ); assertNull( msg.getRecipients( RecipientType.CC ) ); assertNull( msg.getRecipients( RecipientType.BCC ) ); }
@Test public void testEmailNotificationWithTemplate() throws Exception { EmailNotificationPublisher publisher = new EmailNotificationPublisher(connection, userInfo); Map<String, Object> parameters = new HashMap<>(); parameters.put("Name", "John Doe"); Set<OrganizationalEntity> recipients = new HashSet<>(Arrays.asList(factory.newUser("john"))); publisher.publish("admin@jbpm.org", "Test notification", recipients, "basic-email", parameters); assertEquals( 1, wiser.getMessages().size() ); String expectedBody = "<html><body>Hello John Doe</body></html>"; MimeMessage msg = (( WiserMessage ) wiser.getMessages().get( 0 )).getMimeMessage(); String content = ((String) msg.getContent()).replace("\r\n", ""); assertEquals( expectedBody, content ); assertEquals( "Test notification", msg.getSubject() ); assertEquals( "admin@jbpm.org", ((InternetAddress)msg.getFrom()[0]).getAddress() ); assertEquals( "john@domain.com", ((InternetAddress)msg.getRecipients( RecipientType.TO )[0]).getAddress() ); assertNull( msg.getRecipients( RecipientType.CC ) ); assertNull( msg.getRecipients( RecipientType.BCC ) ); }
@Test public void testEmailNotificationWithoutTemplateToGroup() throws Exception { EmailNotificationPublisher publisher = new EmailNotificationPublisher(connection, userInfo); Set<OrganizationalEntity> recipients = new HashSet<>(Arrays.asList(factory.newGroup("managers"))); publisher.publish("admin@jbpm.org", "Test notification", recipients, "Test body"); assertEquals( 1, wiser.getMessages().size() ); MimeMessage msg = (( WiserMessage ) wiser.getMessages().get( 0 )).getMimeMessage(); String content = ((String) msg.getContent()).replace("\r\n", ""); assertEquals( "Test body", content ); assertEquals( "Test notification", msg.getSubject() ); assertEquals( "admin@jbpm.org", ((InternetAddress)msg.getFrom()[0]).getAddress() ); assertEquals( "john@domain.com", ((InternetAddress)msg.getRecipients( RecipientType.TO )[0]).getAddress() ); assertNull( msg.getRecipients( RecipientType.CC ) ); assertNull( msg.getRecipients( RecipientType.BCC ) ); }
@Test public void testEmailNotificationWithoutTemplateToMultipleRecipients() throws Exception { EmailNotificationPublisher publisher = new EmailNotificationPublisher(connection, userInfo); Set<OrganizationalEntity> recipients = new LinkedHashSet<>(Arrays.asList(factory.newGroup("managers"), factory.newUser("mary"))); publisher.publish("admin@jbpm.org", "Test notification", recipients, "Test body"); assertEquals( 2, wiser.getMessages().size() ); MimeMessage msg = (( WiserMessage ) wiser.getMessages().get( 0 )).getMimeMessage(); String content = ((String) msg.getContent()).replace("\r\n", ""); assertEquals( "Test body", content ); assertEquals( "Test notification", msg.getSubject() ); assertEquals( "admin@jbpm.org", ((InternetAddress)msg.getFrom()[0]).getAddress() ); assertEquals( "john@domain.com", ((InternetAddress)msg.getRecipients( RecipientType.TO )[0]).getAddress() ); assertNull( msg.getRecipients( RecipientType.CC ) ); assertNull( msg.getRecipients( RecipientType.BCC ) ); }