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.daily.rule;
17  
18  
19  import java.math.BigDecimal;
20  import java.util.HashMap;
21  
22  import org.junit.Assert;
23  import org.junit.Test;
24  import org.kuali.hr.test.KPMETestCase;
25  import org.kuali.hr.time.test.HtmlUnitUtil;
26  import org.kuali.hr.time.test.TkTestConstants;
27  import org.kuali.hr.time.util.TKUtils;
28  import org.kuali.rice.krad.service.KRADServiceLocator;
29  
30  import com.gargoylesoftware.htmlunit.html.HtmlInput;
31  import com.gargoylesoftware.htmlunit.html.HtmlPage;
32  
33  public class DailyOvertimeRuleMaintenanceTest extends KPMETestCase{
34  		
35  	private static final String TEST_CODE="BL";		
36  	private static String TEST_CODE_INVALID_DEPT_ID ="INVALID";
37  	private static Long TEST_CODE_INVALID_TASK_ID =-1L;
38  	private static Long TEST_CODE_INVALID_WORK_AREA_ID =-1L;	
39  	private static String dailyOvertimeRuleId = "5";
40  	
41  	@Test
42  	public void testDailyOvertimeRuleMaint() throws Exception {
43  		DailyOvertimeRule dor = new DailyOvertimeRule();
44  		HtmlPage dailyOvertimeRuleLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.DAILY_OVERTIME_RULE_MAINT_URL);
45  		dailyOvertimeRuleLookUp = HtmlUnitUtil.clickInputContainingText(dailyOvertimeRuleLookUp, "search");
46  		HtmlUnitUtil.createTempFile(dailyOvertimeRuleLookUp);
47  		Assert.assertTrue("Page contains test DailyOvertimeRule", dailyOvertimeRuleLookUp.asText().contains(TEST_CODE.toString()));		
48  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(dailyOvertimeRuleLookUp, "edit",dailyOvertimeRuleId.toString());		
49  		Assert.assertTrue("Maintenance Page contains test DailyOvertimeRule",maintPage.asText().contains(TEST_CODE.toString()));		
50  	}
51  	
52  	@Test
53  	public void testDailyOvertimeRuleMaintForErrorMessages() throws Exception {
54  		HtmlPage dailyOvertimeRuleLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.DAILY_OVERTIME_RULE_MAINT_URL);
55  		dailyOvertimeRuleLookUp = HtmlUnitUtil.clickInputContainingText(dailyOvertimeRuleLookUp, "search");
56  		Assert.assertTrue("Page contains test DailyOvertimeRule", dailyOvertimeRuleLookUp.asText().contains(TEST_CODE.toString()));		
57  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(dailyOvertimeRuleLookUp, "edit",dailyOvertimeRuleId.toString());		
58  		Assert.assertTrue("Maintenance Page contains test DailyOvertimeRule",maintPage.asText().contains(TEST_CODE.toString()));
59  		
60  		HtmlInput inputForDescription = HtmlUnitUtil.getInputContainingText(
61  				maintPage, "* Document Description");
62  		inputForDescription.setValueAttribute("Test_Description");
63  		HtmlPage resultantPageAfterEdit = HtmlUnitUtil
64  				.clickInputContainingText(maintPage, "submit");
65  		System.out.println(resultantPageAfterEdit.asText());
66  		Assert.assertTrue("Maintenance Page contains test deptErrormessage",
67  				resultantPageAfterEdit.asText().contains(
68  						"The specified department '"
69  								+ TEST_CODE_INVALID_DEPT_ID
70  								+ "' does not exist."));
71  		
72  		// test Convert from EarnCodeGroup has overtime earn codes error
73  		setFieldValue(resultantPageAfterEdit, "document.newMaintainableObject.fromEarnGroup", "OVT");
74  		HtmlPage finalPage = HtmlUnitUtil.clickInputContainingText(resultantPageAfterEdit, "submit");
75  		Assert.assertTrue("Maintenance Page should contains EarnCodeGroup has overtime earn code error",
76  				finalPage.asText().contains("Earn Group 'OVT' has overtime earn codes."));
77  		
78  	}
79  
80  	@Override
81  	public void setUp() throws Exception {
82  		// TODO Auto-generated method stub
83  		super.setUp();
84  		DailyOvertimeRule dor = new DailyOvertimeRule();
85  		dor.setLocation("BL");
86  		dor.setPaytype("HR");
87  		dor.setEffectiveDate(TKUtils.getCurrentDate());
88  		dor.setUserPrincipalId("admin");
89  		dor.setDept(TEST_CODE_INVALID_DEPT_ID);
90  		dor.setWorkArea(TEST_CODE_INVALID_WORK_AREA_ID);
91  		dor.setMaxGap(new BigDecimal(1.0));
92  		dor.setMinHours(new BigDecimal(2));
93  		dor.setActive(true);
94  		dor.setFromEarnGroup("RGN");
95  		dor.setEarnCode("OVT");
96  		
97  		KRADServiceLocator.getBusinessObjectService().save(dor);
98  		dailyOvertimeRuleId = dor.getTkDailyOvertimeRuleId();
99  	}
100 
101 	@Override
102 	public void tearDown() throws Exception {
103 		KRADServiceLocator.getBusinessObjectService().deleteMatching(DailyOvertimeRule.class, new HashMap());
104 		super.tearDown();
105 	}
106 }
107