Search in sources :

Example 1 with SchedulerHomePage

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() + "]");
    }
}
Also used : SchedulerPage(org.xwiki.scheduler.test.po.SchedulerPage) SchedulerHomePage(org.xwiki.scheduler.test.po.SchedulerHomePage) SchedulerEditPage(org.xwiki.scheduler.test.po.editor.SchedulerEditPage) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test)

Example 2 with SchedulerHomePage

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();
}
Also used : SchedulerHomePage(org.xwiki.scheduler.test.po.SchedulerHomePage) MimeMessage(javax.mail.internet.MimeMessage) WatchlistUserProfilePage(org.xwiki.watchlist.test.po.WatchlistUserProfilePage) WatchlistPreferencesEditPage(org.xwiki.watchlist.test.po.editor.WatchlistPreferencesEditPage) ViewPage(org.xwiki.test.ui.po.ViewPage) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) Test(org.junit.Test) AbstractTest(org.xwiki.test.ui.AbstractTest)

Example 3 with SchedulerHomePage

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);
}
Also used : NotificationsUserProfilePage(org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage) SchedulerHomePage(org.xwiki.scheduler.test.po.SchedulerHomePage) Email(org.simplejavamail.email.Email) MimeMessage(javax.mail.internet.MimeMessage) DocumentReference(org.xwiki.model.reference.DocumentReference) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Aggregations

Test (org.junit.Test)3 SchedulerHomePage (org.xwiki.scheduler.test.po.SchedulerHomePage)3 AbstractTest (org.xwiki.test.ui.AbstractTest)3 MimeMessage (javax.mail.internet.MimeMessage)2 IgnoreBrowsers (org.xwiki.test.ui.browser.IgnoreBrowsers)2 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)1 Email (org.simplejavamail.email.Email)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 NotificationsUserProfilePage (org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage)1 SchedulerPage (org.xwiki.scheduler.test.po.SchedulerPage)1 SchedulerEditPage (org.xwiki.scheduler.test.po.editor.SchedulerEditPage)1 ViewPage (org.xwiki.test.ui.po.ViewPage)1 WatchlistUserProfilePage (org.xwiki.watchlist.test.po.WatchlistUserProfilePage)1 WatchlistPreferencesEditPage (org.xwiki.watchlist.test.po.editor.WatchlistPreferencesEditPage)1