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