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.leaveadjustment;
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.HtmlElement;
26  import com.gargoylesoftware.htmlunit.html.HtmlForm;
27  import com.gargoylesoftware.htmlunit.html.HtmlInput;
28  import com.gargoylesoftware.htmlunit.html.HtmlPage;
29  
30  public class LeaveAdjustmentMaintTest extends KPMETestCase{
31  	
32  	private static final String PRINCIPAL_ID = "admin";
33  	
34  	private static final String EFFECTIVE_DATE_REQUIRED = "Effective Date (Effective Date) is a required field.";
35  	private static final String PRINCIPAL_ID_REQUIRED = "Principal Id (Principal Id) is a required field.";
36  	private static final String LEAVE_PLAN_REQUIRED = "Leave Plan (Leave Plan) is a required field.";
37  	private static final String EARN_CODE_REQUIRED = "Earn Code (Earn Code) is a required field.";
38  	private static final String ACCRUAL_CATEGORY_REQUIRED = "Accrual Category (Accrual Category) is a required field.";
39  	private static final String DES_REQUIRED = "Description (Description) is a required field.";
40  	private static final String ADJUSTMENT_AMOUNT_REQUIRED = "Adjustment Amount (Adjustment Amount) is a required field.";
41  	
42  	@Test
43  	public void testRequiredFields() throws Exception {
44  	  	String baseUrl = TkTestConstants.Urls.LEAVE_ADJUSTMENT_MAINT_NEW_URL;
45  	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
46  	  	Assert.assertNotNull(page);
47  	 
48  	  	HtmlForm form = page.getFormByName("KualiForm");
49  	  	Assert.assertNotNull("Search form was missing from page.", form);
50  	  	
51  	  	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
52  	  	Assert.assertNotNull("Could not locate submit button", input);
53  	  	
54  	  	HtmlElement element = page.getElementByName("methodToCall.route");
55  	  	page = element.click();
56  	  	Assert.assertTrue("page text does not contain:\n" + EFFECTIVE_DATE_REQUIRED, page.asText().contains(EFFECTIVE_DATE_REQUIRED));
57  	  	Assert.assertTrue("page text does not contain:\n" + PRINCIPAL_ID_REQUIRED, page.asText().contains(PRINCIPAL_ID_REQUIRED));
58  	  	Assert.assertTrue("page text does not contain:\n" + LEAVE_PLAN_REQUIRED, page.asText().contains(LEAVE_PLAN_REQUIRED));
59  	  	Assert.assertTrue("page text does not contain:\n" + ACCRUAL_CATEGORY_REQUIRED, page.asText().contains(ACCRUAL_CATEGORY_REQUIRED));
60  	  	Assert.assertTrue("page text does not contain:\n" + EARN_CODE_REQUIRED, page.asText().contains(EARN_CODE_REQUIRED));
61  	  	Assert.assertTrue("page text does not contain:\n" + DES_REQUIRED, page.asText().contains(DES_REQUIRED));
62  	    setFieldValue(page, "document.newMaintainableObject.adjustmentAmount", "");
63  	    element = page.getElementByName("methodToCall.route");
64  	  	page = element.click();
65  	  	Assert.assertTrue("page text does not contain:\n" + ADJUSTMENT_AMOUNT_REQUIRED, page.asText().contains(ADJUSTMENT_AMOUNT_REQUIRED));
66  	}
67  	
68  	@Test
69  	public void testLookupPage() throws Exception {	 
70  		HtmlPage leaveAdjustmentLookup = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.LEAVE_ADJUSTMENT_MAINT_URL);
71  		leaveAdjustmentLookup = HtmlUnitUtil.clickInputContainingText(leaveAdjustmentLookup, "search");
72  		System.out.println(leaveAdjustmentLookup.asXml());
73  		Assert.assertTrue("Page contains test LeaveAdjustment", leaveAdjustmentLookup.asText().contains("AC1"));
74  		Assert.assertFalse("Page should not contain edit action", leaveAdjustmentLookup.asText().contains("edit")); 
75  	}
76  	
77  	@Test
78  	public void testAddNew() throws Exception {
79  	  	String baseUrl = TkTestConstants.Urls.LEAVE_ADJUSTMENT_MAINT_NEW_URL;
80  	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
81  	  	Assert.assertNotNull(page);
82  	 
83  	  	HtmlForm form = page.getFormByName("KualiForm");
84  	  	Assert.assertNotNull("Search form was missing from page.", form);
85  	  	
86  	  	setFieldValue(page, "document.documentHeader.documentDescription", "Leave Adjustment - test");
87  	    setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
88  	    setFieldValue(page, "document.newMaintainableObject.principalId", "admin");
89  	    setFieldValue(page, "document.newMaintainableObject.accrualCategory", "myAC");	//nonexist accrual catetory
90  	    setFieldValue(page, "document.newMaintainableObject.earnCode", "myLC");	//nonexist leave Code
91  	  	
92  	  	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
93  	  	Assert.assertNotNull("Could not locate submit button", input);
94  	  	HtmlElement element = page.getElementByName("methodToCall.route");
95  	  	page = element.click();
96  	  	HtmlUnitUtil.createTempFile(page);
97  	  	Assert.assertTrue("page text contains:\n" + "'myAC' does not exist", page.asText().contains("'myAC' does not exist"));
98  	  	  	
99  	  	setFieldValue(page, "document.newMaintainableObject.accrualCategory", "AC1"); // existing accrual category
100 	  	setFieldValue(page, "document.newMaintainableObject.earnCode", "testLC");
101 	  	element = page.getElementByName("methodToCall.route");
102 	  	page = element.click();
103 	  	Assert.assertFalse("page text contains:\n" + "'AC1' does not exist", page.asText().contains("'AC1' does not exist"));
104 	  	
105 	  	setFieldValue(page, "document.newMaintainableObject.principalId", "admin"); // existing principal hr attributes
106 	  	element = page.getElementByName("methodToCall.route");
107 	  	page = element.click();
108 	  	Assert.assertFalse("page text contains:\n" + "'IU-SM' does not exist", page.asText().contains("'IU-SM' does not exist"));
109 	  	
110 	  	setFieldValue(page, "document.newMaintainableObject.earnCode", "EC");	//fraction allowed is 99.9
111 	  	setFieldValue(page, "document.newMaintainableObject.adjustmentAmount", "2.45");
112 	  	element = page.getElementByName("methodToCall.route");
113 	  	page = element.click();
114 	  	Assert.assertTrue("page text does not contain amount fraction error.", page.asText().contains("Earn Code 'EC' only allows 1 decimal point."));
115 	}
116 }