use of org.xwiki.mail.test.po.SendMailAdministrationSectionPage in project xwiki-platform by xwiki.
the class NotificationsIT method setUpEmails.
@Before
public void setUpEmails() throws Exception {
if (this.mail != null) {
// Already done
return;
}
getUtil().login(SUPERADMIN_USER_NAME, SUPERADMIN_PASSWORD);
AdministrationPage wikiAdministrationPage = AdministrationPage.gotoPage();
wikiAdministrationPage.clickSection("Mail", "Mail Sending");
SendMailAdministrationSectionPage sendMailPage = new SendMailAdministrationSectionPage();
sendMailPage.setHost("localhost");
sendMailPage.setPort(String.valueOf(ServerSetupTest.SMTP.getPort()));
sendMailPage.setEmailAddressToSendFrom("test@xwiki.org");
// Make sure we don't wait between email sending in order to speed up the test (and not incur timeouts when
// we wait to receive the mails)
sendMailPage.setSendWaitTime("0");
sendMailPage.clickSave();
this.mail = new GreenMail(ServerSetupTest.SMTP);
this.mail.start();
}
use of org.xwiki.mail.test.po.SendMailAdministrationSectionPage in project xwiki-platform by xwiki.
the class MailTest method testMail.
@Test
public void testMail() throws Exception {
// Step 0: Delete all pre-existing mails to start clean. This also verifies the deleteAll() script service
// API.
String content = "{{velocity}}$services.mailstorage.deleteAll(){{/velocity}}";
ViewPage deleteAllPage = getUtil().createPage(getTestClassName(), "DeleteAll", content, "");
// Verify that the page doesn't display any content (unless there's an error!)
assertEquals("", deleteAllPage.getContent());
// Step 1: Verify that there are 2 email sections in the Mail category
AdministrationPage wikiAdministrationPage = AdministrationPage.gotoPage();
Assert.assertTrue(wikiAdministrationPage.hasSection("Mail", "Mail Sending"));
Assert.assertTrue(wikiAdministrationPage.hasSection("Mail", "Mail Sending Status"));
Assert.assertTrue(wikiAdministrationPage.hasSection("Mail", "Advanced"));
// Verify we can click on Mail > Advanced
wikiAdministrationPage.clickSection("Mail", "Advanced");
// Step 2: Before validating that we can send email, let's verify that we can report errors when the mail
// setup is not correct
// Make sure there's an invalid mail server set.
wikiAdministrationPage.clickSection("Mail", "Mail Sending");
SendMailAdministrationSectionPage sendMailPage = new SendMailAdministrationSectionPage();
sendMailPage.setHost("invalidmailserver");
sendMailPage.clickSave();
// Send the mail that's supposed to fail and validate that it fails
sendMailWithInvalidMailSetup();
// Step 3: Navigate to each mail section and set the mail sending parameters (SMTP host/port)
wikiAdministrationPage = AdministrationPage.gotoPage();
wikiAdministrationPage.clickSection("Mail", "Mail Sending");
sendMailPage = new SendMailAdministrationSectionPage();
sendMailPage.setHost("localhost");
sendMailPage.setPort("3025");
// Make sure we don't wait between email sending in order to speed up the test (and not incur timeouts when
// we wait to receive the mails)
sendMailPage.setSendWaitTime("0");
// Keep all mail statuses including successful ones (so that we verify this works fine)
sendMailPage.setDiscardSuccessStatuses(false);
sendMailPage.clickSave();
// Step 3: Verify that there are no admin email sections when administering a space
// Select XWiki space administration.
AdministrationPage spaceAdministrationPage = AdministrationPage.gotoSpaceAdministrationPage("XWiki");
// 2018-01-31: Got a failure on CI showing that the first assert below this line was failing because the
// current page was still the one before move to the XWiki space admin. Thus taking extra step to ensure we
// wait. However I don't understand why this happens since getDriver().url() called by
// gotoSpaceAdministrationPage() should wait for the page to be loaded before returning.
getDriver().waitUntilCondition(driver -> spaceAdministrationPage.getMetaDataValue("reference").equals("xwiki:XWiki.WebPreferences"));
// All those sections should not be present
Assert.assertTrue(spaceAdministrationPage.hasNotSection("Mail", "Mail Sending"));
Assert.assertTrue(spaceAdministrationPage.hasNotSection("Mail", "Mail Sending Status"));
Assert.assertTrue(spaceAdministrationPage.hasNotSection("Mail", "Advanced"));
// Step 4: Prepare a Template Mail
getUtil().deletePage(getTestClassName(), "MailTemplate");
// Create a Wiki page containing a Mail Template (ie a XWiki.Mail object)
getUtil().createPage(getTestClassName(), "MailTemplate", "", "");
// Note: We use the following bindings in the Template subject and content so that we ensure that they are
// provided by default:
// - "$xwiki"
// - "$xcontext"
// - "$escapetool"
// - "$services"
// - "$request"
// Note: We also use the $name and $doc bindings to show that the user can add new bindings ($doc is not bound
// by default since there isn't always a notion of current doc in all places where mail sending is done).
// Note: We use $xwiki.getURL() in the content to verify that we generate full external URLs.
String velocityContent = "Hello $name from $escapetool.xml($services.model.resolveDocument(" + "$xcontext.getUser()).getName()) - Served from $request.getRequestURL().toString() - " + "url: $xwiki.getURL('Main.WebHome')";
getUtil().addObject(getTestClassName(), "MailTemplate", "XWiki.Mail", "subject", "#if ($xwiki.exists($doc.documentReference))Status for $name on $doc.fullName#{else}wrong#end", "language", "en", "html", "<strong>" + velocityContent + "</strong>", "text", velocityContent);
// We also add an attachment to the Mail Template page to verify that it is sent in the mail
ByteArrayInputStream bais = new ByteArrayInputStream("Content of attachment".getBytes());
getUtil().attachFile(getTestClassName(), "MailTemplate", "something.txt", bais, true, new UsernamePasswordCredentials("superadmin", "pass"));
// Step 5: Send a template email (with an attachment) to a single email address
sendTemplateMailToEmail();
// Step 6: Send a template email to all the users in the XWikiAllGroup Group (we'll create 2 users) + to
// two other users (however since they're part of the group they'll receive only one mail each, we thus test
// deduplicatio!).
sendTemplateMailToUsersAndGroup();
// Step 7: Navigate to the Mail Sending Status Admin page and assert that the Livetable displays the entry for
// the sent mails
wikiAdministrationPage = AdministrationPage.gotoPage();
wikiAdministrationPage.clickSection("Mail", "Mail Sending Status");
MailStatusAdministrationSectionPage statusPage = new MailStatusAdministrationSectionPage();
LiveTableElement liveTableElement = statusPage.getLiveTable();
liveTableElement.filterColumn("xwiki-livetable-sendmailstatus-filter-3", "Test");
liveTableElement.filterColumn("xwiki-livetable-sendmailstatus-filter-5", "send_success");
liveTableElement.filterColumn("xwiki-livetable-sendmailstatus-filter-6", "xwiki");
// Let's wait till we have at least 3 rows. Note that we wait because we could have received the mails above
// but the last mail's status in the database may not have been updated yet. Note that The first 2 are
// guaranteed to have been updated since we send mail in one thread one after another and we update the
// database after sending each mail.
liveTableElement.waitUntilRowCountGreaterThan(3);
liveTableElement.filterColumn("xwiki-livetable-sendmailstatus-filter-4", "john@doe.com");
assertTrue(liveTableElement.getRowCount() > 0);
assertTrue(liveTableElement.hasRow("Error", ""));
}
Aggregations