Search in sources :

Example 1 with TableElement

use of org.xwiki.test.ui.po.TableElement in project xwiki-platform by xwiki.

the class InvitationTest method testDeclineInvitation.

/**
 * This test proves that:
 * 1. A guest can decline an invitation.
 * 2. The message status changes and the footer reflects this.
 * 3. The sender can see the info box seeing the guest's reason for declining.
 * 4. The message history table shows the decline properly.
 * 5. A guest cannot accept a message which has already been declined.
 */
@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 testDeclineInvitation() throws Exception {
    TestUtils.Session admin = getUtil().getSession();
    try {
        startGreenMail();
        getSenderPage().send();
        getGreenMail().waitForIncomingEmail(10000, 1);
        MimeMessage[] messages = getGreenMail().getReceivedMessages();
        String htmlMessage = getMessageContent(messages[0]).get("htmlPart");
        Assert.assertTrue("New invitation is not listed as pending in the footer.", getSenderPage().getFooter().myPendingInvitations() == 1);
        // Now switch to guest.
        getUtil().forceGuestUser();
        InvitationGuestActionsPage guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.DECLINE);
        guestPage.setMemo("I'm not interested thank you.");
        guestPage.confirm();
        Assert.assertTrue("Failed to decline invitation", getDriver().getPageSource().contains("This invitation has successfully been declined."));
        // Switch to admin
        getUtil().setSession(admin);
        // Go to invitation sender.
        setSenderPage(InvitationSenderPage.gotoPage());
        Assert.assertTrue("Declined invitation is still listed as pending in the footer.", getSenderPage().getFooter().spamReports() == 0);
        // View declined invitation.
        InspectInvitationsPage inspectPage = getSenderPage().getFooter().inspectMyInvitations();
        InspectInvitationsPage.OneMessage inspect = inspectPage.getMessageWhere("Status", "Declined");
        Assert.assertTrue("Not showing message box to say the invitation has been declined", inspect.getStatusAndMemo().equals("Declined with message: I'm not interested thank you."));
        // Insure the message history table is correct.
        TableElement messageHistoryTable = inspect.clickMessageHistory();
        List<WebElement> row2 = messageHistoryTable.getRow(2);
        Assert.assertTrue("Message history table not showing correctly.", row2.get(0).getText().equals("Declined"));
        Assert.assertTrue("Message history table not showing correctly.", row2.get(2).getText().equals("I'm not interested thank you."));
        // Make sure a guest can't accept the invitation now.
        getUtil().forceGuestUser();
        guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.ACCEPT);
        Assert.assertTrue("After a message is declined a user can still accept it!", guestPage.getMessage().equals("This invitation has been declined and cannot be accepted now."));
        // Try to decline the invitation.
        guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.DECLINE);
        Assert.assertTrue("User was allowed to decline an invitation twice.", guestPage.getMessage().equals("This invitation has already been declined and " + "cannot be declined again."));
        // Prove that the message can still be reported as spam
        guestPage = InvitationGuestActionsPage.gotoPage(htmlMessage, InvitationGuestActionsPage.Action.REPORT);
        Assert.assertTrue("After the invitation was declined it now cannot be reported as spam.", guestPage.getMessage().equals(""));
    } finally {
        stopGreenMail();
        getUtil().setSession(admin);
    }
}
Also used : InvitationGuestActionsPage(org.xwiki.invitation.test.po.InvitationGuestActionsPage) TestUtils(org.xwiki.test.ui.TestUtils) InspectInvitationsPage(org.xwiki.invitation.test.po.InspectInvitationsPage) MimeMessage(javax.mail.internet.MimeMessage) WebElement(org.openqa.selenium.WebElement) TableElement(org.xwiki.test.ui.po.TableElement) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test)

Example 2 with TableElement

use of org.xwiki.test.ui.po.TableElement in project xwiki-platform by xwiki.

the class InvitationTest method testSendMailToTwoAddresses.

@Test
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146")
public void testSendMailToTwoAddresses() throws Exception {
    try {
        startGreenMail();
        getSenderPage().fillForm("user@localhost.localdomain anotheruser@localhost.localdomain", null, null);
        InvitationSenderPage.InvitationSentPage sent = getSenderPage().send();
        getGreenMail().waitForIncomingEmail(10000, 2);
        MimeMessage[] messages = getGreenMail().getReceivedMessages();
        Assert.assertTrue("wrong number of messages", messages.length == 2);
        // Correspond to messages a and b
        int a = 1, b = 2;
        Map<String, String> messageA = getMessageContent(messages[0]);
        Map<String, String> messageB = getMessageContent(messages[1]);
        Assert.assertFalse("Both messages are going to the same recipient", messageA.get("recipient").equals(messageB.get("recipient")));
        // No guarentee which message will come in first.
        if (messageA.get("recipient").contains("anotheruser@localhost.localdomain")) {
            Map<String, String> temp = messageB;
            messageB = messageA;
            messageA = temp;
            b = 1;
            a = 2;
        }
        Assert.assertTrue("Wrong recipient name.\nExpecting:user@localhost.localdomain\n      Got:" + messageA.get("recipient"), messageA.get("recipient").contains("user@localhost.localdomain"));
        Assert.assertTrue("Wrong recipient name.\nExpecting:anotheruser@localhost.localdomain\n      Got:" + messageB.get("recipient"), messageB.get("recipient").contains("anotheruser@localhost.localdomain"));
        assertMessageValid(messageA);
        assertMessageValid(messageB);
        // Check that the page has the table and the messages.
        Assert.assertTrue(sent.getMessageBoxContent().contains("Your message has been sent."));
        TableElement table = sent.getTable();
        Assert.assertTrue(table.numberOfRows() == 3);
        Assert.assertTrue(table.numberOfColumns() == 3);
        Assert.assertTrue(table.getRow(a).get(1).getText().contains("user@localhost.localdomain"));
        Assert.assertTrue(table.getRow(a).get(2).getText().contains("Pending"));
        Assert.assertTrue(table.getRow(b).get(1).getText().contains("anotheruser@localhost.localdomain"));
        Assert.assertTrue(table.getRow(b).get(2).getText().contains("Pending"));
    } finally {
        stopGreenMail();
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) InvitationSenderPage(org.xwiki.invitation.test.po.InvitationSenderPage) TableElement(org.xwiki.test.ui.po.TableElement) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test) IgnoreBrowser(org.xwiki.test.ui.browser.IgnoreBrowser)

Example 3 with TableElement

use of org.xwiki.test.ui.po.TableElement in project xwiki-platform by xwiki.

the class InvitationTest method testNonAdminCanSend.

@Test
@IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146")
public void testNonAdminCanSend() throws Exception {
    TestUtils.Session s = getUtil().getSession();
    try {
        getUtil().forceGuestUser();
        getUtil().createUserAndLogin("NonMailAdminUser", "WeakPassword");
        setSenderPage(InvitationSenderPage.gotoPage());
        startGreenMail();
        getSenderPage().fillForm("user@localhost.localdomain", null, null);
        InvitationSenderPage.InvitationSentPage sent = getSenderPage().send();
        // Prove that the message was sent.
        getGreenMail().waitForIncomingEmail(10000, 1);
        MimeMessage[] messages = getGreenMail().getReceivedMessages();
        Map<String, String> message = getMessageContent(messages[0]);
        Assert.assertTrue(message.get("recipient").contains("user@localhost.localdomain"));
        assertMessageValid(message);
        // Check that the page has the table and the message.
        Assert.assertTrue(sent.getMessageBoxContent().contains("Your message has been sent."));
        TableElement table = sent.getTable();
        Assert.assertTrue(table.numberOfRows() == 2);
        Assert.assertTrue(table.numberOfColumns() == 3);
        Assert.assertTrue(table.getRow(1).get(1).getText().contains("user@localhost.localdomain"));
        Assert.assertTrue(table.getRow(1).get(2).getText().contains("Pending"));
    } finally {
        stopGreenMail();
        getUtil().setSession(s);
        getUtil().rest().deletePage("XWiki", "NonMailAdminUser");
    }
}
Also used : TestUtils(org.xwiki.test.ui.TestUtils) MimeMessage(javax.mail.internet.MimeMessage) InvitationSenderPage(org.xwiki.invitation.test.po.InvitationSenderPage) TableElement(org.xwiki.test.ui.po.TableElement) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test) IgnoreBrowser(org.xwiki.test.ui.browser.IgnoreBrowser)

Aggregations

MimeMessage (javax.mail.internet.MimeMessage)3 Test (org.junit.Test)3 AbstractTest (org.xwiki.test.ui.AbstractTest)3 TableElement (org.xwiki.test.ui.po.TableElement)3 InvitationSenderPage (org.xwiki.invitation.test.po.InvitationSenderPage)2 TestUtils (org.xwiki.test.ui.TestUtils)2 IgnoreBrowser (org.xwiki.test.ui.browser.IgnoreBrowser)2 WebElement (org.openqa.selenium.WebElement)1 InspectInvitationsPage (org.xwiki.invitation.test.po.InspectInvitationsPage)1 InvitationGuestActionsPage (org.xwiki.invitation.test.po.InvitationGuestActionsPage)1 IgnoreBrowsers (org.xwiki.test.ui.browser.IgnoreBrowsers)1