()
{
public Void execute() throws Throwable
{
// We'll do all this as user 'UserTwo'.
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
//Parent Folder Rule: Outbound
org.alfresco.service.cmr.rule.Rule rule = new org.alfresco.service.cmr.rule.Rule();
rule.setRuleTypes(Collections.singletonList(RuleType.OUTBOUND));
rule.setTitle("RuleServiceTest" + GUID.generate());
rule.setDescription("Send email on delete");
//Mail Action
Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "some.body@example.com");
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, "some.bodyelse@example.com");
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, "alfresco/templates/mail/test.txt.ftl");
mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) getModel());
rule.setAction(mailAction);
//Save Rules to appropriate Folders
RULE_SERVICE.saveRule(childFolder, rule);
return null;
}
});
//Trigger the outbound rule by deleting the node
NODE_SERVICE.deleteNode(childContent);
//Fetch unsent message (Test Mode)
MimeMessage message = MAIL_ACTION_EXECUTER.retrieveLastTestMessage();
Assert.assertNotNull(message);
Assert.assertEquals("Hello Jan 1, 1970", (String) message.getContent());
}
/**
* Adds content to a given node.
*
* Used to trigger rules of type of incomming.
*
* @param nodeRef the node reference
*/
private void addContentToNode(NodeRef nodeRef)
{
ContentWriter contentWriter = CONTENT_SERVICE.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
contentWriter.setEncoding("UTF-8");
assertNotNull(contentWriter);
contentWriter.putContent(STANDARD_TEXT_CONTENT + System.currentTimeMillis());
}
private Serializable getModel()
{
Map model = new HashMap();
model.put("epoch", new Date(0));
return (Serializable) model;
}
}