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.sql.Timestamp;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Iterator;
23 import java.util.List;
24
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.kuali.hr.test.KPMETestCase;
28 import org.kuali.hr.time.graceperiod.rule.GracePeriodRule;
29 import org.kuali.hr.time.service.base.TkServiceLocator;
30 import org.kuali.hr.time.test.HtmlUnitUtil;
31 import org.kuali.hr.time.test.TkTestConstants;
32 import org.kuali.hr.time.timeblock.TimeBlock;
33 import org.kuali.hr.time.timeblock.TimeHourDetail;
34 import org.kuali.hr.time.timesheet.TimesheetDocument;
35 import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
36 import org.kuali.rice.krad.service.KRADServiceLocator;
37
38 import com.gargoylesoftware.htmlunit.html.HtmlPage;
39
40 public class ActualTimeInquiryWebTest extends KPMETestCase {
41 private String documentId;
42 private TimeBlock timeBlock;
43
44 @Override
45 public void setUp() throws Exception {
46 super.setUp();
47
48
49
50
51 }
52
53 @Test
54 public void testActualTimeInquiry() throws Exception {
55 String baseUrl = TkTestConstants.Urls.TIME_DETAIL_URL;
56 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(baseUrl);
57 Assert.assertNotNull(page);
58 Assert.assertTrue("Clock Page contains Actual Time Inquiry Button", page.asText().contains("Actual Time Inquiry"));
59
60 String atiUrl = baseUrl + "?methodToCall=actualTimeInquiry";
61 HtmlPage testPage1 = HtmlUnitUtil.gotoPageAndLogin(atiUrl);
62 Assert.assertNotNull(testPage1);
63 Assert.assertTrue("Actual Time Inquiry page contains close Button", testPage1.asText().contains("Close"));
64 Assert.assertTrue("Actual Time Inquiry page contains No value found message", testPage1.asText().contains("No values match this search."));
65
66 this.createTB();
67 this.changeGracePeriodRule();
68 atiUrl = baseUrl + "?methodToCall=actualTimeInquiry&documentId=" + documentId;
69 HtmlPage testPage2 = HtmlUnitUtil.gotoPageAndLogin(atiUrl);
70 Assert.assertTrue("Actual Time Inquiry page contains One item retrived message", testPage2.asText().contains("One item retrieved."));
71 }
72
73 public void createTB() {
74 timeBlock = new TimeBlock();
75 timeBlock.setUserPrincipalId("admin");
76 timeBlock.setPrincipalId("admin");
77 timeBlock.setJobNumber(2L);
78 timeBlock.setWorkArea(1234L);
79 timeBlock.setTask(1L);
80 timeBlock.setEarnCode("RGN");
81 Timestamp beginTimestamp = new Timestamp(System.currentTimeMillis());
82 timeBlock.setBeginTimestamp(beginTimestamp);
83 Timestamp endTimestamp = new Timestamp(System.currentTimeMillis());
84 timeBlock.setEndTimestamp(endTimestamp);
85 TimeHourDetail timeHourDetail = new TimeHourDetail();
86 timeHourDetail.setEarnCode("RGN");
87 timeHourDetail.setHours(new BigDecimal(2.0));
88 timeBlock.getTimeHourDetails().add(timeHourDetail);
89 timeBlock.setHours(new BigDecimal(2.0));
90 timeBlock.setClockLogCreated(Boolean.TRUE);
91 List<TimeBlock> tbList = new ArrayList<TimeBlock>();
92 documentId = this.maxDocumentId().toString();
93 timeBlock.setDocumentId(documentId);
94 tbList.add(timeBlock);
95 TkServiceLocator.getTimeBlockService().saveTimeBlocks(tbList);
96
97 TimesheetDocument td = TkServiceLocator.getTimesheetService().getTimesheetDocument(documentId.toString());
98 td.setTimeBlocks(tbList);
99 }
100
101 public void changeGracePeriodRule() {
102 GracePeriodRule gracePeriodRule = TkServiceLocator.getGracePeriodService().getGracePeriodRule(timeBlock.getBeginDate());
103 gracePeriodRule.setHourFactor(new BigDecimal("1"));
104 KRADServiceLocator.getBusinessObjectService().save(gracePeriodRule);
105 }
106
107
108 public Long maxDocumentId() {
109 Collection aCol = KRADServiceLocator.getBusinessObjectService().findAll(TimesheetDocumentHeader.class);
110 Long maxId = new Long(-1);
111 Iterator<TimesheetDocumentHeader> itr = aCol.iterator();
112 while (itr.hasNext()) {
113 TimesheetDocumentHeader tdh = itr.next();
114 Long temp = new Long(tdh.getDocumentId());
115 if(temp > maxId) {
116 maxId = temp;
117 }
118 }
119 return maxId;
120 }
121 }