1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.invitation.test.po

File InvitationGuestActionsPage.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

4
18
8
2
122
63
11
0.61
2.25
4
1.38

Classes

Class Line # Actions
InvitationGuestActionsPage 35 17 0% 10 4
0.8571428785.7%
InvitationGuestActionsPage.Action 37 1 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 6 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.invitation.test.po;
21   
22    import java.util.List;
23   
24    import org.openqa.selenium.By;
25    import org.openqa.selenium.WebDriverException;
26    import org.openqa.selenium.WebElement;
27    import org.xwiki.test.ui.po.BasePage;
28   
29    /**
30    * Represents the actions possible by guests on the invitation application.
31    *
32    * @version $Id: de80bef7ffda98d4ded8f23fb7bd9ac162b9886f $
33    * @since 4.2M1
34    */
 
35    public class InvitationGuestActionsPage extends BasePage
36    {
 
37    public enum Action
38    {
39    // Accept is null because the user is forwarded to RegistrationPage, decline is null because it includes the name
40    // of the sender.
41    ACCEPT(null),
42    DECLINE(null),
43    REPORT("Note to the administrator who investigates this report (optional)");
44   
45    public final String label;
46   
 
47  3 toggle private Action(String label)
48    {
49  3 this.label = label;
50    }
51    }
52   
53    private final InvitationActionConfirmationElement confirm;
54   
 
55  0 toggle public InvitationGuestActionsPage(String messageContent, Action action)
56    {
57  0 confirm = new InvitationActionConfirmationElement();
58    }
59   
60    // Constructor for when the page is manually accessed.
 
61  31 toggle public InvitationGuestActionsPage()
62    {
63  31 confirm = new InvitationActionConfirmationElement();
64    }
65   
66    /** This will fail if the action is accept because the user is redirected to a RegistrationPage. */
 
67  3 toggle public void setMemo(String memo)
68    {
69  3 confirm.setMemo(memo);
70    }
71   
 
72  24 toggle public String getMessage()
73    {
74  24 List<WebElement> elements = getDriver().findElementsWithoutWaiting(By.id("invitation-action-message"));
75  24 if (elements.size() > 0) {
76  17 return elements.get(0).getText();
77    }
78    // Returning null would lead to NPE when calling equals and we don't get the friendly test failure message.
79  7 return "";
80    }
81   
82    /** This will fail if the action is accept because the user is redirected to a RegistrationPage. */
83    /** Outputs the message given after clicking the confirm button. */
 
84  3 toggle public String confirm()
85    {
86  3 confirm.confirm();
87  3 return getDriver().findElement(By.id("invitation-action-message")).getText();
88    }
89   
90    /**
91    * @return the InvitationActionConfirmationElement on this page.
92    * @since 6.3M1
93    */
 
94  4 toggle public InvitationActionConfirmationElement getConfirmation()
95    {
96  4 return confirm;
97    }
98   
99    /**
100    * @param htmlMessageContent the html message received by the guest containing the link to the accept page
101    * @param action the action to be performed by the guest
102    * @return the corresponding page object
103    * @since 6.3M1
104    */
 
105  15 toggle public static InvitationGuestActionsPage gotoPage(String htmlMessageContent, Action action)
106    {
107  15 int start =
108    htmlMessageContent.indexOf(getUtil().getURL("Invitation", "InvitationGuestActions", "view",
109    "doAction_" + action.toString().toLowerCase()));
110  15 int end = htmlMessageContent.indexOf("\"", start);
111  15 getUtil().gotoPage(htmlMessageContent.substring(start, end).replaceAll("&amp;", "&"));
112   
113  15 InvitationGuestActionsPage page = new InvitationGuestActionsPage();
114   
115    // Make sure the right messages is displayed otherwise we can't continue.
116  15 if (action.label != null && !page.getConfirmation().getLabel().equalsIgnoreCase(action.label)) {
117  0 throw new WebDriverException("Not on correct page, expecting memo label to say \"" + action.label + "\"");
118    }
119   
120  15 return new InvitationGuestActionsPage();
121    }
122    }