View Javadoc

1   /**
2    * Copyright 2004-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  		// set Description
49  		setFieldValue(editPage, "document.documentHeader.documentDescription",
50  				"Adding role to user" + PRINCIPAL_ID);
51  
52  		// Click on Add and see errors
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  		// Add Global View Only Role.
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  		// Add Location Admin View Only Role.
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  		// Location is required in case of Location View Only roles
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 		// page should not contain any errors
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 		// submit
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 		// again go to the url and do login
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 		// check if this page contains created role Global View Only
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 		// Now update
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 		// again go through maintenance page and check if inactive roles tab contains the role Department Admin
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 		// check if Global view only role is in inactive role list.
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 }