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