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