001/**
002 * Copyright 2004-2015 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.document.header;
017
018import org.apache.commons.lang.StringUtils;
019import org.joda.time.DateTime;
020import org.joda.time.LocalDate;
021import org.junit.Assert;
022import org.junit.Ignore;
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.IntegrationTest;
028import org.kuali.kpme.tklm.time.service.TkServiceLocator;
029import org.kuali.kpme.tklm.time.workflow.TimesheetDocumentHeader;
030import org.kuali.kpme.tklm.utils.TkTestConstants;
031import org.kuali.rice.krad.service.KRADServiceLocator;
032
033import com.gargoylesoftware.htmlunit.html.HtmlPage;
034
035@FunctionalTest
036public class TimesheetDocumentHeaderTest extends KPMEWebTestCase {
037        
038        
039        
040        private static Long documentId = 1L;//id entered in the bootstrap SQL
041
042    // this test will pass once the data is correct
043        //INSERT INTO `tk_document_header_t` (`DOCUMENT_ID`,`PRINCIPAL_ID`,`DOCUMENT_STATUS`,`PAY_BEGIN_DT`,`PAY_END_DT`) VALUES
044          //('1001','admin','I','2011-01-01 00:00:00','2011-01-15 00:00:00'),
045          //('1002','admin','I','2011-01-15 00:00:00','2011-02-01 00:00:00');
046        @IntegrationTest
047        @Test
048        public void testDocumentHeaderPrevFetch() throws Exception{
049                TimesheetDocumentHeader timeHeader = new TimesheetDocumentHeader();
050                timeHeader.setDocumentId("1");
051                timeHeader.setPrincipalId("admin");
052                timeHeader.setDocumentStatus("F");
053                timeHeader.setBeginDateTime(new DateTime(2011, 1, 1, 0, 0, 0));
054                timeHeader.setEndDateTime(new DateTime(2011, 1, 15, 0, 0, 0));
055                KRADServiceLocator.getBusinessObjectService().save(timeHeader);
056        DateTime dateTime = new DateTime(2011,1,15,0,0,0,0);
057                TimesheetDocumentHeader tdh = TkServiceLocator.getTimesheetDocumentHeaderService().getPreviousDocumentHeader("admin", dateTime);
058                Assert.assertTrue(tdh!=null && StringUtils.equals(tdh.getDocumentId(),"1"));
059        }
060        
061        @Ignore
062        @FunctionalTest
063        @Test
064        public void testDocumentHeaderMaint() throws Exception {
065                /**
066                 * there are a number of errors appearing from kboot-xxx.js. This may be preventing the KRAD page from rendering completely from an HtmlUnit perspective.
067                 * When inspected, docHeaderLookUp.asXml() only contains source/data up to the document status field rendered on the form. The field label is rendered,
068                 * but rendering ceases shortly after.
069                 * When using docHeaderLookUp.asText(), only the title of the page is displayed "Kuali :: Timesheet Document Header Lookup" followed by a line containing "1."
070                 * Thus, no input containing text "search" exists and the test fails from an NPE within HtmlUnitUtil.clickInputContainingText(docHeaderLookUp, "search");
071                 */
072                HtmlPage docHeaderLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DOC_HEADER_MAINT_URL);
073                docHeaderLookUp = HtmlUnitUtil.clickInputContainingText(docHeaderLookUp, "search");
074                Assert.assertTrue("Page contains admin entry", docHeaderLookUp.asText().contains("admin"));             
075                HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(docHeaderLookUp, "edit",documentId.toString());
076                Assert.assertTrue("Maintenance Page contains admin entry",maintPage.asText().contains("admin"));                
077        }
078
079        @Override
080        public void setUp() throws Exception {
081                super.setUp();
082                TimesheetDocumentHeader tdh = new TimesheetDocumentHeader();
083                tdh.setDocumentId("1234");
084                tdh.setPrincipalId("admin");
085                tdh.setBeginDate(LocalDate.now().toDate());
086                tdh.setEndDate(LocalDate.now().toDate());
087                
088                KRADServiceLocator.getBusinessObjectService().save(tdh);
089                
090                tdh = new TimesheetDocumentHeader();
091                tdh.setDocumentId("1000");
092                tdh.setPrincipalId("admin");
093                tdh.setBeginDate(LocalDate.now().toDate());
094                tdh.setEndDate(LocalDate.now().toDate());
095                
096                KRADServiceLocator.getBusinessObjectService().save(tdh);
097                
098                tdh = new TimesheetDocumentHeader();
099                tdh.setDocumentId("2345");
100                tdh.setPrincipalId("admin");
101                tdh.setBeginDate(LocalDate.now().toDate());
102                tdh.setEndDate(LocalDate.now().toDate());
103                
104                KRADServiceLocator.getBusinessObjectService().save(tdh);
105        }
106}