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