View Javadoc

1   /**
2    * Copyright 2004-2013 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.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  		// earn code with an existing Accrual category
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  		// earn code without an existing accrual category
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  }