001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.lm.leave.web;
017
018 import com.gargoylesoftware.htmlunit.html.HtmlButton;
019 import com.gargoylesoftware.htmlunit.html.HtmlPage;
020 import junit.framework.Assert;
021 import org.junit.After;
022 import org.junit.Before;
023 import org.junit.Test;
024 import org.kuali.hr.lm.leavecalendar.LeaveCalendarDocument;
025 import org.kuali.hr.test.KPMETestCase;
026 import org.kuali.hr.time.calendar.CalendarEntries;
027 import org.kuali.hr.time.service.base.TkServiceLocator;
028 import org.kuali.hr.time.test.HtmlUnitUtil;
029 import org.kuali.hr.time.test.TkTestConstants;
030
031
032 public class LeaveCalendarWebTest extends KPMETestCase {
033 private String documentId;
034
035 @Before
036 public void setUp() throws Exception {
037 super.setUp();
038
039 CalendarEntries firstCalendarEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("202");
040 LeaveCalendarDocument firstLeaveCalendarDocument = TkServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", firstCalendarEntry);
041 documentId = firstLeaveCalendarDocument.getDocumentId();
042
043 CalendarEntries secondCalendarEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("203");
044 TkServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", secondCalendarEntry);
045
046 CalendarEntries thirdCalendarEntry = TkServiceLocator.getCalendarEntriesService().getCalendarEntries("204");
047 TkServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", thirdCalendarEntry);
048 }
049
050 @After
051 public void tearDown() throws Exception {
052 super.tearDown();
053 }
054
055 @Test
056 public void testLeaveCalendarPage() throws Exception {
057 // get the page and Login
058 HtmlPage leaveCalendarPage = HtmlUnitUtil
059 .gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_CALENDAR_URL+"?documentId=" + documentId, true);
060 Assert.assertNotNull("Leave Request page not found" ,leaveCalendarPage);
061
062 //this.setWebClient(leaveCalendarPage.getWebClient());
063
064 Assert.assertTrue("Page does not have Current calendar ", leaveCalendarPage.asText().contains("March 2012"));
065
066 // Check for next document
067 HtmlButton nextButton = (HtmlButton) leaveCalendarPage
068 .getElementById("nav_next_lc");
069 Assert.assertNotNull(nextButton);
070 //TODO: click not working. Not even getting to the 'execute' method in LeaveCalendarAction
071 HtmlPage page = nextButton.click();
072 Assert.assertNotNull(page);
073
074 synchronized (page) {
075 page.wait(5000);
076 }
077
078 // Check for previous document
079 HtmlButton prevButton = (HtmlButton) page
080 .getElementById("nav_prev_lc");
081 Assert.assertNotNull(prevButton);
082 page = prevButton.click();
083 Assert.assertNotNull(page);
084
085 }
086
087 }