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 junit.framework.Assert;
19  
20  import org.junit.After;
21  import org.junit.Before;
22  import org.junit.Ignore;
23  import org.junit.Test;
24  import org.kuali.hr.test.KPMETestCase;
25  import org.kuali.hr.time.test.HtmlUnitUtil;
26  import org.kuali.hr.time.test.TkTestConstants;
27  
28  import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
29  import com.gargoylesoftware.htmlunit.WebClient;
30  import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
31  import com.gargoylesoftware.htmlunit.html.HtmlElement;
32  import com.gargoylesoftware.htmlunit.html.HtmlPage;
33  
34  public class LeaveRequestWebTest extends KPMETestCase {
35  
36  	@Before
37  	public void setUp() throws Exception {
38  		super.setUp();
39  	}
40  
41  	@After
42  	public void tearDown() throws Exception {
43  		super.tearDown();
44  	}
45  
46  	public void setWebClient(WebClient webClient) {
47  		webClient.setJavaScriptEnabled(true);
48  		webClient.setThrowExceptionOnScriptError(true);
49  		webClient.setAjaxController(new NicelyResynchronizingAjaxController());
50  		webClient.waitForBackgroundJavaScript(10000);
51  	}
52  
53  	@Test
54      @Ignore
55  	public void testLeaveRequestPage() throws Exception {
56  		// get the page and Login
57  		HtmlPage leaveRequestPage = HtmlUnitUtil
58  				.gotoPageAndLogin(TkTestConstants.Urls.LEAVE_REQUEST_PAGE_URL);
59  		Assert.assertNotNull("Leave Request page not found" + leaveRequestPage);
60  
61  		// Check planned requests
62  		Assert.assertTrue("Page does not contain planned leave ", leaveRequestPage
63  				.asText().contains("Send for Approval"));
64  
65  		// check Approved Leaves
66  		Assert.assertTrue("Page does not contain approved leaves ", leaveRequestPage
67  				.asText().contains("Approved Leave"));
68  
69  		// check disapproved Leaves
70  		Assert.assertTrue("Page does not contain approved leaves ", leaveRequestPage
71  				.asText().contains("Disapprove"));
72  
73  		HtmlCheckBoxInput htmlElement = (HtmlCheckBoxInput) leaveRequestPage
74  				.getElementByName("plannedLeaves[0].submit");
75  		leaveRequestPage = (HtmlPage) htmlElement.setValueAttribute("true");
76  
77  		HtmlCheckBoxInput checkbox = (HtmlCheckBoxInput) HtmlUnitUtil
78  				.getInputContainingText(leaveRequestPage,
79  						"plannedLeaves[0].submit");
80  		checkbox.setChecked(true);
81  
82  		HtmlElement elementSubmit = leaveRequestPage.getElementByName("Submit");
83  		Assert.assertNotNull(elementSubmit);
84  
85  		HtmlUnitUtil.createTempFile(leaveRequestPage);
86  
87  		HtmlPage leaveRequestPage1 = elementSubmit.click();
88  
89  		HtmlUnitUtil.createTempFile(leaveRequestPage1);
90  
91  		// check if submitted pending leave comes in the section of Requested
92  		// leave
93  		Assert.assertTrue("Page does not contain Pending leave ", leaveRequestPage1
94  				.asText().contains("Send for Approval"));
95  
96  	}
97  
98  }