001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.lm.leavedonation;
017
018 import java.math.BigDecimal;
019 import java.sql.Date;
020 import java.util.List;
021
022 import com.gargoylesoftware.htmlunit.html.*;
023 import junit.framework.Assert;
024
025 import org.joda.time.DateTime;
026 import org.junit.Test;
027 import org.kuali.hr.lm.LMConstants;
028 import org.kuali.hr.lm.leaveblock.LeaveBlock;
029 import org.kuali.hr.lm.leaveblock.LeaveBlockHistory;
030 import org.kuali.hr.test.KPMETestCase;
031 import org.kuali.hr.time.service.base.TkServiceLocator;
032 import org.kuali.hr.time.test.HtmlUnitUtil;
033 import org.kuali.hr.time.test.TkTestConstants;
034 import org.kuali.hr.time.util.TKUtils;
035 import org.kuali.hr.time.util.TkConstants;
036
037 public class LeaveDonationMaintTest extends KPMETestCase{
038
039 @Test
040 public void testLookupPage() throws Exception {
041 HtmlPage lcLookup = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_DONATION_MAINT_URL);
042 lcLookup = HtmlUnitUtil.clickInputContainingText(lcLookup, "search");
043 Assert.assertTrue("Page contains test Donated Account Category", lcLookup.asText().contains("dAC"));
044 Assert.assertFalse("Page should not contain edit action", lcLookup.asText().contains("edit"));
045 }
046
047 @Test
048 public void testCreatingLeaveBlocks() throws Exception {
049 Date START_DATE = new Date((new DateTime(2012, 4, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
050 Date END_DATE = new Date((new DateTime(2012, 4, 2, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
051
052 List<LeaveBlock> leaveBlockList;
053 leaveBlockList = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser1", START_DATE, END_DATE);
054 Assert.assertTrue("There are leave blocks for principal id " + "testuser1", leaveBlockList.isEmpty());
055 leaveBlockList = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser2", START_DATE, END_DATE);
056 Assert.assertTrue("There are leave blocks for principal id " + "testuser2", leaveBlockList.isEmpty());
057
058 List<LeaveBlockHistory> historyList = TkServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("10001", null);
059 Assert.assertTrue("There are leave block histories for princiapl id testuser1", historyList.isEmpty());
060 historyList = TkServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("testuser2", null);
061 Assert.assertTrue("There are leave block histories for princiapl id testuser2", historyList.isEmpty());
062
063 String baseUrl = TkTestConstants.Urls.LEAVE_DONATION_MAINT_NEW_URL;
064 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
065 Assert.assertNotNull(page);
066
067 HtmlForm form = page.getFormByName("KualiForm");
068 Assert.assertNotNull("Search form was missing from page.", form);
069 setFieldValue(page, "document.documentHeader.documentDescription", "Leave Donation - test");
070 setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
071 setFieldValue(page, "document.newMaintainableObject.donorsPrincipalID", "testuser1");
072 setFieldValue(page, "document.newMaintainableObject.donatedAccrualCategory", "testAC");
073 setFieldValue(page, "document.newMaintainableObject.donatedEarnCode", "EC");
074 setFieldValue(page, "document.newMaintainableObject.amountDonated", "10");
075
076 setFieldValue(page, "document.newMaintainableObject.recipientsPrincipalID", "testuser2");
077 setFieldValue(page, "document.newMaintainableObject.recipientsAccrualCategory", "testAC");
078 setFieldValue(page, "document.newMaintainableObject.recipientsEarnCode", "EC");
079 setFieldValue(page, "document.newMaintainableObject.amountReceived", "8");
080
081 setFieldValue(page, "document.newMaintainableObject.description", "test-donation");
082
083 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
084 Assert.assertNotNull("Could not locate submit button", input);
085 HtmlElement element = page.getElementByName("methodToCall.route");
086 page = element.click();
087 page.asText();
088 Assert.assertTrue("page text does not contain: success ", page.asText().contains("success"));
089
090 leaveBlockList = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser1", START_DATE, END_DATE);
091 Assert.assertTrue("There should be 1 leave blocks for emplyee 'testuser1', not " + leaveBlockList.size(), leaveBlockList.size()== 1);
092 LeaveBlock lb = leaveBlockList.get(0);
093 Assert.assertTrue("Hours of the leave block for donor 'testuser1' should be -10, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(-10)));
094 Assert.assertTrue("Request status of the leave block for donor 'testuser1' should be Approved, not " + lb.getRequestStatus()
095 , lb.getRequestStatus().equals(LMConstants.REQUEST_STATUS.APPROVED));
096
097 leaveBlockList = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser2", START_DATE, END_DATE);
098 Assert.assertTrue("There should be 1 leave blocks for emplyee 'testuser2', not " + leaveBlockList.size(), leaveBlockList.size()== 1);
099 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 }