KickJava   Java API By Example, From Geeks To Geeks.

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


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
38 import org.netbeans.jemmy.Timeouts;
39
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 import org.netbeans.web.test.util.Utils;
48
49 import java.io.File JavaDoc;
50
51 import org.netbeans.jemmy.operators.JTextFieldOperator;
52 import org.netbeans.jemmy.operators.JTextComponentOperator;
53
54 public class ExecuteCLFullPathBrowser extends JellyTestCase {
55     private static String JavaDoc workDir = null;
56     private static String JavaDoc webModule = null;
57     private static String JavaDoc wmName = "wm1";
58     private static String JavaDoc fSep = System.getProperty("file.separator");
59     private static Timeouts tm = null;
60     private static String JavaDoc iSep = "|";
61     private static String JavaDoc classes = "Classes";
62     private static String JavaDoc servletForExecution = "ServletForExecution";
63     private static String JavaDoc htmlForExecution = null;;
64     private static String JavaDoc wmForExecution = "wmForExecution";
65     private static String JavaDoc urlToRedirectFromHTML = "RedirectFromHtmlForExecution.html";
66     private static String JavaDoc jspForExecution = null;
67     private static String JavaDoc pkg = "execution";
68     private static ExplorerOperator explorer = null;
69     private static String JavaDoc netscape = null;
70     private static boolean first = true;
71     private String JavaDoc servletId = "cebde3e2-e8f1-4421-8a1c-df11dcc6e79a";
72     private String JavaDoc jspId = "c78eae2b-39f2-4b41-b2be-032e5373d7f4";
73     private String JavaDoc wmId = "9bc4ac0b-0a21-452a-9e51-ca9df3c2fa04";
74     private int defaultPort = 1357;
75     private int port = 2468;
76     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>";
77     
78
79
80     public ExecuteCLFullPathBrowser(java.lang.String JavaDoc testName) {
81         super(testName);
82     }
83
84     public static void main(java.lang.String JavaDoc[] args) {
85         junit.textui.TestRunner.run(suite());
86     }
87          
88     //method required by JUnit
89
public static junit.framework.Test suite() {
90     workDir = System.getProperty("extbrowser.workdir").replace('/', fSep.charAt(0));
91     webModule = workDir + fSep + wmName;
92     htmlForExecution = webModule + iSep + "html" + iSep + "HtmlFileForExecution";
93     jspForExecution = webModule + iSep + "jsp" + iSep + "JSPForExecution";
94     pkg = webModule + iSep + "WEB-INF" + iSep + classes + iSep + pkg;
95     String JavaDoc wmc = System.getProperty("extbrowser.mountcount");
96     int count = 0;
97     if(wmc != null) {
98         count = new Integer JavaDoc(wmc).intValue();
99     }
100     if(first) {
101         while(count >0) {
102         Utils.handleDialogAfterNewWebModule();
103         count--;
104         }
105         first = false;
106     }
107     netscape = fullPathCommand();
108     tm = new Timeouts();
109     tm.initTimeout("Waiter.WaitingTime", 300000); //5 minutes
110
BrowserUtils.setCLBrowser();
111     BrowserUtils.setCLBrowserCommand(netscape);
112     return new NbTestSuite(ExecuteCLFullPathBrowser.class);
113     }
114     
115     public void testExecuteHtml() {
116     NbFrameOperator fo = null;
117     HTMLNode node1 = null;
118     
119     try {
120         node1 = new HTMLNode(htmlForExecution);
121     }catch(Exception JavaDoc e) {
122         fail("Not found: " + htmlForExecution);
123     }
124     new ExecuteAction().perform(node1);
125     HttpRequestWaitable hrw = new HttpRequestWaitable(urlToRedirectFromHTML, defaultAnswer, defaultPort);
126     Waiter w = new Waiter(hrw);
127     w.setTimeouts(tm);
128     try {
129         w.waitAction(hrw);
130     } catch (Exception JavaDoc e) {
131         e.printStackTrace();
132         fail("Looks like browser not started or URL not loaded");
133     }
134     }
135     
136     public void testExecuteSevlet() {
137     ServletNode node1 = null;
138     
139     try {
140         node1 = new ServletNode(pkg + iSep + servletForExecution);
141     }catch(Exception JavaDoc e) {
142         fail("Not found: " + servletForExecution);
143     }
144     JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(servletId, defaultAnswer, port);
145     node1.execute();
146     Waiter w = new Waiter(jsrw);
147     w.setTimeouts(tm);
148     try {
149         w.waitAction(jsrw);
150     } catch (Exception JavaDoc e) {
151         e.printStackTrace();
152         fail("Looks like browser not started or URL not loaded");
153     }
154     }
155
156     public void testExecuteJSP() {
157     JSPNode node1 = null;
158     
159     try {
160         node1 = new JSPNode(jspForExecution);
161     }catch(Exception JavaDoc e) {
162         fail("Not found: " + jspForExecution);
163     }
164     JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(jspId, defaultAnswer, port);
165     node1.execute();
166     Waiter w = new Waiter(jsrw);
167     w.setTimeouts(tm);
168     try {
169         w.waitAction(jsrw);
170     } catch (Exception JavaDoc e) {
171         e.printStackTrace();
172         fail("Looks like browser not started or URL not loaded");
173     }
174     }
175
176     public void testExecuteWebModule() {
177     FolderNode node1 = null;
178     
179     try {
180         node1 = new FolderNode(workDir + fSep + wmForExecution + iSep + "WEB-INF");
181     }catch(Exception JavaDoc e) {
182         fail("Web Module for execution not found");
183     }
184     JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(wmId, defaultAnswer, port);
185     new ExecuteAction().perform(node1);
186     Waiter w = new Waiter(jsrw);
187     w.setTimeouts(tm);
188     try {
189         w.waitAction(jsrw);
190     } catch (Exception JavaDoc e) {
191         e.printStackTrace();
192         fail("Looks like browser not started or URL not loaded");
193     }
194     }
195     
196     private static String JavaDoc fullPathCommand() {
197     String JavaDoc[] paths = null;
198     String JavaDoc command = null;
199     if(System.getProperty("os.name").indexOf("Windows")!=-1) {
200             fail("This test must be extended for Windows platform");
201         }else {
202         String JavaDoc defBr = System.getProperty("extbrowser.default");
203         if(defBr.equals("ns4"))
204         paths = new String JavaDoc[] {"/usr/bin/netscape","/usr/local/bin/netscape","/bin/netscape"};
205         if(defBr.equals("ns6"))
206         paths = new String JavaDoc[] {"/usr/local/netscape6/netscape", "/usr/dt/bin/netscape6","/usr/dt/appconfig/SUNWns6/netscape"};
207         if(defBr.equals("ns7"))
208         paths = new String JavaDoc[] {"/usr/local/netscape/netscape", "/usr/dt/bin/netscape7","/usr/dt/appconfig/SUNWns7/netscape"}; //NB
209
if(defBr.equals("ie6"))
210         paths = null; //NB
211
}
212     for(int i=0;i<paths.length;i++) {
213         if((new File JavaDoc(paths[i])).exists()) {
214         command = paths[i] + " {URL}";
215         i = paths.length;
216         }
217     }
218     if(command == null) {
219         StringBuffer JavaDoc reason = new StringBuffer JavaDoc("Nothing of following commands found on your system : ");
220         for(int i=0;i<paths.length;i++) {
221         reason.append(paths[i] + ";");
222         }
223         fail(reason.toString());
224     }
225     return command;
226     }
227 }
228
Popular Tags