001 /** 002 * Copyright 2004-2012 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.weekly.rule; 017 018 import java.math.BigDecimal; 019 import java.util.Calendar; 020 021 import org.junit.Assert; 022 import org.junit.Test; 023 import org.kuali.hr.test.KPMETestCase; 024 import org.kuali.hr.time.test.HtmlUnitUtil; 025 import org.kuali.hr.time.test.TkTestConstants; 026 import org.kuali.rice.krad.service.KRADServiceLocator; 027 028 import com.gargoylesoftware.htmlunit.html.HtmlElement; 029 import com.gargoylesoftware.htmlunit.html.HtmlPage; 030 031 public class WeeklyOvertimeRuleMaintenanceTest extends KPMETestCase { 032 033 protected static final String TEST_CODE="TST"; 034 private static final BigDecimal TEST_NO=new BigDecimal(10); 035 private static String weeklyOvertimeRuleId; 036 private static final java.sql.Date TEST_DATE=new java.sql.Date(Calendar.getInstance().getTimeInMillis()); 037 private static final java.sql.Timestamp TEST_TIME_STAMP=new java.sql.Timestamp(Calendar.getInstance().getTimeInMillis()); 038 039 @Test 040 public void testWeeklyOvertimeRuleMaint() throws Exception { 041 HtmlPage weeklyOvertimeRuleLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.WEEKLY_OVERTIME_RULE_MAINT_URL); 042 weeklyOvertimeRuleLookUp = HtmlUnitUtil.clickInputContainingText(weeklyOvertimeRuleLookUp, "search"); 043 Assert.assertTrue("Page contains test WeeklyOvertimeRule", weeklyOvertimeRuleLookUp.asText().contains(TEST_CODE)); 044 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(weeklyOvertimeRuleLookUp, "edit",weeklyOvertimeRuleId); 045 Assert.assertTrue("Maintenance Page contains test WeeklyOvertimeRule",maintPage.asText().contains(TEST_CODE)); 046 047 // test Convert from EarnCodeGroup has overtime earn codes error 048 HtmlPage newMaintPage = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.WEEKLY_OVERTIME_RULE_MAINT_NEW_URL); 049 setFieldValue(newMaintPage, "document.documentHeader.documentDescription", "Test"); 050 setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.effectiveDate", "01/01/2010"); 051 setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.maxHoursEarnGroup", "REG"); 052 setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.convertFromEarnGroup", "OVT"); 053 setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.convertToEarnCode", "RGN"); 054 setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.step", "1"); 055 setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.maxHours", "8"); 056 // HtmlPage finalPage = HtmlUnitUtil.clickInputContainingText(newMaintPage, "add"); 057 HtmlElement element = newMaintPage.getElementById("methodToCall.addLine.lstWeeklyOvertimeRules.(!!org.kuali.hr.time.overtime.weekly.rule.WeeklyOvertimeRule!!)"); 058 HtmlPage finalPage = element.click(); 059 Assert.assertTrue("Maintenance Page should contains EarnCodeGroup has overtime earn code error", 060 finalPage.asText().contains("Earn Group 'OVT' has overtime earn codes.")); 061 } 062 063 @Override 064 public void setUp() throws Exception { 065 super.setUp(); 066 WeeklyOvertimeRule weeklyOvertimeRule = new WeeklyOvertimeRule(); 067 weeklyOvertimeRule.setActive(true); 068 weeklyOvertimeRule.setConvertFromEarnGroup(TEST_CODE); 069 weeklyOvertimeRule.setConvertToEarnCode(TEST_CODE); 070 weeklyOvertimeRule.setEffectiveDate(TEST_DATE); 071 weeklyOvertimeRule.setMaxHours(TEST_NO); 072 weeklyOvertimeRule.setMaxHoursEarnGroup(TEST_CODE); 073 weeklyOvertimeRule.setStep(TEST_NO); 074 weeklyOvertimeRule.setTimestamp(TEST_TIME_STAMP); 075 weeklyOvertimeRule.setUserPrincipalId(TEST_CODE); 076 KRADServiceLocator.getBusinessObjectService().save(weeklyOvertimeRule); 077 weeklyOvertimeRuleId=weeklyOvertimeRule.getTkWeeklyOvertimeRuleId(); 078 } 079 080 @Override 081 public void tearDown() throws Exception { 082 //clean up 083 WeeklyOvertimeRule weeklyOvertimeRuleObj= KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(WeeklyOvertimeRule.class, weeklyOvertimeRuleId); 084 KRADServiceLocator.getBusinessObjectService().delete(weeklyOvertimeRuleObj); 085 super.tearDown(); 086 } 087 088 }