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.overtime.daily.rule; 017 018 019 import java.math.BigDecimal; 020 import java.util.HashMap; 021 022 import org.apache.log4j.Logger; 023 import org.junit.Assert; 024 import org.junit.Test; 025 import org.kuali.hr.test.KPMETestCase; 026 import org.kuali.hr.time.test.HtmlUnitUtil; 027 import org.kuali.hr.time.test.TkTestConstants; 028 import org.kuali.hr.time.util.TKUtils; 029 import org.kuali.rice.krad.service.KRADServiceLocator; 030 031 import com.gargoylesoftware.htmlunit.html.HtmlInput; 032 import com.gargoylesoftware.htmlunit.html.HtmlPage; 033 034 public class DailyOvertimeRuleMaintenanceTest extends KPMETestCase{ 035 private static final Logger LOG = Logger.getLogger(DailyOvertimeRuleMaintenanceTest.class); 036 private static final String TEST_CODE="BL"; 037 private static String TEST_CODE_INVALID_DEPT_ID ="INVALID"; 038 private static Long TEST_CODE_INVALID_TASK_ID =-1L; 039 private static Long TEST_CODE_INVALID_WORK_AREA_ID =-1L; 040 private static String dailyOvertimeRuleId = "5"; 041 042 @Test 043 public void testDailyOvertimeRuleMaint() throws Exception { 044 DailyOvertimeRule dor = new DailyOvertimeRule(); 045 HtmlPage dailyOvertimeRuleLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DAILY_OVERTIME_RULE_MAINT_URL); 046 dailyOvertimeRuleLookUp = HtmlUnitUtil.clickInputContainingText(dailyOvertimeRuleLookUp, "search"); 047 HtmlUnitUtil.createTempFile(dailyOvertimeRuleLookUp); 048 Assert.assertTrue("Page contains test DailyOvertimeRule", dailyOvertimeRuleLookUp.asText().contains(TEST_CODE.toString())); 049 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(dailyOvertimeRuleLookUp, "edit",dailyOvertimeRuleId.toString()); 050 Assert.assertTrue("Maintenance Page contains test DailyOvertimeRule",maintPage.asText().contains(TEST_CODE.toString())); 051 } 052 053 @Test 054 public void testDailyOvertimeRuleMaintForErrorMessages() throws Exception { 055 HtmlPage dailyOvertimeRuleLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DAILY_OVERTIME_RULE_MAINT_URL); 056 dailyOvertimeRuleLookUp = HtmlUnitUtil.clickInputContainingText(dailyOvertimeRuleLookUp, "search"); 057 Assert.assertTrue("Page contains test DailyOvertimeRule", dailyOvertimeRuleLookUp.asText().contains(TEST_CODE.toString())); 058 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(dailyOvertimeRuleLookUp, "edit",dailyOvertimeRuleId.toString()); 059 Assert.assertTrue("Maintenance Page contains test DailyOvertimeRule",maintPage.asText().contains(TEST_CODE.toString())); 060 061 HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText( 062 maintPage, "* Document Description"); 063 inputForDescription.setValueAttribute("Test_Description"); 064 HtmlPage resultantPageAfterEdit = HtmlUnitUtil 065 .clickInputContainingText(maintPage, "submit"); 066 LOG.debug(resultantPageAfterEdit.asText()); 067 Assert.assertTrue("Maintenance Page contains test deptErrormessage", 068 resultantPageAfterEdit.asText().contains( 069 "The specified department '" 070 + TEST_CODE_INVALID_DEPT_ID 071 + "' does not exist.")); 072 073 // test Convert from EarnCodeGroup has overtime earn codes error 074 setFieldValue(resultantPageAfterEdit, "document.newMaintainableObject.fromEarnGroup", "OVT"); 075 HtmlPage finalPage = HtmlUnitUtil.clickInputContainingText(resultantPageAfterEdit, "submit"); 076 Assert.assertTrue("Maintenance Page should contains EarnCodeGroup has overtime earn code error", 077 finalPage.asText().contains("Earn Group 'OVT' has overtime earn codes.")); 078 079 } 080 081 @Override 082 public void setUp() throws Exception { 083 // TODO Auto-generated method stub 084 super.setUp(); 085 DailyOvertimeRule dor = new DailyOvertimeRule(); 086 dor.setLocation("BL"); 087 dor.setPaytype("HR"); 088 dor.setEffectiveDate(TKUtils.getCurrentDate()); 089 dor.setUserPrincipalId("admin"); 090 dor.setDept(TEST_CODE_INVALID_DEPT_ID); 091 dor.setWorkArea(TEST_CODE_INVALID_WORK_AREA_ID); 092 dor.setMaxGap(new BigDecimal(1.0)); 093 dor.setMinHours(new BigDecimal(2)); 094 dor.setActive(true); 095 dor.setFromEarnGroup("RGN"); 096 dor.setEarnCode("OVT"); 097 098 KRADServiceLocator.getBusinessObjectService().save(dor); 099 dailyOvertimeRuleId = dor.getTkDailyOvertimeRuleId(); 100 } 101 102 @Override 103 public void tearDown() throws Exception { 104 KRADServiceLocator.getBusinessObjectService().deleteMatching(DailyOvertimeRule.class, new HashMap()); 105 super.tearDown(); 106 } 107 } 108