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