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.leavedonation;
17  
18  import java.math.BigDecimal;
19  import java.sql.Date;
20  import java.util.List;
21  
22  import junit.framework.Assert;
23  
24  import org.joda.time.DateTime;
25  import org.junit.Test;
26  import org.kuali.hr.lm.LMConstants;
27  import org.kuali.hr.lm.leaveblock.LeaveBlock;
28  import org.kuali.hr.lm.leaveblock.LeaveBlockHistory;
29  import org.kuali.hr.test.KPMETestCase;
30  import org.kuali.hr.time.service.base.TkServiceLocator;
31  import org.kuali.hr.time.test.HtmlUnitUtil;
32  import org.kuali.hr.time.test.TkTestConstants;
33  import org.kuali.hr.time.util.TKUtils;
34  import org.kuali.hr.time.util.TkConstants;
35  
36  import com.gargoylesoftware.htmlunit.html.HtmlElement;
37  import com.gargoylesoftware.htmlunit.html.HtmlForm;
38  import com.gargoylesoftware.htmlunit.html.HtmlInput;
39  import com.gargoylesoftware.htmlunit.html.HtmlPage;
40  
41  public class LeaveDonationMaintTest extends KPMETestCase{
42  	
43  	@Test
44  	public void testLookupPage() throws Exception {	 
45  		HtmlPage lcLookup = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.LEAVE_DONATION_MAINT_URL);
46  		lcLookup = HtmlUnitUtil.clickInputContainingText(lcLookup, "search");
47  		Assert.assertTrue("Page contains test Donated Account Category", lcLookup.asText().contains("dAC"));
48  		Assert.assertFalse("Page should not contain edit action", lcLookup.asText().contains("edit"));
49  	}
50  	
51  	@Test
52  	public void testCreatingLeaveBlocks() throws Exception {
53  		Date START_DATE = new Date((new DateTime(2012, 4, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
54  		Date END_DATE = new Date((new DateTime(2012, 4, 2, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
55  		
56  		List<LeaveBlock> leaveBlockList;
57  		leaveBlockList = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser1", START_DATE, END_DATE);
58  		Assert.assertTrue("There are leave blocks for principal id " + "testuser1", leaveBlockList.isEmpty());
59  		leaveBlockList = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser2", START_DATE, END_DATE);
60  		Assert.assertTrue("There are leave blocks for principal id " + "testuser2", leaveBlockList.isEmpty());
61  		
62  		List<LeaveBlockHistory> historyList = TkServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("10001", null);
63  		Assert.assertTrue("There are leave block histories for princiapl id testuser1", historyList.isEmpty());
64  		historyList = TkServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("testuser2", null);
65  		Assert.assertTrue("There are leave block histories for princiapl id testuser2", historyList.isEmpty());
66  		
67  		String baseUrl = TkTestConstants.Urls.LEAVE_DONATION_MAINT_NEW_URL;
68  	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
69  	  	Assert.assertNotNull(page);
70  	 
71  	  	HtmlForm form = page.getFormByName("KualiForm");
72  	  	Assert.assertNotNull("Search form was missing from page.", form);
73  	  	setFieldValue(page, "document.documentHeader.documentDescription", "Leave Donation - test");
74  	    setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
75  	    setFieldValue(page, "document.newMaintainableObject.donorsPrincipalID", "testuser1");
76  	    setFieldValue(page, "document.newMaintainableObject.donatedAccrualCategory", "testAC");	
77  	    setFieldValue(page, "document.newMaintainableObject.donatedEarnCode", "EC");
78  	    setFieldValue(page, "document.newMaintainableObject.amountDonated", "10");
79  	    
80  	    setFieldValue(page, "document.newMaintainableObject.recipientsPrincipalID", "testuser2");
81  	    setFieldValue(page, "document.newMaintainableObject.recipientsAccrualCategory", "testAC");	
82  	    setFieldValue(page, "document.newMaintainableObject.recipientsEarnCode", "EC");
83  	    setFieldValue(page, "document.newMaintainableObject.amountReceived", "8");
84  	    
85  	    setFieldValue(page, "document.newMaintainableObject.description", "test-donation");
86  	  	
87  	  	HtmlInput  input  = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
88  	  	Assert.assertNotNull("Could not locate submit button", input);
89  	  	HtmlElement element = page.getElementByName("methodToCall.route");
90  	  	page = element.click();
91  	  	page.asText();
92  	  	Assert.assertTrue("page text does not contain: success ", page.asText().contains("success"));
93  	  	
94  	  	leaveBlockList = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser1", START_DATE, END_DATE);
95  	  	Assert.assertTrue("There should be 1 leave blocks for emplyee 'testuser1', not " + leaveBlockList.size(), leaveBlockList.size()== 1);
96  	  	LeaveBlock lb = leaveBlockList.get(0);
97  	  	Assert.assertTrue("Hours of the leave block for donor 'testuser1' should be -10, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(-10)));
98  	  	Assert.assertTrue("Request status of the leave block for donor 'testuser1' should be Approved, not " + lb.getRequestStatus()
99  	  			, lb.getRequestStatus().equals(LMConstants.REQUEST_STATUS.APPROVED));
100 	  	
101 		leaveBlockList = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser2", START_DATE, END_DATE);
102 		Assert.assertTrue("There should be 1 leave blocks for emplyee 'testuser2', not " + leaveBlockList.size(), leaveBlockList.size()== 1);
103 		lb = leaveBlockList.get(0);
104 		Assert.assertTrue("Hours of the leave block for recipient 'testuser2' should be 8, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(8)));
105 		Assert.assertTrue("Request status of the leave block for donor 'testuser2' should be Approved, not " + lb.getRequestStatus()
106 	  			, lb.getRequestStatus().equals(LMConstants.REQUEST_STATUS.APPROVED));
107 	  	
108 		historyList = TkServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("testuser1", null);
109 		Assert.assertTrue("There should be 1 leave block histories for princiapl id testuser1"+ historyList.size(), historyList.size()== 1);
110 		LeaveBlockHistory lbh = historyList.get(0);
111 		Assert.assertTrue("Hours of the leave block history for donor 'testuser1' should be -10, not " + lbh.getLeaveAmount().toString(), lbh.getLeaveAmount().equals(new BigDecimal(-10)));
112 		Assert.assertTrue("Request status of the leave block history for donor 'testuser1' should be Approved, not " + lbh.getRequestStatus()
113 	  			, lbh.getRequestStatus().equals(LMConstants.REQUEST_STATUS.APPROVED));
114 		historyList = TkServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("testuser2", null);
115 		Assert.assertTrue("There should be 1 leave block histories for princiapl id testuser2"+ historyList.size(), historyList.size()== 1);
116 		lbh = historyList.get(0);
117 		Assert.assertTrue("Hours of the leave block history for recipient 'testuser2' should be 8, not " + lbh.getLeaveAmount().toString(), lbh.getLeaveAmount().equals(new BigDecimal(8)));
118 		Assert.assertTrue("Request status of the leave block history for donor 'testuser2' should be Approved, not " + lbh.getRequestStatus()
119 	  			, lbh.getRequestStatus().equals(LMConstants.REQUEST_STATUS.APPROVED));
120 	}
121 	
122 	@Test
123 	public void testValidation() throws Exception {
124 	  	String baseUrl = TkTestConstants.Urls.LEAVE_DONATION_MAINT_NEW_URL;
125 	  	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
126 	  	Assert.assertNotNull(page);
127 	 
128 	  	HtmlForm form = page.getFormByName("KualiForm");
129 	  	Assert.assertNotNull("Search form was missing from page.", form);
130 	  	
131 	  	setFieldValue(page, "document.documentHeader.documentDescription", "Leave Donation - test");
132 	    setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
133 	    setFieldValue(page, "document.newMaintainableObject.donatedEarnCode", "EC");	//fraction allowed is 99
134 	  	setFieldValue(page, "document.newMaintainableObject.amountDonated", "2.45");
135 	  	HtmlElement element = page.getElementByName("methodToCall.route");
136 	  	page = element.click();
137 	  	Assert.assertTrue("page text does not contain donated amount fraction error.", page.asText().contains("Earn Code 'EC' only allows 0 decimal point."));
138 	  	setFieldValue(page, "document.newMaintainableObject.amountDonated", "2");
139 	  	page = page.getElementByName("methodToCall.route").click();
140 	  	Assert.assertFalse("page text contains donated amount fraction error.", page.asText().contains("Earn Code 'EC' only allows 0 decimal point."));
141 	  	
142 	  	setFieldValue(page, "document.newMaintainableObject.recipientsEarnCode", "EC");	//fraction allowed is 99
143 	  	setFieldValue(page, "document.newMaintainableObject.amountReceived", "3.822");
144 	  	element = page.getElementByName("methodToCall.route");
145 	  	page = element.click();
146 	  	Assert.assertTrue("page text does not contain received amount fraction error.", page.asText().contains("Earn Code 'EC' only allows 0 decimal point."));
147 	  	setFieldValue(page, "document.newMaintainableObject.amountReceived", "3");
148 	  	page = page.getElementByName("methodToCall.route").click();
149 	  	Assert.assertFalse("page text contains received amount fraction error.", page.asText().contains("Earn Code 'EC' only allows 0 decimal point."));
150 	}
151 	
152 	// commented out this test, KPME-1207, effectiveDate can be past, current or future
153 	//@Test
154 	/*public void testFutureEffectiveDate() throws Exception {
155 		this.futureEffectiveDateValidation(TkTestConstants.Urls.LEAVE_DONATION_MAINT_NEW_URL);
156 	}*/
157 }