1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
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