KickJava   Java API By Example, From Geeks To Geeks.

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


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
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
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.web.test.util.Utils;
45 import org.netbeans.test.gui.web.util.JSPServletResponseWaitable;
46 import org.netbeans.test.gui.web.util.HttpRequestWaitable;
47 import org.netbeans.test.gui.web.util.BrowserUtils;
48
49 public class ExecuteExternalUnixBrowser extends JellyTestCase {
50     private static String JavaDoc workDir = null;
51     private static String JavaDoc webModule = null;
52     private static String JavaDoc wmName = "wm1";
53     private static String JavaDoc fSep = System.getProperty("file.separator");
54     private static String JavaDoc iSep = "|";
55     private static Timeouts tm = null;
56     private static boolean first = true;
57     private static String JavaDoc classes = "Classes";
58     private static String JavaDoc servletForExecution = "ServletForExecution";
59     private static String JavaDoc htmlForExecution = null;;
60     private static String JavaDoc wmForExecution = "wmForExecution";
61     private static String JavaDoc urlToRedirectFromHTML = "RedirectFromHtmlForExecution.html";
62     private static String JavaDoc jspForExecution = null;
63     private static String JavaDoc pkg = "execution";
64     private static ExplorerOperator explorer = null;
65     private String JavaDoc servletId = "cebde3e2-e8f1-4421-8a1c-df11dcc6e79a";
66     private String JavaDoc jspId = "c78eae2b-39f2-4b41-b2be-032e5373d7f4";
67     private String JavaDoc wmId = "9bc4ac0b-0a21-452a-9e51-ca9df3c2fa04";
68     private int defaultPort = 1357;
69     private int port = 2468;
70     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>";
71     
72
73
74     public ExecuteExternalUnixBrowser(java.lang.String JavaDoc testName) {
75         super(testName);
76     }
77
78     public static void main(java.lang.String JavaDoc[] args) {
79         junit.textui.TestRunner.run(suite());
80     }
81          
82     //method required by JUnit
83
public static junit.framework.Test suite() {
84     workDir = System.getProperty("extbrowser.workdir").replace('/', fSep.charAt(0));
85     webModule = workDir + fSep + wmName;
86     htmlForExecution = webModule + iSep + "html" + iSep + "HtmlFileForExecution";
87     jspForExecution = webModule + iSep + "jsp" + iSep + "JSPForExecution";
88     pkg = webModule + iSep + "WEB-INF" + iSep + classes + iSep + pkg;
89     String JavaDoc wmc = System.getProperty("extbrowser.mountcount");
90     int count = 0;
91     if(wmc != null) {
92         count = new Integer JavaDoc(wmc).intValue();
93     }
94     if(first) {
95         while(count >0) {
96         Utils.handleDialogAfterNewWebModule();
97         count--;
98         }
99         first = false;
100     }
101     tm = new Timeouts();
102     tm.initTimeout("Waiter.WaitingTime", 300000); //5 minutes
103

104     BrowserUtils.setExternalUnixBrowser();
105     return new NbTestSuite(ExecuteExternalUnixBrowser.class);
106     }
107
108     public void testExecuteHtml() {
109     HTMLNode node1 = null;
110     
111     try {
112         node1 = new HTMLNode(htmlForExecution);
113     }catch(Exception JavaDoc e) {
114         fail("Not found: " + htmlForExecution);
115     }
116     new ExecuteAction().perform(node1);
117     HttpRequestWaitable hrw = new HttpRequestWaitable(urlToRedirectFromHTML, defaultAnswer, defaultPort);
118     Waiter w = new Waiter(hrw);
119     w.setTimeouts(tm);
120     try {
121         w.waitAction(hrw);
122     } catch (Exception JavaDoc e) {
123         e.printStackTrace();
124         fail("Looks like browser not started or URL not loaded");
125     }
126     }
127
128     public void testExecuteSevlet() {
129     ServletNode node1 = null;
130     try {
131         node1 = new ServletNode(pkg + iSep + servletForExecution);
132     }catch(Exception JavaDoc e) {
133         fail("Not found: " + servletForExecution);
134     }
135     node1.execute();
136     JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(servletId, defaultAnswer, port);
137     Waiter w = new Waiter(jsrw);
138     w.setTimeouts(tm);
139     try {
140         w.waitAction(jsrw);
141     } catch (Exception JavaDoc e) {
142         e.printStackTrace();
143         fail("Looks like browser not started or URL not loaded");
144     }
145     }
146
147     public void testExecuteJSP() {
148     JSPNode node1 = null;
149     try {
150         node1 = new JSPNode(jspForExecution);
151     }catch(Exception JavaDoc e) {
152         fail("Not found: " + jspForExecution);
153     }
154     node1.execute();
155     JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(jspId, defaultAnswer, port);
156     Waiter w = new Waiter(jsrw);
157     w.setTimeouts(tm);
158     try {
159         w.waitAction(jsrw);
160     } catch (Exception JavaDoc e) {
161         e.printStackTrace();
162         fail("Looks like browser not started or URL not loaded");
163     }
164     }
165
166     public void testExecuteWebModule() {
167     FolderNode node1 = null;
168     try {
169         node1 = new FolderNode(workDir + fSep + wmForExecution + iSep + "WEB-INF");
170     }catch(Exception JavaDoc e) {
171         fail("Web Module for execution not found");
172     }
173     new ExecuteAction().perform(node1);
174     JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(wmId, defaultAnswer, port);
175     Waiter w = new Waiter(jsrw);
176     w.setTimeouts(tm);
177     try {
178         w.waitAction(jsrw);
179     } catch (Exception JavaDoc e) {
180         e.printStackTrace();
181         fail("Looks like browser not started or URL not loaded");
182     }
183     }
184     
185    
186 }
187
Popular Tags