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