001/** 002 * Copyright 2004-2014 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 */ 016package org.kuali.hr.lm.leavedonation; 017 018import java.math.BigDecimal; 019import java.util.List; 020 021import junit.framework.Assert; 022 023import org.joda.time.DateTime; 024import org.junit.Test; 025import org.kuali.hr.KPMEWebTestCase; 026import org.kuali.hr.util.HtmlUnitUtil; 027import org.kuali.kpme.core.FunctionalTest; 028import org.kuali.kpme.core.util.HrConstants; 029import org.kuali.kpme.core.util.TKUtils; 030import org.kuali.kpme.tklm.api.leave.block.LeaveBlock; 031import org.kuali.kpme.tklm.leave.block.LeaveBlockBo; 032import org.kuali.kpme.tklm.leave.block.LeaveBlockHistory; 033import org.kuali.kpme.tklm.leave.service.LmServiceLocator; 034import org.kuali.kpme.tklm.utils.TkTestConstants; 035 036import com.gargoylesoftware.htmlunit.html.HtmlElement; 037import com.gargoylesoftware.htmlunit.html.HtmlForm; 038import com.gargoylesoftware.htmlunit.html.HtmlInput; 039import com.gargoylesoftware.htmlunit.html.HtmlPage; 040@FunctionalTest 041public class LeaveDonationMaintTest extends KPMEWebTestCase{ 042 043 @Test 044 public void testLookupPage() throws Exception { 045 HtmlPage lcLookup = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_DONATION_MAINT_URL); 046 lcLookup = HtmlUnitUtil.clickInputContainingText(lcLookup, "search"); 047 Assert.assertTrue("Page contains test Donated Account Category", lcLookup.asText().contains("dAC")); 048 Assert.assertFalse("Page should not contain edit action", lcLookup.asText().contains("edit")); 049 } 050 051 @Test 052 public void testCreatingLeaveBlocks() throws Exception { 053 DateTime START_DATE = new DateTime(2012, 4, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone()); 054 DateTime END_DATE = new DateTime(2012, 4, 2, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone()); 055 056 List<LeaveBlock> leaveBlockList; 057 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser1", START_DATE.toLocalDate(), END_DATE.toLocalDate()); 058 Assert.assertTrue("There are leave blocks for principal id " + "testuser1", leaveBlockList.isEmpty()); 059 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser2", START_DATE.toLocalDate(), END_DATE.toLocalDate()); 060 Assert.assertTrue("There are leave blocks for principal id " + "testuser2", leaveBlockList.isEmpty()); 061 062 List<LeaveBlockHistory> historyList = LmServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("10001", null); 063 Assert.assertTrue("There are leave block histories for princiapl id testuser1", historyList.isEmpty()); 064 historyList = LmServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("testuser2", null); 065 Assert.assertTrue("There are leave block histories for princiapl id testuser2", historyList.isEmpty()); 066 067 String baseUrl = TkTestConstants.Urls.LEAVE_DONATION_MAINT_NEW_URL; 068 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 069 Assert.assertNotNull(page); 070 071 HtmlForm form = page.getFormByName("KualiForm"); 072 Assert.assertNotNull("Search form was missing from page.", form); 073 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Leave Donation - test"); 074 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012"); 075 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.donorsPrincipalID", "testuser1"); 076 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.donatedAccrualCategory", "testAC"); 077 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.donatedEarnCode", "EC"); 078 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.amountDonated", "10"); 079 080 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.recipientsPrincipalID", "testuser2"); 081 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.recipientsAccrualCategory", "testAC"); 082 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.recipientsEarnCode", "EC"); 083 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.amountReceived", "8"); 084 085 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.description", "test-donation"); 086 087 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route"); 088 Assert.assertNotNull("Could not locate submit button", input); 089 HtmlElement element = page.getElementByName("methodToCall.route"); 090 page = element.click(); 091 page.asText(); 092 Assert.assertTrue("page text does not contain: success ", page.asText().contains("success")); 093 094 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser1", START_DATE.toLocalDate(), END_DATE.toLocalDate()); 095 Assert.assertTrue("There should be 1 leave blocks for emplyee 'testuser1', not " + leaveBlockList.size(), leaveBlockList.size()== 1); 096 LeaveBlock lb = leaveBlockList.get(0); 097 Assert.assertTrue("Hours of the leave block for donor 'testuser1' should be -10, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(-10))); 098 Assert.assertTrue("Request status of the leave block for donor 'testuser1' should be Approved, not " + lb.getRequestStatus() 099 , lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED)); 100 101 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser2", START_DATE.toLocalDate(), END_DATE.toLocalDate()); 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(HrConstants.REQUEST_STATUS.APPROVED)); 107 108 historyList = LmServiceLocator.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(HrConstants.REQUEST_STATUS.APPROVED)); 114 historyList = LmServiceLocator.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(HrConstants.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(getWebClient(), baseUrl); 126 Assert.assertNotNull(page); 127 128 HtmlForm form = page.getFormByName("KualiForm"); 129 Assert.assertNotNull("Search form was missing from page.", form); 130 131 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Leave Donation - test"); 132 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012"); 133 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.donatedEarnCode", "EC"); //fraction allowed is 99 134 HtmlUnitUtil.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 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.amountDonated", "2"); 139 page = ((HtmlElement)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 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.recipientsEarnCode", "EC"); //fraction allowed is 99 143 HtmlUnitUtil.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 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.amountReceived", "3"); 148 page = ((HtmlElement)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}