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;
17  
18  import java.math.BigDecimal;
19  
20  import org.joda.time.LocalDate;
21  import org.junit.Assert;
22  import org.junit.Test;
23  import org.kuali.hr.KPMEWebTestCase;
24  import org.kuali.hr.util.HtmlUnitUtil;
25  import org.kuali.kpme.core.FunctionalTest;
26  import org.kuali.kpme.core.util.TKUtils;
27  import org.kuali.kpme.tklm.time.rules.overtime.weekly.WeeklyOvertimeRule;
28  import org.kuali.kpme.tklm.utils.TkTestConstants;
29  import org.kuali.rice.krad.service.KRADServiceLocator;
30  
31  import com.gargoylesoftware.htmlunit.html.HtmlElement;
32  import com.gargoylesoftware.htmlunit.html.HtmlPage;
33  
34  @FunctionalTest
35  public class WeeklyOvertimeRuleMaintenanceTest extends KPMEWebTestCase {
36  	
37  	protected static final String TEST_CODE="TST";
38  	private static final BigDecimal TEST_NO=new BigDecimal(10);
39  	private static String weeklyOvertimeRuleId;	
40  	private static final LocalDate TEST_DATE = LocalDate.now();
41  	
42  	@Test
43  	public void testWeeklyOvertimeRuleMaint() throws Exception {
44  		HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.WEEKLY_OVERTIME_RULE_MAINT_URL);
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  		HtmlUnitUtil.setFieldValue(newMaintPage, "document.documentHeader.documentDescription", "Test");
50  		HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.effectiveDate", "01/01/2010");
51  		HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.maxHoursEarnGroup", "REG");
52  		HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.convertFromEarnGroup", "OVT");
53  		HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.convertToEarnCode", "RGN");
54  		HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.step", "1");
55  		HtmlUnitUtil.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.kpme.tklm.time.rules.overtime.weekly.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.setEffectiveLocalDate(TEST_DATE);
71  		weeklyOvertimeRule.setMaxHours(TEST_NO);
72  		weeklyOvertimeRule.setMaxHoursEarnGroup(TEST_CODE);
73  		weeklyOvertimeRule.setStep(TEST_NO);
74  		weeklyOvertimeRule.setTimestamp(TKUtils.getCurrentTimestamp());
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  }