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.util.List; 020 021 import junit.framework.Assert; 022 023 import org.joda.time.DateTime; 024 import org.junit.Test; 025 import org.kuali.hr.KPMEWebTestCase; 026 import org.kuali.hr.util.HtmlUnitUtil; 027 import org.kuali.kpme.core.FunctionalTest; 028 import org.kuali.kpme.core.util.HrConstants; 029 import org.kuali.kpme.core.util.TKUtils; 030 import org.kuali.kpme.tklm.leave.block.LeaveBlock; 031 import org.kuali.kpme.tklm.leave.block.LeaveBlockHistory; 032 import org.kuali.kpme.tklm.leave.service.LmServiceLocator; 033 import org.kuali.kpme.tklm.utils.TkTestConstants; 034 035 import com.gargoylesoftware.htmlunit.html.HtmlElement; 036 import com.gargoylesoftware.htmlunit.html.HtmlForm; 037 import com.gargoylesoftware.htmlunit.html.HtmlInput; 038 import com.gargoylesoftware.htmlunit.html.HtmlPage; 039 @FunctionalTest 040 public class LeaveDonationMaintTest extends KPMEWebTestCase{ 041 042 @Test 043 public void testLookupPage() throws Exception { 044 HtmlPage lcLookup = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_DONATION_MAINT_URL); 045 lcLookup = HtmlUnitUtil.clickInputContainingText(lcLookup, "search"); 046 Assert.assertTrue("Page contains test Donated Account Category", lcLookup.asText().contains("dAC")); 047 Assert.assertFalse("Page should not contain edit action", lcLookup.asText().contains("edit")); 048 } 049 050 @Test 051 public void testCreatingLeaveBlocks() throws Exception { 052 DateTime START_DATE = new DateTime(2012, 4, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone()); 053 DateTime END_DATE = new DateTime(2012, 4, 2, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone()); 054 055 List<LeaveBlock> leaveBlockList; 056 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser1", START_DATE.toLocalDate(), END_DATE.toLocalDate()); 057 Assert.assertTrue("There are leave blocks for principal id " + "testuser1", leaveBlockList.isEmpty()); 058 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser2", START_DATE.toLocalDate(), END_DATE.toLocalDate()); 059 Assert.assertTrue("There are leave blocks for principal id " + "testuser2", leaveBlockList.isEmpty()); 060 061 List<LeaveBlockHistory> historyList = LmServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("10001", null); 062 Assert.assertTrue("There are leave block histories for princiapl id testuser1", historyList.isEmpty()); 063 historyList = LmServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("testuser2", null); 064 Assert.assertTrue("There are leave block histories for princiapl id testuser2", historyList.isEmpty()); 065 066 String baseUrl = TkTestConstants.Urls.LEAVE_DONATION_MAINT_NEW_URL; 067 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 068 Assert.assertNotNull(page); 069 070 HtmlForm form = page.getFormByName("KualiForm"); 071 Assert.assertNotNull("Search form was missing from page.", form); 072 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Leave Donation - test"); 073 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012"); 074 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.donorsPrincipalID", "testuser1"); 075 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.donatedAccrualCategory", "testAC"); 076 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.donatedEarnCode", "EC"); 077 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.amountDonated", "10"); 078 079 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.recipientsPrincipalID", "testuser2"); 080 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.recipientsAccrualCategory", "testAC"); 081 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.recipientsEarnCode", "EC"); 082 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.amountReceived", "8"); 083 084 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.description", "test-donation"); 085 086 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route"); 087 Assert.assertNotNull("Could not locate submit button", input); 088 HtmlElement element = page.getElementByName("methodToCall.route"); 089 page = element.click(); 090 page.asText(); 091 Assert.assertTrue("page text does not contain: success ", page.asText().contains("success")); 092 093 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser1", START_DATE.toLocalDate(), END_DATE.toLocalDate()); 094 Assert.assertTrue("There should be 1 leave blocks for emplyee 'testuser1', not " + leaveBlockList.size(), leaveBlockList.size()== 1); 095 LeaveBlock lb = leaveBlockList.get(0); 096 Assert.assertTrue("Hours of the leave block for donor 'testuser1' should be -10, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(-10))); 097 Assert.assertTrue("Request status of the leave block for donor 'testuser1' should be Approved, not " + lb.getRequestStatus() 098 , lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED)); 099 100 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser2", START_DATE.toLocalDate(), END_DATE.toLocalDate()); 101 Assert.assertTrue("There should be 1 leave blocks for emplyee 'testuser2', not " + leaveBlockList.size(), leaveBlockList.size()== 1); 102 lb = leaveBlockList.get(0); 103 Assert.assertTrue("Hours of the leave block for recipient 'testuser2' should be 8, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(8))); 104 Assert.assertTrue("Request status of the leave block for donor 'testuser2' should be Approved, not " + lb.getRequestStatus() 105 , lb.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED)); 106 107 historyList = LmServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("testuser1", null); 108 Assert.assertTrue("There should be 1 leave block histories for princiapl id testuser1"+ historyList.size(), historyList.size()== 1); 109 LeaveBlockHistory lbh = historyList.get(0); 110 Assert.assertTrue("Hours of the leave block history for donor 'testuser1' should be -10, not " + lbh.getLeaveAmount().toString(), lbh.getLeaveAmount().equals(new BigDecimal(-10))); 111 Assert.assertTrue("Request status of the leave block history for donor 'testuser1' should be Approved, not " + lbh.getRequestStatus() 112 , lbh.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED)); 113 historyList = LmServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("testuser2", null); 114 Assert.assertTrue("There should be 1 leave block histories for princiapl id testuser2"+ historyList.size(), historyList.size()== 1); 115 lbh = historyList.get(0); 116 Assert.assertTrue("Hours of the leave block history for recipient 'testuser2' should be 8, not " + lbh.getLeaveAmount().toString(), lbh.getLeaveAmount().equals(new BigDecimal(8))); 117 Assert.assertTrue("Request status of the leave block history for donor 'testuser2' should be Approved, not " + lbh.getRequestStatus() 118 , lbh.getRequestStatus().equals(HrConstants.REQUEST_STATUS.APPROVED)); 119 } 120 121 @Test 122 public void testValidation() throws Exception { 123 String baseUrl = TkTestConstants.Urls.LEAVE_DONATION_MAINT_NEW_URL; 124 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 125 Assert.assertNotNull(page); 126 127 HtmlForm form = page.getFormByName("KualiForm"); 128 Assert.assertNotNull("Search form was missing from page.", form); 129 130 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Leave Donation - test"); 131 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012"); 132 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.donatedEarnCode", "EC"); //fraction allowed is 99 133 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.amountDonated", "2.45"); 134 HtmlElement element = page.getElementByName("methodToCall.route"); 135 page = element.click(); 136 Assert.assertTrue("page text does not contain donated amount fraction error.", page.asText().contains("Earn Code 'EC' only allows 0 decimal point.")); 137 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.amountDonated", "2"); 138 page = ((HtmlElement)page.getElementByName("methodToCall.route")).click(); 139 Assert.assertFalse("page text contains donated amount fraction error.", page.asText().contains("Earn Code 'EC' only allows 0 decimal point.")); 140 141 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.recipientsEarnCode", "EC"); //fraction allowed is 99 142 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.amountReceived", "3.822"); 143 element = page.getElementByName("methodToCall.route"); 144 page = element.click(); 145 Assert.assertTrue("page text does not contain received amount fraction error.", page.asText().contains("Earn Code 'EC' only allows 0 decimal point.")); 146 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.amountReceived", "3"); 147 page = ((HtmlElement)page.getElementByName("methodToCall.route")).click(); 148 Assert.assertFalse("page text contains received amount fraction error.", page.asText().contains("Earn Code 'EC' only allows 0 decimal point.")); 149 } 150 151 // commented out this test, KPME-1207, effectiveDate can be past, current or future 152 //@Test 153 /*public void testFutureEffectiveDate() throws Exception { 154 this.futureEffectiveDateValidation(TkTestConstants.Urls.LEAVE_DONATION_MAINT_NEW_URL); 155 }*/ 156 }