use of org.motechproject.email.builder.EmailRecordSearchCriteria 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.builder.EmailRecordSearchCriteria 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.builder.EmailRecordSearchCriteria in project motech by motech.
the class AbstractSearchExecutionTest method shouldSetCorrectParams.
@Test
public void shouldSetCorrectParams() {
when(restriction.isEmpty()).thenReturn(false);
when(restriction.isByCreator()).thenReturn(true);
when(query.executeWithArray(anyVararg())).thenReturn(queryResult());
EmailRecordSearchCriteria criteria = new EmailRecordSearchCriteria().withFromAddress("from@address.com").withMessageTimeRange(new Range<>(PAST, FUTURE)).withMessage("text to search").withDeliveryStatuses(DeliveryStatus.RECEIVED, DeliveryStatus.ERROR).withQueryParams(queryParams);
AbstractSearchExecution execution = createExecution(criteria);
Object result = execution.execute(query, restriction);
verify(query).setFilter("deliveryTime>=param0lb && deliveryTime<=param0ub && " + "(deliveryStatus == param1_0 || deliveryStatus == param1_1) && (fromAddress.matches(param2) || " + "message.matches(param3)) && creator == param4");
verify(query).declareParameters("org.joda.time.DateTime param0lb, org.joda.time.DateTime param0ub, " + DeliveryStatus.class.getName() + " param1_0, " + DeliveryStatus.class.getName() + " param1_1, " + "java.lang.String param2, java.lang.String param3, java.lang.String param4");
verify(query).executeWithArray(argThat(new QueryExecutionMatcher()));
verifyImplementationDetails();
assertResult(result);
}
use of org.motechproject.email.builder.EmailRecordSearchCriteria in project motech by motech.
the class EmailControllerTest method shouldExportEmailMonthAsCsv.
@Test
public void shouldExportEmailMonthAsCsv() throws Exception {
StringWriter writer = new StringWriter();
when(response.getWriter()).thenReturn(new PrintWriter(writer));
emailController.exportEmailLog("month", "01-1969", response, request);
ArgumentCaptor<EmailRecordSearchCriteria> captor = ArgumentCaptor.forClass(EmailRecordSearchCriteria.class);
verify(auditService).findEmailRecords(captor.capture());
assertTrue(captor.getValue().getDeliveryTimeRange().getMin().isEqual(DateTime.parse("1969-01-01T00:00:00.000")));
assertTrue(captor.getValue().getDeliveryTimeRange().getMax().isEqual(DateTime.parse("1969-01-31T23:59:59.999")));
assertEquals(writer.toString(), getTestEmailRecordsAsCsv());
}
use of org.motechproject.email.builder.EmailRecordSearchCriteria in project motech by motech.
the class EmailControllerTest method shouldExportEmailTableAsCsv.
@Test
public void shouldExportEmailTableAsCsv() throws Exception {
StringWriter writer = new StringWriter();
GridSettings filter = new GridSettings();
filter.setDeliveryStatus("SENT");
filter.setPage(1);
filter.setRows(5);
filter.setTimeFrom("1969-01-01 00:00:00");
filter.setTimeTo("1969-01-31 23:59:59");
when(lastFilter.get(anyString())).thenReturn(filter);
when(response.getWriter()).thenReturn(new PrintWriter(writer));
emailController.exportEmailLog("table", null, response, request);
ArgumentCaptor<EmailRecordSearchCriteria> captor = ArgumentCaptor.forClass(EmailRecordSearchCriteria.class);
verify(auditService).findEmailRecords(captor.capture());
assertArrayEquals(new DeliveryStatus[] { DeliveryStatus.SENT }, captor.getValue().getDeliveryStatuses().toArray());
assertEquals(filter.getPage(), captor.getValue().getQueryParams().getPage());
assertEquals(filter.getRows(), captor.getValue().getQueryParams().getPageSize());
assertTrue(captor.getValue().getDeliveryTimeRange().getMin().isEqual(DateTime.parse("1969-01-01T00:00:00")));
assertTrue(captor.getValue().getDeliveryTimeRange().getMax().isEqual(DateTime.parse("1969-01-31T23:59:59")));
assertEquals(getTestEmailRecordsAsCsv(), writer.toString());
}
Aggregations