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 java.util.Calendar;
019    
020    import junit.framework.Assert;
021    
022    import org.junit.After;
023    import org.junit.Before;
024    import org.junit.Test;
025    import org.kuali.hr.test.KPMETestCase;
026    import org.kuali.hr.time.test.HtmlUnitUtil;
027    import org.kuali.hr.time.test.TkTestConstants;
028    import org.kuali.hr.time.util.TKUtils;
029    
030    import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
031    import com.gargoylesoftware.htmlunit.WebClient;
032    import com.gargoylesoftware.htmlunit.html.HtmlButton;
033    import com.gargoylesoftware.htmlunit.html.HtmlPage;
034    
035    public class LeaveBlockDisplayWebTest extends KPMETestCase {
036    
037            @Before
038            public void setUp() throws Exception {
039                    super.setUp();
040            }
041    
042            @After
043            public void tearDown() throws Exception {
044                    super.tearDown();
045            }
046    
047            public void setWebClient(WebClient webClient) {
048                    webClient.setJavaScriptEnabled(true);
049                    webClient.setThrowExceptionOnScriptError(true);
050                    webClient.setAjaxController(new NicelyResynchronizingAjaxController());
051                    webClient.waitForBackgroundJavaScript(10000);
052            }
053    
054            @Test
055            public void testLeaveBlockDisplayPage() throws Exception {
056                    // get the page and Login
057                    Calendar currentCalendar = Calendar.getInstance();
058                    HtmlPage leaveBlockDisplayPage = HtmlUnitUtil
059                                    .gotoPageAndLogin(TkTestConstants.Urls.LEAVE_BLOCK_DISPLAY_URL);
060                    Assert.assertNotNull("Leave Request page not found" + leaveBlockDisplayPage);
061    
062                    this.setWebClient(leaveBlockDisplayPage.getWebClient());
063    
064                    // check page contains the current year
065                    Assert.assertTrue("Page is not current year ",
066                                    leaveBlockDisplayPage.asText().contains(Integer.toString(currentCalendar.get(Calendar.YEAR))));
067    
068                    // Check Main section
069                    // depends on injection of test data for current year.
070                    Assert.assertTrue("Page does not contain planned leave ",
071                                    leaveBlockDisplayPage.asText().contains("Send for Approval"));
072    
073                    // check Days Removed in correction section
074                    Assert.assertTrue("Page does not contain approved leaves ",
075                                    leaveBlockDisplayPage.asText().contains("Updated by others"));
076                    
077                    // check Inactive Leave entries
078                    Assert.assertTrue("Page does not contain approved leaves ",
079                                    leaveBlockDisplayPage.asText().contains("Updated by self"));
080                    
081                    // check page contains Document Status column
082                    Assert.assertTrue("Page does not contain Document Status ",
083                                    leaveBlockDisplayPage.asText().contains("Document Status"));
084                    Assert.assertTrue("Page does not contain 'FINAL' Document Status ",
085                                    leaveBlockDisplayPage.asText().contains("FINAL"));
086                    
087                    // check page contains Planning Status column
088                    Assert.assertTrue("Page does not contain Planning Status ",
089                                    leaveBlockDisplayPage.asText().contains("Planning Status"));
090                    
091                    // Check for next year
092                    HtmlButton nextButton = (HtmlButton) leaveBlockDisplayPage
093                                    .getElementById("nav_lb_next");
094                    leaveBlockDisplayPage = nextButton.click();
095    
096                    // check page contains the next year
097                    Assert.assertTrue("Page does not contain next year ",
098                                    leaveBlockDisplayPage.asText().contains(Integer.toString(currentCalendar.get(Calendar.YEAR)+1)));
099            }
100    
101    }