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.core.assignment;
17  
18  import java.util.List;
19  
20  import org.apache.log4j.Logger;
21  import org.joda.time.DateTime;
22  import org.junit.Assert;
23  import org.junit.Before;
24  import org.junit.Test;
25  import org.kuali.kpme.core.CoreUnitTestCase;
26  import org.kuali.kpme.core.IntegrationTest;
27  import org.kuali.kpme.core.assignment.service.AssignmentService;
28  import org.kuali.kpme.core.calendar.entry.CalendarEntry;
29  import org.kuali.kpme.core.service.HrServiceLocator;
30  import org.kuali.kpme.core.util.TKUtils;
31  
32  @IntegrationTest
33  public class AssignmentServiceImplTest extends CoreUnitTestCase {
34  
35  	private static final Logger LOG = Logger.getLogger(AssignmentServiceImplTest.class);
36  	AssignmentService assignmentService = null;
37  
38  	@Before
39  	public void setUp() throws Exception {
40  		super.setUp();
41  		assignmentService=HrServiceLocator.getAssignmentService();
42  	}
43  	
44  	@Test
45  	public void testGetAssignments() throws Exception {
46  		List<Assignment> assignments = assignmentService.getAssignments("admin", new DateTime(2010,8,5,1,0,0,0, TKUtils.getSystemDateTimeZone()).toLocalDate());
47  		Assert.assertNotNull("Null assignment list", assignments);
48  		Assert.assertTrue("No assignments found", assignments.size() > 0);
49  		
50  		for(Assignment assign : assignments){
51  			Assert.assertNotNull("Null job found", assign.getJob());
52  			Assert.assertTrue("Job number is same", assign.getJob().getJobNumber().compareTo(assign.getJobNumber())==0);
53  		}
54  		
55  	}
56  	@Test
57  	public void testGetAssignmentsByCalEntryForLeaveCalendar() throws Exception {
58  		CalendarEntry ce = HrServiceLocator.getCalendarEntryService().getCalendarEntry("55");
59  		List<Assignment> assignments = assignmentService.getAssignmentsByCalEntryForLeaveCalendar("testUser", ce);
60  		Assert.assertNotNull("Null assignment list", assignments);
61  		
62  		Assert.assertTrue("Assignments size for Leave calendar should be 2, not " + assignments.size(), assignments.size() == 2);
63  		for(Assignment anAssignment : assignments) {
64  			Assert.assertTrue("Assignment found for Leave calendar should be '5001' or '5002', not " + anAssignment.getTkAssignmentId(), 
65  					anAssignment.getTkAssignmentId().equals("5001") || anAssignment.getTkAssignmentId().equals("5002") );
66  		}
67  	}
68  	
69  	@Test
70  	public void testGetAssignmentsByCalEntryForTimeCalendar() throws Exception {
71  		CalendarEntry ce = HrServiceLocator.getCalendarEntryService().getCalendarEntry("55");
72  		List<Assignment> assignments = assignmentService.getAssignmentsByCalEntryForTimeCalendar("testUser", ce);
73  		Assert.assertNotNull("Null assignment list", assignments);
74  		
75  		Assert.assertTrue("Assignments size for Time calendar should be 2, not " + assignments.size(), assignments.size() == 2);
76  		for(Assignment anAssignment : assignments) {
77  			Assert.assertTrue("Assignment found for Time calendar should be '5000' or '5001', not " + anAssignment.getTkAssignmentId(), 
78  					anAssignment.getTkAssignmentId().equals("5000") || anAssignment.getTkAssignmentId().equals("5001") );
79  		}
80  		
81  	}
82  	@Test
83  	public void testGetAssignmentsByPayEntry() throws Exception {
84  		CalendarEntry ce = HrServiceLocator.getCalendarEntryService().getCalendarEntry("55");
85  		List<Assignment> assignments = assignmentService.getAssignmentsByPayEntry("testUser", ce);
86  		Assert.assertNotNull("Null assignment list", assignments);
87  		Assert.assertTrue("Assignments size for Calendar Entry 5000 should be 3, not " + assignments.size(), assignments.size() == 3);
88  		
89  		ce = HrServiceLocator.getCalendarEntryService().getCalendarEntry("5001");
90  		assignments = assignmentService.getAssignmentsByPayEntry("testUser", ce);
91  		Assert.assertNotNull("Null assignment list", assignments);
92  		Assert.assertTrue("Assignments size for Calendar Entry 5000 should be 4, not " + assignments.size(), assignments.size() == 4);
93  	}
94  	
95  	@Test
96  	public void testSearchAssignments() throws Exception {
97  		List<Assignment> allResults = HrServiceLocator.getAssignmentService().searchAssignments("admin", null, null, null, null, null, null, "Y", "N");
98  		Assert.assertEquals("Search returned the wrong number of results.", 14, allResults.size());
99  		
100 		List<Assignment> restrictedResults = HrServiceLocator.getAssignmentService().searchAssignments("testuser6", null, null, null, null, null, null, "Y", "N");
101 		Assert.assertEquals("Search returned the wrong number of results.", 5, restrictedResults.size());
102 	}
103 	
104 }