Search in sources :

Example 1 with EmailRecord

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()));
}
Also used : Order(org.motechproject.mds.util.Order) EmailRecord(org.motechproject.email.domain.EmailRecord) QueryParams(org.motechproject.mds.query.QueryParams) EmailRecordSearchCriteria(org.motechproject.email.builder.EmailRecordSearchCriteria) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with EmailRecord

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());
}
Also used : EmailRecord(org.motechproject.email.domain.EmailRecord) DeliveryStatus(org.motechproject.email.domain.DeliveryStatus) EmailRecordSearchCriteria(org.motechproject.email.builder.EmailRecordSearchCriteria) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with EmailRecord

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());
}
Also used : EmailRecord(org.motechproject.email.domain.EmailRecord) Test(org.junit.Test)

Example 4 with EmailRecord

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()));
}
Also used : EmailRecord(org.motechproject.email.domain.EmailRecord) DeliveryStatus(org.motechproject.email.domain.DeliveryStatus) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 5 with EmailRecord

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;
}
Also used : EmailRecord(org.motechproject.email.domain.EmailRecord) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime)

Aggregations

EmailRecord (org.motechproject.email.domain.EmailRecord)14 ArrayList (java.util.ArrayList)6 DateTime (org.joda.time.DateTime)6 Test (org.junit.Test)6 DeliveryStatus (org.motechproject.email.domain.DeliveryStatus)5 EmailRecordSearchCriteria (org.motechproject.email.builder.EmailRecordSearchCriteria)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 HashSet (java.util.HashSet)1 EmailRecords (org.motechproject.email.domain.EmailRecords)1 Mail (org.motechproject.email.domain.Mail)1 EmailSendException (org.motechproject.email.exception.EmailSendException)1 QueryParams (org.motechproject.mds.query.QueryParams)1 Order (org.motechproject.mds.util.Order)1 MailException (org.springframework.mail.MailException)1 Transactional (org.springframework.transaction.annotation.Transactional)1 CsvBeanWriter (org.supercsv.io.CsvBeanWriter)1