View Javadoc

1   /**
2    * Copyright 2004-2012 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.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          //create current timeshee
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 }