use of org.motechproject.email.domain.DeliveryStatus 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.DeliveryStatus 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.DeliveryStatus in project motech by motech.
the class EmailRecordServiceBundleIT method shouldCreateIdenticalMessages.
@Test
public void shouldCreateIdenticalMessages() {
DeliveryStatus deliveryStatus = DeliveryStatus.SENT;
String fromAddress = "f@adr";
String toAddress = "t@adr";
String subject = "test-subject";
String message = "test-message";
DateTime messageTime = DateUtil.now().toDateTime(DateTimeZone.UTC);
EmailRecord emailRecord = new EmailRecord(fromAddress, toAddress, subject, message, messageTime, deliveryStatus);
emailRecordService.create(emailRecord);
EmailRecord duplicateMessage = new EmailRecord(fromAddress, toAddress, subject, message, messageTime, deliveryStatus);
emailRecordService.create(duplicateMessage);
List<EmailRecord> allMessages = emailRecordService.findByRecipientAddress(toAddress);
assertEquals(2, allMessages.size());
}
use of org.motechproject.email.domain.DeliveryStatus in project motech by motech.
the class EmailRecordServiceBundleIT method shouldAddAndUpdateEmail.
@Test
public void shouldAddAndUpdateEmail() {
DeliveryStatus deliveryStatus = DeliveryStatus.SENT;
String fromAddress = "f@adr";
String toAddress = "t@adr";
String subject = "test-subject";
String message = "test-message";
DateTime messageTime = DateUtil.now().toDateTime(DateTimeZone.UTC);
EmailRecord expected = new EmailRecord(fromAddress, toAddress, subject, message, messageTime, deliveryStatus);
emailRecordService.create(expected);
List<EmailRecord> emailRecords = emailRecordService.retrieveAll();
assertEquals(asList(expected), emailRecords);
EmailRecord actual = emailRecords.get(0);
actual.setMessage("test-newmessage");
emailRecordService.update(actual);
emailRecords = emailRecordService.retrieveAll();
assertEquals(asList(actual), emailRecords);
}
use of org.motechproject.email.domain.DeliveryStatus in project motech by motech.
the class AbstractSearchExecution method execute.
@Override
public T execute(Query query, InstanceSecurityRestriction restriction) {
List<Property> properties = new ArrayList<>();
Range<DateTime> deliveryTimeRange = criteria.getDeliveryTimeRange();
boolean dateRangeUsed = isUsableRange(deliveryTimeRange);
if (dateRangeUsed) {
properties.add(new RangeProperty<>("deliveryTime", deliveryTimeRange, DateTime.class.getName()));
}
Set<DeliveryStatus> deliveryStatuses = criteria.getDeliveryStatuses();
if (deliveryStatuses.isEmpty()) {
deliveryStatuses = new HashSet<>(Arrays.asList(DeliveryStatus.values()));
}
properties.add(new SetProperty<>("deliveryStatus", deliveryStatuses, DeliveryStatus.class.getName()));
StringBuilder queryBuilder = new StringBuilder(initialQuery(dateRangeUsed));
int initialLength = queryBuilder.length();
if (StringUtils.isNotEmpty(criteria.getToAddress())) {
properties.add(new MatchesProperty("toAddress", criteria.getToAddress()));
extendQueryWithOrClause(queryBuilder, initialLength);
}
if (StringUtils.isNotEmpty(criteria.getFromAddress())) {
properties.add(new MatchesProperty("fromAddress", criteria.getFromAddress()));
extendQueryWithOrClause(queryBuilder, initialLength);
}
if (StringUtils.isNotEmpty(criteria.getMessage())) {
properties.add(new MatchesProperty("message", criteria.getMessage()));
extendQueryWithOrClause(queryBuilder, initialLength);
}
if (StringUtils.isNotEmpty(criteria.getSubject())) {
properties.add(new MatchesProperty("subject", criteria.getSubject()));
extendQueryWithOrClause(queryBuilder, initialLength);
}
closeQuery(queryBuilder, initialLength);
if (restriction != null && !restriction.isEmpty()) {
properties.add(new RestrictionProperty(restriction, SecurityUtil.getUsername()));
queryBuilder.append(" && %s");
}
QueryUtil.useFilterFromPattern(query, queryBuilder.toString(), properties);
return execute(query, properties);
}
Aggregations