1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.userrole;
17
18 import org.junit.Assert;
19 import org.junit.Test;
20 import org.kuali.hr.test.KPMETestCase;
21 import org.kuali.hr.time.test.HtmlUnitUtil;
22 import org.kuali.hr.time.util.TkConstants;
23
24 import com.gargoylesoftware.htmlunit.html.HtmlElement;
25 import com.gargoylesoftware.htmlunit.html.HtmlPage;
26 import com.gargoylesoftware.htmlunit.html.HtmlSpan;
27
28 public class UserRoleMaintenanceDocumentTest extends KPMETestCase {
29
30 private static final String PRINCIPAL_ID = "fred";
31
32 @Test
33 public void testUserRoleMaintenanceDocumentTest() throws Exception {
34 String baseUrl = HtmlUnitUtil.getBaseURL()
35 + "/kr/lookup.do?methodToCall=start&businessObjectClassName=org.kuali.hr.time.roles.TkRoleGroup&returnLocation="
36 + HtmlUnitUtil.getBaseURL()
37 + "/portal.do&hideReturnLink=true&docFormKey=88888888";
38
39 HtmlPage lookUpPage = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
40 Assert.assertNotNull(lookUpPage);
41
42 lookUpPage = HtmlUnitUtil
43 .clickInputContainingText(lookUpPage, "search");
44
45 HtmlPage editPage = HtmlUnitUtil.clickAnchorContainingText(lookUpPage,
46 "edit", "principalId=" + PRINCIPAL_ID);
47
48
49 setFieldValue(editPage, "document.documentHeader.documentDescription",
50 "Adding role to user" + PRINCIPAL_ID);
51
52
53 HtmlElement elementAddRole = HtmlUnitUtil.getInputContainingText(
54 editPage, "methodToCall.addLine.roles");
55 editPage = elementAddRole.click();
56
57 Assert.assertTrue(
58 "page text:\n" + editPage.asText() + "\n does not contain:\n",
59 editPage.asText().contains(
60 "Effective Date (Effective Date) is a required field."));
61
62
63 elementAddRole = HtmlUnitUtil.getInputContainingText(editPage,
64 "methodToCall.addLine.roles");
65 setFieldValue(editPage,
66 "document.newMaintainableObject.add.roles.effectiveDate",
67 "01/01/2011");
68 setFieldValue(editPage,
69 "document.newMaintainableObject.add.roles.roleName",
70 TkConstants.ROLE_TK_GLOBAL_VO);
71
72 editPage = elementAddRole.click();
73
74 Assert.assertTrue("page text:\n" + editPage.asText()
75 + "\n does not contain:\n",
76 !editPage.asText().contains("error(s) found on page."));
77
78
79 elementAddRole = HtmlUnitUtil.getInputContainingText(editPage,
80 "methodToCall.addLine.roles");
81 setFieldValue(editPage,
82 "document.newMaintainableObject.add.roles.effectiveDate",
83 "01/01/2011");
84 setFieldValue(editPage,
85 "document.newMaintainableObject.add.roles.roleName",
86 TkConstants.ROLE_TK_LOCATION_VO);
87
88 editPage = elementAddRole.click();
89
90
91 Assert.assertTrue("page text:\n" + editPage.asText()
92 + "\n does not contain:\n",
93 editPage.asText().contains("error(s) found on page."));
94
95 setFieldValue(editPage,
96 "document.newMaintainableObject.add.roles.chart", "BL");
97
98 elementAddRole = HtmlUnitUtil.getInputContainingText(editPage,
99 "methodToCall.addLine.roles");
100 editPage = elementAddRole.click();
101
102
103 Assert.assertTrue("page text:\n" + editPage.asText()
104 + "\n does not contain:\n",
105 !editPage.asText().contains("error(s) found on page."));
106
107
108 HtmlElement submitElement = HtmlUnitUtil.getInputContainingText(
109 editPage, "methodToCall.route");
110
111 editPage = submitElement.click();
112 Assert.assertTrue(
113 "page text:\n" + editPage.asText() + "\n does not contain:\n",
114 editPage.asText().contains(
115 "Document was successfully submitted."));
116
117
118 lookUpPage = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
119 Assert.assertNotNull(lookUpPage);
120
121 lookUpPage = HtmlUnitUtil
122 .clickInputContainingText(lookUpPage, "search");
123 editPage = HtmlUnitUtil.clickAnchorContainingText(lookUpPage, "edit",
124 "principalId=" + PRINCIPAL_ID);
125
126
127 HtmlSpan oldRoleEle = (HtmlSpan) editPage
128 .getElementById("document.oldMaintainableObject.roles[1].roleName.div");
129 Assert.assertTrue("page text:\n" + oldRoleEle.asText()
130 + "\n does not contain:\n",
131 oldRoleEle.asText().contains("Global View Only"));
132
133
134 setFieldValue(editPage, "document.documentHeader.documentDescription",
135 "Inactivating location admin role");
136 setFieldValue(editPage,
137 "document.newMaintainableObject.roles[1].active", "off");
138
139 submitElement = HtmlUnitUtil.getInputContainingText(editPage,
140 "methodToCall.route");
141
142 editPage = submitElement.click();
143
144 Assert.assertTrue(
145 "page text:\n" + editPage.asText() + "\n does not contain:\n",
146 editPage.asText().contains(
147 "Document was successfully submitted"));
148
149
150 lookUpPage = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
151 Assert.assertNotNull(lookUpPage);
152
153 lookUpPage = HtmlUnitUtil
154 .clickInputContainingText(lookUpPage, "search");
155 editPage = HtmlUnitUtil.clickAnchorContainingText(lookUpPage, "edit",
156 "principalId=" + PRINCIPAL_ID);
157
158 editPage = HtmlUnitUtil.clickInputContainingText(editPage,
159 "methodToCall.toggleTab.tabInactivePersonRoles");
160
161
162 HtmlSpan oldIARoleEle = (HtmlSpan) editPage
163 .getElementById("document.oldMaintainableObject.inactiveRoles[0].roleName.div");
164 Assert.assertTrue("Inactive Roles "+oldIARoleEle.asText() +" does not contains", oldIARoleEle.asText().contains("Global View Only"));
165
166 oldIARoleEle = (HtmlSpan) editPage
167 .getElementById("document.oldMaintainableObject.inactiveRoles[0].active.div");
168 Assert.assertTrue("Inactive Roles "+oldIARoleEle.asText() +" does not contains", oldIARoleEle.asText().contains("No"));
169 }
170
171 }