KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > gui > web > extbrowser > execution > ExecuteCLBrowser


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.test.gui.web.extbrowser.execution;
21
22 import org.netbeans.jellytools.JellyTestCase;
23 import org.netbeans.jellytools.Bundle;
24 import org.netbeans.jellytools.ExplorerOperator;
25 import org.netbeans.jellytools.NbFrameOperator;
26
27
28
29 import org.netbeans.jellytools.nodes.FolderNode;
30 import org.netbeans.jellytools.nodes.JavaNode;
31 import org.netbeans.jellytools.nodes.HTMLNode;
32
33
34 import org.netbeans.jellytools.actions.ExecuteAction;
35
36 import org.netbeans.junit.NbTestSuite;
37 import org.netbeans.web.test.util.Utils;
38
39 import org.netbeans.jemmy.Timeouts;
40 import org.netbeans.jemmy.Waiter;
41
42 import org.netbeans.web.test.nodes.JSPNode;
43 import org.netbeans.web.test.nodes.ServletNode;
44 import org.netbeans.test.gui.web.util.JSPServletResponseWaitable;
45 import org.netbeans.test.gui.web.util.HttpRequestWaitable;
46 import org.netbeans.test.gui.web.util.BrowserUtils;
47
48
49
50 import org.netbeans.jemmy.operators.JTextFieldOperator;
51 import org.netbeans.jemmy.operators.JTextComponentOperator;
52
53 public class ExecuteCLBrowser extends JellyTestCase {
54     private static String JavaDoc workDir = null;
55     private static String JavaDoc webModule = null;
56     private static String JavaDoc wmName = "wm1";
57     private static String JavaDoc fSep = System.getProperty("file.separator");
58     private static Timeouts tm = null;
59     private static String JavaDoc iSep = "|";
60     private static String JavaDoc classes = "Classes";
61     private static String JavaDoc servletForExecution = "ServletForExecution";
62     private static String JavaDoc htmlForExecution = null;;
63     private static String JavaDoc wmForExecution = "wmForExecution";
64     private static String JavaDoc urlToRedirectFromHTML = "RedirectFromHtmlForExecution.html";
65     private static String JavaDoc jspForExecution = null;
66     private static String JavaDoc pkg = "execution";
67     private static ExplorerOperator explorer = null;
68     private static boolean first = true;
69     private static String JavaDoc netscape = "netscape {URL}";
70     private String JavaDoc servletId = "cebde3e2-e8f1-4421-8a1c-df11dcc6e79a";
71     private String JavaDoc jspId = "c78eae2b-39f2-4b41-b2be-032e5373d7f4";
72     private String JavaDoc wmId = "9bc4ac0b-0a21-452a-9e51-ca9df3c2fa04";
73     private int defaultPort = 1357;
74     private int port = 2468;
75     private String JavaDoc defaultAnswer = "HTTP/1.0 200 OK\nServer: FFJ Automated Tests SimpleServ\nLast-Modified: Fri, 12 Jul 2002 09:53:56 GMT\nContent-Length: 281\nConnection: close\nContent-Type: text/html\n\n<html>\n<head>\n <title>Tests passed</title>\n</head>\n<body>\n<center><H1>Request Accepted</H1></center>\n</body>\n</html>";
76     private static int defaultBrowser = -1;
77     
78
79     public ExecuteCLBrowser(java.lang.String JavaDoc testName) {
80         super(testName);
81     }
82
83     public static void main(java.lang.String JavaDoc[] args) {
84         junit.textui.TestRunner.run(suite());
85     }
86          
87     //method required by JUnit
88
public static junit.framework.Test suite() {
89     workDir = System.getProperty("extbrowser.workdir").replace('/', fSep.charAt(0));
90     webModule = workDir + fSep + wmName;
91     htmlForExecution = webModule + iSep + "html" + iSep + "HtmlFileForExecution";
92     jspForExecution = webModule + iSep + "jsp" + iSep + "JSPForExecution";
93     pkg = webModule + iSep + "WEB-INF" + iSep + classes + iSep + pkg;
94     String JavaDoc defBr = System.getProperty("extbrowser.default");
95     if(defBr.equals("ns4")) {
96         defaultBrowser = BrowserUtils.NETSCAPE4;
97         netscape = "netscape {URL}";
98     }
99     if(defBr.equals("ns6")) {
100         defaultBrowser = BrowserUtils.NETSCAPE6;
101         netscape = "netscape6 {URL}";
102     }
103     if(defBr.equals("ns7")) {
104         defaultBrowser = BrowserUtils.NETSCAPE7;
105         netscape = "netscape7 {URL}";
106     }
107     if(defBr.equals("ie6"))
108         defaultBrowser = BrowserUtils.MSIE6;
109
110     BrowserUtils.setCLBrowser();
111     BrowserUtils.setCLBrowserCommand(netscape);
112     String JavaDoc wmc = System.getProperty("extbrowser.mountcount");
113     int count = 0;
114     if(wmc != null) {
115         count = new Integer JavaDoc(wmc).intValue();
116     }
117     if(first) {
118         while(count >0) {
119         Utils.handleDialogAfterNewWebModule();
120         count--;
121         }
122         first = false;
123     }
124     tm = new Timeouts();
125     tm.initTimeout("Waiter.WaitingTime", 300000); //5 minutes
126
return new NbTestSuite(ExecuteCLBrowser.class);
127     }
128     
129     public void testExecuteHtml() {
130     NbFrameOperator fo = null;
131     HTMLNode node1 = null;
132     try {
133         node1 = new HTMLNode(htmlForExecution);
134     }catch(Exception JavaDoc e) {
135         fail("Not found: " + htmlForExecution);
136     }
137     new ExecuteAction().perform(node1);
138     HttpRequestWaitable hrw = new HttpRequestWaitable(urlToRedirectFromHTML, defaultAnswer, defaultPort);
139     Waiter w = new Waiter(hrw);
140     w.setTimeouts(tm);
141     try {
142         w.waitAction(hrw);
143     } catch (Exception JavaDoc e) {
144         e.printStackTrace();
145         fail("Looks like browser not started or URL not loaded");
146     }
147     if(BrowserUtils.getBrowserVersion(hrw.getUserAgent()) != defaultBrowser) {
148         fail("Wrong browser used.\n" + hrw.getUserAgent() + " instead of " + BrowserUtils.getBrowserDescription(defaultBrowser));
149     }
150     }
151     
152     public void testExecuteSevlet() {
153     ServletNode node1 = null;
154     try {
155         node1 = new ServletNode(pkg + iSep + servletForExecution);
156     }catch(Exception JavaDoc e) {
157         fail("Not found: " + servletForExecution);
158     }
159     JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(servletId, defaultAnswer, port);
160     node1.execute();
161     Waiter w = new Waiter(jsrw);
162     w.setTimeouts(tm);
163     try {
164         w.waitAction(jsrw);
165     } catch (Exception JavaDoc e) {
166         e.printStackTrace();
167         fail("Looks like browser not started or URL not loaded");
168     }
169     }
170
171     public void testExecuteJSP() {
172     JSPNode node1 = null;
173     try {
174         node1 = new JSPNode(jspForExecution);
175     }catch(Exception JavaDoc e) {
176         fail("Not found: " + jspForExecution);
177     }
178     JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(jspId, defaultAnswer, port);
179     node1.execute();
180     Waiter w = new Waiter(jsrw);
181     w.setTimeouts(tm);
182     try {
183         w.waitAction(jsrw);
184     } catch (Exception JavaDoc e) {
185         e.printStackTrace();
186         fail("Looks like browser not started or URL not loaded");
187     }
188     }
189
190     public void testExecuteWebModule() {
191     FolderNode node1 = null;
192     try {
193         node1 = new FolderNode(workDir + fSep + wmForExecution + iSep + "WEB-INF");
194     }catch(Exception JavaDoc e) {
195         fail("Web Module for execution not found");
196     }
197     JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(wmId, defaultAnswer, port);
198     new ExecuteAction().perform(node1);
199     Waiter w = new Waiter(jsrw);
200     w.setTimeouts(tm);
201     try {
202         w.waitAction(jsrw);
203     } catch (Exception JavaDoc e) {
204         e.printStackTrace();
205         fail("Looks like browser not started or URL not loaded");
206     }
207     }
208     
209    
210 }
211
212
213
214
215
216
217
218
219
220
221
222
223
Popular Tags