1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.leavedonation;
17
18 import java.math.BigDecimal;
19 import java.util.List;
20
21 import junit.framework.Assert;
22
23 import org.joda.time.DateTime;
24 import org.junit.Test;
25 import org.kuali.hr.KPMEWebTestCase;
26 import org.kuali.hr.util.HtmlUnitUtil;
27 import org.kuali.kpme.core.FunctionalTest;
28 import org.kuali.kpme.core.util.HrConstants;
29 import org.kuali.kpme.core.util.TKUtils;
30 import org.kuali.kpme.tklm.api.leave.block.LeaveBlock;
31 import org.kuali.kpme.tklm.leave.block.LeaveBlockBo;
32 import org.kuali.kpme.tklm.leave.block.LeaveBlockHistory;
33 import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
34 import org.kuali.kpme.tklm.utils.TkTestConstants;
35
36 import com.gargoylesoftware.htmlunit.html.HtmlElement;
37 import com.gargoylesoftware.htmlunit.html.HtmlForm;
38 import com.gargoylesoftware.htmlunit.html.HtmlInput;
39 import com.gargoylesoftware.htmlunit.html.HtmlPage;
40 @FunctionalTest
41 public class LeaveDonationMaintTest extends KPMEWebTestCase{
42
43 @Test
44 public void testLookupPage() throws Exception {
45 HtmlPage lcLookup = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_DONATION_MAINT_URL);
46 lcLookup = HtmlUnitUtil.clickInputContainingText(lcLookup, "search");
47 Assert.assertTrue("Page contains test Donated Account Category", lcLookup.asText().contains("dAC"));
48 Assert.assertFalse("Page should not contain edit action", lcLookup.asText().contains("edit"));
49 }
50
51 @Test
52 public void testCreatingLeaveBlocks() throws Exception {
53 DateTime START_DATE = new DateTime(2012, 4, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
54 DateTime END_DATE = new DateTime(2012, 4, 2, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone());
55
56 List<LeaveBlock> leaveBlockList;
57 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser1", START_DATE.toLocalDate(), END_DATE.toLocalDate());
58 Assert.assertTrue("There are leave blocks for principal id " + "testuser1", leaveBlockList.isEmpty());
59 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser2", START_DATE.toLocalDate(), END_DATE.toLocalDate());
60 Assert.assertTrue("There are leave blocks for principal id " + "testuser2", leaveBlockList.isEmpty());
61
62 List<LeaveBlockHistory> historyList = LmServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("10001", null);
63 Assert.assertTrue("There are leave block histories for princiapl id testuser1", historyList.isEmpty());
64 historyList = LmServiceLocator.getLeaveBlockHistoryService().getLeaveBlockHistories("testuser2", null);
65 Assert.assertTrue("There are leave block histories for princiapl id testuser2", historyList.isEmpty());
66
67 String baseUrl = TkTestConstants.Urls.LEAVE_DONATION_MAINT_NEW_URL;
68 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
69 Assert.assertNotNull(page);
70
71 HtmlForm form = page.getFormByName("KualiForm");
72 Assert.assertNotNull("Search form was missing from page.", form);
73 HtmlUnitUtil.setFieldValue(page, "document.documentHeader.documentDescription", "Leave Donation - test");
74 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.effectiveDate", "04/01/2012");
75 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.donorsPrincipalID", "testuser1");
76 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.donatedAccrualCategory", "testAC");
77 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.donatedEarnCode", "EC");
78 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.amountDonated", "10");
79
80 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.recipientsPrincipalID", "testuser2");
81 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.recipientsAccrualCategory", "testAC");
82 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.recipientsEarnCode", "EC");
83 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.amountReceived", "8");
84
85 HtmlUnitUtil.setFieldValue(page, "document.newMaintainableObject.description", "test-donation");
86
87 HtmlInput input = HtmlUnitUtil.getInputContainingText(form, "methodToCall.route");
88 Assert.assertNotNull("Could not locate submit button", input);
89 HtmlElement element = page.getElementByName("methodToCall.route");
90 page = element.click();
91 page.asText();
92 Assert.assertTrue("page text does not contain: success ", page.asText().contains("success"));
93
94 leaveBlockList = LmServiceLocator.getLeaveBlockService().getLeaveBlocks("testuser1", START_DATE.toLocalDate(), END_DATE.toLocalDate());
95 Assert.assertTrue("There should be 1 leave blocks for emplyee 'testuser1', not " + leaveBlockList.size(), leaveBlockList.size()== 1);
96 LeaveBlock lb = leaveBlockList.get(0);
97 Assert.assertTrue("Hours of the leave block for donor 'testuser1' should be -10, not " + lb.getLeaveAmount().toString(), lb.getLeaveAmount().equals(new BigDecimal(-10)));
98 Assert.assertTrue("Request status of the leave block for donor 'testuser1' should be Approved, not " + lb.getRequestStatus()
99 , 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");
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");
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
153
154
155
156
157 }