1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.balancetransfer;
17 import static org.junit.Assert.*;
18
19 import java.math.BigDecimal;
20 import java.sql.Date;
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import junit.framework.Assert;
25
26 import org.joda.time.DateTime;
27 import org.joda.time.Interval;
28 import org.junit.Test;
29 import org.kuali.hr.lm.leave.web.LeaveCalendarWSForm;
30 import org.kuali.hr.lm.leaveCalendar.LeaveCalendarWebTestBase;
31 import org.kuali.hr.lm.leaveSummary.LeaveSummary;
32 import org.kuali.hr.lm.leaveSummary.LeaveSummaryRow;
33 import org.kuali.hr.lm.leaveblock.LeaveBlock;
34 import org.kuali.hr.lm.leavecalendar.LeaveCalendarDocument;
35 import org.kuali.hr.lm.leavecalendar.web.LeaveCalendarSubmitForm;
36 import org.kuali.hr.lm.util.LeaveCalendarTestUtils;
37 import org.kuali.hr.test.KPMETestCase;
38 import org.kuali.hr.time.calendar.CalendarEntries;
39 import org.kuali.hr.time.service.base.TkServiceLocator;
40 import org.kuali.hr.time.test.HtmlUnitUtil;
41 import org.kuali.hr.time.test.TkTestConstants;
42 import org.kuali.hr.time.util.TKUtils;
43 import org.kuali.hr.time.util.TkConstants;
44
45 import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
46 import com.gargoylesoftware.htmlunit.WebClient;
47 import com.gargoylesoftware.htmlunit.html.HtmlPage;
48
49
50 public class BalanceTransferTest extends LeaveCalendarWebTestBase {
51
52 public static final String USER_PRINCIPAL_ID = "admin";
53 private Date JAN_AS_OF_DATE = new Date((new DateTime(2010, 1, 1, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
54 private BalanceTransfer balanceTransfer;
55
56 @Override
57 public void setUp() throws Exception {
58 super.setUp();
59 setBaseDetailURL(TkTestConstants.Urls.LEAVE_CALENDAR_SUBMIT_URL + "?documentId=");
60 balanceTransfer = new BalanceTransfer();
61 balanceTransfer.setTransferAmount(new BigDecimal(20));
62 balanceTransfer.setForfeitedAmount(new BigDecimal(0));
63 balanceTransfer.setAmountTransferred(new BigDecimal(10));
64 balanceTransfer.setAccrualCategoryRule("5000");
65 }
66
67 @Test
68 public void testTransferWithAccrualRule() throws Exception {
69 BalanceTransfer btd = new BalanceTransfer();
70
71 assertTrue("Dummy assertion",true);
72 }
73
74 @Test
75 public void testAdjustLowerTransferAmount() {
76 BigDecimal adjustedTransferAmount = new BigDecimal(10);
77 balanceTransfer = balanceTransfer.adjust(adjustedTransferAmount);
78
79 assertTrue("Transfer Amount not equals", balanceTransfer.getTransferAmount().compareTo(adjustedTransferAmount) == 0);
80 assertTrue("Forfeited amount not updated", balanceTransfer.getForfeitedAmount().compareTo(new BigDecimal(10)) == 0);
81 assertTrue(balanceTransfer.getAmountTransferred().compareTo(new BigDecimal(5)) == 0);
82 }
83
84 @Test
85 public void testAdjustLowerTransferAmountWithForfeiture() {
86 BigDecimal adjustedTransferAmount = new BigDecimal(10);
87 balanceTransfer.setForfeitedAmount(new BigDecimal(10));
88 balanceTransfer = balanceTransfer.adjust(adjustedTransferAmount);
89
90 assertTrue("Transfer Amount not equals", balanceTransfer.getTransferAmount().compareTo(adjustedTransferAmount) == 0);
91 assertTrue("Forfeited amount not updated", balanceTransfer.getForfeitedAmount().compareTo(new BigDecimal(20)) == 0);
92 assertTrue(balanceTransfer.getAmountTransferred().compareTo(new BigDecimal(5)) == 0);
93 }
94
95 @Test
96 public void testAdjustRaiseTransferAmount() {
97 BigDecimal adjustedTransferAmount = new BigDecimal(30);
98 balanceTransfer = balanceTransfer.adjust(adjustedTransferAmount);
99
100 assertTrue("Transfer Amount not equals", balanceTransfer.getTransferAmount().compareTo(adjustedTransferAmount) == 0);
101 assertTrue("Forfeited amount not updated", balanceTransfer.getForfeitedAmount().compareTo(BigDecimal.ZERO) == 0);
102 assertTrue(balanceTransfer.getAmountTransferred().compareTo(new BigDecimal(15)) == 0);
103 }
104
105 @Test
106 public void testAdjustRaiseTransferAmountWithForfeitureLessThanDifference() {
107 BigDecimal adjustedTransferAmount = new BigDecimal(40);
108 balanceTransfer.setForfeitedAmount(new BigDecimal(10));
109
110 balanceTransfer = balanceTransfer.adjust(adjustedTransferAmount);
111
112 assertTrue("Transfer Amount not equals", balanceTransfer.getTransferAmount().compareTo(adjustedTransferAmount) == 0);
113 assertTrue("Forfeited amount not updated", balanceTransfer.getForfeitedAmount().compareTo(BigDecimal.ZERO) == 0);
114 assertTrue(balanceTransfer.getAmountTransferred().compareTo(new BigDecimal(20)) == 0);
115 }
116
117 @Test
118 public void testAdjustRaiseTransferAmountWithForfeitureMoreThanDifference() {
119 BigDecimal adjustedTransferAmount = new BigDecimal(30);
120 balanceTransfer.setForfeitedAmount(new BigDecimal(15));
121 balanceTransfer = balanceTransfer.adjust(adjustedTransferAmount);
122
123 assertTrue("Transfer Amount not equals", balanceTransfer.getTransferAmount().compareTo(adjustedTransferAmount) == 0);
124 assertTrue("Forfeited amount not updated", balanceTransfer.getForfeitedAmount().compareTo(new BigDecimal(5)) == 0);
125 assertTrue(balanceTransfer.getAmountTransferred().compareTo(new BigDecimal(15)) == 0);
126 }
127
128
129
130
131
132
133
134
135 @Test
136 public void testSingleLeaveApproveBalanceTransfer() throws Exception {
137
138
139 LeaveSummary ls = new LeaveSummary();
140
141
142 Date startDate = new Date((new DateTime(2012, 1, 1, 0, 0, 0, 1, TKUtils.getSystemDateTimeZone())).getMillis());
143 Date asOfDate = new Date((new DateTime(2012, 11, 1, 12, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
144 TkServiceLocator.getAccrualService().runAccrual(USER_PRINCIPAL_ID,startDate,asOfDate,false);
145 CalendarEntries pcd = TkServiceLocator.getCalendarService().getCurrentCalendarDatesForLeaveCalendar(USER_PRINCIPAL_ID, asOfDate);
146 Assert.assertNotNull("No CalendarEntries", pcd);
147
148
149 LeaveCalendarDocument tdoc = TkServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument(USER_PRINCIPAL_ID, pcd);
150 String tdocId = tdoc.getDocumentId();
151
152
153
154
155 ls = TkServiceLocator.getLeaveSummaryService().getLeaveSummary(USER_PRINCIPAL_ID, pcd);
156 LeaveCalendarWSForm tdaf = LeaveCalendarTestUtils.buildLeaveCalendarFormForSubmission(tdoc, ls);
157 LeaveCalendarSubmitForm lcsf = new LeaveCalendarSubmitForm();
158 lcsf.setAction(TkConstants.DOCUMENT_ACTIONS.ROUTE);
159 lcsf.setDocumentId(tdaf.getDocumentId());
160 for(LeaveSummaryRow lsRow : ls.getLeaveSummaryRows()) {
161 System.out.println("Accrued balance : " + lsRow.getAccruedBalance());
162 }
163 HtmlPage page = LeaveCalendarTestUtils.submitLeaveCalendar2(getLeaveCalendarUrl(tdocId), tdaf);
164
165
166 Assert.assertNotNull(page);
167 HtmlUnitUtil.createTempFile(page, "LeaveBlockPresent");
168
169
170 String pageAsText = page.asText();
171 System.out.print(pageAsText);
172
173
174
175
176
177
178
179
180
181
182
183 assertTrue("Dummy assertion 2", true);
184 }
185
186
187
188
189
190
191 @Test
192 public void testMultipleLeaveApproveBalanceTransfer() throws Exception {
193
194
195
196
197
198
199
200
201
202
203 assertTrue("Dummy assertion 3",true);
204 }
205
206
207
208
209
210 @Test
211 public void testNoEligibleAccrualCategorysForLeaveApproveBalanceTransfer() throws Exception {
212
213
214
215
216
217
218
219
220
221
222 assertTrue("Dummy assertion 4", true);
223 }
224
225
226
227
228
229 @Test
230 public void testLookupPage() throws Exception {
231 HtmlPage btLookup = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.BALANCE_TRANSFER_MAINT_URL);
232 btLookup = HtmlUnitUtil.clickInputContainingText(btLookup, "search");
233 System.out.println(btLookup.asXml());
234 Assert.assertTrue("Page contains test Balance Transfer", btLookup.asText().contains("fromAC"));
235 Assert.assertFalse("Page should not contain edit action", btLookup.asText().contains("edit"));
236 Assert.assertTrue("Page should contain view action", btLookup.asText().contains("view"));
237 }
238
239
240 }