mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -147,6 +147,7 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
|||||||
* "mocked out" or some other better way of running the unit tests.
|
* "mocked out" or some other better way of running the unit tests.
|
||||||
*/
|
*/
|
||||||
private boolean testMode = false;
|
private boolean testMode = false;
|
||||||
|
private MimeMessage lastTestMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param javaMailSender the java mail sender
|
* @param javaMailSender the java mail sender
|
||||||
@@ -437,6 +438,16 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
|||||||
{
|
{
|
||||||
javaMailSender.send(mailPreparer);
|
javaMailSender.send(mailPreparer);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
|
||||||
|
mailPreparer.prepare(mimeMessage);
|
||||||
|
lastTestMessage = mimeMessage;
|
||||||
|
} catch(Exception e) {
|
||||||
|
System.err.println(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (MailException e)
|
catch (MailException e)
|
||||||
{
|
{
|
||||||
@@ -528,6 +539,15 @@ public class MailActionExecuter extends ActionExecuterAbstractBase
|
|||||||
{
|
{
|
||||||
return testMode;
|
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
|
public static class URLHelper
|
||||||
{
|
{
|
||||||
|
@@ -22,6 +22,8 @@ package org.alfresco.repo.invitation;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.mail.internet.MimeMessage;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.action.executer.MailActionExecuter;
|
import org.alfresco.repo.action.executer.MailActionExecuter;
|
||||||
import org.alfresco.repo.management.subsystems.ApplicationContextFactory;
|
import org.alfresco.repo.management.subsystems.ApplicationContextFactory;
|
||||||
@@ -49,6 +51,7 @@ public class InvitationServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
private AuthenticationComponent authenticationComponent;
|
private AuthenticationComponent authenticationComponent;
|
||||||
private PersonService personService;
|
private PersonService personService;
|
||||||
private InvitationService invitationService;
|
private InvitationService invitationService;
|
||||||
|
private MailActionExecuter mailService;
|
||||||
|
|
||||||
private final String SITE_SHORT_NAME_INVITE = "InvitationTest";
|
private final String SITE_SHORT_NAME_INVITE = "InvitationTest";
|
||||||
private final String SITE_SHORT_NAME_RED = "InvitationTestRed";
|
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
|
// TODO MER 20/11/2009 Bodge - turn off email sending to prevent errors
|
||||||
// during unit testing
|
// during unit testing
|
||||||
// (or sending out email by accident from tests)
|
// (or sending out email by accident from tests)
|
||||||
MailActionExecuter mail = (MailActionExecuter) ((ApplicationContextFactory) this.applicationContext
|
mailService = (MailActionExecuter) ((ApplicationContextFactory) this.applicationContext
|
||||||
.getBean("OutboundSMTP")).getApplicationContext().getBean("mail");
|
.getBean("OutboundSMTP")).getApplicationContext().getBean("mail");
|
||||||
mail.setTestMode(true);
|
mailService.setTestMode(true);
|
||||||
|
|
||||||
createPerson(USER_MANAGER, USER_MANAGER + "@alfrescotesting.com", PERSON_FIRSTNAME, PERSON_LASTNAME);
|
createPerson(USER_MANAGER, USER_MANAGER + "@alfrescotesting.com", PERSON_FIRSTNAME, PERSON_LASTNAME);
|
||||||
createPerson(USER_ONE, USER_ONE_EMAIL, USER_ONE_FIRSTNAME, USER_ONE_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 early", sentDate.after(startDate));
|
||||||
assertTrue("sentDate wrong - too late", sentDate.before(new Date(new Date().getTime() + 1)));
|
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
|
* Search for the new invitation
|
||||||
|
Reference in New Issue
Block a user