1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.assignment.service;
17
18 import java.sql.Date;
19 import java.util.List;
20
21 import org.apache.log4j.Logger;
22 import org.joda.time.DateTime;
23 import org.joda.time.DateTimeZone;
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.kuali.hr.test.KPMETestCase;
28 import org.kuali.hr.time.assignment.Assignment;
29 import org.kuali.hr.time.assignment.dao.AssignmentDao;
30 import org.kuali.hr.time.calendar.CalendarEntries;
31 import org.kuali.hr.time.service.base.TkServiceLocator;
32 import org.kuali.hr.time.util.TKUtils;
33
34 public class AssignmentServiceImplTest extends KPMETestCase {
35
36 private static final Logger LOG = Logger.getLogger(AssignmentServiceImplTest.class);
37 AssignmentDao assignmentDao = null;
38 AssignmentService assignmentService = null;
39
40 @Before
41 public void setUp() throws Exception {
42 super.setUp();
43 assignmentDao = TkServiceLocator.getAssignmentDao();
44 assignmentService=TkServiceLocator.getAssignmentService();
45 }
46
47 @Test
48 public void testGetAssignments() throws Exception {
49 List<Assignment> assignments = assignmentService.getAssignments("admin", new Date((new DateTime(2010,8,5,1,0,0,0, TKUtils.getSystemDateTimeZone())).getMillis()));
50 Assert.assertNotNull("Null assignment list", assignments);
51 Assert.assertTrue("No assignments found", assignments.size() > 0);
52
53 for(Assignment assign : assignments){
54 Assert.assertNotNull("Null job found", assign.getJob());
55 Assert.assertTrue("Job number is same", assign.getJob().getJobNumber().compareTo(assign.getJobNumber())==0);
56 }
57
58 }
59 @Test
60 public void testGetAssignmentsByCalEntryForLeaveCalendar() throws Exception {
61 CalendarEntries ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("55");
62 List<Assignment> assignments = assignmentService.getAssignmentsByCalEntryForLeaveCalendar("testUser", ce);
63 Assert.assertNotNull("Null assignment list", assignments);
64
65 Assert.assertTrue("Assignments size for Leave calendar should be 2, not " + assignments.size(), assignments.size() == 2);
66 for(Assignment anAssignment : assignments) {
67 Assert.assertTrue("Assignment found for Leave calendar should be '5001' or '5002', not " + anAssignment.getTkAssignmentId(),
68 anAssignment.getTkAssignmentId().equals("5001") || anAssignment.getTkAssignmentId().equals("5002") );
69 }
70 }
71
72 @Test
73 public void testGetAssignmentsByCalEntryForTimeCalendar() throws Exception {
74 CalendarEntries ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("55");
75 List<Assignment> assignments = assignmentService.getAssignmentsByCalEntryForTimeCalendar("testUser", ce);
76 Assert.assertNotNull("Null assignment list", assignments);
77
78 Assert.assertTrue("Assignments size for Time calendar should be 2, not " + assignments.size(), assignments.size() == 2);
79 for(Assignment anAssignment : assignments) {
80 Assert.assertTrue("Assignment found for Time calendar should be '5000' or '5001', not " + anAssignment.getTkAssignmentId(),
81 anAssignment.getTkAssignmentId().equals("5000") || anAssignment.getTkAssignmentId().equals("5001") );
82 }
83
84 }
85 @Test
86 public void testGetAssignmentsByPayEntry() throws Exception {
87 CalendarEntries ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("55");
88 List<Assignment> assignments = assignmentService.getAssignmentsByPayEntry("testUser", ce);
89 Assert.assertNotNull("Null assignment list", assignments);
90 Assert.assertTrue("Assignments size for Calendar Entry 5000 should be 3, not " + assignments.size(), assignments.size() == 3);
91
92 ce = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("5001");
93 assignments = assignmentService.getAssignmentsByPayEntry("testUser", ce);
94 Assert.assertNotNull("Null assignment list", assignments);
95 Assert.assertTrue("Assignments size for Calendar Entry 5000 should be 4, not " + assignments.size(), assignments.size() == 4);
96 }
97 }