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.approval.service;
17  
18  import java.text.DateFormat;
19  import java.text.ParseException;
20  import java.text.SimpleDateFormat;
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.junit.Assert;
25  import org.junit.Test;
26  import org.kuali.hr.test.KPMETestCase;
27  import org.kuali.hr.time.service.base.TkServiceLocator;
28  
29  public class TimeApproveServiceTest extends KPMETestCase {
30  	
31  	@Test
32  	public void testGetTimePrincipalIdsWithSearchCriteria() throws ParseException {
33  		List<String> workAreaList = new ArrayList<String>();
34  		String calendarGroup = "payCal";
35  		DateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yy");
36  		java.sql.Date beginDate = new java.sql.Date(DATE_FORMAT.parse("03/01/2012").getTime());
37  		java.sql.Date endDate = new java.sql.Date(DATE_FORMAT.parse("03/30/2012").getTime());
38  		
39  		List<String> idList = TkServiceLocator.getTimeApproveService()
40  								.getTimePrincipalIdsWithSearchCriteria(workAreaList, calendarGroup, endDate, beginDate, endDate);		
41  		Assert.assertTrue("There should be 0 principal ids when searching with empty workarea list, not " + idList.size(), idList.isEmpty());
42  		
43  		workAreaList.add("1111");
44  		workAreaList.add("2222");
45  		idList = TkServiceLocator.getTimeApproveService()
46  					.getTimePrincipalIdsWithSearchCriteria(workAreaList, calendarGroup, endDate, beginDate, endDate);	
47  		// there's an principal id '1033' in setup that does not have jobs with flsaStatus = NE, so it should not be in the search results
48  		Assert.assertTrue("There should be 2 principal ids when searching with both workareas, not " + idList.size(), idList.size() == 2);
49  		for(String anId : idList) {
50  			if(!(anId.equals("1011") || anId.equals("1022"))) {
51  				Assert.fail("PrincipalIds searched with both workareas should be either '1011' or '1022', not " + anId);
52  			}
53  		}
54  		
55  		workAreaList = new ArrayList<String>();
56  		workAreaList.add("1111");
57  		idList = TkServiceLocator.getTimeApproveService()
58  					.getTimePrincipalIdsWithSearchCriteria(workAreaList, calendarGroup, endDate, beginDate, endDate);		
59  		Assert.assertTrue("There should be 1 principal ids for workArea '1111', not " + idList.size(), idList.size() == 1);
60  		Assert.assertTrue("Principal id for workArea '1111' should be principalA, not " + idList.get(0), idList.get(0).equals("1011"));
61  		
62  		workAreaList = new ArrayList<String>();
63  		workAreaList.add("2222");
64  		idList = TkServiceLocator.getTimeApproveService()
65  						.getTimePrincipalIdsWithSearchCriteria(workAreaList, calendarGroup, endDate, beginDate, endDate);	
66  		Assert.assertTrue("There should be 1 principal ids for workArea '2222', not " + idList.size(), idList.size() == 1);
67  		Assert.assertTrue("Principal id for workArea '2222' should be principalB, not " + idList.get(0), idList.get(0).equals("1022"));
68  	}
69  
70  }