Test to cover ALF-2221 - update the test to check the from email address on invites which are sent out

MailActionExecuter has been updated to track the last message it didn't send out when in test mode


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19901 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2010-04-19 15:25:12 +00:00
parent a711bff301
commit b0e61d1f28
2 changed files with 45 additions and 2 deletions

View File

@@ -147,6 +147,7 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
* "mocked out" or some other better way of running the unit tests.
*/
private boolean testMode = false;
private MimeMessage lastTestMessage;
/**
* @param javaMailSender the java mail sender
@@ -437,6 +438,16 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
{
javaMailSender.send(mailPreparer);
}
else
{
try {
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
mailPreparer.prepare(mimeMessage);
lastTestMessage = mimeMessage;
} catch(Exception e) {
System.err.println(e);
}
}
}
catch (MailException e)
{
@@ -528,6 +539,15 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
{
return testMode;
}
/**
* Returns the most recent message that wasn't sent
* because TestMode had been enabled.
*/
public MimeMessage retrieveLastTestMessage()
{
return lastTestMessage;
}
public static class URLHelper
{

View File

@@ -22,6 +22,8 @@ package org.alfresco.repo.invitation;
import java.util.Date;
import java.util.List;
import javax.mail.internet.MimeMessage;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.MailActionExecuter;
import org.alfresco.repo.management.subsystems.ApplicationContextFactory;
@@ -49,6 +51,7 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
private AuthenticationComponent authenticationComponent;
private PersonService personService;
private InvitationService invitationService;
private MailActionExecuter mailService;
private final String SITE_SHORT_NAME_INVITE = "InvitationTest";
private final String SITE_SHORT_NAME_RED = "InvitationTestRed";
@@ -83,9 +86,9 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
// TODO MER 20/11/2009 Bodge - turn off email sending to prevent errors
// during unit testing
// (or sending out email by accident from tests)
MailActionExecuter mail = (MailActionExecuter) ((ApplicationContextFactory) this.applicationContext
mailService = (MailActionExecuter) ((ApplicationContextFactory) this.applicationContext
.getBean("OutboundSMTP")).getApplicationContext().getBean("mail");
mail.setTestMode(true);
mailService.setTestMode(true);
createPerson(USER_MANAGER, USER_MANAGER + "@alfrescotesting.com", PERSON_FIRSTNAME, PERSON_LASTNAME);
createPerson(USER_ONE, USER_ONE_EMAIL, USER_ONE_FIRSTNAME, USER_ONE_LASTNAME);
@@ -213,6 +216,26 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
assertTrue("sentDate wrong too early", sentDate.after(startDate));
assertTrue("sentDate wrong - too late", sentDate.before(new Date(new Date().getTime() + 1)));
}
/**
* Check the email itself, and check it
* is as we would expect it to be
*/
{
MimeMessage msg = mailService.retrieveLastTestMessage();
assertEquals(1, msg.getAllRecipients().length);
assertEquals(inviteeEmail, msg.getAllRecipients()[0].toString());
assertEquals(1, msg.getFrom().length);
assertEquals(USER_MANAGER + "@alfrescotesting.com", msg.getFrom()[0].toString());
// Hasn't been sent, so no sent or received date
assertNull("Not been sent yet", msg.getSentDate());
assertNull("Not been sent yet", msg.getReceivedDate());
// TODO - check some more details of the email
}
/**
* Search for the new invitation