1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.util;
17
18 import java.math.BigDecimal;
19 import java.sql.Date;
20 import java.util.Map;
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.joda.time.DateTime;
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.kuali.hr.lm.leaveblock.LeaveBlock;
28 import org.kuali.hr.test.KPMETestCase;
29 import org.kuali.hr.time.detail.web.ActionFormUtils;
30 import org.kuali.hr.time.earncode.EarnCode;
31 import org.kuali.hr.time.service.base.TkServiceLocator;
32 import org.kuali.hr.time.test.TkTestUtils;
33 import org.kuali.hr.time.timesheet.TimesheetDocument;
34
35 public class ActionFormUtilsTest extends KPMETestCase {
36
37 @Test
38 public void testBuildAssignmentStyleClassMap() {
39 Date aDate = new Date((new DateTime(2011, 7, 7, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
40 TimesheetDocument doc = TkTestUtils.populateTimesheetDocument(aDate);
41 Map<String, String> aMap = ActionFormUtils.buildAssignmentStyleClassMap(doc.getTimeBlocks());
42 Assert.assertEquals("Wrong number of classes in style class map", 1, aMap.size());
43 Assert.assertEquals("Wrong key for class assignment0", "assignment0", aMap.get("1_1234_1"));
44 }
45
46 @Test
47 public void testGetUnitOfTimeForEarnCode() throws Exception {
48
49 EarnCode earnCode = TkServiceLocator.getEarnCodeService().getEarnCodeById("5000");
50 String unitOfTime = ActionFormUtils.getUnitOfTimeForEarnCode(earnCode);
51 Assert.assertTrue("Unit of Time should be 'H', not " + unitOfTime, unitOfTime.equals("H"));
52
53 earnCode = TkServiceLocator.getEarnCodeService().getEarnCodeById("5002");
54 unitOfTime = ActionFormUtils.getUnitOfTimeForEarnCode(earnCode);
55 Assert.assertTrue("Unit of Time should be 'H', not " + unitOfTime, unitOfTime.equals("H"));
56
57 }
58
59 @Test
60 public void testGetLeaveBlocksJson() {
61 List<LeaveBlock> lbList = new ArrayList<LeaveBlock>();
62 LeaveBlock lb = new LeaveBlock();
63 lb.setAssignmentTitle("testAssignment");
64 lb.setAssignmentKey("0-123-0");
65 lb.setEarnCode("EarnCode");
66 lb.setLmLeaveBlockId("1111");
67 lb.setLeaveAmount(new BigDecimal(3));
68 lb.setLeaveDate(new Date((new DateTime(2012, 2, 20, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis()));
69 lb.setAccrualGenerated(false);
70 lbList.add(lb);
71
72 String jsonString = ActionFormUtils.getLeaveBlocksJson(lbList);
73 String expectedString = "[{\"title\":\"\",\"assignment\":\"0-123-0\",\"earnCode\":\"EarnCode\",\"lmLeaveBlockId\":\"1111\",\"leaveAmount\":\"3\",\"leaveDate\":\"02\\/20\\/2012\",\"id\":\"1111\",\"canTransfer\":false,\"startDate\":\"02\\/20\\/2012\",\"endDate\":\"02\\/20\\/2012\"}]";
74 Assert.assertTrue("Leave Block Json should include assignment", jsonString.equals(expectedString));
75
76
77 }
78
79
80 }