use of com.haulmont.cuba.core.entity.SendingMessage in project cuba by cuba-platform.
the class Emailer method migrateMessagesBatch.
protected int migrateMessagesBatch() {
List<SendingMessage> resultList;
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
String qstr = "select m from sys$SendingMessage m where m.contentText is not null";
TypedQuery<SendingMessage> query = em.createQuery(qstr, SendingMessage.class);
query.setMaxResults(50);
query.setViewName(View.MINIMAL);
resultList = query.getResultList();
tx.commit();
} finally {
tx.end();
}
if (!resultList.isEmpty()) {
emailer.migrateEmailsToFileStorage(resultList);
}
return resultList.size();
}
use of com.haulmont.cuba.core.entity.SendingMessage in project cuba by cuba-platform.
the class EmailerTest method doTestAsynchronous.
private void doTestAsynchronous(boolean useFs) throws Exception {
emailerConfig.setFileStorageUsed(useFs);
testMailSender.clearBuffer();
String body = "Test Email Body";
EmailInfo myInfo = new EmailInfo("recipient@example.com", "Test", body);
List<SendingMessage> messages = emailer.sendEmailAsync(myInfo);
assertEquals(1, messages.size());
// not sent yet
assertTrue(testMailSender.isEmpty());
SendingMessage sendingMsg = reload(messages.get(0));
assertEquals(SendingStatus.QUEUE, sendingMsg.getStatus());
// run scheduler
emailer.processQueuedEmails();
// check
assertEquals(1, testMailSender.getBufferSize());
MimeMessage msg = testMailSender.fetchSentEmail();
assertEquals(1, msg.getAllRecipients().length);
assertEquals("recipient@example.com", msg.getAllRecipients()[0].toString());
assertEquals("Test", msg.getSubject());
assertEquals(body, getBody(msg));
assertTrue(getBodyContentType(msg).startsWith("text/plain;"));
sendingMsg = reload(messages.get(0));
assertEquals(SendingStatus.SENT, sendingMsg.getStatus());
}
use of com.haulmont.cuba.core.entity.SendingMessage in project cuba by cuba-platform.
the class EmailerTest method testAsynchronousAttemptLimit.
@Test
public void testAsynchronousAttemptLimit() throws Exception {
testMailSender.clearBuffer();
String body = "Test Email Body";
EmailInfo myInfo = new EmailInfo("recipient@example.com", "Test", body);
List<SendingMessage> messages = emailer.sendEmailAsync(myInfo, 2, getDeadlineWhichDoesntMatter());
assertEquals(1, messages.size());
// not sent yet
assertTrue(testMailSender.isEmpty());
SendingMessage sendingMsg = reload(messages.get(0));
assertEquals(SendingStatus.QUEUE, sendingMsg.getStatus());
// will fail
testMailSender.failPlease();
try {
// try once
emailer.processQueuedEmails();
sendingMsg = reload(sendingMsg);
assertEquals(SendingStatus.QUEUE, sendingMsg.getStatus());
// try second time
emailer.processQueuedEmails();
sendingMsg = reload(sendingMsg);
assertEquals(SendingStatus.QUEUE, sendingMsg.getStatus());
} finally {
testMailSender.workNormallyPlease();
}
// marks as not-sent in the next tick
emailer.processQueuedEmails();
sendingMsg = reload(sendingMsg);
assertEquals(SendingStatus.NOTSENT, sendingMsg.getStatus());
assertEquals(2, sendingMsg.getAttemptsCount().intValue());
}
use of com.haulmont.cuba.core.entity.SendingMessage in project cuba by cuba-platform.
the class EmailerTest method doTestLoadBody.
private void doTestLoadBody(boolean useFs) throws Exception {
emailerConfig.setFileStorageUsed(useFs);
String body = "Hi! This is test email. Bye.";
EmailInfo emailInfo = new EmailInfo("test@example.com", "Test", body);
List<SendingMessage> messages = emailer.sendEmailAsync(emailInfo);
SendingMessage msg = reload(messages.get(0));
String actualBody = emailer.loadContentText(msg);
assertEquals(body, actualBody);
}
Aggregations