View Javadoc

1   /**
2    * Copyright 2004-2012 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 com.gargoylesoftware.htmlunit.html.HtmlPage;
19  import org.apache.commons.lang.StringUtils;
20  import org.joda.time.DateTime;
21  import org.junit.Assert;
22  import org.junit.Test;
23  import org.kuali.hr.test.KPMETestCase;
24  import org.kuali.hr.time.service.base.TkServiceLocator;
25  import org.kuali.hr.time.test.HtmlUnitUtil;
26  import org.kuali.hr.time.test.TkTestConstants;
27  import org.kuali.hr.time.test.TkTestUtils;
28  import org.kuali.hr.time.util.TKUtils;
29  import org.kuali.hr.time.workflow.TimesheetDocumentHeader;
30  import org.kuali.rice.krad.service.KRADServiceLocator;
31  
32  public class DocumentHeaderTest extends KPMETestCase {
33  
34  
35  
36  	private static Long documentId = 1L;//id entered in the bootstrap SQL
37  
38      // this test will pass once the data is correct
39  	//INSERT INTO `tk_document_header_t` (`DOCUMENT_ID`,`PRINCIPAL_ID`,`DOCUMENT_STATUS`,`PAY_BEGIN_DT`,`PAY_END_DT`) VALUES
40  	  //('1001','admin','I','2011-01-01 00:00:00','2011-01-15 00:00:00'),
41  	  //('1002','admin','I','2011-01-15 00:00:00','2011-02-01 00:00:00');
42  	@Test
43  	public void testDocumentHeaderPrevFetch() throws Exception{
44  		TimesheetDocumentHeader timeHeader = new TimesheetDocumentHeader();
45  		timeHeader.setDocumentId("1");
46  		timeHeader.setPrincipalId("admin");
47  		timeHeader.setDocumentStatus("F");
48  		timeHeader.setPayBeginDate(TkTestUtils.createDate(1, 1, 2011, 0, 0, 0));
49  		timeHeader.setPayEndDate(TkTestUtils.createDate(1, 15, 2011, 0, 0, 0));
50  		KRADServiceLocator.getBusinessObjectService().save(timeHeader);
51          DateTime dateTime = new DateTime(2011,1,15,0,0,0,0);
52  		TimesheetDocumentHeader tdh = TkServiceLocator.getTimesheetDocumentHeaderService().getPreviousDocumentHeader("admin", new java.util.Date(dateTime.getMillis()));
53  		Assert.assertTrue(tdh!=null && StringUtils.equals(tdh.getDocumentId(),"1"));
54  	}
55  
56  	@Test
57  	public void testDocumentHeaderMaint() throws Exception {
58  		HtmlPage docHeaderLookUp = HtmlUnitUtil.gotoPageAndLogin(TkTestConstants.Urls.DOC_HEADER_MAINT_URL);
59  		docHeaderLookUp = HtmlUnitUtil.clickInputContainingText(docHeaderLookUp, "search");
60  		Assert.assertTrue("Page contains admin entry", docHeaderLookUp.asText().contains("admin"));		
61  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(docHeaderLookUp, "edit",documentId.toString());		
62  		Assert.assertTrue("Maintenance Page contains admin entry",maintPage.asText().contains("admin"));		
63  	}
64  
65  	@Override
66  	public void setUp() throws Exception {
67  		super.setUp();
68  		TimesheetDocumentHeader tdh = new TimesheetDocumentHeader();
69  		tdh.setDocumentId("1234");
70  		tdh.setPrincipalId("admin");
71  		tdh.setPayBeginDate(TKUtils.getCurrentDate());
72  		tdh.setPayEndDate(TKUtils.getCurrentDate());
73  
74  		KRADServiceLocator.getBusinessObjectService().save(tdh);
75  
76  		tdh = new TimesheetDocumentHeader();
77  		tdh.setDocumentId("1000");
78  		tdh.setPrincipalId("admin");
79  		tdh.setPayBeginDate(TKUtils.getCurrentDate());
80  		tdh.setPayEndDate(TKUtils.getCurrentDate());
81  
82  		KRADServiceLocator.getBusinessObjectService().save(tdh);
83  
84  		tdh = new TimesheetDocumentHeader();
85  		tdh.setDocumentId("2345");
86  		tdh.setPrincipalId("admin");
87  		tdh.setPayBeginDate(TKUtils.getCurrentDate());
88  		tdh.setPayEndDate(TKUtils.getCurrentDate());
89  
90  		KRADServiceLocator.getBusinessObjectService().save(tdh);
91  	}
92  }