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.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  		//get the page with planning months
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  		//submit a leave plan with planning months changed
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  		// KPME- Kagata - value is between 1 and 24 now
56  		planningMonthsText.setValueAttribute("999"); //max value
57  		HtmlPage outputPage = HtmlUnitUtil.clickInputContainingText(leavePlanMaintPage, "submit");
58  		HtmlUnitUtil.createTempFile(outputPage);
59  		//assertTrue("Maintenance page text contains:\n" + "Document was successfully submitted", outputPage.asText().contains("Document was successfully submitted"));
60  		//assertTrue("Maintenance page contains:\n" + "Planning Months changed to 999", outputPage.asText().contains("999"));
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  	// KPME-1250 Kagata
77  	@Test
78  	public void testInactivateLeavePlan() throws Exception {
79  		
80  		//get the page with planning months
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  	// KPME-1489 Kagata
97  	@Test
98  	public void testRequiredFields() throws Exception {
99  		
100 		//get the page with planning months
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 		//submit a leave plan with planning months changed
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 }