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