001/**
002 * Copyright 2004-2014 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 */
016package org.kuali.hr.lm.leave.approval;
017
018import org.junit.After;
019import org.junit.Assert;
020import org.junit.Before;
021import org.junit.Test;
022import org.kuali.hr.KPMEWebTestCase;
023import org.kuali.hr.util.HtmlUnitUtil;
024import org.kuali.kpme.core.FunctionalTest;
025import org.kuali.kpme.core.api.calendar.entry.CalendarEntry;
026import org.kuali.kpme.core.calendar.entry.CalendarEntryBo;
027import org.kuali.kpme.core.service.HrServiceLocator;
028import org.kuali.kpme.tklm.leave.calendar.LeaveCalendarDocument;
029import org.kuali.kpme.tklm.leave.service.LmServiceLocator;
030import org.kuali.kpme.tklm.utils.TkTestConstants;
031
032import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
033import com.gargoylesoftware.htmlunit.WebClient;
034import com.gargoylesoftware.htmlunit.html.HtmlButton;
035import com.gargoylesoftware.htmlunit.html.HtmlPage;
036
037@FunctionalTest
038public class LeaveCalendarWebTest extends KPMEWebTestCase {
039        
040        private String documentId;
041
042        @Before
043        public void setUp() throws Exception {
044                super.setUp();
045                
046                CalendarEntry firstCalendarEntry =  HrServiceLocator.getCalendarEntryService().getCalendarEntry("202");
047        LeaveCalendarDocument firstLeaveCalendarDocument = LmServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", firstCalendarEntry);
048        documentId = firstLeaveCalendarDocument.getDocumentId();
049
050        CalendarEntry secondCalendarEntry =  HrServiceLocator.getCalendarEntryService().getCalendarEntry("203");
051        LmServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", secondCalendarEntry);
052        
053        CalendarEntry thirdCalendarEntry =  HrServiceLocator.getCalendarEntryService().getCalendarEntry("204");
054        LmServiceLocator.getLeaveCalendarService().openLeaveCalendarDocument("admin", thirdCalendarEntry);
055        }
056
057        @After
058        public void tearDown() throws Exception {
059                super.tearDown();
060        }
061
062    @Override
063        public void setWebClient(WebClient webClient) {
064        super.setWebClient(webClient);
065                webClient.setAjaxController(new NicelyResynchronizingAjaxController());
066                webClient.waitForBackgroundJavaScript(10000);
067        }
068
069        @Test
070        public void testLeaveCalendarPage() throws Exception {
071                // get the page and Login
072                HtmlPage leaveCalendarPage = HtmlUnitUtil
073                                .gotoPageAndLogin(getWebClient(), TkTestConstants.Urls.LEAVE_CALENDAR_URL+"?documentId=" + documentId, true);
074                Assert.assertNotNull("Leave Request page not found" ,leaveCalendarPage);
075
076                //this.setWebClient(leaveCalendarPage.getWebClient());
077
078                Assert.assertTrue("Page does not have Current calendar ", leaveCalendarPage.asText().contains("March 2012"));
079
080        // Check for next document
081        HtmlButton nextButton = (HtmlButton) leaveCalendarPage
082                .getElementById("nav_next_lc");
083        Assert.assertNotNull(nextButton);
084        //TODO: click not working.  Not even getting to the 'execute' method in LeaveCalendarAction
085        HtmlPage page = nextButton.click();
086        Assert.assertNotNull(page);
087        
088        synchronized (page) {
089            page.wait(5000);
090        }
091        String pageText = page.asText();
092        LOG.info(pageText);
093                // Check for previous document
094                HtmlButton prevButton = (HtmlButton) page
095                                .getElementById("nav_prev_lc");
096                Assert.assertNotNull(prevButton);
097        page = prevButton.click();
098        Assert.assertNotNull(page);
099
100        }
101
102}