use of org.xwiki.test.ui.po.ViewPage in project xwiki-platform by xwiki.
the class MailTest method sendTemplateMailToUsersAndGroup.
private void sendTemplateMailToUsersAndGroup() throws Exception {
// Remove existing pages (for pages that we create below)
getUtil().deletePage(getTestClassName(), "SendMailGroupAndUsers");
// Create 2 users
getUtil().createUser("user1", "password1", getUtil().getURLToNonExistentPage(), "email", "user1@doe.com");
getUtil().createUser("user2", "password2", getUtil().getURLToNonExistentPage(), "email", "user2@doe.com");
// Create another page with the Velocity script to send the template email
// Note: the $xcontext and $request bindings are present and have their values at the moment the call to send
// the mail asynchronously was done.
String velocity = "{{velocity}}\n" + "#set ($templateParameters = " + " {'velocityVariables' : { 'name' : 'John', 'doc' : $doc }, " + " 'language' : 'en', 'from' : 'localhost@xwiki.org'})\n" + "#set ($templateReference = $services.model.createDocumentReference('', '" + getTestClassName() + "', 'MailTemplate'))\n" + "#set ($parameters = {'hint' : 'template', 'source' : $templateReference, " + "'parameters' : $templateParameters, 'type' : 'Test'})\n" + "#set ($groupReference = $services.model.createDocumentReference('', 'XWiki', 'XWikiAllGroup'))\n" + "#set ($user1Reference = $services.model.createDocumentReference('', 'XWiki', 'user1'))\n" + "#set ($user2Reference = $services.model.createDocumentReference('', 'XWiki', 'user2'))\n" + "#set ($source = {'groups' : [$groupReference], 'users' : [$user1Reference, $user2Reference]})\n" + "#set ($messages = $services.mailsender.createMessages('usersandgroups', $source, $parameters))\n" + "#set ($result = $services.mailsender.send($messages, 'database'))\n" + "#if ($services.mailsender.lastError)\n" + " {{error}}$exceptiontool.getStackTrace($services.mailsender.lastError){{/error}}\n" + "#end\n" + "#foreach ($status in $result.statusResult.getByState('SEND_ERROR'))\n" + " {{error}}\n" + " $status.messageId - $status.errorSummary\n" + " $status.errorDescription\n" + " {{/error}}\n" + "#end\n" + "{{/velocity}}";
// This will create the page and execute its content and thus send the mail
ViewPage vp = getUtil().createPage(getTestClassName(), "SendMailGroupAndUsers", velocity, "");
// Verify that the page doesn't display any content (unless there's an error!)
assertEquals("", vp.getContent());
// Verify that the mails have been received (first mail above + the 2 mails sent to the group)
this.mail.waitForIncomingEmail(30000L, 3);
assertEquals(3, this.mail.getReceivedMessages().length);
assertReceivedMessages(2, "Subject: Status for John on " + getTestClassName() + ".SendMailGroupAndUsers", "Hello John from superadmin - Served from " + "http://localhost:8080/xwiki/bin/view/MailTest/SendMailGroupAndUsers - " + "url: http://localhost:8080/xwiki/bin/view/Main/");
}
use of org.xwiki.test.ui.po.ViewPage in project xwiki-platform by xwiki.
the class MailTest method sendTemplateMailToEmail.
private void sendTemplateMailToEmail() throws Exception {
// Remove existing pages (for pages that we create below)
getUtil().deletePage(getTestClassName(), "SendMail");
// Create another page with the Velocity script to send the template email
// Note that we didn't need to bind the "$doc" velocity variable because the send is done synchronously and
// thus the current XWiki Context is cloned before being passed to the template evaluation, and thus it
// already contains the "$doc" binding!
String velocity = "{{velocity}}\n" + "#set ($templateReference = $services.model.createDocumentReference('', '" + getTestClassName() + "', 'MailTemplate'))\n" + "#set ($parameters = {'velocityVariables' : { 'name' : 'John' }, 'language' : 'en', " + "'includeTemplateAttachments' : true})\n" + "#set ($message = $services.mailsender.createMessage('template', $templateReference, $parameters))\n" + "#set ($discard = $message.setFrom('localhost@xwiki.org'))\n" + "#set ($discard = $message.addRecipients('to', 'john@doe.com'))\n" + "#set ($discard = $message.setType('Test'))\n" + "#set ($result = $services.mailsender.send([$message], 'database'))\n" + "#if ($services.mailsender.lastError)\n" + " {{error}}$exceptiontool.getStackTrace($services.mailsender.lastError){{/error}}\n" + "#end\n" + "#foreach ($status in $result.statusResult.getByState('SEND_ERROR'))\n" + " {{error}}\n" + " $status.messageId - $status.errorSummary\n" + " $status.errorDescription\n" + " {{/error}}\n" + "#end\n" + "{{/velocity}}";
// This will create the page and execute its content and thus send the mail
ViewPage vp = getUtil().createPage(getTestClassName(), "SendMail", velocity, "");
// Verify that the page doesn't display any content (unless there's an error!)
assertEquals("", vp.getContent());
// Verify that the mail has been received.
this.mail.waitForIncomingEmail(30000L, 1);
assertEquals(1, this.mail.getReceivedMessages().length);
assertReceivedMessages(1, "Subject: Status for John on " + getTestClassName() + ".SendMail", "Hello John from superadmin - Served from http://localhost:8080/xwiki/bin/view/MailTest/SendMail", "<strong>Hello John from superadmin - Served from " + "http://localhost:8080/xwiki/bin/view/MailTest/SendMail - " + "url: http://localhost:8080/xwiki/bin/view/Main/</strong>", "X-MailType: Test", "Content-Type: text/plain; name=something.txt", "Content-ID: <something.txt>", "Content-Disposition: attachment; filename=something.txt", "Content of attachment");
}
use of org.xwiki.test.ui.po.ViewPage 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.test.ui.po.ViewPage in project xwiki-platform by xwiki.
the class ActiveInstallsIT method verifyActiveInstalls.
@Test
public void verifyActiveInstalls() throws Exception {
// provision ES).
if (ElasticSearchRunner.esSetup != null) {
// When XWiki was started by ElasticSearchRunner from AllITs, a page was checked to verify that the XWiki
// instance was up. This, in turn, triggered the send of an asynchronous ping to the ES instance
// (started prior to the XWiki start in ElasticSearchRunner).
//
// Since the ping may take some time to be sent to our ES instance, we wait till we have 1 index in ES or
// till the timeout expires.
long count = 0;
long time = System.currentTimeMillis();
while (count != 1 && (System.currentTimeMillis() - time) < 5000L) {
count = ElasticSearchRunner.esSetup.countAll();
Thread.sleep(100L);
}
assertEquals("AS ping wasn't sent by the XWiki instance", 1, count);
// In order to verify backward compatibility with the previous Active Install format, we also add an index
// in the older format.
ElasticSearchRunner.esSetup.execute(index("installs", "install", "156231f3-705b-44c6-afe3-e191bcc4b746").withSource("{ \"formatVersion\": \"1.0\", \"distributionVersion\": \"5.2\", " + "\"distributionId\": \"org.xwiki.platform:xwiki-platform-web\", " + "\"date\": \"2013-09-16T20:00:34.277Z\", \"extensions\": [ ] }"));
}
// Navigate to the ActiveInstalls app by clicking in the Application Panel.
// This verifies that the ActiveInstalls application is registered in the Applications Panel.
// It also verifies that the Translation is registered properly.
ApplicationsPanel applicationPanel = ApplicationsPanel.gotoPage();
ViewPage vp = applicationPanel.clickApplication("Active Installs");
// Verify we're on the right page!
Assert.assertEquals(ActiveInstallsHomePage.getSpace(), vp.getMetaDataValue("space"));
Assert.assertEquals(ActiveInstallsHomePage.getPage(), vp.getMetaDataValue("page"));
// Configure the Active Installs feature to count "org.xwiki.*" distribution ids.
getUtil().updateObject("ActiveInstalls", "ActiveInstallsConfig", "ActiveInstalls.ActiveInstallsConfig", 0, "distributionId", "org.xwiki.*");
// By default we don't show SNAPSHOTs, verify that!
// The default query doesn't show SNAPSHOT versions and thus we expect 0
getUtil().gotoPage("ActiveInstalls", "ActiveCounterValue2");
vp = new ViewPage();
assertEquals("0", vp.getContent());
// The default query doesn't show SNAPSHOT versions and thus we expect 0
getUtil().gotoPage("ActiveInstalls", "TotalCounterValue2");
vp = new ViewPage();
assertEquals("0", vp.getContent());
// Configure the Active Installs feature to count SNAPSHOTs and to count
// "org.xwiki.platform:xwiki-platform-web" distribution ids.
getUtil().updateObject("ActiveInstalls", "ActiveInstallsConfig", "ActiveInstalls.ActiveInstallsConfig", 0, "snapshots", true);
// Navigate to the Active Installs Counter Value page to verify that the ping has been received
getUtil().gotoPage("ActiveInstalls", "ActiveCounterValue2");
vp = new ViewPage();
assertEquals("1", vp.getContent());
// Also verify the Active Installs Counter for the old format
getUtil().gotoPage("ActiveInstalls", "ActiveCounterValue1");
vp = new ViewPage();
assertEquals("0", vp.getContent());
// Navigate to the Total Installs Counter Value page to verify that the ping has been received
getUtil().gotoPage("ActiveInstalls", "TotalCounterValue2");
vp = new ViewPage();
assertEquals("1", vp.getContent());
// Also verify the Total Installs Counter for the old format
getUtil().gotoPage("ActiveInstalls", "TotalCounterValue1");
vp = new ViewPage();
assertEquals("1", vp.getContent());
// Verify JavaVersion data
getUtil().gotoPage("ActiveInstalls", "JavaVersionsData");
vp = new ViewPage();
assertTrue("Got [" + vp.getContent() + "]", vp.getContent().matches("Java Version Active Installs Count\\r?\\n1\\.[0-9_\\.]* 1"));
// Verify Databases data
getUtil().gotoPage("ActiveInstalls", "DatabasesData");
vp = new ViewPage();
assertTrue("Got [" + vp.getContent() + "]", vp.getContent().matches("Database Active Installs Count\\r?\\nHSQL Database Engine 1"));
// Verify Distribution data
getUtil().gotoPage("ActiveInstalls", "DistributionData");
vp = new ViewPage();
assertTrue("Got [" + vp.getContent() + "]", vp.getContent().matches("Distributions Active Installs Count\\r?\\n" + "org.xwiki.platform:xwiki-platform-web 1"));
// Verify top 10 XWiki versions data
getUtil().gotoPage("ActiveInstalls", "XWikiVersionsData");
vp = new ViewPage();
assertTrue("Got [" + vp.getContent() + "]", vp.getContent().matches("XWiki Version Active Installs Count\\r?\\n[0-9]+\\.[0-9]+.* 1"));
// Verify XWiki Cycle versions data
getUtil().gotoPage("ActiveInstalls", "XWikiVersionsCycleData");
vp = new ViewPage();
assertTrue("Got [" + vp.getContent() + "]", vp.getContent().matches("XWiki Version Active Installs Count\\r?\\n[0-9]+\\.x 1"));
// Verify ServletContainers data
getUtil().gotoPage("ActiveInstalls", "ServletContainersData");
vp = new ViewPage();
assertTrue("Got [" + vp.getContent() + "]", vp.getContent().matches("Servlet Container Active Installs Count\\r?\\njetty 1"));
// Verify Extension Count
// Create a page calling the Extension Count macro
String content = "{{include reference=\"ActiveInstalls.ExtensionCount\"/}}\n" + "\n" + "{{velocity}}\n" + "#set ($extensionIds = [\n" + " 'org.xwiki.contrib:xwiki-totem-application',\n" + " 'jsimard:event-reporter-application',\n" + " 'mouhb:likeapplication'\n" + "])\n" + "|=Extension Id|=Count\n" + "#foreach($extensionId in $extensionIds)\n" + " #countActiveInstallsUsingExtension($extensionId $count)\n" + " |$extensionId|$count\n" + "#end\n" + "{{/velocity}}";
vp = getUtil().createPage(getTestClassName(), "ExtensionCountExample", content, "Example");
assertTrue("Got [" + vp.getContent() + "]", vp.getContent().matches("Extension Id Count\n" + "org.xwiki.contrib:xwiki-totem-application 0\n" + "jsimard:event-reporter-application 0\n" + "mouhb:likeapplication 0"));
}
use of org.xwiki.test.ui.po.ViewPage 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();
}
Aggregations