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.assignment.service;
017
018 import java.sql.Date;
019 import java.util.List;
020
021 import org.apache.log4j.Logger;
022 import org.joda.time.DateTime;
023 import org.joda.time.DateTimeZone;
024 import org.junit.Assert;
025 import org.junit.Before;
026 import org.junit.Test;
027 import org.kuali.hr.test.KPMETestCase;
028 import org.kuali.hr.time.assignment.Assignment;
029 import org.kuali.hr.time.assignment.dao.AssignmentDao;
030 import org.kuali.hr.time.calendar.CalendarEntries;
031 import org.kuali.hr.time.service.base.TkServiceLocator;
032 import org.kuali.hr.time.util.TKUtils;
033
034 public class AssignmentServiceImplTest extends KPMETestCase {
035
036 private static final Logger LOG = Logger.getLogger(AssignmentServiceImplTest.class);
037 AssignmentDao assignmentDao = null;
038 AssignmentService assignmentService = null;
039
040 @Before
041 public void setUp() throws Exception {
042 super.setUp();
043 assignmentDao = TkServiceLocator.getAssignmentDao();
044 assignmentService=TkServiceLocator.getAssignmentService();
045 }
046
047 @Test
048 public void testGetAssignments() throws Exception {
049 List<Assignment> assignments = assignmentService.getAssignments("admin", new Date((new DateTime(2010,8,5,1,0,0,0, TKUtils.getSystemDateTimeZone())).getMillis()));
050 Assert.assertNotNull("Null assignment list", assignments);
051 Assert.assertTrue("No assignments found", assignments.size() > 0);
052
053 for(Assignment assign : assignments){
054 Assert.assertNotNull("Null job found", assign.getJob());
055 Assert.assertTrue("Job number is same", assign.getJob().getJobNumber().compareTo(assign.getJobNumber())==0);
056 }
057
058 }
059 @Test
060 public void testGetAssignmentsByCalEntryForLeaveCalendar() throws Exception {
061 CalendarEntries ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("55");
062 List<Assignment> assignments = assignmentService.getAssignmentsByCalEntryForLeaveCalendar("testUser", ce);
063 Assert.assertNotNull("Null assignment list", assignments);
064
065 Assert.assertTrue("Assignments size for Leave calendar should be 2, not " + assignments.size(), assignments.size() == 2);
066 for(Assignment anAssignment : assignments) {
067 Assert.assertTrue("Assignment found for Leave calendar should be '5001' or '5002', not " + anAssignment.getTkAssignmentId(),
068 anAssignment.getTkAssignmentId().equals("5001") || anAssignment.getTkAssignmentId().equals("5002") );
069 }
070 }
071
072 @Test
073 public void testGetAssignmentsByCalEntryForTimeCalendar() throws Exception {
074 CalendarEntries ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("55");
075 List<Assignment> assignments = assignmentService.getAssignmentsByCalEntryForTimeCalendar("testUser", ce);
076 Assert.assertNotNull("Null assignment list", assignments);
077
078 Assert.assertTrue("Assignments size for Time calendar should be 2, not " + assignments.size(), assignments.size() == 2);
079 for(Assignment anAssignment : assignments) {
080 Assert.assertTrue("Assignment found for Time calendar should be '5000' or '5001', not " + anAssignment.getTkAssignmentId(),
081 anAssignment.getTkAssignmentId().equals("5000") || anAssignment.getTkAssignmentId().equals("5001") );
082 }
083
084 }
085 @Test
086 public void testGetAssignmentsByPayEntry() throws Exception {
087 CalendarEntries ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("55");
088 List<Assignment> assignments = assignmentService.getAssignmentsByPayEntry("testUser", ce);
089 Assert.assertNotNull("Null assignment list", assignments);
090 Assert.assertTrue("Assignments size for Calendar Entry 5000 should be 3, not " + assignments.size(), assignments.size() == 3);
091
092 ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("5001");
093 assignments = assignmentService.getAssignmentsByPayEntry("testUser", ce);
094 Assert.assertNotNull("Null assignment list", assignments);
095 Assert.assertTrue("Assignments size for Calendar Entry 5000 should be 4, not " + assignments.size(), assignments.size() == 4);
096 }
097 }