1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.core.leaveplan;
17
18 import junit.framework.Assert;
19
20 import org.apache.log4j.Logger;
21 import org.junit.Test;
22 import org.kuali.hr.KPMEWebTestCase;
23 import org.kuali.hr.util.HtmlUnitUtil;
24 import org.kuali.kpme.core.FunctionalTest;
25 import org.kuali.kpme.core.util.HrTestConstants;
26
27 import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
28 import com.gargoylesoftware.htmlunit.html.HtmlInput;
29 import com.gargoylesoftware.htmlunit.html.HtmlPage;
30
31 @FunctionalTest
32 public class LeavePlanMaintTest extends KPMEWebTestCase {
33 private static final Logger LOG = Logger.getLogger(LeavePlanMaintTest.class);
34 public static final String TEST_USER = "admin";
35
36
37
38 @Test
39 public void testLeavePlanMonthsSave() throws Exception {
40
41
42 HtmlPage leavePlan = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.LEAVE_PLAN_MAINT_URL);
43 LOG.debug("Leave plan text page is : " + leavePlan.asText());
44 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(leavePlan, "search");
45 HtmlUnitUtil.createTempFile(resultPage);
46 LOG.debug("Result page is : "+resultPage.asText());
47 Assert.assertTrue("Maintenance page contains:\n" + "Testing Leave Plan Months", resultPage.asText().contains("Testing Leave Plan Months"));
48
49
50 HtmlPage leavePlanMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit", "5555");
51 HtmlUnitUtil.setFieldValue(leavePlanMaintPage, "document.documentHeader.documentDescription", "LeavePlan change planningMonths - test");
52 HtmlUnitUtil.setFieldValue(leavePlanMaintPage, "document.newMaintainableObject.effectiveDate", "01/01/2013");
53 HtmlInput planningMonthsText = HtmlUnitUtil.getInputContainingText(leavePlanMaintPage, "document.newMaintainableObject.planningMonths");
54
55
56 planningMonthsText.setValueAttribute("999");
57 HtmlPage outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit");
58 HtmlUnitUtil.createTempFile(outputPage);
59
60
61 Assert.assertTrue("Maintenance page text contains:\n" + "\'Planning Months\' should be between 1 and 24", outputPage.asText().contains("\'Planning Months\' should be between 1 and 24"));
62
63 planningMonthsText.setValueAttribute("0");
64 outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit");
65 HtmlUnitUtil.createTempFile(outputPage);
66 Assert.assertTrue("Maintenance page text contains:\n" + "\'Planning Months\' should be between 1 and 24", outputPage.asText().contains("\'Planning Months\' should be between 1 and 24"));
67
68 planningMonthsText.setValueAttribute("24");
69 outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit");
70 HtmlUnitUtil.createTempFile(outputPage);
71 Assert.assertTrue("Maintenance page text contains:\n" + "Document was successfully submitted", outputPage.asText().contains("Document was successfully submitted"));
72 Assert.assertTrue("Maintenance page contains:\n" + "Planning Months changed to 24", outputPage.asText().contains("24"));
73
74 }
75
76
77 @Test
78 public void testInactivateLeavePlan() throws Exception {
79
80
81 HtmlPage leavePlan = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.LEAVE_PLAN_MAINT_URL);
82 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(leavePlan, "search");
83 HtmlUnitUtil.createTempFile(resultPage);
84 Assert.assertTrue("Maintenance page contains:\n" + "Testing LP Inactive Flag", resultPage.asText().contains("Testing LP Inactive Flag"));
85
86 HtmlPage leavePlanMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit", "2000");
87 HtmlUnitUtil.setFieldValue(leavePlanMaintPage, "document.documentHeader.documentDescription", "LeavePlan change active flag");
88 HtmlCheckBoxInput activeCheckbox = (HtmlCheckBoxInput) HtmlUnitUtil.getInputContainingText(leavePlanMaintPage, "document.newMaintainableObject.active");
89 activeCheckbox.setChecked(false);
90
91 HtmlPage outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit");
92 HtmlUnitUtil.createTempFile(outputPage);
93
94 }
95
96
97 @Test
98 public void testRequiredFields() throws Exception {
99
100
101 HtmlPage leavePlan = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), HrTestConstants.Urls.LEAVE_PLAN_MAINT_URL);
102 HtmlPage resultPage = HtmlUnitUtil.clickInputContainingText(leavePlan, "search");
103 HtmlUnitUtil.createTempFile(resultPage);
104 Assert.assertTrue("Maintenance page contains:\n" + "Testing Leave Plan Months", resultPage.asText().contains("Testing Leave Plan Months"));
105
106 HtmlPage leavePlanMaintPage = HtmlUnitUtil.clickAnchorContainingText(resultPage, "edit", "5555");
107
108 HtmlUnitUtil.setFieldValue(leavePlanMaintPage, "document.documentHeader.documentDescription", "Testing required fields");
109 HtmlInput planningMonthsText = HtmlUnitUtil.getInputContainingText(leavePlanMaintPage, "document.newMaintainableObject.planningMonths");
110 HtmlInput calendarYearStartText = HtmlUnitUtil.getInputContainingText(leavePlanMaintPage, "document.newMaintainableObject.calendarYearStart");
111
112 planningMonthsText.setValueAttribute("");
113 calendarYearStartText.setValueAttribute("");
114 HtmlPage outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit");
115 HtmlUnitUtil.createTempFile(outputPage);
116 Assert.assertTrue("Maintenance page text contains:\n" + "Planning Months (Planning Months) is a required field", outputPage.asText().contains("Planning Months (Planning Months) is a required field"));
117 Assert.assertTrue("Maintenance page text contains:\n" + "Calendar Year Start (MM/DD) (Calendar Year Start (MM/DD)) is a required field", outputPage.asText().contains("Calendar Year Start (MM/DD) (Calendar Year Start (MM/DD)) is a required field"));
118
119 HtmlUnitUtil.setFieldValue(outputPage, "document.newMaintainableObject.effectiveDate", "");
120 HtmlPage page = HtmlUnitUtil.clickInputContainingText(outputPage, "submit");
121 Assert.assertTrue("Maintenance page text contains:\n" + "Effective Date (Effective Date) is a required field.", page.asText().contains("Effective Date (Effective Date) is a required field."));
122 Assert.assertFalse("Maintenance page text contains:\n" + "Incident Report", page.asText().contains("Incident Report "));
123
124 }
125
126
127 }