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.approval.service;
017    
018    import java.text.DateFormat;
019    import java.text.ParseException;
020    import java.text.SimpleDateFormat;
021    import java.util.ArrayList;
022    import java.util.List;
023    
024    import org.junit.Assert;
025    import org.junit.Test;
026    import org.kuali.hr.test.KPMETestCase;
027    import org.kuali.hr.time.service.base.TkServiceLocator;
028    
029    public class TimeApproveServiceTest extends KPMETestCase {
030            
031            @Test
032            public void testGetTimePrincipalIdsWithSearchCriteria() throws ParseException {
033                    List<String> workAreaList = new ArrayList<String>();
034                    String calendarGroup = "payCal";
035                    DateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yy");
036                    java.sql.Date beginDate = new java.sql.Date(DATE_FORMAT.parse("03/01/2012").getTime());
037                    java.sql.Date endDate = new java.sql.Date(DATE_FORMAT.parse("03/30/2012").getTime());
038                    
039                    List<String> idList = TkServiceLocator.getTimeApproveService()
040                                                                    .getTimePrincipalIdsWithSearchCriteria(workAreaList, calendarGroup, endDate, beginDate, endDate);               
041                    Assert.assertTrue("There should be 0 principal ids when searching with empty workarea list, not " + idList.size(), idList.isEmpty());
042                    
043                    workAreaList.add("1111");
044                    workAreaList.add("2222");
045                    idList = TkServiceLocator.getTimeApproveService()
046                                            .getTimePrincipalIdsWithSearchCriteria(workAreaList, calendarGroup, endDate, beginDate, endDate);       
047                    // 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
048                    Assert.assertTrue("There should be 2 principal ids when searching with both workareas, not " + idList.size(), idList.size() == 2);
049                    for(String anId : idList) {
050                            if(!(anId.equals("1011") || anId.equals("1022"))) {
051                                    Assert.fail("PrincipalIds searched with both workareas should be either '1011' or '1022', not " + anId);
052                            }
053                    }
054                    
055                    workAreaList = new ArrayList<String>();
056                    workAreaList.add("1111");
057                    idList = TkServiceLocator.getTimeApproveService()
058                                            .getTimePrincipalIdsWithSearchCriteria(workAreaList, calendarGroup, endDate, beginDate, endDate);               
059                    Assert.assertTrue("There should be 1 principal ids for workArea '1111', not " + idList.size(), idList.size() == 1);
060                    Assert.assertTrue("Principal id for workArea '1111' should be principalA, not " + idList.get(0), idList.get(0).equals("1011"));
061                    
062                    workAreaList = new ArrayList<String>();
063                    workAreaList.add("2222");
064                    idList = TkServiceLocator.getTimeApproveService()
065                                                    .getTimePrincipalIdsWithSearchCriteria(workAreaList, calendarGroup, endDate, beginDate, endDate);       
066                    Assert.assertTrue("There should be 1 principal ids for workArea '2222', not " + idList.size(), idList.size() == 1);
067                    Assert.assertTrue("Principal id for workArea '2222' should be principalB, not " + idList.get(0), idList.get(0).equals("1022"));
068            }
069    
070    }