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