1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.shiftdiff;
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.tklm.time.rules.shiftdifferential.ShiftDifferentialRule;
27 import org.kuali.kpme.tklm.utils.TkTestConstants;
28 import org.kuali.rice.krad.service.KRADServiceLocator;
29
30 import com.gargoylesoftware.htmlunit.html.HtmlElement;
31 import com.gargoylesoftware.htmlunit.html.HtmlForm;
32 import com.gargoylesoftware.htmlunit.html.HtmlInput;
33 import com.gargoylesoftware.htmlunit.html.HtmlPage;
34
35 @FunctionalTest
36 public class ShiftDifferentialRuleMaintTest extends KPMEWebTestCase{
37 private static final String TEST_CODE="_T";
38
39 private static final BigDecimal TEST_NO=new BigDecimal(2);
40 private static String shiftDifferentialRuleId;
41
42
43
44 @Test
45 public void testShiftDifferentialRuleMaint() throws Exception {
46 HtmlPage shiftDifferentialRuleLookup = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.SHIFT_DIFFERENTIAL_RULE_MAINT_URL);
47 shiftDifferentialRuleLookup = HtmlUnitUtil.clickInputContainingText(shiftDifferentialRuleLookup, "search");
48 Assert.assertTrue("Page contains test Shift Differential Rule", shiftDifferentialRuleLookup.asText().contains(TEST_CODE.toString()));
49 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(shiftDifferentialRuleLookup, "edit",shiftDifferentialRuleId.toString());
50 Assert.assertTrue("Maintenance Page contains test ShiftDifferentialRule",maintPage.asText().contains(TEST_CODE));
51 }
52
53 @Test
54 public void testRequiredFields() throws Exception {
55 String baseUrl = TkTestConstants.Urls.SHIFT_DIFFERENTIAL_RULE_MAINT_NEW_URL;
56 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
57 Assert.assertNotNull(page);
58
59 HtmlForm form = page.getFormByName("KualiForm");
60 Assert.assertNotNull("Search form was missing from page.", form);
61
62 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
63 Assert.assertNotNull("Could not locate submit button", input);
64
65 HtmlElement element = page.getElementByName("methodToCall.route");
66 page = element.click();
67
68 String errorMessage = "Min. Hours (Min. Hours) is a required field.";
69 Assert.assertFalse("page text contains:\n" + errorMessage, page.asText().contains(errorMessage));
70 errorMessage = "Begin Time (00:00 AM) (Begin Time) is a required field.";
71 Assert.assertFalse("page text contains:\n" + errorMessage, page.asText().contains(errorMessage));
72 errorMessage = "End Time (00:00 AM) (End Time) is a required field.";
73 Assert.assertFalse("page text contains:\n" + errorMessage, page.asText().contains(errorMessage));
74 errorMessage = "Max. Gap Minutes (Max. Gap Minutes) is a required field.";
75 Assert.assertFalse("page text contains:\n" + errorMessage, page.asText().contains(errorMessage));
76
77
78 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.minHours", "");
79 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.beginTime", "");
80 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.endTime", "");
81 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.maxGap", "");
82 element = page.getElementByName("methodToCall.route");
83 HtmlPage nextPage = element.click();
84 errorMessage = "Effective Date (Effective Date) is a required field.";
85 Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
86 errorMessage = "Location (Location) is a required field.";
87 Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
88 errorMessage = "Salary Group (Salary Group) is a required field.";
89 Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
90 errorMessage = "Pay Grade (Pay Grade) is a required field.";
91 Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
92 errorMessage = "Earn Code (Earn Code) is a required field.";
93 Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
94 errorMessage = "From Earn Group (From Earn Group) is a required field.";
95 Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
96 errorMessage = "Begin Time (00:00 AM) (Begin Time) is a required field.";
97 Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
98 errorMessage = "End Time (00:00 AM) (End Time) is a required field.";
99 Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
100 errorMessage = "Max. Gap Minutes (Max. Gap Minutes) is a required field.";
101 Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
102 errorMessage = "Pay Calendar Group (Pay Calendar Group) is a required field.";
103 Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
104 errorMessage = "Min. Hours (Min. Hours) is a required field.";
105 Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
106 errorMessage = "At least one day must be checked.";
107 Assert.assertTrue("page text does not contain:\n" + errorMessage, nextPage.asText().contains(errorMessage));
108 }
109
110
111 @Override
112 public void setUp() throws Exception {
113 super.setUp();
114
115 ShiftDifferentialRule shiftDifferentialRule = new ShiftDifferentialRule();
116 shiftDifferentialRule.setActive(true);
117
118 shiftDifferentialRule.setEarnCode(TEST_CODE);
119 shiftDifferentialRule.setEffectiveLocalDate(LocalDate.now().minusDays(1));
120
121 shiftDifferentialRule.setLocation(TEST_CODE);
122 shiftDifferentialRule.setMaxGap(new BigDecimal(2));
123 shiftDifferentialRule.setMinHours(TEST_NO);
124 shiftDifferentialRule.setPayGrade(TEST_CODE);
125 shiftDifferentialRule.setPyCalendarGroup("BW-CAL");
126 shiftDifferentialRule.setSunday(true);
127 shiftDifferentialRule.setMonday(true);
128 shiftDifferentialRule.setTuesday(true);
129 shiftDifferentialRule.setWednesday(true);
130 shiftDifferentialRule.setThursday(true);
131 shiftDifferentialRule.setFriday(true);
132 shiftDifferentialRule.setSaturday(true);
133 shiftDifferentialRule.setPyCalendarGroup("TEST");
134
135 ShiftDifferentialRule rule = KRADServiceLocator.getBusinessObjectService().save(shiftDifferentialRule);
136 shiftDifferentialRuleId = rule.getTkShiftDiffRuleId();
137 }
138
139 @Override
140 public void tearDown() throws Exception {
141 ShiftDifferentialRule shiftDifferentialRuleObj = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(ShiftDifferentialRule.class, shiftDifferentialRuleId);
142 KRADServiceLocator.getBusinessObjectService().delete(shiftDifferentialRuleObj);
143 super.tearDown();
144 }
145 }
146