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.leavecode;
17  
18  import java.text.SimpleDateFormat;
19  import java.util.Calendar;
20  
21  import junit.framework.Assert;
22  
23  import org.junit.Test;
24  import org.kuali.hr.test.KPMETestCase;
25  import org.kuali.hr.time.test.HtmlUnitUtil;
26  import org.kuali.hr.time.test.TkTestConstants;
27  
28  import com.gargoylesoftware.htmlunit.html.HtmlElement;
29  import com.gargoylesoftware.htmlunit.html.HtmlForm;
30  import com.gargoylesoftware.htmlunit.html.HtmlPage;
31  
32  public class LeaveCodeMaintTest extends KPMETestCase{
33  	private static final String SUCCESS_MESSAGE = "Document was successfully submitted.";
34  	private static final String ERROR_MESSAGE_ALLOW_NEGATIVE_ACC_BAN_REQUIRED = "Allow Negative Accrual Balance (Allow Negative Accrual Balance) is a required field";//KPME-1350
35  	
36  	@Test
37  	public void testLookupPage() throws Exception {	 
38  		HtmlPage lcLookup = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.LEAVE_CODE_MAINT_URL);
39  		lcLookup = HtmlUnitUtil.clickInputContainingText(lcLookup, "search");
40  		Assert.assertTrue("Page contains test Leave Code", lcLookup.asText().contains("testLC"));
41  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(lcLookup, "edit");
42  		Assert.assertTrue("Maintenance Page contains test Leave Code",maintPage.asText().contains("testLC"));	 
43  	}
44  	
45  	/*@Test
46  	 * do not need this test, KPME1466
47  	public void testFutureEffectiveDate() throws Exception {
48  		this.futureEffectiveDateValidation(TkTestConstants.Urls.LEAVE_CODE_MAINT_NEW_URL);
49  	}*/
50  
51  	@Test
52  	public void testGetLeavePlanBasedOnAccrualCategory() throws Exception {
53  	  	String baseUrl = TkTestConstants.Urls.LEAVE_CODE_MAINT_NEW_URL;
54  	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
55  	  	Assert.assertNotNull(page);
56  	 
57  	  	HtmlForm form = page.getFormByName("KualiForm");
58  	  	Assert.assertNotNull("Search form was missing from page.", form);
59  	  	Assert.assertTrue("page text contains:\n" + "Leave Code Maintenance", page.asText().contains("Leave Code Maintenance"));
60  	  	Assert.assertTrue("page text contains:\n" + "Allow Scheduled Leave", page.asText().contains("Allow Scheduled Leave"));
61  	  	
62  	  	Calendar validDate = Calendar.getInstance();
63  	  	// add 150 days in the future, need to add dates instead of month 
64  	  	// because if we happen to be running the test on the 31 of a month, some future months do not have 31st 
65  	  	validDate.add(Calendar.DATE, 150);   	
66  	  	String validDateString = new SimpleDateFormat("MM/dd/yyyy").format(validDate.getTime());
67  	  	
68  	  	setFieldValue(page, "document.documentHeader.documentDescription", "Leave Code - test");
69  	    setFieldValue(page, "document.newMaintainableObject.defaultAmountofTime", "25"); // a wrong default amount of time
70  	    setFieldValue(page, "document.newMaintainableObject.effectiveDate", validDateString); // jira1360
71  	    setFieldValue(page, "document.newMaintainableObject.accrualCategory", "AC1"); // jira1360
72  	    
73  	    HtmlElement element = page.getElementByName("methodToCall.route");
74  	  	page = element.click();
75  	  	HtmlUnitUtil.createTempFile(page);
76  	  	Assert.assertTrue("page text contains:\n" + "should be between 0 and 24", page.asText().contains("should be between 0 and 24"));
77  	  	Assert.assertTrue("page text contains:\n" + "IU-SM", page.asText().contains("IU-SM"));
78  	  	Assert.assertTrue("page text contains:\n" + "IU-SM", page.asText().contains("Affect Pay"));
79  	}
80  }