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