Search in sources :

Example 1 with WatchlistUserProfilePage

use of org.xwiki.watchlist.test.po.WatchlistUserProfilePage in project xwiki-platform by xwiki.

the class WatchThisPageAndWholeSpaceTest method setUp.

@Before
public void setUp() throws Exception {
    // Set the SMTP port to the default port used by Greenmail (3025)
    getUtil().updateObject("Mail", "MailConfig", "Mail.SendMailConfigClass", 0, "host", "localhost", "port", "3025", "sendWaitTime", "0");
    // Start GreenMail test server
    this.greenMail = new GreenMail();
    this.greenMail.start();
    // Delete the users if they already exists.
    getUtil().deletePage("XWiki", testUserName);
    getUtil().deletePage("XWiki", testUserName2);
    // Delete the test pages.
    getUtil().deletePage(testSinglePageToWatchSpace, testSinglePageToWatch);
    getUtil().deletePage(testSpaceToWatch, testSpaceToWatchPage);
    // Create a user for the test.
    getUtil().createUserAndLogin(testUserName, PASSWORD, "email", testEmail);
    WatchlistUserProfilePage watchlistPage = WatchlistUserProfilePage.gotoPage(testUserName);
    // Disable auto watch.
    WatchlistPreferencesEditPage watchlistPreferences = watchlistPage.editPreferences();
    watchlistPreferences.setAutomaticWatchNone();
    watchlistPreferences.clickSaveAndContinue();
}
Also used : WatchlistUserProfilePage(org.xwiki.watchlist.test.po.WatchlistUserProfilePage) GreenMail(com.icegreen.greenmail.util.GreenMail) WatchlistPreferencesEditPage(org.xwiki.watchlist.test.po.editor.WatchlistPreferencesEditPage) Before(org.junit.Before)

Example 2 with WatchlistUserProfilePage

use of org.xwiki.watchlist.test.po.WatchlistUserProfilePage in project xwiki-platform by xwiki.

the class WatchThisPageAndWholeSpaceTest method testRealtimeNotifier.

/**
 * Realtime notifications.
 */
private void testRealtimeNotifier() throws Exception {
    // Log back in with the user to test realtime notifications.
    getUtil().login(testUserName, PASSWORD);
    // Set the notifier to 'Realtime'.
    WatchlistUserProfilePage profilePage = WatchlistUserProfilePage.gotoPage(testUserName);
    WatchlistUserProfilePage watchlistPage = profilePage.switchToWatchlist();
    WatchlistPreferencesEditPage watchlistPreferences = watchlistPage.editPreferences();
    watchlistPreferences.setNotifierRealtime();
    watchlistPreferences.clickSaveAndContinue();
    // Make a change in a watched document.
    // Note: Taking a shortcut and just using the save action.
    String content = "New content that watchlist should ignore.";
    getUtil().gotoPage(testSinglePageToWatchSpace, testSinglePageToWatch, "save", "content", content);
    // Wait for an email that should never come.
    Assert.assertFalse("Mail should not be received for own changes", this.greenMail.waitForIncomingEmail(3000, 2));
    // Create a second user that should trigger a realtime notification to the first user.
    getUtil().createUserAndLogin(testUserName2, PASSWORD);
    // Make a change in a document watched by the first user.
    // Note: Taking a shortcut and just using the save action.
    String newContent = "New content that watchlist should notify about.";
    content += "\n" + newContent;
    getUtil().gotoPage(testSinglePageToWatchSpace, testSinglePageToWatch, "save", "content", content);
    // Wait for the email with a timeout.
    Assert.assertTrue("Realtime notification mail not received", this.greenMail.waitForIncomingEmail(70000, 2));
    // Verify email content.
    MimeMessage[] receivedMails = this.greenMail.getReceivedMessages();
    // Second mail we`ve received, including the previous one from the daily notifier.
    assertEquals(2, receivedMails.length);
    String messageFromXWiki = GreenMailUtil.getBody(receivedMails[1]).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("TestWatchThisPage"));
    Assert.assertTrue("should have second user in the message " + messageFromXWiki, messageFromXWiki.contains(testUserName2));
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) WatchlistUserProfilePage(org.xwiki.watchlist.test.po.WatchlistUserProfilePage) WatchlistPreferencesEditPage(org.xwiki.watchlist.test.po.editor.WatchlistPreferencesEditPage)

Example 3 with WatchlistUserProfilePage

use of org.xwiki.watchlist.test.po.WatchlistUserProfilePage 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 4 with WatchlistUserProfilePage

use of org.xwiki.watchlist.test.po.WatchlistUserProfilePage in project xwiki-platform by xwiki.

the class AutoWatchTest method testAutomaticWatchDefaultAndNone.

@Test
@IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177")
public void testAutomaticWatchDefaultAndNone() {
    /*
         * Scenario 1: 'Default' autowatch mode should watch new and modified documents.
         */
    WatchlistUserProfilePage watchlistPage = WatchlistUserProfilePage.gotoPage(testUserName);
    String newPageName1 = "testpage";
    // Ensure the pages are not already watched.
    Assert.assertFalse("The test page should not be already watched when just starting", watchlistPage.getWatchlistMacro().isWatched(this.testSpace, newPageName1));
    Assert.assertFalse("The test page should not be already watched when just starting", watchlistPage.getWatchlistMacro().isWatched(this.testSpace, this.existingPageName));
    // Set to 'default' automatic watch mode.
    WatchlistPreferencesEditPage preferences = watchlistPage.editPreferences();
    preferences.setAutomaticWatchDefault();
    preferences.clickSaveAndContinue();
    // Create the new page and modify the existing one.
    getUtil().createPage(this.testSpace, newPageName1, null, null);
    getUtil().gotoPage(this.testSpace, this.existingPageName, "save", "content", "Test content");
    // Go back to watchlist profile.
    watchlistPage = WatchlistUserProfilePage.gotoPage(testUserName);
    // Check if they are registered in the watchlist.
    Assert.assertTrue("Newly created page is not watched", watchlistPage.getWatchlistMacro().isWatched(this.testSpace, newPageName1));
    Assert.assertTrue("Newly created page is not watched", watchlistPage.getWatchlistMacro().isWatched(this.testSpace, this.existingPageName));
    /*
         * Scenario 2: 'None' autowatch mode should not watch new or modified documents.
         */
    String newPageName2 = "testpage2";
    // Cleanup from the previous test. Assume the existing page is unwatched.
    watchlistPage.getWatchlistMacro().unWatch(this.testSpace, this.existingPageName);
    // Ensure the pages are not already watched.
    Assert.assertFalse("The test page should not be already watched when just starting", watchlistPage.getWatchlistMacro().isWatched(this.testSpace, newPageName2));
    Assert.assertFalse("The test page should not be already watched when just starting", watchlistPage.getWatchlistMacro().isWatched(this.testSpace, this.existingPageName));
    // Set to 'none' automatic watch mode.
    preferences = watchlistPage.editPreferences();
    preferences.setAutomaticWatchNone();
    preferences.clickSaveAndContinue();
    // Create the new page and modify the existing one.
    getUtil().createPage(this.testSpace, newPageName2, null, null);
    getUtil().gotoPage(this.testSpace, this.existingPageName, "save", "content", "Test content");
    // Go back to watchlist profile
    watchlistPage = WatchlistUserProfilePage.gotoPage(testUserName);
    // Check if it's registered in the watchlist
    Assert.assertFalse("Newly created page is watched even if autowatch is set to 'none'", watchlistPage.getWatchlistMacro().isWatched(this.testSpace, newPageName2));
    Assert.assertFalse("Modified page is watched even if autowatch is set to 'none'", watchlistPage.getWatchlistMacro().isWatched(this.testSpace, this.existingPageName));
}
Also used : WatchlistUserProfilePage(org.xwiki.watchlist.test.po.WatchlistUserProfilePage) WatchlistPreferencesEditPage(org.xwiki.watchlist.test.po.editor.WatchlistPreferencesEditPage) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test) IgnoreBrowser(org.xwiki.test.ui.browser.IgnoreBrowser)

Aggregations

WatchlistUserProfilePage (org.xwiki.watchlist.test.po.WatchlistUserProfilePage)4 WatchlistPreferencesEditPage (org.xwiki.watchlist.test.po.editor.WatchlistPreferencesEditPage)4 MimeMessage (javax.mail.internet.MimeMessage)2 Test (org.junit.Test)2 AbstractTest (org.xwiki.test.ui.AbstractTest)2 GreenMail (com.icegreen.greenmail.util.GreenMail)1 Before (org.junit.Before)1 SchedulerHomePage (org.xwiki.scheduler.test.po.SchedulerHomePage)1 IgnoreBrowser (org.xwiki.test.ui.browser.IgnoreBrowser)1 IgnoreBrowsers (org.xwiki.test.ui.browser.IgnoreBrowsers)1 ViewPage (org.xwiki.test.ui.po.ViewPage)1