1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
50 webClient.setJavaScriptEnabled(false);
51 final HtmlImageInput button = (HtmlImageInput) form.getInputByName(travelDocPage.asXml().substring(idx1, idx2)
52 .replace("&", "&").replace("((<>))", "((<>))"));
53
54 final HtmlPage inquiryPage = (HtmlPage) button.click();
55
56 assertTrue("Inquiry page should have 'Travel Account Inquiry' in title bar", HtmlUnitUtil.pageContainsText(
57 inquiryPage, "Travel Account Inquiry"));
58
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
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 "&", "&").replace("((<>))", "((<>))"));
74 final HtmlPage errorPage = (HtmlPage) button1.click();
75 assertTrue(errorPage.asText().contains("Kuali :: Errors in Request "));
76
77
78
79
80
81
82
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
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 }