View Javadoc

1   /**
2    * Copyright 2004-2013 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.web;
17  
18  import com.gargoylesoftware.htmlunit.html.HtmlButton;
19  import com.gargoylesoftware.htmlunit.html.HtmlPage;
20  import junit.framework.Assert;
21  import org.junit.After;
22  import org.junit.Before;
23  import org.junit.Test;
24  import org.kuali.hr.lm.leavecalendar.LeaveCalendarDocument;
25  import org.kuali.hr.test.KPMETestCase;
26  import org.kuali.hr.time.calendar.CalendarEntries;
27  import org.kuali.hr.time.service.base.TkServiceLocator;
28  import org.kuali.hr.time.test.HtmlUnitUtil;
29  import org.kuali.hr.time.test.TkTestConstants;
30  
31  
32  public class LeaveCalendarWebTest extends KPMETestCase {
33  	private String documentId;
34  
35  	@Before
36  	public void setUp() throws Exception {
37  		super.setUp();
38  
39          CalendarEntries firstCalendarEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("202");
40          LeaveCalendarDocument firstLeaveCalendarDocument = TkServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", firstCalendarEntry);
41          documentId = firstLeaveCalendarDocument.getDocumentId();
42  
43          CalendarEntries secondCalendarEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("203");
44          TkServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", secondCalendarEntry);
45  
46          CalendarEntries thirdCalendarEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("204");
47          TkServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", thirdCalendarEntry);
48  	}
49  
50  	@After
51  	public void tearDown() throws Exception {
52  		super.tearDown();
53  	}
54  
55  	@Test
56  	public void testLeaveCalendarPage() throws Exception {
57  		// get the page and Login
58  		HtmlPage leaveCalendarPage = HtmlUnitUtil
59  				.gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_CALENDAR_URL+"?documentId=" + documentId, true);
60  		Assert.assertNotNull("Leave Request page not found" ,leaveCalendarPage);
61  
62  		//this.setWebClient(leaveCalendarPage.getWebClient());
63  
64  		Assert.assertTrue("Page does not have Current calendar ", leaveCalendarPage.asText().contains("March 2012"));
65  
66          // Check for next document
67          HtmlButton nextButton = (HtmlButton) leaveCalendarPage
68                  .getElementById("nav_next_lc");
69          Assert.assertNotNull(nextButton);
70          //TODO: click not working.  Not even getting to the 'execute' method in LeaveCalendarAction
71          HtmlPage page = nextButton.click();
72          Assert.assertNotNull(page);
73  
74          synchronized (page) {
75              page.wait(5000);
76          }
77  
78  		// Check for previous document
79  		HtmlButton prevButton = (HtmlButton) page
80  				.getElementById("nav_prev_lc");
81  		Assert.assertNotNull(prevButton);
82          page = prevButton.click();
83          Assert.assertNotNull(page);
84  
85  	}
86  
87  }