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