use of org.xwiki.scheduler.test.po.SchedulerHomePage in project xwiki-platform by xwiki.
the class SchedulerIT method testScheduler.
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void testScheduler() {
// Make sure the job doesn't exist. Note that we don't delete the job after the test is executed (@After)
// because we want to remain on the same page in case of a test failure so that our TestDebugger rule can
// collect accurate information about the failure. It's not a problem if the job remains scheduled because it
// does nothing. Other tests should not rely on the number of scheduler jobs though.
getUtil().deletePage("Scheduler", "SchedulerTestJob");
// Create Job
SchedulerHomePage schedulerHomePage = SchedulerHomePage.gotoPage();
schedulerHomePage.setJobName("SchedulerTestJob");
SchedulerEditPage schedulerEdit = schedulerHomePage.clickAdd();
String jobName = "Tester problem";
schedulerEdit.setJobName(jobName);
schedulerEdit.setJobDescription(jobName);
schedulerEdit.setCron("0 15 10 ? * MON-FRI");
SchedulerPage schedulerPage = schedulerEdit.clickSaveAndView();
schedulerHomePage = schedulerPage.backToHome();
// View Job
schedulerPage = schedulerHomePage.clickJobActionView(jobName);
// Tests that a scheduler job page's default edit mode is Form
// Note: This line below will fail if the page is not edited in Form mode!
schedulerPage.edit();
new SchedulerEditPage().setJobDescription("test");
schedulerEdit.clickCancel();
schedulerHomePage = schedulerPage.backToHome();
// Edit Job
schedulerEdit = schedulerHomePage.clickJobActionEdit(jobName);
schedulerEdit.setJobDescription("Tester problem2");
schedulerEdit.setCron("0 0/5 14 * * ?");
schedulerPage = schedulerEdit.clickSaveAndView();
schedulerHomePage = schedulerPage.backToHome();
// Delete and Restore Job
schedulerHomePage.clickJobActionDelete(jobName).clickYes();
schedulerHomePage = SchedulerHomePage.gotoPage();
Assert.assertFalse(getDriver().hasElementWithoutWaiting(By.linkText(jobName)));
// Note: since the page doesn't exist, we need to disable the space redirect feature so that we end up on the
// terminal page that was removed.
getUtil().gotoPage("Scheduler", "SchedulerTestJob", "view", "spaceRedirect=false");
getDriver().findElement(By.linkText("Restore")).click();
schedulerPage = new SchedulerPage();
schedulerPage.backToHome();
// Schedule Job
schedulerHomePage.clickJobActionSchedule(jobName);
if (schedulerHomePage.hasError()) {
Assert.fail("Failed to schedule job. Error [" + schedulerHomePage.getErrorMessage() + "]");
}
// Trigger Job (a Job can only be triggered after it's been scheduled)
schedulerHomePage.clickJobActionTrigger(jobName);
if (schedulerHomePage.hasError()) {
Assert.fail("Failed to trigger job. Error [" + schedulerHomePage.getErrorMessage() + "]");
}
// Pause Job
schedulerHomePage.clickJobActionPause(jobName);
if (schedulerHomePage.hasError()) {
Assert.fail("Failed to pause job. Error [" + schedulerHomePage.getErrorMessage() + "]");
}
// Resume Job
schedulerHomePage.clickJobActionResume(jobName);
if (schedulerHomePage.hasError()) {
Assert.fail("Failed to resume job. Error [" + schedulerHomePage.getErrorMessage() + "]");
}
// Unschedule Job
schedulerHomePage.clickJobActionUnschedule(jobName);
if (schedulerHomePage.hasError()) {
Assert.fail("Failed to unschedule job. Error [" + schedulerHomePage.getErrorMessage() + "]");
}
}
use of org.xwiki.scheduler.test.po.SchedulerHomePage in project xwiki-platform by xwiki.
the class WatchThisPageAndWholeSpaceTest method testWatchThisPageAndWholeSpace.
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void testWatchThisPageAndWholeSpace() throws Exception {
// Clear the list of watched documents and spaces
getUtil().updateObject("XWiki", this.testUserName, "XWiki.WatchListClass", 0, "spaces", "", "documents", "");
// Watch Test.TestWatchThisPage
ViewPage page = getUtil().createPage(testSinglePageToWatchSpace, testSinglePageToWatch, "TestWatchThisPage ui", null);
page.watchDocument();
// Watch TestWatchWholeSpace.Test1
page = getUtil().createPage(testSpaceToWatch, testSpaceToWatchPage, "TestWatchWholeSpace ui", null);
page.watchSpace();
// Verify that the watched page & space are present in the watchlist manager
WatchlistUserProfilePage watchlistPage = WatchlistUserProfilePage.gotoPage(this.testUserName);
Assert.assertTrue(watchlistPage.getWatchlistMacro().isWatched(testSinglePageToWatchSpace, testSinglePageToWatch));
Assert.assertTrue(watchlistPage.getWatchlistMacro().isWatched(testSpaceToWatch));
// Ensure that the watchlist notified is set to Daily since we're going to trigger that notifier scheduler job
WatchlistPreferencesEditPage watchlistPreferences = watchlistPage.editPreferences();
watchlistPreferences.setNotifierDaily();
watchlistPreferences.clickSaveAndContinue();
// Switch to superadmin user and go to the scheduler home page
SchedulerHomePage schedulerHomePage = new SchedulerHomePage();
getUtil().loginAsSuperAdminAndGotoPage(schedulerHomePage.getURL());
// Trigger the notification for the Daily job
schedulerHomePage.clickJobActionTrigger("WatchList daily notifier");
// Wait for the email with a timeout
Assert.assertTrue("Scheduled notification mail not received", this.greenMail.waitForIncomingEmail(70000, 1));
// Verify email content
MimeMessage[] receivedMails = this.greenMail.getReceivedMessages();
assertEquals(1, receivedMails.length);
String messageFromXWiki = GreenMailUtil.getBody(receivedMails[0]).replaceAll("=\r?\n", "");
Assert.assertFalse("should have no exception in " + messageFromXWiki, messageFromXWiki.contains("Exception"));
Assert.assertTrue("should have test page in the message " + messageFromXWiki, messageFromXWiki.contains(testSinglePageToWatch));
Assert.assertTrue("should have test space in the message " + messageFromXWiki, messageFromXWiki.contains(testSpaceToWatch));
// // Clear the mock inbox for the following step.
// GreenMailUser mailUser = this.greenMail.getManagers().getUserManager().getUser("admin@localhost");
// this.greenMail.getManagers().getImapHostManager().deleteMailbox(mailUser, "INBOX");
// TODO: we might need the commented code above to make sure the mail is destined for our current test user and
// not other users created by previous tests.
testRealtimeNotifier();
}
use of org.xwiki.scheduler.test.po.SchedulerHomePage in project xwiki-platform by xwiki.
the class NotificationsIT method testNotificationsEmails.
@Test
public void testNotificationsEmails() throws Exception {
getUtil().login(SECOND_USER_NAME, SECOND_USER_PASSWORD);
NotificationsUserProfilePage p;
p = NotificationsUserProfilePage.gotoPage(SECOND_USER_NAME);
p.getApplication(SYSTEM).setCollapsed(false);
p.setEventTypeState(SYSTEM, CREATE, EMAIL_FORMAT, BootstrapSwitch.State.ON);
getUtil().login(FIRST_USER_NAME, FIRST_USER_PASSWORD);
DocumentReference page1 = new DocumentReference("xwiki", NOTIFICATIONS_EMAIL_TEST, "Page1");
DocumentReference page2 = new DocumentReference("xwiki", NOTIFICATIONS_EMAIL_TEST, "Page2");
// Yes we wait on a timer, but it is to be sure the following events will be stored AFTER the settings have been
// changed.
Thread.sleep(1000);
getUtil().createPage(NOTIFICATIONS_EMAIL_TEST, "Page1", "Content 1", "Title 1");
getUtil().createPage(NOTIFICATIONS_EMAIL_TEST, "Page2", "Content 2", "Title 2");
// Trigger the notification email job
getUtil().login(SUPERADMIN_USER_NAME, SUPERADMIN_PASSWORD);
SchedulerHomePage schedulerHomePage = SchedulerHomePage.gotoPage();
schedulerHomePage.clickJobActionTrigger("Notifications daily email");
this.mail.waitForIncomingEmail(1);
assertEquals(1, this.mail.getReceivedMessages().length);
MimeMessage message = this.mail.getReceivedMessages()[0];
// Convert to org.simplejavamail.email because it is more simple to read
Email email = EmailConverter.mimeMessageToEmail(message);
assertTrue(email.getSubject().endsWith("event(s) on the wiki"));
assertEquals("test@xwiki.org", email.getFromRecipient().getAddress());
assertNotNull(email.getText());
assertNotNull(email.getTextHTML());
assertNotNull(email.getAttachments());
assertFalse(email.getAttachments().isEmpty());
// Events inside an email comes in random order, so we just verify that all the expected content is there
String plainTextContent = prepareMail(email.getText());
String expectedContent;
expectedContent = prepareMail(IOUtils.toString(getClass().getResourceAsStream("/expectedMail1.txt")));
assertTrue(String.format("Email is supposed to contain: [\n%s\n], but all we have is [\n%s\n].", expectedContent, plainTextContent), plainTextContent.contains(expectedContent));
expectedContent = prepareMail(IOUtils.toString(getClass().getResourceAsStream("/expectedMail2.txt")));
assertTrue(String.format("Email is supposed to contain: [\n%s\n], but all we we have is [\n%s\n].", expectedContent, plainTextContent), plainTextContent.contains(expectedContent));
getUtil().rest().delete(page1);
getUtil().rest().delete(page2);
}
Aggregations