001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.time.detail.web; 017 018 import java.math.BigDecimal; 019 import java.sql.Timestamp; 020 import java.util.ArrayList; 021 import java.util.Collection; 022 import java.util.Iterator; 023 import java.util.List; 024 025 import org.junit.Assert; 026 import org.junit.Test; 027 import org.kuali.hr.test.KPMETestCase; 028 import org.kuali.hr.time.graceperiod.rule.GracePeriodRule; 029 import org.kuali.hr.time.service.base.TkServiceLocator; 030 import org.kuali.hr.time.test.HtmlUnitUtil; 031 import org.kuali.hr.time.test.TkTestConstants; 032 import org.kuali.hr.time.timeblock.TimeBlock; 033 import org.kuali.hr.time.timeblock.TimeHourDetail; 034 import org.kuali.hr.time.timesheet.TimesheetDocument; 035 import org.kuali.hr.time.workflow.TimesheetDocumentHeader; 036 import org.kuali.rice.krad.service.KRADServiceLocator; 037 038 import com.gargoylesoftware.htmlunit.html.HtmlPage; 039 040 public class ActualTimeInquiryWebTest extends KPMETestCase { 041 private String documentId; 042 private TimeBlock timeBlock; 043 044 @Override 045 public void setUp() throws Exception { 046 super.setUp(); 047 048 //create current timeshee 049 050 051 } 052 053 @Test 054 public void testActualTimeInquiry() throws Exception { 055 String baseUrl = TkTestConstants.Urls.TIME_DETAIL_URL; 056 HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl); 057 Assert.assertNotNull(page); 058 Assert.assertTrue("Clock Page contains Actual Time Inquiry Button", page.asText().contains("Actual Time Inquiry")); 059 060 String atiUrl = baseUrl + "?methodToCall=actualTimeInquiry"; 061 HtmlPage testPage1 = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), atiUrl); 062 Assert.assertNotNull(testPage1); 063 Assert.assertTrue("Actual Time Inquiry page contains close Button", testPage1.asText().contains("Close")); 064 Assert.assertTrue("Actual Time Inquiry page contains No value found message", testPage1.asText().contains("No values match this search.")); 065 066 this.createTB(); 067 this.changeGracePeriodRule(); 068 atiUrl = baseUrl + "?methodToCall=actualTimeInquiry&documentId=" + documentId; 069 HtmlPage testPage2 = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), atiUrl); 070 Assert.assertTrue("Actual Time Inquiry page contains One item retrived message", testPage2.asText().contains("One item retrieved.")); 071 } 072 073 public void createTB() { 074 timeBlock = new TimeBlock(); 075 timeBlock.setUserPrincipalId("admin"); 076 timeBlock.setPrincipalId("admin"); 077 timeBlock.setJobNumber(2L); 078 timeBlock.setWorkArea(1234L); 079 timeBlock.setTask(1L); 080 timeBlock.setEarnCode("RGN"); 081 Timestamp beginTimestamp = new Timestamp(System.currentTimeMillis()); 082 timeBlock.setBeginTimestamp(beginTimestamp); 083 Timestamp endTimestamp = new Timestamp(System.currentTimeMillis()); 084 timeBlock.setEndTimestamp(endTimestamp); 085 TimeHourDetail timeHourDetail = new TimeHourDetail(); 086 timeHourDetail.setEarnCode("RGN"); 087 timeHourDetail.setHours(new BigDecimal(2.0)); 088 timeBlock.getTimeHourDetails().add(timeHourDetail); 089 timeBlock.setHours(new BigDecimal(2.0)); 090 timeBlock.setClockLogCreated(Boolean.TRUE); 091 List<TimeBlock> tbList = new ArrayList<TimeBlock>(); 092 documentId = this.maxDocumentId().toString(); 093 timeBlock.setDocumentId(documentId); 094 tbList.add(timeBlock); 095 TkServiceLocator.getTimeBlockService().saveTimeBlocks(tbList); 096 097 TimesheetDocument td = TkServiceLocator.getTimesheetService().getTimesheetDocument(documentId.toString()); 098 td.setTimeBlocks(tbList); 099 } 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 }