KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > validation > ServletDebuggingTest


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package validation;
20
21 import java.io.File JavaDoc;
22 import junit.textui.TestRunner;
23 import org.netbeans.jellytools.Bundle;
24 import org.netbeans.jellytools.EditorOperator;
25 import org.netbeans.jellytools.JellyTestCase;
26 import org.netbeans.jellytools.MainWindowOperator;
27 import org.netbeans.jellytools.NbDialogOperator;
28 import org.netbeans.jellytools.actions.ActionNoBlock;
29 import org.netbeans.jellytools.actions.OpenAction;
30 import org.netbeans.jellytools.modules.debugger.SourcesOperator;
31 import org.netbeans.jellytools.modules.debugger.actions.ApplyCodeChangesAction;
32 import org.netbeans.jellytools.modules.debugger.actions.StepIntoAction;
33 import org.netbeans.jellytools.modules.debugger.actions.StepOutAction;
34 import org.netbeans.jellytools.modules.debugger.actions.DebugAction;
35 import org.netbeans.jellytools.modules.debugger.actions.StepOverAction;
36 import org.netbeans.jellytools.modules.j2ee.nodes.J2eeServerNode;
37 import org.netbeans.jellytools.nodes.Node;
38 import org.netbeans.jellytools.nodes.SourcePackagesNode;
39 import org.netbeans.junit.NbTestSuite;
40
41 /** Test of web application debugging. Manual test specification is here:
42  * http://qa.netbeans.org/modules/webapps/promo-f/jspdebug/jspdebug-testspec.html
43  *
44  * @author Jiri.Skrivanek@sun.com
45  */

46 public class ServletDebuggingTest extends JellyTestCase {
47     // status bar tracer used to wait for state
48
private MainWindowOperator.StatusTextTracer stt;
49     
50     public ServletDebuggingTest(String JavaDoc testName) {
51         super(testName);
52     }
53     
54     public static void main(String JavaDoc[] args) {
55         TestRunner.run(suite());
56     }
57     
58     public static NbTestSuite suite() {
59         NbTestSuite suite = new NbTestSuite();
60         suite.addTest(new ServletDebuggingTest("testSetBreakpoint"));
61         suite.addTest(new ServletDebuggingTest("testStepInto"));
62         suite.addTest(new ServletDebuggingTest("testStepOut"));
63         suite.addTest(new ServletDebuggingTest("testStepOver"));
64         suite.addTest(new ServletDebuggingTest("testApplyCodeChanges"));
65         suite.addTest(new ServletDebuggingTest("testStopServer"));
66         return suite;
67     }
68     
69     /** Print test name and initialize status bar tracer. */
70     public void setUp() {
71         System.out.println("######## "+getName()+" #######");
72         stt = MainWindowOperator.getDefault().getStatusTextTracer();
73         // start to track Main Window status bar
74
stt.start();
75         // increase timeout to 60 seconds when waiting for status bar text
76
MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 60000);
77         // find servlet node in Projects view
78
servletNode = new Node(new SourcePackagesNode(SAMPLE_WEB_PROJECT_NAME),
79                                "org.netbeans.test.servlets|DivideServlet.java"); //NOI18N
80
}
81     
82     /** Stops status bar tracer. */
83     public void tearDown() {
84         stt.stop();
85     }
86     
87     // name of sample web application project
88
private static final String JavaDoc SAMPLE_WEB_PROJECT_NAME = "MainTestApplication"; //NOI18N
89
// line number of breakpoint
90
private static int line;
91     // servlet node in Projects view
92
private Node servletNode;
93
94     /** Set breakpoint.
95      * - open Source Packages|org.netbeans.test.servlets|DivideServlet.java
96      * - select <h1> in editor
97      * - toggle breakpoint at selected line
98      */

99     public void testSetBreakpoint() throws Exception JavaDoc {
100         new OpenAction().performAPI(servletNode);
101         // find file in Editor
102
EditorOperator eo = new EditorOperator("DivideServlet.java"); // NOI18N
103
line = Utils.setBreakpoint(eo, "<h1>"); // NOI18N
104
}
105
106     /** Step into in Servlet.
107      * - call Debug File popup on servlets node
108      * - wait until debugger stops at previously set breakpoint
109      * - set sources from TestFreeformLibrary to be used for debugging
110      * - call Run|Step Into from main menu
111      * - wait until debugger stops at next line
112      * - call Run|Step Into from main menu again
113      * - wait until debugger stops at line in Divider.java
114      * - find and close editor tab with Divider.java
115      * - finish debugger
116      */

117     public void testStepInto() {
118         new ActionNoBlock(null, new DebugAction().getPopupPath()).perform(servletNode);
119         String JavaDoc setURITitle = Bundle.getString("org.netbeans.modules.web.project.ui.Bundle", "TTL_setServletExecutionUri");
120         new NbDialogOperator(setURITitle).ok();
121         Utils.waitFinished(this, SAMPLE_WEB_PROJECT_NAME, "debug");
122         Utils.reloadPage(SAMPLE_WEB_PROJECT_NAME+"/DivideServlet");
123         stt.waitText("DivideServlet.java:"+line); //NOI18N
124
// set sources from TestFreeformLibrary to be used for debugging
125
SourcesOperator so = SourcesOperator.invoke();
126         so.useSource("TestFreeformLibrary"+File.separator+"src1", true); // NOI18N
127
so.useSource("TestFreeformLibrary"+File.separator+"src2", true); // NOI18N
128
so.close();
129         new StepIntoAction().perform();
130         stt.waitText("DivideServlet.java:"+(line+2)); //NOI18N
131
new StepIntoAction().perform();
132         stt.waitText("Divider.java:"); //NOI18N
133
new EditorOperator("Divider.java").close(); //NOI18N
134
Utils.finishDebugger();
135     }
136
137     /** Step out from servlet.
138      * - call Debug File popup on servlets node
139      * - wait until debugger stops at previously set breakpoint
140      * - call Run|Step Out from main menu
141      * - wait until debugger stops in doGet method
142      * - finish debugger
143      */

144     public void testStepOut() {
145         new DebugAction().perform(servletNode);
146         Utils.waitFinished(this, SAMPLE_WEB_PROJECT_NAME, "debug");
147         Utils.reloadPage(SAMPLE_WEB_PROJECT_NAME+"/DivideServlet");
148         stt.waitText("DivideServlet.java:"+line); //NOI18N
149
stt.clear();
150         new StepOutAction().perform();
151         // it stops at doGet method
152
stt.waitText("DivideServlet.java:"); //NOI18N
153
Utils.finishDebugger();
154     }
155
156     /** Step over servlet.
157      * - call Debug File popup on servlets node
158      * - wait until debugger stops at previously set breakpoint
159      * - call Run|Step Over from main menu
160      * - wait until debugger stops at next line
161      * - call Run|Step Over from main menu again
162      * - wait until debugger stops at next line
163      * - finish debugger
164      */

165     public void testStepOver() {
166         new DebugAction().perform(servletNode);
167         Utils.waitFinished(this, SAMPLE_WEB_PROJECT_NAME, "debug");
168         Utils.reloadPage(SAMPLE_WEB_PROJECT_NAME+"/DivideServlet");
169         stt.waitText("DivideServlet.java:"+line); //NOI18N
170
new StepOverAction().perform();
171         stt.waitText("DivideServlet.java:"+(line+2)); //NOI18N
172
new StepOverAction().perform();
173         stt.waitText("DivideServlet.java:"+(line+4)); //NOI18N
174
Utils.finishDebugger();
175     }
176
177     /** Apply code changes in servlet.
178      * - call Debug File popup on servlets node
179      * - wait until debugger stops at previously set breakpoint
180      * - replace "Servlet DIVIDE" by "Servlet DIVIDE Changed" in DivideServlet.java
181      * - call Run|Apply Code Changes from main menu
182      * - wait until debugger stops somewhere in DivideServlet.java
183      * - finish debugger
184      * - open URL connection and wait for changed text
185      */

186     public void testApplyCodeChanges() {
187         new DebugAction().perform(servletNode);
188         Utils.waitFinished(this, SAMPLE_WEB_PROJECT_NAME, "debug");
189         Utils.reloadPage(SAMPLE_WEB_PROJECT_NAME+"/DivideServlet");
190         stt.waitText("DivideServlet.java:"+line); //NOI18N
191
stt.clear();
192         EditorOperator eo = new EditorOperator("DivideServlet.java"); // NOI18N
193
eo.replace("Servlet DIVIDE", "Servlet DIVIDE Changed"); //NOI18N
194
new ApplyCodeChangesAction().perform();
195         stt.waitText("DivideServlet.java:"); //NOI18N
196
Utils.finishDebugger();
197         Utils.waitText(SAMPLE_WEB_PROJECT_NAME+"/DivideServlet", 240000, "Servlet DIVIDE Changed");
198     }
199     
200     /** Stop server just for clean-up.
201      * - stop server and wait until it finishes
202      */

203     public void testStopServer() {
204         J2eeServerNode serverNode = new J2eeServerNode(Utils.DEFAULT_SERVER);
205         serverNode.stop();
206     }
207 }
208
Popular Tags