View Javadoc
1   /**
2    * Copyright 2004-2014 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  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
34  
35  @FunctionalTest
36  public class WeeklyOvertimeRuleMaintenanceTest extends KPMEWebTestCase {
37  	
38  	protected static final String TEST_CODE="TST";
39  	private static final BigDecimal TEST_NO=new BigDecimal(10);
40  	private static String weeklyOvertimeRuleId;	
41  	private static final LocalDate TEST_DATE = LocalDate.now();
42  	
43  	@Test
44  	public void testWeeklyOvertimeRuleMaint() throws Exception {
45  		HtmlPage maintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.WEEKLY_OVERTIME_RULE_MAINT_URL);
46  		Assert.assertTrue("Maintenance Page contains test WeeklyOvertimeRule",maintPage.asText().contains(TEST_CODE));
47  		
48  		// test Convert from EarnCodeGroup has overtime earn codes error		
49  		HtmlPage newMaintPage = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.WEEKLY_OVERTIME_RULE_MAINT_NEW_URL);
50  		HtmlUnitUtil.setFieldValue(newMaintPage, "document.documentHeader.documentDescription", "Test");
51  		HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.effectiveDate", "01/01/2010");
52  		HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.maxHoursEarnGroup", "REG");
53  		HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.convertFromEarnGroup", "OVT");
54  		HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.convertToEarnCode", "RGN");
55  		HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.step", "1");
56  		HtmlUnitUtil.setFieldValue(newMaintPage, "document.newMaintainableObject.add.lstWeeklyOvertimeRules.maxHours", "8");
57  //		HtmlPage finalPage = HtmlUnitUtil.clickInputContainingText(newMaintPage, "add");
58  		HtmlElement element = (HtmlElement)newMaintPage.getElementById("methodToCall.addLine.lstWeeklyOvertimeRules.(!!org.kuali.kpme.tklm.time.rules.overtime.weekly.WeeklyOvertimeRule!!)");
59          HtmlPage finalPage = element.click();
60  		Assert.assertTrue("Maintenance Page should contains EarnCodeGroup has overtime earn code error",
61  				finalPage.asText().contains("Earn Group 'OVT' has overtime earn codes."));
62  	}
63  
64  	@Override
65  	public void setUp() throws Exception {
66  		super.setUp();
67  		WeeklyOvertimeRule weeklyOvertimeRule = new WeeklyOvertimeRule();
68  		weeklyOvertimeRule.setActive(true);
69  		weeklyOvertimeRule.setConvertFromEarnGroup(TEST_CODE);
70  		weeklyOvertimeRule.setConvertToEarnCode(TEST_CODE);
71  		weeklyOvertimeRule.setEffectiveLocalDate(TEST_DATE);
72  		weeklyOvertimeRule.setMaxHours(TEST_NO);
73  		weeklyOvertimeRule.setMaxHoursEarnGroup(TEST_CODE);
74  		weeklyOvertimeRule.setStep(TEST_NO);
75  		weeklyOvertimeRule.setTimestamp(TKUtils.getCurrentTimestamp());
76  		weeklyOvertimeRule.setUserPrincipalId(TEST_CODE);	
77  		KRADServiceLocatorWeb.getLegacyDataAdapter().save(weeklyOvertimeRule);
78  		weeklyOvertimeRuleId=weeklyOvertimeRule.getTkWeeklyOvertimeRuleId();		
79  	}
80  
81  	@Override
82  	public void tearDown() throws Exception {	
83  		//clean up
84  		WeeklyOvertimeRule weeklyOvertimeRuleObj= KRADServiceLocatorWeb.getLegacyDataAdapter().findBySinglePrimaryKey(WeeklyOvertimeRule.class, weeklyOvertimeRuleId);
85  		KRADServiceLocatorWeb.getLegacyDataAdapter().delete(weeklyOvertimeRuleObj);
86  		super.tearDown();
87  	}
88  
89  }