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.hr.time.detail.web;
17  
18  import java.math.BigDecimal;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.junit.Assert;
23  import org.junit.Test;
24  import org.kuali.hr.KPMEWebTestCase;
25  import org.kuali.hr.util.HtmlUnitUtil;
26  import org.kuali.kpme.core.FunctionalTest;
27  import org.kuali.kpme.core.calendar.entry.CalendarEntry;
28  import org.kuali.kpme.core.service.HrServiceLocator;
29  import org.kuali.kpme.core.util.TKUtils;
30  import org.kuali.kpme.tklm.time.rules.graceperiod.GracePeriodRule;
31  import org.kuali.kpme.tklm.time.service.TkServiceLocator;
32  import org.kuali.kpme.tklm.time.timeblock.TimeBlock;
33  import org.kuali.kpme.tklm.time.timehourdetail.TimeHourDetail;
34  import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
35  import org.kuali.kpme.tklm.utils.TkTestConstants;
36  import org.kuali.rice.krad.service.KRADServiceLocator;
37  
38  import com.gargoylesoftware.htmlunit.html.HtmlPage;
39  
40  @FunctionalTest
41  public class ActualTimeInquiryWebTest extends KPMEWebTestCase {
42  	private String documentId;
43  	private TimeBlock timeBlock;
44  
45      @Override
46      public void setUp() throws Exception {
47          super.setUp();
48  
49          CalendarEntry calendarEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry("5000");
50          TimesheetDocument timesheetDocument = TkServiceLocator.getTimesheetService().openTimesheetDocument("admin", calendarEntry);
51          documentId = timesheetDocument.getDocumentId();
52      }
53  
54      @Test
55  	public void testActualTimeInquiry() throws Exception {
56  		String baseUrl = TkTestConstants.Urls.TIME_DETAIL_URL;
57      	HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
58      	Assert.assertNotNull(page);
59      	Assert.assertTrue("Clock Page contains Actual Time Inquiry Button", page.asText().contains("Actual Time Inquiry"));
60  	  	
61  	  	String atiUrl = baseUrl + "?methodToCall=actualTimeInquiry";
62  		HtmlPage testPage1 = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), atiUrl);
63  		Assert.assertNotNull(testPage1);
64  		Assert.assertTrue("Actual Time Inquiry page contains close Button", testPage1.asText().contains("Close"));
65  		Assert.assertTrue("Actual Time Inquiry page contains No value found message", testPage1.asText().contains("No values match this search."));
66      	
67      	this.createTB();
68      	this.changeGracePeriodRule();
69      	atiUrl = baseUrl + "?methodToCall=actualTimeInquiry&documentId=" + documentId;
70      	HtmlPage testPage2 = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), atiUrl);
71      	Assert.assertTrue("Actual Time Inquiry page contains One item retrived message", testPage2.asText().contains("One item retrieved."));
72  	}
73  
74  	public void createTB() {
75  		timeBlock = new TimeBlock();
76  		timeBlock.setUserPrincipalId("admin");
77  		timeBlock.setPrincipalId("admin");
78  		timeBlock.setJobNumber(2L);
79  		timeBlock.setWorkArea(1234L);
80  		timeBlock.setTask(1L);
81  		timeBlock.setEarnCode("RGN");
82  		timeBlock.setBeginTimestamp(TKUtils.getCurrentTimestamp());
83  		timeBlock.setEndTimestamp(TKUtils.getCurrentTimestamp());
84  		TimeHourDetail timeHourDetail = new TimeHourDetail();
85  		timeHourDetail.setEarnCode("RGN");
86  		timeHourDetail.setHours(new BigDecimal(2.0));
87  		timeBlock.getTimeHourDetails().add(timeHourDetail);
88  		timeBlock.setHours(new BigDecimal(2.0));
89  		timeBlock.setClockLogCreated(Boolean.TRUE);
90  		List<TimeBlock> tbList = new ArrayList<TimeBlock>();
91  		timeBlock.setDocumentId(documentId);
92  		tbList.add(timeBlock);
93  		TkServiceLocator.getTimeBlockService().saveTimeBlocks(tbList);
94  
95  		TimesheetDocument td = TkServiceLocator.getTimesheetService().getTimesheetDocument(documentId.toString());
96  		td.setTimeBlocks(tbList);
97  	}
98  	
99  	public void changeGracePeriodRule() {
100 		GracePeriodRule gracePeriodRule = TkServiceLocator.getGracePeriodService().getGracePeriodRule(timeBlock.getBeginDateTime().toLocalDate());
101 		gracePeriodRule.setHourFactor(new BigDecimal("1"));
102 		KRADServiceLocator.getBusinessObjectService().save(gracePeriodRule);
103 	}
104 
105 }