View Javadoc

1   /**
2    * Copyright 2004-2013 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.overtime.weekly.rule;
17  
18  import java.math.BigDecimal;
19  import java.util.Calendar;
20  
21  import org.junit.Assert;
22  import org.junit.Test;
23  import org.kuali.hr.test.KPMETestCase;
24  import org.kuali.hr.time.test.HtmlUnitUtil;
25  import org.kuali.hr.time.test.TkTestConstants;
26  import org.kuali.rice.krad.service.KRADServiceLocator;
27  
28  import com.gargoylesoftware.htmlunit.html.HtmlElement;
29  import com.gargoylesoftware.htmlunit.html.HtmlPage;
30  
31  public class WeeklyOvertimeRuleMaintenanceTest extends KPMETestCase {
32  	
33  	protected static final String TEST_CODE="TST";
34  	private static final BigDecimal TEST_NO=new BigDecimal(10);
35  	private static String weeklyOvertimeRuleId;	
36  	private static final java.sql.Date TEST_DATE=new java.sql.Date(Calendar.getInstance().getTimeInMillis());
37  	private static final java.sql.Timestamp TEST_TIME_STAMP=new java.sql.Timestamp(Calendar.getInstance().getTimeInMillis());
38  	
39  	@Test
40  	public void testWeeklyOvertimeRuleMaint() throws Exception {
41  		HtmlPage weeklyOvertimeRuleLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.WEEKLY_OVERTIME_RULE_MAINT_URL);
42  		weeklyOvertimeRuleLookUp = HtmlUnitUtil.clickInputContainingText(weeklyOvertimeRuleLookUp, "search");
43  		Assert.assertTrue("Page contains test WeeklyOvertimeRule", weeklyOvertimeRuleLookUp.asText().contains(TEST_CODE));
44  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(weeklyOvertimeRuleLookUp, "edit",weeklyOvertimeRuleId);
45  		Assert.assertTrue("Maintenance Page contains test WeeklyOvertimeRule",maintPage.asText().contains(TEST_CODE));
46  		
47  		// test Convert from EarnCodeGroup has overtime earn codes error		
48  		HtmlPage newMaintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.WEEKLY_OVERTIME_RULE_MAINT_NEW_URL);
49  		setFieldValue(newMaintPage, "document.documentHeader.documentDescription", "Test");
50  		setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.effectiveDate", "01/01/2010");
51  		setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.maxHoursEarnGroup", "REG");
52  		setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.convertFromEarnGroup", "OVT");
53  		setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.convertToEarnCode", "RGN");
54  		setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.step", "1");
55  		setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.maxHours", "8");
56  //		HtmlPage finalPage = HtmlUnitUtil.clickInputContainingText(newMaintPage, "add");
57  		HtmlElement element = (HtmlElement)newMaintPage.getElementById("methodToCall.addLine.lstWeeklyOvertimeRules.(!!org.kuali.hr.time.overtime.weekly.rule.WeeklyOvertimeRule!!)");
58          HtmlPage finalPage = element.click();
59  		Assert.assertTrue("Maintenance Page should contains EarnCodeGroup has overtime earn code error",
60  				finalPage.asText().contains("Earn Group 'OVT' has overtime earn codes."));
61  	}
62  
63  	@Override
64  	public void setUp() throws Exception {
65  		super.setUp();
66  		WeeklyOvertimeRule weeklyOvertimeRule = new WeeklyOvertimeRule();
67  		weeklyOvertimeRule.setActive(true);
68  		weeklyOvertimeRule.setConvertFromEarnGroup(TEST_CODE);
69  		weeklyOvertimeRule.setConvertToEarnCode(TEST_CODE);
70  		weeklyOvertimeRule.setEffectiveDate(TEST_DATE);
71  		weeklyOvertimeRule.setMaxHours(TEST_NO);
72  		weeklyOvertimeRule.setMaxHoursEarnGroup(TEST_CODE);
73  		weeklyOvertimeRule.setStep(TEST_NO);
74  		weeklyOvertimeRule.setTimestamp(TEST_TIME_STAMP);
75  		weeklyOvertimeRule.setUserPrincipalId(TEST_CODE);	
76  		KRADServiceLocator.getBusinessObjectService().save(weeklyOvertimeRule);		
77  		weeklyOvertimeRuleId=weeklyOvertimeRule.getTkWeeklyOvertimeRuleId();		
78  	}
79  
80  	@Override
81  	public void tearDown() throws Exception {	
82  		//clean up
83  		WeeklyOvertimeRule weeklyOvertimeRuleObj= KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(WeeklyOvertimeRule.class, weeklyOvertimeRuleId);			
84  		KRADServiceLocator.getBusinessObjectService().delete(weeklyOvertimeRuleObj);				
85  		super.tearDown();
86  	}
87  
88  }