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