001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.time.userrole; 017 018 import org.junit.Assert; 019 import org.junit.Test; 020 import org.kuali.hr.test.KPMETestCase; 021 import org.kuali.hr.time.test.HtmlUnitUtil; 022 import org.kuali.hr.time.util.TkConstants; 023 024 import com.gargoylesoftware.htmlunit.html.HtmlElement; 025 import com.gargoylesoftware.htmlunit.html.HtmlPage; 026 import com.gargoylesoftware.htmlunit.html.HtmlSpan; 027 028 public class UserRoleMaintenanceDocumentTest extends KPMETestCase { 029 030 private static final String PRINCIPAL_ID = "fred"; 031 032 @Test 033 public void testUserRoleMaintenanceDocumentTest() throws Exception { 034 String baseUrl = HtmlUnitUtil.getBaseURL() 035 + "/kr/lookup.do?methodToCall=start&businessObjectClassName=org.kuali.hr.time.roles.TkRoleGroup&returnLocation=" 036 + HtmlUnitUtil.getBaseURL() 037 + "/portal.do&hideReturnLink=true&docFormKey=88888888"; 038 039 HtmlPage lookUpPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 040 Assert.assertNotNull(lookUpPage); 041 042 lookUpPage = HtmlUnitUtil 043 .clickInputContainingText(lookUpPage, "search"); 044 045 HtmlPage editPage = HtmlUnitUtil.clickAnchorContainingText(lookUpPage, 046 "edit", "principalId=" + PRINCIPAL_ID); 047 048 // set Description 049 setFieldValue(editPage, "document.documentHeader.documentDescription", 050 "Adding role to user" + PRINCIPAL_ID); 051 052 // Click on Add and see errors 053 HtmlElement elementAddRole = HtmlUnitUtil.getInputContainingText( 054 editPage, "methodToCall.addLine.roles"); 055 editPage = elementAddRole.click(); 056 057 Assert.assertTrue( 058 "page text:\n" + editPage.asText() + "\n does not contain:\n", 059 editPage.asText().contains( 060 "Effective Date (Effective Date) is a required field.")); 061 062 // Add Global View Only Role. 063 elementAddRole = HtmlUnitUtil.getInputContainingText(editPage, 064 "methodToCall.addLine.roles"); 065 setFieldValue(editPage, 066 "document.newMaintainableObject.add.roles.effectiveDate", 067 "01/01/2011"); 068 setFieldValue(editPage, 069 "document.newMaintainableObject.add.roles.roleName", 070 TkConstants.ROLE_TK_GLOBAL_VO); 071 072 editPage = elementAddRole.click(); 073 074 Assert.assertTrue("page text:\n" + editPage.asText() 075 + "\n does not contain:\n", 076 !editPage.asText().contains("error(s) found on page.")); 077 078 // Add Location Admin View Only Role. 079 elementAddRole = HtmlUnitUtil.getInputContainingText(editPage, 080 "methodToCall.addLine.roles"); 081 setFieldValue(editPage, 082 "document.newMaintainableObject.add.roles.effectiveDate", 083 "01/01/2011"); 084 setFieldValue(editPage, 085 "document.newMaintainableObject.add.roles.roleName", 086 TkConstants.ROLE_TK_LOCATION_VO); 087 088 editPage = elementAddRole.click(); 089 090 // Location is required in case of Location View Only roles 091 Assert.assertTrue("page text:\n" + editPage.asText() 092 + "\n does not contain:\n", 093 editPage.asText().contains("error(s) found on page.")); 094 095 setFieldValue(editPage, 096 "document.newMaintainableObject.add.roles.chart", "BL"); 097 098 elementAddRole = HtmlUnitUtil.getInputContainingText(editPage, 099 "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(getWebClient(), 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[0].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 global view only role"); 136 setFieldValue(editPage, 137 "document.newMaintainableObject.roles[0].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(getWebClient(), 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 }