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.lm.leave.approval;
17  
18  import org.junit.After;
19  import org.junit.Assert;
20  import org.junit.Before;
21  import org.junit.Test;
22  import org.kuali.hr.KPMEWebTestCase;
23  import org.kuali.hr.util.HtmlUnitUtil;
24  import org.kuali.kpme.core.FunctionalTest;
25  import org.kuali.kpme.core.calendar.entry.CalendarEntry;
26  import org.kuali.kpme.core.service.HrServiceLocator;
27  import org.kuali.kpme.tklm.leave.calendar.LeaveCalendarDocument;
28  import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
29  import org.kuali.kpme.tklm.utils.TkTestConstants;
30  
31  import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
32  import com.gargoylesoftware.htmlunit.WebClient;
33  import com.gargoylesoftware.htmlunit.html.HtmlButton;
34  import com.gargoylesoftware.htmlunit.html.HtmlPage;
35  
36  @FunctionalTest
37  public class LeaveCalendarWebTest extends KPMEWebTestCase {
38  	
39  	private String documentId;
40  
41  	@Before
42  	public void setUp() throws Exception {
43  		super.setUp();
44  		
45  		CalendarEntry firstCalendarEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry("202");
46          LeaveCalendarDocument firstLeaveCalendarDocument = LmServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", firstCalendarEntry);
47          documentId = firstLeaveCalendarDocument.getDocumentId();
48          
49          CalendarEntry secondCalendarEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry("203");
50          LmServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", secondCalendarEntry);
51          
52          CalendarEntry thirdCalendarEntry = HrServiceLocator.getCalendarEntryService().getCalendarEntry("204");
53          LmServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", thirdCalendarEntry);
54  	}
55  
56  	@After
57  	public void tearDown() throws Exception {
58  		super.tearDown();
59  	}
60  
61      @Override
62  	public void setWebClient(WebClient webClient) {
63          super.setWebClient(webClient);
64  		webClient.setAjaxController(new NicelyResynchronizingAjaxController());
65  		webClient.waitForBackgroundJavaScript(10000);
66  	}
67  
68  	@Test
69  	public void testLeaveCalendarPage() throws Exception {
70  		// get the page and Login
71  		HtmlPage leaveCalendarPage = HtmlUnitUtil
72  				.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_CALENDAR_URL+"?documentId=" + documentId, true);
73  		Assert.assertNotNull("Leave Request page not found" ,leaveCalendarPage);
74  
75  		//this.setWebClient(leaveCalendarPage.getWebClient());
76  
77  		Assert.assertTrue("Page does not have Current calendar ", leaveCalendarPage.asText().contains("March 2012"));
78  
79          // Check for next document
80          HtmlButton nextButton = (HtmlButton) leaveCalendarPage
81                  .getElementById("nav_next_lc");
82          Assert.assertNotNull(nextButton);
83          //TODO: click not working.  Not even getting to the 'execute' method in LeaveCalendarAction
84          HtmlPage page = nextButton.click();
85          Assert.assertNotNull(page);
86          
87          synchronized (page) {
88              page.wait(5000);
89          }
90          String pageText = page.asText();
91          LOG.info(pageText);
92  		// Check for previous document
93  		HtmlButton prevButton = (HtmlButton) page
94  				.getElementById("nav_prev_lc");
95  		Assert.assertNotNull(prevButton);
96          page = prevButton.click();
97          Assert.assertNotNull(page);
98  
99  	}
100 
101 }