Search in sources :

Example 1 with NotificationsUserProfilePage

use of org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage in project xwiki-platform by xwiki.

the class NotificationsIT method testNotificationDisplayerClass.

@Test
public void testNotificationDisplayerClass() throws Exception {
    // Create the pages and a custom displayer for "update" events
    getUtil().login(SUPERADMIN_USER_NAME, SUPERADMIN_PASSWORD);
    getUtil().gotoPage(getTestClassName(), "WebHome");
    getUtil().createPage(getTestClassName(), "ARandomPageThatShouldBeModified", "Page used for the tests of the NotificationDisplayerClass XObject.", "Test page");
    getUtil().createPage(getTestClassName(), "NotificationDisplayerClassTest", "Page used for the tests of the NotificationDisplayerClass XObject.", "Test page 2");
    Map<String, String> notificationDisplayerParameters = new HashMap<String, String>() {

        {
            put("XWiki.Notifications.Code.NotificationDisplayerClass_0_eventType", "update");
            put("XWiki.Notifications.Code.NotificationDisplayerClass_0_notificationTemplate", "This is a test template");
        }
    };
    ObjectEditPage editObjects = getUtil().editObjects(getTestClassName(), "NotificationDisplayerClassTest");
    editObjects.addObject("XWiki.Notifications.Code.NotificationDisplayerClass");
    editObjects.getObjectsOfClass("XWiki.Notifications.Code.NotificationDisplayerClass").get(0).fillFieldsByName(notificationDisplayerParameters);
    editObjects.clickSaveAndContinue(true);
    // Login as first user, and enable notifications on document updates
    getUtil().login(FIRST_USER_NAME, FIRST_USER_PASSWORD);
    NotificationsUserProfilePage p = NotificationsUserProfilePage.gotoPage(FIRST_USER_NAME);
    p.getApplication(SYSTEM).setCollapsed(false);
    p.setEventTypeState(SYSTEM, UPDATE, ALERT_FORMAT, BootstrapSwitch.State.ON);
    // Login as second user and modify ARandomPageThatShouldBeModified
    getUtil().login(SECOND_USER_NAME, SECOND_USER_PASSWORD);
    ViewPage viewPage = getUtil().gotoPage(getTestClassName(), "ARandomPageThatShouldBeModified");
    viewPage.edit();
    WikiEditPage editPage = new WikiEditPage();
    editPage.setContent("Something");
    editPage.clickSaveAndView(true);
    // Login as the first user, ensure that the notification is displayed with a custom template
    getUtil().login(FIRST_USER_NAME, FIRST_USER_PASSWORD);
    getUtil().gotoPage(getTestClassName(), "WebHome");
    NotificationsTrayPage tray = new NotificationsTrayPage();
    assertEquals("This is a test template", tray.getNotificationRawContent(0));
}
Also used : NotificationsUserProfilePage(org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage) HashMap(java.util.HashMap) ObjectEditPage(org.xwiki.test.ui.po.editor.ObjectEditPage) ViewPage(org.xwiki.test.ui.po.ViewPage) NotificationsTrayPage(org.xwiki.platform.notifications.test.po.NotificationsTrayPage) WikiEditPage(org.xwiki.test.ui.po.editor.WikiEditPage) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 2 with NotificationsUserProfilePage

use of org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage in project xwiki-platform by xwiki.

the class NotificationsIT method testCompositeNotifications.

@Test
public void testCompositeNotifications() throws Exception {
    NotificationsUserProfilePage p;
    NotificationsTrayPage tray;
    // Now we enable "create", "update" and "comment" for user 2
    getUtil().login(SECOND_USER_NAME, SECOND_USER_PASSWORD);
    p = NotificationsUserProfilePage.gotoPage(SECOND_USER_NAME);
    p.getApplication(SYSTEM).setCollapsed(false);
    p.setEventTypeState(SYSTEM, CREATE, ALERT_FORMAT, BootstrapSwitch.State.OFF);
    p.setEventTypeState(SYSTEM, UPDATE, ALERT_FORMAT, BootstrapSwitch.State.ON);
    p.setEventTypeState(SYSTEM, ADD_COMMENT, ALERT_FORMAT, BootstrapSwitch.State.ON);
    getUtil().gotoPage("Main", "WebHome");
    tray = new NotificationsTrayPage();
    tray.clearAllNotifications();
    // Create a page, edit it twice, and finally add a comment
    getUtil().login(FIRST_USER_NAME, FIRST_USER_PASSWORD);
    getUtil().createPage(getTestClassName(), "Linux", "Simple content", "Linux as a title");
    ViewPage page = getUtil().gotoPage(getTestClassName(), "Linux");
    page.edit();
    WikiEditPage edit = new WikiEditPage();
    edit.setContent("Linux is a part of GNU/Linux");
    edit.clickSaveAndContinue(true);
    edit.setContent("Linux is a part of GNU/Linux - it's the kernel");
    edit.clickSaveAndView(true);
    page = getUtil().gotoPage(getTestClassName(), "Linux");
    CommentsTab commentsTab = page.openCommentsDocExtraPane();
    commentsTab.postComment("Linux is a great OS", true);
    // Check that events have been grouped together (see: https://jira.xwiki.org/browse/XWIKI-14114)
    getUtil().login(SECOND_USER_NAME, SECOND_USER_PASSWORD);
    getUtil().gotoPage(getTestClassName(), "WebHome");
    tray = new NotificationsTrayPage();
    assertEquals(2, tray.getNotificationsCount());
    assertEquals("Linux as a title", tray.getNotificationPage(0));
    assertTrue(tray.getNotificationDescription(0).startsWith("commented by user1"));
    assertEquals("Linux as a title", tray.getNotificationPage(1));
    assertEquals("update", tray.getNotificationType(1));
    assertTrue(tray.getNotificationDescription(1).startsWith("edited by user1"));
    tray.clearAllNotifications();
}
Also used : NotificationsUserProfilePage(org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage) CommentsTab(org.xwiki.test.ui.po.CommentsTab) NotificationsTrayPage(org.xwiki.platform.notifications.test.po.NotificationsTrayPage) ViewPage(org.xwiki.test.ui.po.ViewPage) WikiEditPage(org.xwiki.test.ui.po.editor.WikiEditPage) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 3 with NotificationsUserProfilePage

use of org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage in project xwiki-platform by xwiki.

the class NotificationsIT method setUpUsers.

@Before
public void setUpUsers() throws Exception {
    // Create the two users we will be using
    getUtil().createUser(FIRST_USER_NAME, FIRST_USER_PASSWORD, "", "");
    getUtil().createUser(SECOND_USER_NAME, SECOND_USER_PASSWORD, "", "");
    NotificationsUserProfilePage p;
    getUtil().login(FIRST_USER_NAME, FIRST_USER_PASSWORD);
    p = NotificationsUserProfilePage.gotoPage(FIRST_USER_NAME);
    p.disableAllParameters();
    getUtil().login(SECOND_USER_NAME, SECOND_USER_PASSWORD);
    p = NotificationsUserProfilePage.gotoPage(SECOND_USER_NAME);
    p.disableAllParameters();
    ProfileEditPage profileEditPage = ProfileUserProfilePage.gotoPage(SECOND_USER_NAME).editProfile();
    profileEditPage.setUserEmail("test@xwiki.org");
    profileEditPage.clickSaveAndView(true);
}
Also used : NotificationsUserProfilePage(org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage) ProfileEditPage(org.xwiki.user.test.po.ProfileEditPage) Before(org.junit.Before)

Example 4 with NotificationsUserProfilePage

use of org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage in project xwiki-platform by xwiki.

the class NotificationsIT method testNotificationsSwitches.

@Test
public void testNotificationsSwitches() throws Exception {
    getUtil().login(FIRST_USER_NAME, FIRST_USER_PASSWORD);
    NotificationsUserProfilePage p = NotificationsUserProfilePage.gotoPage(FIRST_USER_NAME);
    assertEquals(1, p.getApplicationPreferences().size());
    // Open system
    ApplicationPreferences system = p.getApplication(SYSTEM);
    assertTrue(system.isCollapsed());
    system.setCollapsed(false);
    assertFalse(system.isCollapsed());
    assertEquals("Pages", system.getApplicationName());
    assertEquals("A comment is posted", p.getEventType(SYSTEM, ADD_COMMENT).getEventTypeDescription());
    assertEquals("A new page is created", p.getEventType(SYSTEM, CREATE).getEventTypeDescription());
    assertEquals("A page is deleted", p.getEventType(SYSTEM, DELETE).getEventTypeDescription());
    assertEquals("A page is modified", p.getEventType(SYSTEM, UPDATE).getEventTypeDescription());
    // Check default
    assertEquals(BootstrapSwitch.State.OFF, p.getApplicationState(SYSTEM, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getApplicationState(SYSTEM, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, ADD_COMMENT, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, ADD_COMMENT, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, CREATE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, CREATE, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, DELETE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, DELETE, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, UPDATE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, UPDATE, EMAIL_FORMAT));
    // Enable alert on system
    p.setApplicationState(SYSTEM, ALERT_FORMAT, BootstrapSwitch.State.ON);
    assertEquals(BootstrapSwitch.State.ON, p.getApplicationState(SYSTEM, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getApplicationState(SYSTEM, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, ADD_COMMENT, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, ADD_COMMENT, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, CREATE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, CREATE, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, DELETE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, DELETE, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, UPDATE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, UPDATE, EMAIL_FORMAT));
    // Enable email on system
    p.setApplicationState(SYSTEM, EMAIL_FORMAT, BootstrapSwitch.State.ON);
    assertEquals(BootstrapSwitch.State.ON, p.getApplicationState(SYSTEM, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getApplicationState(SYSTEM, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, ADD_COMMENT, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, ADD_COMMENT, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, CREATE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, CREATE, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, DELETE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, DELETE, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, UPDATE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, UPDATE, EMAIL_FORMAT));
    // Disable email on system
    p.setApplicationState(SYSTEM, EMAIL_FORMAT, BootstrapSwitch.State.OFF);
    assertEquals(BootstrapSwitch.State.ON, p.getApplicationState(SYSTEM, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getApplicationState(SYSTEM, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, ADD_COMMENT, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, ADD_COMMENT, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, CREATE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, CREATE, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, DELETE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, DELETE, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, UPDATE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, UPDATE, EMAIL_FORMAT));
    // Disable alert on "update"
    p.setEventTypeState(SYSTEM, UPDATE, ALERT_FORMAT, BootstrapSwitch.State.OFF);
    assertEquals(BootstrapSwitch.State.UNDETERMINED, p.getApplicationState(SYSTEM, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getApplicationState(SYSTEM, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, ADD_COMMENT, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, ADD_COMMENT, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, CREATE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, CREATE, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, DELETE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, DELETE, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, UPDATE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, UPDATE, EMAIL_FORMAT));
    // Enable email on "delete"
    p.setEventTypeState(SYSTEM, DELETE, EMAIL_FORMAT, BootstrapSwitch.State.ON);
    assertEquals(BootstrapSwitch.State.UNDETERMINED, p.getApplicationState(SYSTEM, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.UNDETERMINED, p.getApplicationState(SYSTEM, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, ADD_COMMENT, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, ADD_COMMENT, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, CREATE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, CREATE, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, DELETE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.ON, p.getEventTypeState(SYSTEM, DELETE, EMAIL_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, UPDATE, ALERT_FORMAT));
    assertEquals(BootstrapSwitch.State.OFF, p.getEventTypeState(SYSTEM, UPDATE, EMAIL_FORMAT));
    // Forget it
    p.disableAllParameters();
}
Also used : NotificationsUserProfilePage(org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage) ApplicationPreferences(org.xwiki.platform.notifications.test.po.preferences.ApplicationPreferences) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test) ServerSetupTest(com.icegreen.greenmail.util.ServerSetupTest)

Example 5 with NotificationsUserProfilePage

use of org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage 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

NotificationsUserProfilePage (org.xwiki.platform.notifications.test.po.NotificationsUserProfilePage)6 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)5 Test (org.junit.Test)5 AbstractTest (org.xwiki.test.ui.AbstractTest)5 NotificationsTrayPage (org.xwiki.platform.notifications.test.po.NotificationsTrayPage)3 ViewPage (org.xwiki.test.ui.po.ViewPage)2 WikiEditPage (org.xwiki.test.ui.po.editor.WikiEditPage)2 HashMap (java.util.HashMap)1 MimeMessage (javax.mail.internet.MimeMessage)1 Before (org.junit.Before)1 Email (org.simplejavamail.email.Email)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 ApplicationPreferences (org.xwiki.platform.notifications.test.po.preferences.ApplicationPreferences)1 SchedulerHomePage (org.xwiki.scheduler.test.po.SchedulerHomePage)1 CommentsTab (org.xwiki.test.ui.po.CommentsTab)1 ObjectEditPage (org.xwiki.test.ui.po.editor.ObjectEditPage)1 ProfileEditPage (org.xwiki.user.test.po.ProfileEditPage)1