use of org.incode.module.communications.dom.mixins.Document_sendByEmail in project estatio by estatio.
the class InvoiceForLease_sendByEmail method choices0$$.
public List<Document> choices0$$() {
final List<Paperclip> paperclips = paperclipRepository.findByAttachedTo(invoice);
final List<Document> documents = Lists.newArrayList();
for (Paperclip paperclip : paperclips) {
final DocumentAbstract documentAbs = paperclip.getDocument();
if (!(documentAbs instanceof Document)) {
continue;
}
final Document document = (Document) documentAbs;
if (document.getState() != DocumentState.RENDERED) {
continue;
}
if (!DocumentTypeData.isPrimaryType(document)) {
continue;
}
final Document_sendByEmail document_email = document_sendByEmail(document);
if (document_email.disableAct() != null) {
continue;
}
documents.add(document);
}
return documents;
}
use of org.incode.module.communications.dom.mixins.Document_sendByEmail in project estatio by estatio.
the class Smoke_IntegTest method can_send_email.
@Test
public void can_send_email() throws Exception {
// given
fixtureScripts.runFixtureScript(new CommandDomModule().getTeardownFixtureWillDelete(), null);
fixtureScripts.runFixtureScript(new DemoObjectWithNotes_and_DemoInvoice_and_docs_and_comms_create(), null);
transactionService.nextTransaction();
// and so given customer with an email
final DemoObjectWithNotes fred = customerMenu.findDemoObjectsWithNotesByName(DemoObjectWithNote_and_DemoInvoice_create3.FRED_HAS_EMAIL_AND_PHONE).get(0);
final EmailAddress fredEmail = (EmailAddress) linkRepository.findByOwnerAndCommunicationChannelType(fred, CommunicationChannelType.EMAIL_ADDRESS).get(0).getCommunicationChannel();
// and with an invoice
final DemoInvoice fredInvoice = invoiceRepository.findByCustomer(fred).get(0);
// that has an attached document
final Paperclip paperclip = paperclipRepository.findByAttachedTo(fredInvoice).get(0);
final DocumentAbstract document = paperclip.getDocument();
// when
final Document_sendByEmail documentEmail = mixin(Document_sendByEmail.class, document);
final Set<EmailAddress> emailAddresses = documentEmail.choices0Act();
// then
assertThat(emailAddresses).contains(fredEmail);
// and when
// REVIEW: should be wrapped, however the DocumentCommunicationSupportForDocumentsAttachedToInvoiceForLease
// vetoes this, and there is current no way to exclude classes that are not part of the "effective" module
// final Communication comm = wrap(documentEmail).act(fredEmail, null, null, null, null, null);
final Communication comm = documentEmail.act(fredEmail, null, null, null, null, null);
// then
assertThat(comm).isNotNull();
assertThat(comm.getState()).isEqualTo(CommunicationState.PENDING);
assertThat(comm.getCreatedAt()).isNotNull();
assertThat(comm.getType()).isEqualTo(CommunicationChannelType.EMAIL_ADDRESS);
assertThat(comm.getSubject()).isNotNull();
assertThat(comm.getSentAt()).isNull();
final List<CommunicationChannel> correspondentChannels = Lists.newArrayList(comm.getCorrespondents()).stream().map(CommChannelRole::getChannel).filter(Objects::nonNull).collect(Collectors.toList());
assertThat(correspondentChannels).contains(fredEmail);
List<EmailMessage> emailMessages = fakeEmailService.listSentEmails();
assertThat(emailMessages).isEmpty();
List<CommandJdo> commands = backgroundCommandRepository.findBackgroundCommandsNotYetStarted();
assertThat(commands.size()).isEqualTo(1);
// when
fakeScheduler.runBackgroundCommands(5000);
// then
assertThat(comm.getState()).isEqualTo(CommunicationState.SENT);
assertThat(comm.getSentAt()).isNotNull();
emailMessages = fakeEmailService.listSentEmails();
assertThat(emailMessages).isNotEmpty();
}
Aggregations