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 java.util.Calendar;
19  
20  import junit.framework.Assert;
21  
22  import org.junit.After;
23  import org.junit.Before;
24  import org.junit.Test;
25  import org.kuali.hr.test.KPMETestCase;
26  import org.kuali.hr.time.test.HtmlUnitUtil;
27  import org.kuali.hr.time.test.TkTestConstants;
28  import org.kuali.hr.time.util.TKUtils;
29  
30  import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
31  import com.gargoylesoftware.htmlunit.WebClient;
32  import com.gargoylesoftware.htmlunit.html.HtmlButton;
33  import com.gargoylesoftware.htmlunit.html.HtmlPage;
34  
35  public class LeaveBlockDisplayWebTest extends KPMETestCase {
36  
37  	@Before
38  	public void setUp() throws Exception {
39  		super.setUp();
40  	}
41  
42  	@After
43  	public void tearDown() throws Exception {
44  		super.tearDown();
45  	}
46  
47  	public void setWebClient(WebClient webClient) {
48  		webClient.setJavaScriptEnabled(true);
49  		webClient.setThrowExceptionOnScriptError(true);
50  		webClient.setAjaxController(new NicelyResynchronizingAjaxController());
51  		webClient.waitForBackgroundJavaScript(10000);
52  	}
53  
54  	@Test
55  	public void testLeaveBlockDisplayPage() throws Exception {
56  		// get the page and Login
57  		Calendar currentCalendar = Calendar.getInstance();
58  		HtmlPage leaveBlockDisplayPage = HtmlUnitUtil
59  				.gotoPageAndLogin(TkTestConstants.Urls.LEAVE_BLOCK_DISPLAY_URL);
60  		Assert.assertNotNull("Leave Request page not found" + leaveBlockDisplayPage);
61  
62  		this.setWebClient(leaveBlockDisplayPage.getWebClient());
63  
64  		// check page contains the current year
65  		Assert.assertTrue("Page is not current year ",
66  				leaveBlockDisplayPage.asText().contains(Integer.toString(currentCalendar.get(Calendar.YEAR))));
67  
68  		// Check Main section
69  		// depends on injection of test data for current year.
70  		Assert.assertTrue("Page does not contain planned leave ",
71  				leaveBlockDisplayPage.asText().contains("Send for Approval"));
72  
73  		// check Days Removed in correction section
74  		Assert.assertTrue("Page does not contain approved leaves ",
75  				leaveBlockDisplayPage.asText().contains("Updated by others"));
76  		
77  		// check Inactive Leave entries
78  		Assert.assertTrue("Page does not contain approved leaves ",
79  				leaveBlockDisplayPage.asText().contains("Updated by self"));
80  		
81  		// check page contains Document Status column
82  		Assert.assertTrue("Page does not contain Document Status ",
83  				leaveBlockDisplayPage.asText().contains("Document Status"));
84  		Assert.assertTrue("Page does not contain 'FINAL' Document Status ",
85  				leaveBlockDisplayPage.asText().contains("FINAL"));
86  		
87  		// check page contains Planning Status column
88  		Assert.assertTrue("Page does not contain Planning Status ",
89  				leaveBlockDisplayPage.asText().contains("Planning Status"));
90  		
91  		// Check for next year
92  		HtmlButton nextButton = (HtmlButton) leaveBlockDisplayPage
93  				.getElementById("nav_lb_next");
94  		leaveBlockDisplayPage = nextButton.click();
95  
96  		// check page contains the next year
97  		Assert.assertTrue("Page does not contain next year ",
98  				leaveBlockDisplayPage.asText().contains(Integer.toString(currentCalendar.get(Calendar.YEAR)+1)));
99  	}
100 
101 }