public void testUnpermittedUserCannotSendToMultipleAddresses() throws Exception
{
TestUtils.Session admin = getUtil().getSession();
// Make sure users don't have the right to send to multiple.
AdministrationSectionPage config = AdministrationSectionPage.gotoPage("Invitation");
config.getForm().setFieldValue(By.id("Invitation.InvitationConfig_Invitation.WebHome_0_"
+ "usersMaySendToMultiple"), "false");
config.clickSave();
try {
getUtil().forceGuestUser();
getUtil().createUserAndLogin("NonMailAdminUser", "WeakPassword");
setSenderPage(InvitationSenderPage.gotoPage());
startGreenMail();
getSenderPage().fillForm("user@localhost.localdomain anotheruser@localhost.localdomain", null, null);
InvitationSenderPage.InvitationSentPage sent = getSenderPage().send();
getGreenMail().waitForIncomingEmail(2000, 2);
MimeMessage[] messages = getGreenMail().getReceivedMessages();
Assert.assertTrue("Messages were received when they shouldn't have been sent!", messages.length == 0);
Assert.assertTrue("User was not shown the correct error message.",
sent.getMessageBoxContent().equals("Your message couldn't be sent because there were no valid email "
+ "addresses to send to."));
stopGreenMail();
// Become admin and allow users to send to multiple.
TestUtils.Session nonAdmin = getUtil().getSession();
getUtil().setSession(admin);
config = AdministrationSectionPage.gotoPage("Invitation");
config.getForm().setFieldValue(By.id("Invitation.InvitationConfig_Invitation.WebHome_0_"
+ "usersMaySendToMultiple"), "true");
config.clickSave();
getUtil().setSession(nonAdmin);
// Prove that the user can now send to multiple recipients.
startGreenMail();
setSenderPage(InvitationSenderPage.gotoPage());