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