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.document.header;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.joda.time.DateTime;
020    import org.junit.Assert;
021    import org.junit.Test;
022    import org.kuali.hr.test.KPMETestCase;
023    import org.kuali.hr.time.service.base.TkServiceLocator;
024    import org.kuali.hr.time.test.HtmlUnitUtil;
025    import org.kuali.hr.time.test.TkTestConstants;
026    import org.kuali.hr.time.test.TkTestUtils;
027    import org.kuali.hr.time.util.TKUtils;
028    import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
029    import org.kuali.rice.krad.service.KRADServiceLocator;
030    
031    import com.gargoylesoftware.htmlunit.html.HtmlPage;
032    
033    public class DocumentHeaderTest extends KPMETestCase {
034            
035            
036            
037            private static Long documentId = 1L;//id entered in the bootstrap SQL
038    
039        // this test will pass once the data is correct
040            //INSERT INTO `tk_document_header_t` (`DOCUMENT_ID`,`PRINCIPAL_ID`,`DOCUMENT_STATUS`,`PAY_BEGIN_DT`,`PAY_END_DT`) VALUES
041              //('1001','admin','I','2011-01-01 00:00:00','2011-01-15 00:00:00'),
042              //('1002','admin','I','2011-01-15 00:00:00','2011-02-01 00:00:00');
043            @Test
044            public void testDocumentHeaderPrevFetch() throws Exception{
045                    TimesheetDocumentHeader timeHeader = new TimesheetDocumentHeader();
046                    timeHeader.setDocumentId("1");
047                    timeHeader.setPrincipalId("admin");
048                    timeHeader.setDocumentStatus("F");
049                    timeHeader.setBeginDate(TkTestUtils.createDate(1, 1, 2011, 0, 0, 0));
050                    timeHeader.setEndDate(TkTestUtils.createDate(1, 15, 2011, 0, 0, 0));
051                    KRADServiceLocator.getBusinessObjectService().save(timeHeader);
052            DateTime dateTime = new DateTime(2011,1,15,0,0,0,0);
053                    TimesheetDocumentHeader tdh = TkServiceLocator.getTimesheetDocumentHeaderService().getPreviousDocumentHeader("admin", new java.util.Date(dateTime.getMillis()));
054                    Assert.assertTrue(tdh!=null && StringUtils.equals(tdh.getDocumentId(),"1"));
055            }
056            
057            @Test
058            public void testDocumentHeaderMaint() throws Exception {
059                    HtmlPage docHeaderLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DOC_HEADER_MAINT_URL);
060                    docHeaderLookUp = HtmlUnitUtil.clickInputContainingText(docHeaderLookUp, "search");
061                    Assert.assertTrue("Page contains admin entry", docHeaderLookUp.asText().contains("admin"));             
062                    HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(docHeaderLookUp, "edit",documentId.toString());             
063                    Assert.assertTrue("Maintenance Page contains admin entry",maintPage.asText().contains("admin"));                
064            }
065    
066            @Override
067            public void setUp() throws Exception {
068                    super.setUp();
069                    TimesheetDocumentHeader tdh = new TimesheetDocumentHeader();
070                    tdh.setDocumentId("1234");
071                    tdh.setPrincipalId("admin");
072                    tdh.setBeginDate(TKUtils.getCurrentDate());
073                    tdh.setEndDate(TKUtils.getCurrentDate());
074                    
075                    KRADServiceLocator.getBusinessObjectService().save(tdh);
076                    
077                    tdh = new TimesheetDocumentHeader();
078                    tdh.setDocumentId("1000");
079                    tdh.setPrincipalId("admin");
080                    tdh.setBeginDate(TKUtils.getCurrentDate());
081                    tdh.setEndDate(TKUtils.getCurrentDate());
082                    
083                    KRADServiceLocator.getBusinessObjectService().save(tdh);
084                    
085                    tdh = new TimesheetDocumentHeader();
086                    tdh.setDocumentId("2345");
087                    tdh.setPrincipalId("admin");
088                    tdh.setBeginDate(TKUtils.getCurrentDate());
089                    tdh.setEndDate(TKUtils.getCurrentDate());
090                    
091                    KRADServiceLocator.getBusinessObjectService().save(tdh);
092            }
093    }