001/**
002 * Copyright 2004-2014 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 */
016package org.kuali.hr.time.detail.web;
017
018import java.math.BigDecimal;
019import java.util.ArrayList;
020import java.util.List;
021
022import org.junit.Assert;
023import org.junit.Test;
024import org.kuali.hr.KPMEWebTestCase;
025import org.kuali.hr.util.HtmlUnitUtil;
026import org.kuali.kpme.core.FunctionalTest;
027import org.kuali.kpme.core.api.calendar.entry.CalendarEntry;
028import org.kuali.kpme.core.calendar.entry.CalendarEntryBo;
029import org.kuali.kpme.core.service.HrServiceLocator;
030import org.kuali.kpme.core.util.TKUtils;
031import org.kuali.kpme.tklm.api.time.timeblock.TimeBlock;
032import org.kuali.kpme.tklm.time.rules.graceperiod.GracePeriodRule;
033import org.kuali.kpme.tklm.time.service.TkServiceLocator;
034import org.kuali.kpme.tklm.time.timeblock.TimeBlockBo;
035import org.kuali.kpme.tklm.time.timehourdetail.TimeHourDetailBo;
036import org.kuali.kpme.tklm.time.timesheet.TimesheetDocument;
037import org.kuali.kpme.tklm.utils.TkTestConstants;
038import org.kuali.rice.krad.service.KRADServiceLocator;
039
040import com.gargoylesoftware.htmlunit.html.HtmlPage;
041
042@FunctionalTest
043public class ActualTimeInquiryWebTest extends KPMEWebTestCase {
044        private String documentId;
045        private TimeBlockBo timeBlock;
046
047    @Override
048    public void setUp() throws Exception {
049        super.setUp();
050
051        CalendarEntry calendarEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry("5000");
052        TimesheetDocument timesheetDocument = TkServiceLocator.getTimesheetService().openTimesheetDocument("admin", calendarEntry);
053        documentId = timesheetDocument.getDocumentId();
054    }
055
056    @Test
057        public void testActualTimeInquiry() throws Exception {
058                String baseUrl = TkTestConstants.Urls.TIME_DETAIL_URL;
059        HtmlPage page = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), baseUrl);
060        Assert.assertNotNull(page);
061        Assert.assertTrue("Clock Page contains Actual Time Inquiry Button", page.asText().contains("Actual Time Inquiry"));
062                
063                String atiUrl = baseUrl + "?methodToCall=actualTimeInquiry";
064                HtmlPage testPage1 = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), atiUrl);
065                Assert.assertNotNull(testPage1);
066                Assert.assertTrue("Actual Time Inquiry page contains close Button", testPage1.asText().contains("Close"));
067                Assert.assertTrue("Actual Time Inquiry page contains No value found message", testPage1.asText().contains("No values match this search."));
068        
069        this.createTB();
070        this.changeGracePeriodRule();
071        atiUrl = baseUrl + "?methodToCall=actualTimeInquiry&documentId=" + documentId;
072        HtmlPage testPage2 = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), atiUrl);
073        Assert.assertTrue("Actual Time Inquiry page contains One item retrived message", testPage2.asText().contains("One item retrieved."));
074        }
075
076        public void createTB() {
077                timeBlock = new TimeBlockBo();
078                timeBlock.setUserPrincipalId("admin");
079                timeBlock.setPrincipalId("admin");
080        timeBlock.setGroupKeyCode("IU-BL");
081                timeBlock.setJobNumber(2L);
082                timeBlock.setWorkArea(1234L);
083                timeBlock.setTask(1L);
084                timeBlock.setEarnCode("RGN");
085                timeBlock.setBeginTimestamp(TKUtils.getCurrentTimestamp());
086                timeBlock.setEndTimestamp(TKUtils.getCurrentTimestamp());
087                TimeHourDetailBo timeHourDetail = new TimeHourDetailBo();
088                timeHourDetail.setEarnCode("RGN");
089                timeHourDetail.setHours(new BigDecimal(2.0));
090        timeHourDetail.setTotalMinutes(BigDecimal.valueOf(120));
091                timeBlock.getTimeHourDetails().add(timeHourDetail);
092                timeBlock.setHours(new BigDecimal(2.0));
093        timeBlock.setTotalMinutes(BigDecimal.valueOf(120));
094                timeBlock.setClockLogCreated(Boolean.TRUE);
095                List<TimeBlock> tbList = new ArrayList<TimeBlock>();
096                timeBlock.setDocumentId(documentId);
097                tbList.add(TimeBlockBo.to(timeBlock));
098                TkServiceLocator.getTimeBlockService().saveTimeBlocks(tbList);
099
100                TimesheetDocument td = TkServiceLocator.getTimesheetService().getTimesheetDocument(documentId);
101                td.setTimeBlocks(tbList);
102        }
103        
104        public void changeGracePeriodRule() {
105                GracePeriodRule gracePeriodRule = TkServiceLocator.getGracePeriodService().getGracePeriodRule(timeBlock.getBeginDateTime().toLocalDate());
106                gracePeriodRule.setHourFactor(new BigDecimal("1"));
107                KRADServiceLocator.getBusinessObjectService().save(gracePeriodRule);
108        }
109
110}