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 junit.framework.Assert; 023 024 import org.joda.time.DateTime; 025 import org.junit.Test; 026 import org.kuali.hr.lm.LMConstants; 027 import org.kuali.hr.lm.leaveblock.LeaveBlock; 028 import org.kuali.hr.lm.leaveblock.LeaveBlockHistory; 029 import org.kuali.hr.test.KPMETestCase; 030 import org.kuali.hr.time.service.base.TkServiceLocator; 031 import org.kuali.hr.time.test.HtmlUnitUtil; 032 import org.kuali.hr.time.test.TkTestConstants; 033 import org.kuali.hr.time.util.TKUtils; 034 import org.kuali.hr.time.util.TkConstants; 035 036 import com.gargoylesoftware.htmlunit.html.HtmlElement; 037 import com.gargoylesoftware.htmlunit.html.HtmlForm; 038 import com.gargoylesoftware.htmlunit.html.HtmlInput; 039 import com.gargoylesoftware.htmlunit.html.HtmlPage; 040 041 public class LeaveDonationMaintTest extends KPMETestCase{ 042 043 @Test 044 public void testLookupPage() throws Exception { 045 HtmlPage lcLookup = HtmlUnitUtil.gotoPageAndLogin(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 Date START_DATE = new Date((new DateTime(2012, 4, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis()); 054 Date END_DATE = new Date((new DateTime(2012, 4, 2, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis()); 055 056 List<LeaveBlock> leaveBlockList; 057 leaveBlockList = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser1", START_DATE, END_DATE); 058 Assert.assertTrue("There are leave blocks for principal id " + "testuser1", leaveBlockList.isEmpty()); 059 leaveBlockList = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser2", START_DATE, END_DATE); 060 Assert.assertTrue("There are leave blocks for principal id " + "testuser2", leaveBlockList.isEmpty()); 061 062 List<LeaveBlockHistory> historyList = TkServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("10001", null); 063 Assert.assertTrue("There are leave block histories for princiapl id testuser1", historyList.isEmpty()); 064 historyList = TkServiceLocator.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(baseUrl); 069 Assert.assertNotNull(page); 070 071 HtmlForm form = page.getFormByName("KualiForm"); 072 Assert.assertNotNull("Search form was missing from page.", form); 073 setFieldValue(page, "document.documentHeader.documentDescription", "Leave Donation - test"); 074 setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012"); 075 setFieldValue(page, "document.newMaintainableObject.donorsPrincipalID", "testuser1"); 076 setFieldValue(page, "document.newMaintainableObject.donatedAccrualCategory", "testAC"); 077 setFieldValue(page, "document.newMaintainableObject.donatedEarnCode", "EC"); 078 setFieldValue(page, "document.newMaintainableObject.amountDonated", "10"); 079 080 setFieldValue(page, "document.newMaintainableObject.recipientsPrincipalID", "testuser2"); 081 setFieldValue(page, "document.newMaintainableObject.recipientsAccrualCategory", "testAC"); 082 setFieldValue(page, "document.newMaintainableObject.recipientsEarnCode", "EC"); 083 setFieldValue(page, "document.newMaintainableObject.amountReceived", "8"); 084 085 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 = TkServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser1", START_DATE, END_DATE); 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(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 }