001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.time.util;
017
018 import java.math.BigDecimal;
019 import java.sql.Date;
020 import java.util.Map;
021 import java.util.ArrayList;
022 import java.util.List;
023
024 import org.joda.time.DateTime;
025 import org.junit.Assert;
026 import org.junit.Test;
027 import org.kuali.hr.lm.leaveblock.LeaveBlock;
028 import org.kuali.hr.test.KPMETestCase;
029 import org.kuali.hr.time.detail.web.ActionFormUtils;
030 import org.kuali.hr.time.earncode.EarnCode;
031 import org.kuali.hr.time.service.base.TkServiceLocator;
032 import org.kuali.hr.time.test.TkTestUtils;
033 import org.kuali.hr.time.timesheet.TimesheetDocument;
034
035 public class ActionFormUtilsTest extends KPMETestCase {
036
037 @Test
038 public void testBuildAssignmentStyleClassMap() {
039 Date aDate = new Date((new DateTime(2011, 7, 7, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis());
040 TimesheetDocument doc = TkTestUtils.populateTimesheetDocument(aDate);
041 Map<String, String> aMap = ActionFormUtils.buildAssignmentStyleClassMap(doc.getTimeBlocks());
042 Assert.assertEquals("Wrong number of classes in style class map", 1, aMap.size());
043 Assert.assertEquals("Wrong key for class assignment0", "assignment0", aMap.get("1_1234_1"));
044 }
045
046 @Test
047 public void testGetUnitOfTimeForEarnCode() throws Exception {
048 // earn code with an existing Accrual category
049 EarnCode earnCode = TkServiceLocator.getEarnCodeService().getEarnCodeById("5000");
050 String unitOfTime = ActionFormUtils.getUnitOfTimeForEarnCode(earnCode);
051 Assert.assertTrue("Unit of Time should be 'D', not " + unitOfTime, unitOfTime.equals("D"));
052 // earn code without an existing accrual category
053 earnCode = TkServiceLocator.getEarnCodeService().getEarnCodeById("5002");
054 unitOfTime = ActionFormUtils.getUnitOfTimeForEarnCode(earnCode);
055 Assert.assertTrue("Unit of Time should be 'H', not " + unitOfTime, unitOfTime.equals("H"));
056
057 }
058
059 @Test
060 public void testGetLeaveBlocksJson() {
061 List<LeaveBlock> lbList = new ArrayList<LeaveBlock>();
062 LeaveBlock lb = new LeaveBlock();
063 lb.setAssignmentTitle("testAssignment");
064 lb.setAssignmentKey("0-123-0");
065 lb.setEarnCode("EarnCode");
066 lb.setLmLeaveBlockId("1111");
067 lb.setLeaveAmount(new BigDecimal(3));
068 lb.setLeaveDate(new Date((new DateTime(2012, 2, 20, 0, 0, 0, 0, TKUtils.getSystemDateTimeZone())).getMillis()));
069 lb.setAccrualGenerated(false);
070 lbList.add(lb);
071
072 String jsonString = ActionFormUtils.getLeaveBlocksJson(lbList);
073 String expectedString = "[{\"title\":\"\",\"assignment\":\"0-123-0\",\"earnCode\":\"EarnCode\",\"lmLeaveBlockId\":\"1111\",\"leaveAmount\":\"3\",\"leaveDate\":\"02\\/20\\/2012\",\"id\":\"1111\",\"canTransfer\":false}]";
074 Assert.assertTrue("Leave Block Json should include assignment", jsonString.equals(expectedString));
075
076
077 }
078
079
080 }