View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.kpme.tklm.leave.block;
17  
18  
19  import java.util.ArrayList;
20  import java.util.Calendar;
21  import java.util.Date;
22  import java.util.List;
23  import java.util.Map;
24  
25  import junit.framework.Assert;
26  
27  import org.joda.time.LocalDate;
28  import org.junit.After;
29  import org.junit.Before;
30  import org.junit.Test;
31  import org.kuali.kpme.core.IntegrationTest;
32  import org.kuali.kpme.core.util.HrConstants;
33  import org.kuali.kpme.tklm.TKLMIntegrationTestCase;
34  import org.kuali.kpme.tklm.common.LMConstants;
35  import org.kuali.kpme.tklm.leave.block.service.LeaveBlockService;
36  import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
37  
38  @IntegrationTest
39  public class LeaveBlockServiceImplTest extends TKLMIntegrationTestCase {
40  	
41  	private String TEST_USER = "admin";
42  	private LeaveBlockService leaveBlockService;
43  
44  	@Before
45  	public void setUp() throws Exception{
46  		super.setUp();
47  		leaveBlockService = LmServiceLocator.getLeaveBlockService();
48  	}
49  
50  	@After
51  	public void tearDown() throws Exception {
52  		super.tearDown();
53  	}
54  
55  	@Test
56  	public void testGetLeaveBlock() {
57  		LeaveBlock leaveBlock = leaveBlockService.getLeaveBlock("1000");
58  		Assert.assertNotNull("Leave Block not found ", leaveBlock);
59  	}
60  
61      @Test
62      public void testGetLeaveCarryOverDates() {
63          Map<String, LeaveBlock> dates = leaveBlockService.getLastCarryOverBlocks("admin", null);
64          Assert.assertNotNull("Leave Block not found ", dates);
65      }
66  
67  
68  	
69  	@Test
70  	public void testGetLeaveBlocks(){
71  		// 03/01/2012 to 03/02/2012
72  		Calendar cal = Calendar.getInstance();
73  		cal.setTime(LocalDate.now().toDate());
74  		cal.set(Calendar.YEAR, 2012);
75  		cal.set(Calendar.MONTH, 2);
76  		cal.set(Calendar.DATE, 1);
77  		
78  		Date beginDate = cal.getTime();
79  		cal.add(Calendar.DATE,1);
80  		Date endDate = cal.getTime();
81  		List<LeaveBlock> leaveBlocks = leaveBlockService.getLeaveBlocks(TEST_USER, LocalDate.fromDateFields(beginDate), LocalDate.fromDateFields(endDate));
82  		Assert.assertNotNull("Leave blocks not found for user ", leaveBlocks);
83  		Assert.assertTrue("There should be 2 leave blocks, not " + leaveBlocks.size(), leaveBlocks.size()== 2);
84  	}
85  	
86  	@Test
87  	public void testGetLeaveBlocksForDocumentId() {
88  		List<LeaveBlock> leaveBlocks = leaveBlockService.getLeaveBlocksForDocumentId("12546");
89  		Assert.assertNotNull("Leave Blocks not foudn for document", leaveBlocks);
90  	}
91  	
92  	@Test
93  	public void testGetLeaveBlocksByLeaveRequestStatus(){
94  		String requestStatus = HrConstants.REQUEST_STATUS.PLANNED;
95  		List<LeaveBlock> leaveBlocks = leaveBlockService.getLeaveBlocks(TEST_USER, LMConstants.LEAVE_BLOCK_TYPE.LEAVE_CALENDAR, requestStatus, LocalDate.now());
96  		Assert.assertNotNull("Leave Blocks not found of Request status", leaveBlocks);
97  	}
98  	@Test
99  	public void testGetLeaveBlocksForLeaveDate(){
100 		List<LeaveBlock> leaveBlocks = leaveBlockService.getLeaveBlocksForDate(TEST_USER, LocalDate.now());
101 		Assert.assertNotNull("Leave Blocks not found of Request status", leaveBlocks);
102 	}
103 	
104 	@Test
105 	public void testGetLeaveBlocksForTimeCalendar() {
106 		// 03/01/2012 to 03/06/2012
107 		Calendar cal = Calendar.getInstance();
108 		cal.setTime(LocalDate.now().toDate());
109 		cal.set(Calendar.YEAR, 2012);
110 		cal.set(Calendar.MONTH, 2);
111 		cal.set(Calendar.DATE, 1);
112 		
113 		Date beginDate = cal.getTime();
114 		cal.add(Calendar.DATE,5);
115 		Date endDate = cal.getTime();
116 		List<String> assignmentKeys = new ArrayList<String>();
117 		List<LeaveBlock> leaveBlocks = leaveBlockService.getLeaveBlocksForTimeCalendar(TEST_USER, LocalDate.fromDateFields(beginDate), LocalDate.fromDateFields(endDate), assignmentKeys);
118 		Assert.assertNotNull("Leave blocks not found for user ", leaveBlocks);
119 		Assert.assertTrue("There should be 6 leave blocks, not " + leaveBlocks.size(), leaveBlocks.size()== 6);
120 		
121 		assignmentKeys.add("0_12345_0");
122 		leaveBlocks = leaveBlockService.getLeaveBlocksForTimeCalendar(TEST_USER, LocalDate.fromDateFields(beginDate), LocalDate.fromDateFields(endDate), assignmentKeys);
123 		Assert.assertNotNull("Leave blocks not found for user ", leaveBlocks);
124 		Assert.assertTrue("There should be 2 leave blocks, not " + leaveBlocks.size(), leaveBlocks.size()== 2);
125 		
126 		LeaveBlock lb = LmServiceLocator.getLeaveBlockService().getLeaveBlock("1001");
127 		lb.setRequestStatus(HrConstants.REQUEST_STATUS.APPROVED);
128 		LmServiceLocator.getLeaveBlockService().saveLeaveBlock(lb, TEST_USER);
129 		leaveBlocks = leaveBlockService.getLeaveBlocksForTimeCalendar(TEST_USER, LocalDate.fromDateFields(beginDate), LocalDate.fromDateFields(endDate), assignmentKeys);
130 		Assert.assertTrue("There should be 3 leave blocks, not " + leaveBlocks.size(), leaveBlocks.size()== 3);
131 		Assert.assertTrue("Approved leave block should be in the list", leaveBlocks.contains(lb));
132 	}
133 	
134 	@Test
135 	public void testGetLeaveBlocksForLeaveCalendar() {
136 		// 03/01/2012 to 03/06/2012
137 		Calendar cal = Calendar.getInstance();
138 		cal.setTime(LocalDate.now().toDate());
139 		cal.set(Calendar.YEAR, 2012);
140 		cal.set(Calendar.MONTH, 2);
141 		cal.set(Calendar.DATE, 1);
142 		
143 		Date beginDate = cal.getTime();
144 		cal.add(Calendar.DATE,5);
145 		Date endDate = cal.getTime();
146 		List<String> assignmentKeys = new ArrayList<String>();
147 		List<LeaveBlock> leaveBlocks = leaveBlockService.getLeaveBlocksForLeaveCalendar(TEST_USER, LocalDate.fromDateFields(beginDate), LocalDate.fromDateFields(endDate), assignmentKeys);
148 		Assert.assertNotNull("Leave blocks not found for user ", leaveBlocks);
149 		Assert.assertTrue("There should be 6 leave blocks, not " + leaveBlocks.size(), leaveBlocks.size()== 6);
150 		
151 		assignmentKeys.add("0_12345_0");
152 		leaveBlocks = leaveBlockService.getLeaveBlocksForLeaveCalendar(TEST_USER, LocalDate.fromDateFields(beginDate), LocalDate.fromDateFields(endDate), assignmentKeys);
153 		Assert.assertNotNull("Leave blocks not found for user ", leaveBlocks);
154 		Assert.assertTrue("There should be 5 leave blocks, not " + leaveBlocks.size(), leaveBlocks.size()== 5);
155 		
156 		assignmentKeys.add("1_12345_0");
157 		leaveBlocks = leaveBlockService.getLeaveBlocksForLeaveCalendar(TEST_USER, LocalDate.fromDateFields(beginDate), LocalDate.fromDateFields(endDate), assignmentKeys);
158 		Assert.assertNotNull("Leave blocks not found for user ", leaveBlocks);
159 		Assert.assertTrue("There should be 6 leave blocks, not " + leaveBlocks.size(), leaveBlocks.size()== 6);
160 	}
161 
162 
163 }