View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  		//get the page with planning months
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  		//submit a leave plan with planning months changed
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  		// KPME- Kagata - value is between 1 and 24 now
53  		planningMonthsText.setValueAttribute("999"); //max value
54  		HtmlPage outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit");
55  		HtmlUnitUtil.createTempFile(outputPage);
56  		//assertTrue("Maintenance page text contains:\n" + "Document was successfully submitted", outputPage.asText().contains("Document was successfully submitted"));
57  		//assertTrue("Maintenance page contains:\n" + "Planning Months changed to 999", outputPage.asText().contains("999"));
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  	// KPME-1250 Kagata
74  	@Test
75  	public void testInactivateLeavePlan() throws Exception {
76  		
77  		//get the page with planning months
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  	// KPME-1489 Kagata
94  	@Test
95  	public void testRequiredFields() throws Exception {
96  		
97  		//get the page with planning months
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 		//submit a leave plan with planning months changed
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 }