View Javadoc
1   /**
2    * Copyright 2004-2014 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.joda.time.LocalDate;
21  import org.junit.Assert;
22  import org.junit.Ignore;
23  import org.junit.Test;
24  import org.kuali.hr.KPMEWebTestCase;
25  import org.kuali.hr.util.HtmlUnitUtil;
26  import org.kuali.kpme.core.FunctionalTest;
27  import org.kuali.kpme.core.IntegrationTest;
28  import org.kuali.kpme.tklm.time.service.TkServiceLocator;
29  import org.kuali.kpme.tklm.time.workflow.TimesheetDocumentHeader;
30  import org.kuali.kpme.tklm.utils.TkTestConstants;
31  import org.kuali.rice.krad.service.KRADServiceLocator;
32  
33  import com.gargoylesoftware.htmlunit.html.HtmlPage;
34  
35  @FunctionalTest
36  public class TimesheetDocumentHeaderTest extends KPMEWebTestCase {
37  	
38  	
39  	
40  	private static Long documentId = 1L;//id entered in the bootstrap SQL
41  
42      // this test will pass once the data is correct
43  	//INSERT INTO `tk_document_header_t` (`DOCUMENT_ID`,`PRINCIPAL_ID`,`DOCUMENT_STATUS`,`PAY_BEGIN_DT`,`PAY_END_DT`) VALUES
44  	  //('1001','admin','I','2011-01-01 00:00:00','2011-01-15 00:00:00'),
45  	  //('1002','admin','I','2011-01-15 00:00:00','2011-02-01 00:00:00');
46  	@IntegrationTest
47  	@Test
48  	public void testDocumentHeaderPrevFetch() throws Exception{
49  		TimesheetDocumentHeader timeHeader = new TimesheetDocumentHeader();
50  		timeHeader.setDocumentId("1");
51  		timeHeader.setPrincipalId("admin");
52  		timeHeader.setDocumentStatus("F");
53  		timeHeader.setBeginDateTime(new DateTime(2011, 1, 1, 0, 0, 0));
54  		timeHeader.setEndDateTime(new DateTime(2011, 1, 15, 0, 0, 0));
55  		KRADServiceLocator.getBusinessObjectService().save(timeHeader);
56          DateTime dateTime = new DateTime(2011,1,15,0,0,0,0);
57  		TimesheetDocumentHeader tdh = TkServiceLocator.getTimesheetDocumentHeaderService().getPreviousDocumentHeader("admin", dateTime);
58  		Assert.assertTrue(tdh!=null && StringUtils.equals(tdh.getDocumentId(),"1"));
59  	}
60  	
61  	@Ignore
62  	@FunctionalTest
63  	@Test
64  	public void testDocumentHeaderMaint() throws Exception {
65  		/**
66  		 * 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.
67  		 * When inspected, docHeaderLookUp.asXml() only contains source/data up to the document status field rendered on the form. The field label is rendered,
68  		 * but rendering ceases shortly after.
69  		 * When using docHeaderLookUp.asText(), only the title of the page is displayed "Kuali :: Timesheet Document Header Lookup" followed by a line containing "1."
70  		 * Thus, no input containing text "search" exists and the test fails from an NPE within HtmlUnitUtil.clickInputContainingText(docHeaderLookUp, "search");
71  		 */
72  		HtmlPage docHeaderLookUp = HtmlUnitUtil.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.DOC_HEADER_MAINT_URL);
73  		docHeaderLookUp = HtmlUnitUtil.clickInputContainingText(docHeaderLookUp, "search");
74  		Assert.assertTrue("Page contains admin entry", docHeaderLookUp.asText().contains("admin"));		
75  		HtmlPage maintPage = HtmlUnitUtil.clickAnchorContainingText(docHeaderLookUp, "edit",documentId.toString());
76  		Assert.assertTrue("Maintenance Page contains admin entry",maintPage.asText().contains("admin"));		
77  	}
78  
79  	@Override
80  	public void setUp() throws Exception {
81  		super.setUp();
82  		TimesheetDocumentHeader tdh = new TimesheetDocumentHeader();
83  		tdh.setDocumentId("1234");
84  		tdh.setPrincipalId("admin");
85  		tdh.setBeginDate(LocalDate.now().toDate());
86  		tdh.setEndDate(LocalDate.now().toDate());
87  		
88  		KRADServiceLocator.getBusinessObjectService().save(tdh);
89  		
90  		tdh = new TimesheetDocumentHeader();
91  		tdh.setDocumentId("1000");
92  		tdh.setPrincipalId("admin");
93  		tdh.setBeginDate(LocalDate.now().toDate());
94  		tdh.setEndDate(LocalDate.now().toDate());
95  		
96  		KRADServiceLocator.getBusinessObjectService().save(tdh);
97  		
98  		tdh = new TimesheetDocumentHeader();
99  		tdh.setDocumentId("2345");
100 		tdh.setPrincipalId("admin");
101 		tdh.setBeginDate(LocalDate.now().toDate());
102 		tdh.setEndDate(LocalDate.now().toDate());
103 		
104 		KRADServiceLocator.getBusinessObjectService().save(tdh);
105 	}
106 }