View Javadoc

1   /*
2    * Copyright 2007-2009 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.rice.web.inquirable;
17  
18  import java.net.URL;
19  
20  import org.junit.Ignore;
21  import org.junit.Test;
22  import org.kuali.rice.test.web.HtmlUnitUtil;
23  import org.kuali.rice.web.test.ServerTestBase;
24  
25  import com.gargoylesoftware.htmlunit.BrowserVersion;
26  import com.gargoylesoftware.htmlunit.WebClient;
27  import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
28  import com.gargoylesoftware.htmlunit.html.HtmlForm;
29  import com.gargoylesoftware.htmlunit.html.HtmlImageInput;
30  import com.gargoylesoftware.htmlunit.html.HtmlPage;
31  import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
32  import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
33  
34  @Ignore("KULRICE-3011")
35  public class BaseDirectInquiryTest extends ServerTestBase {
36  
37      @Test
38      public void testDirectInquiry() throws Exception {
39  	final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_6_0);
40  	HtmlPage travelDocPage = gotoPageAndLogin(webClient, HtmlUnitUtil.BASE_URL
41  		+ "/travelDocument2.do?methodToCall=docHandler&command=initiate&docTypeName=TravelRequest");
42  	assertEquals("Kuali :: Travel Doc 2", travelDocPage.getTitleText());
43  	final HtmlForm form = (HtmlForm) travelDocPage.getForms().get(0);
44  	final HtmlTextInput travelAcctNumber = (HtmlTextInput) form.getInputByName("travelAccount.number");
45  	travelAcctNumber.setValueAttribute("a1");
46  	int idx1 = travelDocPage.asXml().indexOf(
47  		"methodToCall.performInquiry.(!!edu.sampleu.travel.bo.TravelAccount!!).((`travelAccount.number:number`))");
48  	int idx2 = travelDocPage.asXml().indexOf("\"", idx1);
49  	// no popup for now
50  	webClient.setJavaScriptEnabled(false);
51  	final HtmlImageInput button = (HtmlImageInput) form.getInputByName(travelDocPage.asXml().substring(idx1, idx2)
52  		.replace("&amp;", "&").replace("((&lt;&gt;))", "((<>))"));
53  
54  	final HtmlPage inquiryPage = (HtmlPage) button.click();
55  	// final HtmlForm form1=(HtmlForm)inquiryPage.getForms().get(0);
56  	assertTrue("Inquiry page should have 'Travel Account Inquiry' in title bar", HtmlUnitUtil.pageContainsText(
57  		inquiryPage, "Travel Account Inquiry"));
58  	// assertTrue(inquiryPage.asText().contains("Type: CAT - Clearing Account "));
59  	HtmlAnchor anchor = (HtmlAnchor) inquiryPage.getHtmlElementById("closeDirectInquiry");
60  	assertNotNull(anchor);
61  	final HtmlPage page = (HtmlPage) anchor.click();
62  	final HtmlForm form2 = (HtmlForm) page.getForms().get(0);
63  	assertEquals("Kuali :: Travel Doc 2", page.getTitleText());
64  	final HtmlTextInput travelAcctNumber1 = (HtmlTextInput) form2.getInputByName("travelAccount.number");
65  	assertEquals(travelAcctNumber1.getValueAttribute(), "a1");
66  
67  	// test account number can't be found
68  	travelAcctNumber1.setValueAttribute("");
69  	idx1 = page.asXml().indexOf(
70  		"methodToCall.performInquiry.(!!edu.sampleu.travel.bo.TravelAccount!!).((`travelAccount.number:number`))");
71  	idx2 = page.asXml().indexOf("\"", idx1);
72  	final HtmlImageInput button1 = (HtmlImageInput) form2.getInputByName(page.asXml().substring(idx1, idx2).replace(
73  		"&amp;", "&").replace("((&lt;&gt;))", "((<>))"));
74  	final HtmlPage errorPage = (HtmlPage) button1.click();
75  	assertTrue(errorPage.asText().contains("Kuali :: Errors in Request "));
76  	// there's no close button on error page, KualiError.jsp, which is what the inquiry will forward to if no input is
77          // specified
78  	// final HtmlForm form3=(HtmlForm)errorPage.getForms().get(0);
79  	// HtmlAnchor anchor1 = (HtmlAnchor)errorPage.getHtmlElementById("closeDirectInquiry");
80  	// assertNotNull(anchor1);
81  	// final HtmlPage page1=(HtmlPage)anchor1.click();
82  	// final HtmlForm form4=(HtmlForm)page1.getForms().get(0);
83  	assertEquals("Kuali :: Travel Doc 2", page.getTitleText());
84  	final HtmlForm form4 = (HtmlForm) page.getForms().get(0);
85  	final HtmlTextInput travelAcctNumber2 = (HtmlTextInput) form4.getInputByName("travelAccount.number");
86  	assertEquals(travelAcctNumber2.getValueAttribute(), "");
87  
88      }
89  
90      private HtmlPage gotoPageAndLogin(WebClient webClient, String url) throws Exception {
91  	// need webclient in the main test program, so create login here. not using from htmlutil
92  	HtmlPage loginPage = (HtmlPage) webClient.getPage(new URL(url));
93  	HtmlForm htmlForm = (HtmlForm) loginPage.getForms().get(0);
94  	htmlForm.getInputByName("__login_user").setValueAttribute("admin");
95  	HtmlSubmitInput button = (HtmlSubmitInput) htmlForm.getInputByValue("Login");
96  	return (HtmlPage) button.click();
97      }
98  
99  }