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