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