KickJava   Java API By Example, From Geeks To Geeks.

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


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
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
48
49
50 import org.netbeans.jemmy.operators.JTextFieldOperator;
51 import org.netbeans.jemmy.operators.JTextComponentOperator;
52
53 public class ExecuteSwingBrowser 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 String JavaDoc iSep = "|";
59     private static String JavaDoc classes = "Classes";
60     private static String JavaDoc servletForExecution = "ServletForExecution";
61     private static String JavaDoc htmlForExecution = null;;
62     private static String JavaDoc wmForExecution = "wmForExecution";
63     private static String JavaDoc urlToRedirectFromHTML = "RedirectFromHtmlForExecution.html";
64     private static String JavaDoc jspForExecution = null;
65     private static String JavaDoc pkg = "execution";
66     private static ExplorerOperator explorer = null;
67     private String JavaDoc servletId = "cebde3e2-e8f1-4421-8a1c-df11dcc6e79a";
68     private String JavaDoc jspId = "c78eae2b-39f2-4b41-b2be-032e5373d7f4";
69     private String JavaDoc wmId = "9bc4ac0b-0a21-452a-9e51-ca9df3c2fa04";
70     private int defaultPort = 1357;
71     private int port = 2468;
72     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>";
73     
74
75
76     public ExecuteSwingBrowser(java.lang.String JavaDoc testName) {
77         super(testName);
78     }
79
80     public static void main(java.lang.String JavaDoc[] args) {
81         junit.textui.TestRunner.run(suite());
82     }
83          
84     //method required by JUnit
85
public static junit.framework.Test suite() {
86     workDir = System.getProperty("extbrowser.workdir").replace('/', fSep.charAt(0));
87     webModule = workDir + fSep + wmName;
88     htmlForExecution = webModule + iSep + "html" + iSep + "HtmlFileForExecution";
89     jspForExecution = webModule + iSep + "jsp" + iSep + "JSPForExecution";
90     pkg = webModule + iSep + "WEB-INF" + iSep + classes + iSep + pkg;
91     return new NbTestSuite(ExecuteSwingBrowser.class);
92     }
93     
94     public void testExecuteHtml() {
95     NbFrameOperator fo = null;
96     HTMLNode node1 = null;
97     BrowserUtils.setSwingBrowser();
98     try {
99         node1 = new HTMLNode(htmlForExecution);
100     }catch(Exception JavaDoc e) {
101         fail("Not found: " + htmlForExecution);
102     }
103     new ExecuteAction().perform(node1);
104     BrowserUtils.handleSwingBrowserDialog();
105     try {
106         fo = new NbFrameOperator("Web Browser");
107     }catch(Exception JavaDoc e) {
108         e.printStackTrace();
109         fail("Looks like browser not started.");
110     }
111     JTextFieldOperator tf = new JTextFieldOperator(fo,0);
112     if(tf.getText().indexOf("HtmlFileForExecution")==-1) {
113         fail("Wrong URL in SWING browser: " + tf.getText());
114     }
115     JTextComponentOperator tf1 = new JTextComponentOperator(fo,0);
116     System.out.println("TEXTFIELD 1: " + tf1.getText());
117     if(tf1.getText().indexOf("Html file executed correctly")==-1) {
118         fail("Wrong CONTENT shown in SWING browser: " + tf1.getText());
119     }
120     }
121     
122     public void testExecuteSevlet() {
123     ServletNode node1 = null;
124     BrowserUtils.setSwingBrowser();
125     try {
126         node1 = new ServletNode(pkg + iSep + servletForExecution);
127     }catch(Exception JavaDoc e) {
128         fail("Not found: " + servletForExecution);
129     }
130     JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(servletId, defaultAnswer, port);
131     node1.execute();
132     BrowserUtils.handleSwingBrowserDialog();
133     Waiter w = new Waiter(jsrw);
134     try {
135         w.waitAction(jsrw);
136     } catch (Exception JavaDoc e) {
137         e.printStackTrace();
138         fail("Looks like browser not started or URL not loaded");
139     }
140     }
141
142     public void testExecuteJSP() {
143     JSPNode node1 = null;
144     BrowserUtils.setSwingBrowser();
145     try {
146         node1 = new JSPNode(jspForExecution);
147     }catch(Exception JavaDoc e) {
148         fail("Not found: " + jspForExecution);
149     }
150     JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(jspId, defaultAnswer, port);
151     node1.execute();
152     BrowserUtils.handleSwingBrowserDialog();
153     Waiter w = new Waiter(jsrw);
154     try {
155         w.waitAction(jsrw);
156     } catch (Exception JavaDoc e) {
157         e.printStackTrace();
158         fail("Looks like browser not started or URL not loaded");
159     }
160     }
161
162     public void testExecuteWebModule() {
163     FolderNode node1 = null;
164     BrowserUtils.setSwingBrowser();
165     try {
166         node1 = new FolderNode(workDir + fSep + wmForExecution + iSep + "WEB-INF");
167     }catch(Exception JavaDoc e) {
168         fail("Web Module for execution not found");
169     }
170     JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(wmId, defaultAnswer, port);
171     new ExecuteAction().perform(node1);
172     BrowserUtils.handleSwingBrowserDialog();
173     Waiter w = new Waiter(jsrw);
174     try {
175         w.waitAction(jsrw);
176     } catch (Exception JavaDoc e) {
177         e.printStackTrace();
178         fail("Looks like browser not started or URL not loaded");
179     }
180     }
181     
182    
183 }
184
Popular Tags