1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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 }