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.setJobNumber(2L);
77 timeBlock.setWorkArea(1234L);
78 timeBlock.setTask(1L);
79 timeBlock.setEarnCode("RGN");
80 Timestamp beginTimestamp = new Timestamp(System.currentTimeMillis());
81 timeBlock.setBeginTimestamp(beginTimestamp);
82 Timestamp endTimestamp = new Timestamp(System.currentTimeMillis());
83 timeBlock.setEndTimestamp(endTimestamp);
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 timeBlock.setTkWorkAreaId("1");
91 timeBlock.setTkTaskId("1");
92 timeBlock.setHrJobId("1");
93 List<TimeBlock> tbList = new ArrayList<TimeBlock>();
94 documentId = this.maxDocumentId().toString();
95 timeBlock.setDocumentId(documentId);
96 tbList.add(timeBlock);
97 TkServiceLocator.getTimeBlockService().saveTimeBlocks(tbList);
98
99 TimesheetDocument td = TkServiceLocator.getTimesheetService().getTimesheetDocument(documentId.toString());
100 td.setTimeBlocks(tbList);
101 }
102
103 public void changeGracePeriodRule() {
104 GracePeriodRule gracePeriodRule = TkServiceLocator.getGracePeriodService().getGracePeriodRule(timeBlock.getBeginDate());
105 gracePeriodRule.setHourFactor(new BigDecimal("1"));
106 KRADServiceLocator.getBusinessObjectService().save(gracePeriodRule);
107 }
108
109
110 public Long maxDocumentId() {
111 Collection aCol = KRADServiceLocator.getBusinessObjectService().findAll(TimesheetDocumentHeader.class);
112 Long maxId = new Long(-1);
113 Iterator<TimesheetDocumentHeader> itr = aCol.iterator();
114 while (itr.hasNext()) {
115 TimesheetDocumentHeader tdh = itr.next();
116 Long temp = new Long(tdh.getDocumentId());
117 if(temp > maxId) {
118 maxId = temp;
119 }
120 }
121 return maxId;
122 }
123 }