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.department.lunch.rule; 017 import org.apache.log4j.Logger; 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.test.TkTestConstants; 023 024 import com.gargoylesoftware.htmlunit.html.HtmlInput; 025 import com.gargoylesoftware.htmlunit.html.HtmlPage; 026 027 public class DepartmentLunchRuleMaintTest extends KPMETestCase { 028 private static final Logger LOG = Logger.getLogger(DepartmentLunchRuleMaintTest.class); 029 private static final String TEST_CODE = "admin"; 030 private static String TEST_CODE_DEPT_INVALID = "INVALID"; 031 private static Long TEST_CODE_WORKAREA_INVALID = 9999L; 032 033 private static Long deptLunchRuleIdWithInvalidDept = 1L; 034 private static Long deptLunchRuleIdWithInvalidWorkArea = 3L; 035 036 /** 037 * Test to check whether it is showing error message for Department on maintenance screen 038 * if we supply non exist deptId 039 * 040 * @throws Exception 041 */ 042 @Test 043 public void testDepartmentLunchRuleMaintForDeptErrorMessage() 044 throws Exception { 045 HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil 046 .gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL); 047 departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText( 048 departmentLunchRuleLookUp, "search"); 049 Assert.assertTrue("Page contains test DepartmentLunchRule", 050 departmentLunchRuleLookUp.asText().contains(TEST_CODE)); 051 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText( 052 departmentLunchRuleLookUp, "edit", 053 deptLunchRuleIdWithInvalidDept.toString()); 054 HtmlInput inputForDept = HtmlUnitUtil.getInputContainingText(maintPage, 055 TEST_CODE_DEPT_INVALID); 056 inputForDept.setValueAttribute(TEST_CODE_DEPT_INVALID); 057 HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText( 058 maintPage, "* Document Description"); 059 inputForDescription.setValueAttribute("Description"); 060 HtmlPage resultantPageAfterEdit = HtmlUnitUtil 061 .clickInputContainingText(maintPage, "submit"); 062 LOG.debug(resultantPageAfterEdit.asText()); 063 Assert.assertTrue("Maintenance Page contains error message for dept", 064 resultantPageAfterEdit.asText().contains( 065 "The specified department '" + TEST_CODE_DEPT_INVALID 066 + "' does not exist.")); 067 } 068 069 /** 070 * Test to check whether it is showing error message for WorkArea on maintenance screen 071 * if we supply non exist workArea 072 * 073 * @throws Exception 074 */ 075 @Test 076 public void testDepartmentLunchRuleMaintForWorkAreaErrorMessage() 077 throws Exception { 078 HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil 079 .gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL); 080 departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText( 081 departmentLunchRuleLookUp, "search"); 082 Assert.assertTrue("Page contains test DepartmentLunchRule", 083 departmentLunchRuleLookUp.asText().contains(TEST_CODE)); 084 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText( 085 departmentLunchRuleLookUp, "edit", 086 deptLunchRuleIdWithInvalidWorkArea.toString()); 087 HtmlUnitUtil.createTempFile(maintPage); 088 089 HtmlInput inputForWorkArea = HtmlUnitUtil.getInputContainingText(maintPage, 090 "newMaintainableObject.workArea"); 091 inputForWorkArea.setValueAttribute(Long.toString(TEST_CODE_WORKAREA_INVALID)); 092 HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText( 093 maintPage, "* Document Description"); 094 inputForDescription.setValueAttribute("Description"); 095 HtmlPage resultantPageAfterEdit = HtmlUnitUtil 096 .clickInputContainingText(maintPage, "submit"); 097 HtmlUnitUtil.createTempFile(resultantPageAfterEdit); 098 Assert.assertTrue("Maintenance Page contains contains error message for workarea", 099 resultantPageAfterEdit.asText().contains( 100 "The specified workArea '" + TEST_CODE_WORKAREA_INVALID 101 + "' does not exist.")); 102 } 103 104 @Test 105 public void testDepartmentLunchRuleMaintForMaxShiftHourErrorMessage() throws Exception { 106 HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil 107 .gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL); 108 departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText( 109 departmentLunchRuleLookUp, "search"); 110 Assert.assertTrue("Page contains test DepartmentLunchRule", 111 departmentLunchRuleLookUp.asText().contains(TEST_CODE)); 112 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText( 113 departmentLunchRuleLookUp, "edit", 114 deptLunchRuleIdWithInvalidWorkArea.toString()); 115 116 setFieldValue(maintPage, TkTestConstants.DOC_NEW_ELEMENT_ID_PREFIX + "shiftHours", "34"); 117 setFieldValue(maintPage, "document.documentHeader.documentDescription", "test"); 118 HtmlPage resultantPageAfterEdit = HtmlUnitUtil.clickInputContainingText(maintPage, "submit"); 119 HtmlUnitUtil.createTempFile(resultantPageAfterEdit); 120 Assert.assertTrue("Maintenance Page contains contains error message for Shift Hours", 121 resultantPageAfterEdit.asText().contains("Shift Hour cannot be greater than 24.")); 122 } 123 124 @Test 125 public void testDepartmentLunchRuleMaint() throws Exception { 126 HtmlPage departmentLunchRuleLookUp = HtmlUnitUtil 127 .gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DEPT_LUNCH_RULE_MAINT_URL); 128 departmentLunchRuleLookUp = HtmlUnitUtil.clickInputContainingText( 129 departmentLunchRuleLookUp, "search"); 130 Assert.assertTrue("Page contains test DepartmentLunchRule", 131 departmentLunchRuleLookUp.asText().contains( 132 TEST_CODE.toString())); 133 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText( 134 departmentLunchRuleLookUp, "edit", 135 deptLunchRuleIdWithInvalidDept.toString()); 136 Assert.assertTrue("Maintenance Page contains test DepartmentLunchRule", 137 maintPage.asText().contains(TEST_CODE.toString())); 138 } 139 }