View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.time.document.header;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.joda.time.DateTime;
20  import org.junit.Assert;
21  import org.junit.Test;
22  import org.kuali.hr.test.KPMETestCase;
23  import org.kuali.hr.time.service.base.TkServiceLocator;
24  import org.kuali.hr.time.test.HtmlUnitUtil;
25  import org.kuali.hr.time.test.TkTestConstants;
26  import org.kuali.hr.time.test.TkTestUtils;
27  import org.kuali.hr.time.util.TKUtils;
28  import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
29  import org.kuali.rice.krad.service.KRADServiceLocator;
30  
31  import com.gargoylesoftware.htmlunit.html.HtmlPage;
32  
33  public class DocumentHeaderTest extends KPMETestCase {
34  	
35  	
36  	
37  	private static Long documentId = 1L;//id entered in the bootstrap SQL
38  
39      // this test will pass once the data is correct
40  	//INSERT INTO `tk_document_header_t` (`DOCUMENT_ID`,`PRINCIPAL_ID`,`DOCUMENT_STATUS`,`PAY_BEGIN_DT`,`PAY_END_DT`) VALUES
41  	  //('1001','admin','I','2011-01-01 00:00:00','2011-01-15 00:00:00'),
42  	  //('1002','admin','I','2011-01-15 00:00:00','2011-02-01 00:00:00');
43  	@Test
44  	public void testDocumentHeaderPrevFetch() throws Exception{
45  		TimesheetDocumentHeader timeHeader = new TimesheetDocumentHeader();
46  		timeHeader.setDocumentId("1");
47  		timeHeader.setPrincipalId("admin");
48  		timeHeader.setDocumentStatus("F");
49  		timeHeader.setBeginDate(TkTestUtils.createDate(1, 1, 2011, 0, 0, 0));
50  		timeHeader.setEndDate(TkTestUtils.createDate(1, 15, 2011, 0, 0, 0));
51  		KRADServiceLocator.getBusinessObjectService().save(timeHeader);
52          DateTime dateTime = new DateTime(2011,1,15,0,0,0,0);
53  		TimesheetDocumentHeader tdh = TkServiceLocator.getTimesheetDocumentHeaderService().getPreviousDocumentHeader("admin", new java.util.Date(dateTime.getMillis()));
54  		Assert.assertTrue(tdh!=null && StringUtils.equals(tdh.getDocumentId(),"1"));
55  	}
56  	
57  	@Test
58  	public void testDocumentHeaderMaint() throws Exception {
59  		HtmlPage docHeaderLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DOC_HEADER_MAINT_URL);
60  		docHeaderLookUp = HtmlUnitUtil.clickInputContainingText(docHeaderLookUp, "search");
61  		Assert.assertTrue("Page contains admin entry", docHeaderLookUp.asText().contains("admin"));		
62  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(docHeaderLookUp, "edit",documentId.toString());		
63  		Assert.assertTrue("Maintenance Page contains admin entry",maintPage.asText().contains("admin"));		
64  	}
65  
66  	@Override
67  	public void setUp() throws Exception {
68  		super.setUp();
69  		TimesheetDocumentHeader tdh = new TimesheetDocumentHeader();
70  		tdh.setDocumentId("1234");
71  		tdh.setPrincipalId("admin");
72  		tdh.setBeginDate(TKUtils.getCurrentDate());
73  		tdh.setEndDate(TKUtils.getCurrentDate());
74  		
75  		KRADServiceLocator.getBusinessObjectService().save(tdh);
76  		
77  		tdh = new TimesheetDocumentHeader();
78  		tdh.setDocumentId("1000");
79  		tdh.setPrincipalId("admin");
80  		tdh.setBeginDate(TKUtils.getCurrentDate());
81  		tdh.setEndDate(TKUtils.getCurrentDate());
82  		
83  		KRADServiceLocator.getBusinessObjectService().save(tdh);
84  		
85  		tdh = new TimesheetDocumentHeader();
86  		tdh.setDocumentId("2345");
87  		tdh.setPrincipalId("admin");
88  		tdh.setBeginDate(TKUtils.getCurrentDate());
89  		tdh.setEndDate(TKUtils.getCurrentDate());
90  		
91  		KRADServiceLocator.getBusinessObjectService().save(tdh);
92  	}
93  }