1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.lm.leaveblock.service;
17
18
19 import java.util.*;
20
21 import junit.framework.Assert;
22
23 import org.joda.time.DateTime;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.kuali.hr.lm.LMConstants;
28 import org.kuali.hr.lm.leaveblock.LeaveBlock;
29 import org.kuali.hr.test.KPMETestCase;
30 import org.kuali.hr.time.service.base.TkServiceLocator;
31 import org.kuali.hr.time.util.TKUtils;
32
33 public class LeaveBlockServiceImplTest extends KPMETestCase {
34
35 private String TEST_USER = "admin";
36 private LeaveBlockService leaveBlockService;
37
38 @Before
39 public void setUp() throws Exception{
40 super.setUp();
41 leaveBlockService = TkServiceLocator.getLeaveBlockService();
42 }
43
44 @After
45 public void tearDown() throws Exception {
46 super.tearDown();
47 }
48
49 @Test
50 public void testGetLeaveBlock() {
51 LeaveBlock leaveBlock = leaveBlockService.getLeaveBlock("1000");
52 Assert.assertNotNull("Leave Block not found ", leaveBlock);
53 }
54
55 @Test
56 public void testGetLeaveCarryOverDates() {
57 Map<String, LeaveBlock> dates = leaveBlockService.getLastCarryOverBlocks("admin", null);
58 Assert.assertNotNull("Leave Block not found ", dates);
59 }
60
61
62
63 @Test
64 public void testGetLeaveBlocks(){
65
66 Calendar cal = Calendar.getInstance();
67 cal.setTime(TKUtils.getTimelessDate(null));
68 cal.set(Calendar.YEAR, 2012);
69 cal.set(Calendar.MONTH, 2);
70 cal.set(Calendar.DATE, 1);
71
72 Date beginDate = cal.getTime();
73 cal.add(Calendar.DATE,1);
74 Date endDate = cal.getTime();
75 List<LeaveBlock> leaveBlocks = leaveBlockService.getLeaveBlocks(TEST_USER, beginDate, endDate);
76 Assert.assertNotNull("Leave blocks not found for user ", leaveBlocks);
77 Assert.assertTrue("There should be 2 leave blocks, not " + leaveBlocks.size(), leaveBlocks.size()== 2);
78 }
79
80 @Test
81 public void testGetLeaveBlocksForDocumentId() {
82 List<LeaveBlock> leaveBlocks = leaveBlockService.getLeaveBlocksForDocumentId("12546");
83 Assert.assertNotNull("Leave Blocks not foudn for document", leaveBlocks);
84 }
85
86 @Test
87 public void testGetLeaveBlocksByLeaveRequestStatus(){
88 String requestStatus = LMConstants.REQUEST_STATUS.PLANNED;
89 Date currentDate = TKUtils.getTimelessDate(new Date());
90 List<LeaveBlock> leaveBlocks = leaveBlockService.getLeaveBlocks(TEST_USER, LMConstants.LEAVE_BLOCK_TYPE.LEAVE_CALENDAR, requestStatus, currentDate);
91 Assert.assertNotNull("Leave Blocks not found of Request status", leaveBlocks);
92 }
93 @Test
94 public void testGetLeaveBlocksForLeaveDate(){
95 Date leaveDate = TKUtils.getTimelessDate(new Date());
96 List<LeaveBlock> leaveBlocks = leaveBlockService.getLeaveBlocksForDate(TEST_USER, leaveDate);
97 Assert.assertNotNull("Leave Blocks not found of Request status", leaveBlocks);
98 }
99
100 @Test
101 public void testGetLeaveBlocksForTimeCalendar() {
102
103 Calendar cal = Calendar.getInstance();
104 cal.setTime(TKUtils.getTimelessDate(null));
105 cal.set(Calendar.YEAR, 2012);
106 cal.set(Calendar.MONTH, 2);
107 cal.set(Calendar.DATE, 1);
108
109 Date beginDate = cal.getTime();
110 cal.add(Calendar.DATE,5);
111 Date endDate = cal.getTime();
112 List<String> assignmentKeys = new ArrayList<String>();
113 List<LeaveBlock> leaveBlocks = leaveBlockService.getLeaveBlocksForTimeCalendar(TEST_USER, beginDate, endDate, assignmentKeys);
114 Assert.assertNotNull("Leave blocks not found for user ", leaveBlocks);
115 Assert.assertTrue("There should be 6 leave blocks, not " + leaveBlocks.size(), leaveBlocks.size()== 6);
116
117 assignmentKeys.add("0_12345_0");
118 leaveBlocks = leaveBlockService.getLeaveBlocksForTimeCalendar(TEST_USER, beginDate, endDate, assignmentKeys);
119 Assert.assertNotNull("Leave blocks not found for user ", leaveBlocks);
120 Assert.assertTrue("There should be 2 leave blocks, not " + leaveBlocks.size(), leaveBlocks.size()== 2);
121
122 LeaveBlock lb = TkServiceLocator.getLeaveBlockService().getLeaveBlock("1001");
123 lb.setRequestStatus(LMConstants.REQUEST_STATUS.APPROVED);
124 TkServiceLocator.getLeaveBlockService().saveLeaveBlock(lb, TEST_USER);
125 leaveBlocks = leaveBlockService.getLeaveBlocksForTimeCalendar(TEST_USER, beginDate, endDate, assignmentKeys);
126 Assert.assertTrue("There should be 3 leave blocks, not " + leaveBlocks.size(), leaveBlocks.size()== 3);
127 Assert.assertTrue("Approved leave block should be in the list", leaveBlocks.contains(lb));
128 }
129
130 @Test
131 public void testGetLeaveBlocksForLeaveCalendar() {
132
133 Calendar cal = Calendar.getInstance();
134 cal.setTime(TKUtils.getTimelessDate(null));
135 cal.set(Calendar.YEAR, 2012);
136 cal.set(Calendar.MONTH, 2);
137 cal.set(Calendar.DATE, 1);
138
139 Date beginDate = cal.getTime();
140 cal.add(Calendar.DATE,5);
141 Date endDate = cal.getTime();
142 List<String> assignmentKeys = new ArrayList<String>();
143 List<LeaveBlock> leaveBlocks = leaveBlockService.getLeaveBlocksForLeaveCalendar(TEST_USER, beginDate, endDate, assignmentKeys);
144 Assert.assertNotNull("Leave blocks not found for user ", leaveBlocks);
145 Assert.assertTrue("There should be 6 leave blocks, not " + leaveBlocks.size(), leaveBlocks.size()== 6);
146
147 assignmentKeys.add("0_12345_0");
148 leaveBlocks = leaveBlockService.getLeaveBlocksForLeaveCalendar(TEST_USER, beginDate, endDate, assignmentKeys);
149 Assert.assertNotNull("Leave blocks not found for user ", leaveBlocks);
150 Assert.assertTrue("There should be 5 leave blocks, not " + leaveBlocks.size(), leaveBlocks.size()== 5);
151
152 assignmentKeys.add("1_12345_0");
153 leaveBlocks = leaveBlockService.getLeaveBlocksForLeaveCalendar(TEST_USER, beginDate, endDate, assignmentKeys);
154 Assert.assertNotNull("Leave blocks not found for user ", leaveBlocks);
155 Assert.assertTrue("There should be 6 leave blocks, not " + leaveBlocks.size(), leaveBlocks.size()== 6);
156 }
157
158
159 }