1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.timeoff;
17
18 import org.joda.time.LocalDate;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.kuali.hr.KPMEWebTestCase;
22 import org.kuali.hr.util.HtmlUnitUtil;
23 import org.kuali.kpme.core.FunctionalTest;
24 import org.kuali.kpme.core.util.HrTestConstants;
25 import org.kuali.kpme.core.util.TKUtils;
26 import org.kuali.kpme.tklm.utils.TkTestConstants;
27
28 import com.gargoylesoftware.htmlunit.html.HtmlElement;
29 import com.gargoylesoftware.htmlunit.html.HtmlForm;
30 import com.gargoylesoftware.htmlunit.html.HtmlInput;
31 import com.gargoylesoftware.htmlunit.html.HtmlPage;
32
33 @FunctionalTest
34 public class SystemScheduledTimeOffMaintTest extends KPMEWebTestCase{
35 private static final String EFFECTIVE_DATE_REQUIRED = "Effective Date (Effective Date) is a required field.";
36 private static final String LEAVE_PLAN_REQUIRED = "Leave Plan (Leave Plan) is a required field.";
37 private static final String ACCRUAL_CATEGORY_REQUIRED = "Accrual Category (Accrual Category) is a required field.";
38 private static final String EARN_CODE_REQUIRED = "Earn Code (Earn Code) is a required field.";
39 private static final String ACCRUED_DATE_REQUIRED = "Accrued Date (Accrued Date) is a required field.";
40 private static final String LOCATION_REQUIRED = "Location (Location) is a required field.";
41 private static final String DESCRIPTION_REQUIRED = "Description (Desc) is a required field.";
42 private static final String AMOUNT_OF_TIME_REQUIRED = "Amount of Time (Amount of Time) is a required field.";
43 private static final String PREMIUM_HOLIDAY_REQUIRED = "Premium Holiday (Premium Holiday) is a required field.";
44 private static final String ACCRUED_DATE_PAST_ERROR = "'Accrued Date' needs to be a future date.";
45 private static final String SCHEDULED_TO_DATE_PAST_ERROR = "'Scheduled Time Off Date' needs to be a future date.";
46 private static final String SUCCESS_MESSAGE = "Document was successfully submitted.";
47 private static final String ERROR_LEAVE_CODE = "The specified earnCode 'TESTLCL' does not exist";
48
49 @Test
50 public void testRequiredFields() throws Exception {
51 String baseUrl = TkTestConstants.Urls.TIME_OFF_MAINT_NEW_URL;
52 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
53 Assert.assertNotNull(page);
54
55 HtmlForm form = page.getFormByName("KualiForm");
56 Assert.assertNotNull("Search form was missing from page.", form);
57
58 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
59 Assert.assertNotNull("Could not locate submit button", input);
60
61 Assert.assertTrue("Preminum Holiday is not default to No", page.getHtmlElementById("document.newMaintainableObject.premiumHolidayNo").asText().equals("checked"));
62
63 HtmlElement element = page.getElementByName("methodToCall.route");
64 page = element.click();
65 Assert.assertTrue("page text does not contain:\n" + EFFECTIVE_DATE_REQUIRED, page.asText().contains(EFFECTIVE_DATE_REQUIRED));
66 Assert.assertTrue("page text does not contain:\n" + LEAVE_PLAN_REQUIRED, page.asText().contains(LEAVE_PLAN_REQUIRED));
67 Assert.assertTrue("page text does not contain:\n" + ACCRUAL_CATEGORY_REQUIRED, page.asText().contains(ACCRUAL_CATEGORY_REQUIRED));
68 Assert.assertTrue("page text does not contain:\n" + EARN_CODE_REQUIRED, page.asText().contains(EARN_CODE_REQUIRED));
69
70 Assert.assertTrue("page text does not contain:\n" + ACCRUED_DATE_REQUIRED, page.asText().contains(ACCRUED_DATE_REQUIRED));
71 Assert.assertTrue("page text does not contain:\n" + LOCATION_REQUIRED, page.asText().contains(LOCATION_REQUIRED));
72 Assert.assertTrue("page text does not contain:\n" + DESCRIPTION_REQUIRED, page.asText().contains(DESCRIPTION_REQUIRED));
73 Assert.assertTrue("page text does not contain:\n" + AMOUNT_OF_TIME_REQUIRED, page.asText().contains(AMOUNT_OF_TIME_REQUIRED));
74
75 Assert.assertFalse("page text contains:\n" + PREMIUM_HOLIDAY_REQUIRED, page.asText().contains(PREMIUM_HOLIDAY_REQUIRED));
76 }
77
78 @Test
79 public void testLookupPage() throws Exception {
80 HtmlPage sstoLookup = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.TIME_OFF_MAINT_URL);
81 sstoLookup = HtmlUnitUtil.clickInputContainingText(sstoLookup, "search");
82 HtmlUnitUtil.createTempFile(sstoLookup);
83 Assert.assertTrue("Page contains test SystemScheduledTimeOff", sstoLookup.asText().contains("TLC"));
84 Assert.assertTrue("Page contains test SystemScheduledTimeOff", sstoLookup.asText().contains("EC"));
85 Assert.assertFalse("Page contains test SystemScheduledTimeOff", sstoLookup.asText().contains("InactiveLP"));
86
87 HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(sstoLookup, "edit");
88 Assert.assertTrue("Maintenance Page contains test SystemScheduledTimeOff",maintPage.asText().contains("EC"));
89 }
90
91 @Test
92 public void testErrorMessages() throws Exception {
93 String baseUrl = TkTestConstants.Urls.TIME_OFF_MAINT_NEW_URL;
94 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
95 Assert.assertNotNull(page);
96
97 HtmlForm form = page.getFormByName("KualiForm");
98 Assert.assertNotNull("Search form was missing from page.", form);
99 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "System Scheduled Time Off - test");
100
101 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2011");
102 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.accruedDate", "04/01/2011");
103 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.scheduledTimeOffDate", "04/01/2011");
104
105 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
106 Assert.assertNotNull("Could not locate submit button", input);
107 HtmlElement element = page.getElementByName("methodToCall.route");
108 page = element.click();
109 Assert.assertTrue("page text does not contain:\n" + HrTestConstants.EFFECTIVE_DATE_ERROR, page.asText().contains(HrTestConstants.EFFECTIVE_DATE_ERROR));
110 Assert.assertTrue("page text does not contain:\n" + ACCRUED_DATE_PAST_ERROR, page.asText().contains(ACCRUED_DATE_PAST_ERROR));
111 Assert.assertTrue("page text does not contain:\n" + SCHEDULED_TO_DATE_PAST_ERROR, page.asText().contains(SCHEDULED_TO_DATE_PAST_ERROR));
112 }
113
114 @Test
115
116 public void testGetLeavePlanAccrualCategoryFromSelectedEarnCode() throws Exception {
117 String baseUrl = TkTestConstants.Urls.TIME_OFF_MAINT_NEW_URL;
118 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
119 Assert.assertNotNull(page);
120
121 HtmlForm form = page.getFormByName("KualiForm");
122 Assert.assertNotNull("Search form was missing from page.", form);
123
124
125
126 LocalDate validDate = LocalDate.now().plusDays(150);
127 String validDateString = TKUtils.formatDate(validDate);
128
129 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "something clever...");
130 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", validDateString);
131 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.earnCode", "EC");
132 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.descr", "this is my description");
133 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.amountofTime", "8");
134 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.location", "CST");
135 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.accruedDate", validDateString);
136
137 page = ((HtmlElement)page.getElementByName("methodToCall.route")).click();
138 HtmlUnitUtil.createTempFile(page);
139 Assert.assertTrue("page text contains:\n" + "testLP", page.asText().contains("testLP"));
140 Assert.assertTrue("page text contains:\n" + "testAC", page.asText().contains("testAC"));
141 }
142
143 @Test
144
145 public void testValidateLeaveCode() throws Exception {
146 String baseUrl = TkTestConstants.Urls.TIME_OFF_MAINT_NEW_URL;
147 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
148 Assert.assertNotNull(page);
149
150 HtmlForm form = page.getFormByName("KualiForm");
151 Assert.assertNotNull("Search form was missing from page.", form);
152
153
154
155 LocalDate validDate = LocalDate.now().plusDays(150);
156 String validDateString = TKUtils.formatDate(validDate);
157
158 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", validDateString);
159 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.earnCode", "testLCL");
160
161 page = ((HtmlElement)page.getElementByName("methodToCall.route")).click();
162 HtmlUnitUtil.createTempFile(page);
163 Assert.assertTrue("page text does not contain:\n" + ERROR_LEAVE_CODE, page.asText().contains(ERROR_LEAVE_CODE));
164 }
165 }