use of org.motechproject.email.domain.EmailRecord in project motech by motech.
the class EmailAuditServiceBundleIT method shouldCountAndRetrieveEmailsBasedOnCriteria.
@Test
public void shouldCountAndRetrieveEmailsBasedOnCriteria() {
emailRecordService.create(createEmailRecord("address@1.com", "something", DeliveryStatus.SENT));
emailRecordService.create(createEmailRecord("address@2.com", "a subject", DeliveryStatus.SENT));
emailRecordService.create(createEmailRecord("address3@1.com", "received this?", DeliveryStatus.RECEIVED));
emailRecordService.create(createEmailRecord("something@1.com", "was sent", DeliveryStatus.SENT));
emailRecordService.create(createEmailRecord("address@1.com", "error", DeliveryStatus.ERROR));
QueryParams queryParams = new QueryParams(1, 10, new Order("subject", Order.Direction.DESC));
EmailRecordSearchCriteria criteria = new EmailRecordSearchCriteria().withToAddress("address").withDeliveryStatuses(DeliveryStatus.SENT, DeliveryStatus.RECEIVED).withQueryParams(queryParams).withMessageTimeRange(new Range<DateTime>(null, null));
assertEquals(3, emailAuditService.countEmailRecords(criteria));
List<EmailRecord> records = emailAuditService.findEmailRecords(criteria);
assertEquals(asList("something", "received this?", "a subject"), extract(records, on(EmailRecord.class).getSubject()));
assertEquals(asList("address@1.com", "address3@1.com", "address@2.com"), extract(records, on(EmailRecord.class).getToAddress()));
assertEquals(asList(DeliveryStatus.SENT, DeliveryStatus.RECEIVED, DeliveryStatus.SENT), extract(records, on(EmailRecord.class).getDeliveryStatus()));
}
use of org.motechproject.email.domain.EmailRecord in project motech by motech.
the class EmailAuditServiceBundleIT method shouldRetrieveEmailRecordWithSearchCriteria.
@Test
public void shouldRetrieveEmailRecordWithSearchCriteria() {
emailRecordService.create(createEmailRecord("to1@address", "s 1", DeliveryStatus.SENT));
emailRecordService.create(createEmailRecord("to@address2", "s 2", DeliveryStatus.SENT));
Set<DeliveryStatus> deliveryStatuses = new HashSet<>();
deliveryStatuses.add(DeliveryStatus.SENT);
EmailRecordSearchCriteria criteriaToAddress = new EmailRecordSearchCriteria().withToAddress("to@address").withDeliveryStatuses(deliveryStatuses);
List<EmailRecord> emailRecordsToAddress = emailAuditService.findEmailRecords(criteriaToAddress);
assertNotNull(emailRecordsToAddress);
assertEquals(1, emailRecordsToAddress.size());
}
use of org.motechproject.email.domain.EmailRecord in project motech by motech.
the class EmailAuditServiceBundleIT method shouldRetrieveEmailAuditRecord.
@Test
public void shouldRetrieveEmailAuditRecord() {
EmailRecord emailRecord = createEmailRecord("to@address", "topic", DeliveryStatus.SENT);
emailRecordService.create(emailRecord);
List<EmailRecord> emailRecords = emailAuditService.findAllEmailRecords();
assertNotNull(emailRecords);
assertTrue(emailRecords.size() > 0);
assertEquals(emailRecord.getFromAddress(), emailRecords.get(0).getFromAddress());
assertEquals(emailRecord.getToAddress(), emailRecords.get(0).getToAddress());
assertEquals("topic", emailRecords.get(0).getSubject());
}
use of org.motechproject.email.domain.EmailRecord in project motech by motech.
the class EmailRecordServiceBundleIT method shouldCreateEmail.
@Test
public void shouldCreateEmail() {
DeliveryStatus deliveryStatus = DeliveryStatus.SENT;
String fromAddress = "f@adr";
String toAddress = "t@adr";
String subject = "test-subject";
String message = "test-message";
DateTime sentDate = DateUtil.now();
EmailRecord emailRecord = new EmailRecord(fromAddress, toAddress, subject, message, sentDate, deliveryStatus);
emailRecordService.create(emailRecord);
List<EmailRecord> savedMessages = emailRecordService.findByRecipientAddress(toAddress);
assertNotNull(savedMessages);
assertEquals(asList(subject), extract(savedMessages, on(EmailRecord.class).getSubject()));
assertEquals(asList(message), extract(savedMessages, on(EmailRecord.class).getMessage()));
}
use of org.motechproject.email.domain.EmailRecord in project motech by motech.
the class EmailControllerTest method getTestEmailRecords.
private List<EmailRecord> getTestEmailRecords() {
List<EmailRecord> records = new ArrayList<>();
records.add(new EmailRecord("abc@gmail.com", "def@gmail.com", "subject", "message", new DateTime(1000), DeliveryStatus.SENT));
records.add(new EmailRecord("def@gmail.com", "abc@gmail.com", "subject2", "message2", new DateTime(2000), DeliveryStatus.SENT));
records.add(new EmailRecord("abc@yahoo.com", "def@gmail.com", "Asubject3", "message3", new DateTime(3000), DeliveryStatus.SENT));
records.add(new EmailRecord("abc@yahoo.com", "abc@gmail.com", "subject4", "message4", new DateTime(5000), DeliveryStatus.SENT));
records.add(new EmailRecord("abc@yahoo.com", "def@yahoo.com", "Bsubject5", "message5", new DateTime(4000), DeliveryStatus.SENT));
return records;
}
Aggregations