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.tklm.time.clock.log;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.junit.Assert;
22  import org.junit.Test;
23  import org.kuali.kpme.core.IntegrationTest;
24  import org.kuali.kpme.tklm.TKLMIntegrationTestCase;
25  import org.kuali.kpme.tklm.api.time.timeblock.TimeBlock;
26  import org.kuali.kpme.tklm.time.service.TkServiceLocator;
27  import org.kuali.kpme.tklm.time.timeblock.TimeBlockBo;
28  
29  @IntegrationTest
30  public class ClockLogServiceTest extends TKLMIntegrationTestCase {
31  	
32  	@Test
33  	public void testGetUnapprovedIPWarning() throws Exception {
34  		List<TimeBlock> tbLists = new ArrayList<TimeBlock>();
35  		TimeBlockBo timeBlock = new TimeBlockBo();
36          timeBlock.setUserPrincipalId("testUser");
37          timeBlock.setClockLogCreated(true);
38          timeBlock.setClockLogEndId("5000");
39          tbLists.add(TimeBlockBo.to(timeBlock));
40  		
41  		List<String> warningList = TkServiceLocator.getClockLogService().getUnapprovedIPWarning(tbLists);
42  		Assert.assertTrue("There should be 1 warning message ", warningList.size()== 1);
43  		String warning = warningList.get(0);
44  		Assert.assertTrue("Warning message should be 'Warning: Action 'Clock Out' taken at 03/01/2012 08:08:08.000 was from an unapproved IP address - TEST', not " + warning,
45  				warning.equals("Warning: Action 'Clock Out' taken at 03/01/2012 08:08:08.000 was from an unapproved IP address - TEST"));
46  		
47  	}
48  	
49  	@Test
50  	public void testIsClockLogCreatedByMissedPunch() throws Exception {
51  		boolean isMissedPunch = TkServiceLocator.getClockLogService().isClockLogCreatedByMissedPunch("5000");
52  		Assert.assertTrue("Clock Log 5000 is created by Missed Punch", isMissedPunch);
53  		
54  		isMissedPunch = TkServiceLocator.getClockLogService().isClockLogCreatedByMissedPunch("5001");
55  		Assert.assertFalse("Clock Log 5001 is NOT created by Missed Punch", isMissedPunch);
56  	}
57  }