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