KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > validation > JSPDebuggingOverallTest


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.OutputTabOperator;
29 import org.netbeans.jellytools.ProjectsTabOperator;
30 import org.netbeans.jellytools.actions.Action;
31 import org.netbeans.jellytools.actions.DebugProjectAction;
32 import org.netbeans.jellytools.actions.OpenAction;
33 import org.netbeans.jellytools.modules.debugger.AttachDialogOperator;
34 import org.netbeans.jellytools.modules.debugger.SessionsOperator;
35 import org.netbeans.jellytools.modules.debugger.actions.ContinueAction;
36 import org.netbeans.jellytools.modules.debugger.actions.DebugAction;
37 import org.netbeans.jellytools.modules.j2ee.actions.RefreshAction;
38 import org.netbeans.jellytools.modules.j2ee.actions.RestartAction;
39 import org.netbeans.jellytools.modules.j2ee.actions.StartAction;
40 import org.netbeans.jellytools.modules.j2ee.actions.StartDebugAction;
41 import org.netbeans.jellytools.modules.j2ee.actions.StopAction;
42 import org.netbeans.jellytools.modules.j2ee.nodes.J2eeServerNode;
43 import org.netbeans.jellytools.modules.web.nodes.WebPagesNode;
44 import org.netbeans.jellytools.nodes.Node;
45 import org.netbeans.jellytools.nodes.SourcePackagesNode;
46 import org.netbeans.jemmy.Waitable;
47 import org.netbeans.jemmy.Waiter;
48 import org.netbeans.jemmy.Waiter;
49 import org.netbeans.jemmy.operators.ContainerOperator;
50 import org.netbeans.jemmy.operators.JCheckBoxOperator;
51 import org.netbeans.jemmy.operators.JTreeOperator;
52 import org.netbeans.junit.NbTestSuite;
53 import org.netbeans.junit.ide.ProjectSupport;
54
55 /** Test of web application debugging. Manual test specification is here:
56  * http://qa.netbeans.org/modules/webapps/promo-f/jspdebug/jspdebug-testspec.html
57  *
58  * @author Jiri.Skrivanek@sun.com
59  */

60 public class JSPDebuggingOverallTest extends JellyTestCase {
61     // status bar tracer used to wait for state
62
private MainWindowOperator.StatusTextTracer stt;
63     
64     public JSPDebuggingOverallTest(String JavaDoc testName) {
65         super(testName);
66     }
67     
68     public static void main(String JavaDoc[] args) {
69         TestRunner.run(suite());
70     }
71     
72     public static NbTestSuite suite() {
73         NbTestSuite suite = new NbTestSuite();
74         suite.addTest(new JSPDebuggingOverallTest("testOpenProjects"));
75         if(Utils.DEFAULT_SERVER.equals(Utils.TOMCAT)) {
76             suite.addTest(new JSPDebuggingOverallTest("testSetTomcatPort"));
77         }
78         suite.addTest(new JSPDebuggingOverallTest("testRunProject"));
79         suite.addTest(new JSPDebuggingOverallTest("testDebugProject"));
80         suite.addTest(new JSPDebuggingOverallTest("testSetBreakpoint"));
81         suite.addTest(new JSPDebuggingOverallTest("testDebugReload"));
82         suite.addTest(new JSPDebuggingOverallTest("testAttachDebugger"));
83         suite.addTest(new JSPDebuggingOverallTest("testDebugAfterBreakpoint"));
84         suite.addTest(new JSPDebuggingOverallTest("testDebugAndStopServer"));
85         suite.addTest(new JSPDebuggingOverallTest("testStartAnotherSession"));
86         suite.addTest(new JSPDebuggingOverallTest("testJavaSession"));
87         suite.addTest(new JSPDebuggingOverallTest("testStopServer"));
88         return suite;
89     }
90     
91     /** Print test name and initialize status bar tracer. */
92     public void setUp() {
93         System.out.println("######## "+getName()+" #######");
94         stt = MainWindowOperator.getDefault().getStatusTextTracer();
95         // start to track Main Window status bar
96
stt.start();
97         // increase timeout to 60 seconds when waiting for status bar text
98
MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 60000);
99     }
100     
101     /** Stops status bar tracer. */
102     public void tearDown() {
103         stt.stop();
104     }
105     
106     // name of sample web application project
107
private static final String JavaDoc SAMPLE_WEB_PROJECT_NAME = "MainTestApplication"; //NOI18N
108

109     
110     /** Opens test projects. */
111     public void testOpenProjects() {
112         String JavaDoc[] projects = {"MainTestApplication", "TestFreeformLibrary", "TestLibrary", "TestTagLibrary"}; //NOI18N
113
for(int i=0;i<projects.length;i++) {
114             ProjectSupport.openProject(new File JavaDoc(getDataDir(), projects[i]));
115         }
116         // Set Main Project
117
String JavaDoc setMainItem = Bundle.getString("org.netbeans.modules.project.ui.actions.Bundle", "LBL_SetMainProjectAction_Name");
118         new Action(null, setMainItem).perform(new ProjectsTabOperator().getProjectRootNode(SAMPLE_WEB_PROJECT_NAME));
119         // not display browser on run
120
// open project properties
121
ProjectsTabOperator.invoke().getProjectRootNode(SAMPLE_WEB_PROJECT_NAME).properties();
122         // "Project Properties"
123
String JavaDoc projectPropertiesTitle = Bundle.getStringTrimmed("org.netbeans.modules.web.project.ui.customizer.Bundle", "LBL_Customizer_Title");
124         NbDialogOperator propertiesDialogOper = new NbDialogOperator(projectPropertiesTitle);
125         // select "Run" category
126
new Node(new JTreeOperator(propertiesDialogOper), "Run").select();
127         String JavaDoc displayBrowserLabel = Bundle.getStringTrimmed("org.netbeans.modules.web.project.ui.customizer.Bundle", "LBL_CustomizeRun_DisplayBrowser_JCheckBox");
128         new JCheckBoxOperator(propertiesDialogOper, displayBrowserLabel).setSelected(false);
129         // confirm properties dialog
130
propertiesDialogOper.ok();
131     }
132     
133     /** Set a random port for Tomcat server and socket debugger transport. */
134     public void testSetTomcatPort() throws Exception JavaDoc {
135         Utils.setTomcatProperties();
136     }
137     
138     /** Run project. */
139     public void testRunProject() {
140         String JavaDoc runProjectItem = Bundle.getString("org.netbeans.modules.web.project.ui.Bundle", "LBL_RunAction_Name");
141         new Action(null, runProjectItem).perform(new ProjectsTabOperator().getProjectRootNode(SAMPLE_WEB_PROJECT_NAME));
142         Utils.waitFinished(this, SAMPLE_WEB_PROJECT_NAME, "run");
143     }
144     
145     /** Debug project.
146      * - on project node call Debug Project popup
147      * - wait until page appears in browser
148      */

149     public void testDebugProject() {
150         Node rootNode = new ProjectsTabOperator().getProjectRootNode(SAMPLE_WEB_PROJECT_NAME);
151         new DebugProjectAction().perform(rootNode);
152         Utils.waitFinished(this, SAMPLE_WEB_PROJECT_NAME, "debug");
153     }
154     
155     /** Set breakpoint.
156      * - open index.jsp
157      * - select <h1> in editor
158      * - toggle breakpoint at selected line
159      */

160     public void testSetBreakpoint() throws Exception JavaDoc {
161         new OpenAction().performAPI(new Node(new WebPagesNode(SAMPLE_WEB_PROJECT_NAME), "index.jsp")); // NOI18N
162
// find sample file in Editor
163
EditorOperator eo = new EditorOperator("index.jsp"); // NOI18N
164
Utils.setBreakpoint(eo, "<h1>"); // NOI18N
165
}
166     
167     /** Reload browser while debugging.
168      * - reload page in browser
169      * - wait until debugger stops at previously set breakpoint
170      * - continue debugging
171      * - finish debugger
172      */

173     public void testDebugReload() {
174         Utils.reloadPage(SAMPLE_WEB_PROJECT_NAME);
175         // check breakpoint reached
176
// wait status text "Thread main stopped at SampleClass1.java:##"
177
EditorOperator eo = new EditorOperator("index.jsp"); // NOI18N
178
int line = eo.getLineNumber();
179         stt.waitText("index.jsp:"+line);
180         new ContinueAction().perform();
181         Utils.finishDebugger();
182     }
183     
184     /** Attach debugger.
185      * - call Run|Attach Debugger... main menu item
186      * - in Attach dialog set socket attach, port and click OK
187      * - wait User program running appears in status bar
188      * - reload page in browser
189      * - check breakpoint reached
190      * - finish debugger
191      */

192     public void testAttachDebugger() {
193         // assuming server is running in debug mode
194
AttachDialogOperator ado = AttachDialogOperator.invoke();
195         ado.selectConnector(ado.ITEM_SOCKET_ATTACH);
196         ado.setPort(Utils.getSocketPort());
197         ado.ok();
198         // "User program running"
199
String JavaDoc runningLabel = Bundle.getString("org.netbeans.modules.debugger.jpda.ui.Bundle", "CTL_Debugger_running");
200         stt.waitText(runningLabel);
201         Utils.reloadPage(SAMPLE_WEB_PROJECT_NAME);
202         // check breakpoint reached
203
// wait status text "Thread main stopped at SampleClass1.java:##"
204
EditorOperator eo = new EditorOperator("index.jsp"); // NOI18N
205
int line = eo.getLineNumber();
206         stt.waitText("index.jsp:"+line);
207         Utils.finishDebugger();
208     }
209     
210     /** Restart debugger after breakpoint reached.
211      * - start to debug main project from main menu
212      * - wait until debugger stops at previously set breakpoint
213      * - finish debugger
214      * - start debugger again
215      * - wait until debugger stops at breakpoint
216      * - finish debugger
217      */

218     public void testDebugAfterBreakpoint() {
219         // start debugging
220
new DebugProjectAction().perform();
221         Utils.waitFinished(this, SAMPLE_WEB_PROJECT_NAME, "debug");
222         Utils.reloadPage(SAMPLE_WEB_PROJECT_NAME);
223         // check the first breakpoint reached
224
// wait status text "Thread main stopped at index.jsp:##"
225
EditorOperator eo = new EditorOperator("index.jsp"); // NOI18N
226
int line = eo.getLineNumber();
227         stt.waitText("index.jsp:"+line);
228         stt.clear();
229         Utils.finishDebugger();
230         // start debugger again
231
new DebugProjectAction().perform();
232         Utils.waitFinished(this, SAMPLE_WEB_PROJECT_NAME, "debug");
233         Utils.reloadPage(SAMPLE_WEB_PROJECT_NAME);
234         stt.waitText("index.jsp:"+line); // NOI18N
235
Utils.finishDebugger();
236     }
237     
238     /** Restart debugger after server stopped.
239      * - start to debug main project from main menu
240      * - wait until debugger stops at previously set breakpoint
241      * - check it is not possible to stop server
242      * - finish debugger
243      * - stop server
244      * - start debugger again
245      * - wait until debugger stops at breakpoint
246      * - finish debugger
247      */

248     public void testDebugAndStopServer() {
249         // start debugging
250
new DebugProjectAction().perform();
251         Utils.waitFinished(this, SAMPLE_WEB_PROJECT_NAME, "debug");
252         Utils.reloadPage(SAMPLE_WEB_PROJECT_NAME);
253         // check the first breakpoint reached
254
// wait status text "Thread main stopped at index.jsp:##"
255
EditorOperator eo = new EditorOperator("index.jsp"); // NOI18N
256
int line = eo.getLineNumber();
257         stt.waitText("index.jsp:"+line);
258         stt.clear();
259         
260         // check it is not possible to stop server
261
J2eeServerNode serverNode = new J2eeServerNode(Utils.DEFAULT_SERVER);
262         assertFalse("Start action on server node should be disabled when stopped at breakpoint.", new StartAction().isEnabled(serverNode));
263         assertFalse("Stop action on server node should be disabled when stopped at breakpoint.", new StopAction().isEnabled(serverNode));
264         assertFalse("Restart action on server node should be disabled when stopped at breakpoint.", new RestartAction().isEnabled(serverNode));
265         assertFalse("Start in Debug Mode action on server node should be disabled when stopped at breakpoint.", new StartDebugAction().isEnabled(serverNode));
266         assertTrue("Refresh action on server node should be enabled when stopped at breakpoint.", new RefreshAction().isEnabled(serverNode));
267         
268         Utils.finishDebugger();
269         serverNode.stop();
270         // start debugger again
271
new DebugProjectAction().perform();
272         Utils.waitFinished(this, SAMPLE_WEB_PROJECT_NAME, "debug");
273         Utils.reloadPage(SAMPLE_WEB_PROJECT_NAME);
274         stt.waitText("index.jsp:"+line);
275         Utils.finishDebugger();
276     }
277     
278     /** Start another session.
279      * - start to debug main project from main menu
280      * - wait until debugger stops at previously set breakpoint
281      * - try to start debugger again
282      * - wait until message informing that server is in suspended state appears
283      * - try to run project
284      * - wait until message informing that server is in suspended state appears
285      * - finish debugger
286      * - wait for page in browser and close it
287      */

288     public void testStartAnotherSession() {
289         // start debugging
290
new DebugProjectAction().perform();
291         Utils.waitFinished(this, SAMPLE_WEB_PROJECT_NAME, "debug");
292         Utils.reloadPage(SAMPLE_WEB_PROJECT_NAME);
293         // check the first breakpoint reached
294
// wait status text "Thread main stopped at index.jsp:##"
295
EditorOperator eo = new EditorOperator("index.jsp"); // NOI18N
296
int line = eo.getLineNumber();
297         stt.waitText("index.jsp:"+line);
298         
299         new DebugProjectAction().perform();
300         OutputTabOperator outputOper = new OutputTabOperator(SAMPLE_WEB_PROJECT_NAME);
301         // "Cannot perform required operation, since the server is currently in suspended state and thus cannot handle any requests."
302
String JavaDoc suspendedMessage = Bundle.getString("org.netbeans.modules.j2ee.deployment.impl.Bundle", "MSG_ServerSuspended");
303         outputOper.waitText(suspendedMessage);
304         outputOper.close();
305         
306         String JavaDoc runProjectItem = Bundle.getString("org.netbeans.modules.web.project.ui.Bundle", "LBL_RunAction_Name");
307         Action runProjectAction = new Action(null, runProjectItem);
308         runProjectAction.perform(new ProjectsTabOperator().getProjectRootNode(SAMPLE_WEB_PROJECT_NAME));
309         outputOper = new OutputTabOperator(SAMPLE_WEB_PROJECT_NAME);
310         outputOper.waitText(suspendedMessage);
311         outputOper.close();
312         Utils.finishDebugger();
313     }
314     
315     /** Test concurrent java and jsp debugging sessions. Also test debugging
316      * of jsp in sub folder.
317      * - open main class MyBean.java
318      * - set breakpoint in it
319      * - start debugger from popup on MyBean node
320      * - wait until debugger stops at breakpoint
321      * - open page simpleInclude.jsp in incl folder
322      * - set breakpoint in it
323      * - start debugger from popup on simpleInclude.jsp node
324      * - wait until debugger stops at breakpoint
325      * - open Window|Debugging|Session view
326      * - call Make Current popup on MyBean debugging session
327      * - wait until pointer is on breakpoint in MyBean.java
328      * - call Make Current popup on simpleInclude.jsp debugging session
329      * - wait until pointer is on breakpoint in simpleInclude.jsp
330      * - call Finish All popup in Sessions view
331      * - wait until debugger is finished
332      * - close Sessions view
333      */

334     public void testJavaSession() throws Exception JavaDoc {
335         Node beanNode = new Node(new SourcePackagesNode(SAMPLE_WEB_PROJECT_NAME), "org.netbeans.test|MyBean.java"); //NOI18N
336
new OpenAction().performAPI(beanNode); // NOI18N
337
EditorOperator eoBean = new EditorOperator("MyBean.java"); // NOI18N
338
final int lineJavaSource = Utils.setBreakpoint(eoBean, "System.out.println"); // NOI18N
339
new DebugAction().perform(beanNode);
340         stt.waitText("MyBean.java:"+lineJavaSource); //NOI18N
341

342         Node pageNode = new Node(new WebPagesNode(SAMPLE_WEB_PROJECT_NAME), "incl|simpleInclude.jsp"); //NOI18N
343
new OpenAction().performAPI(pageNode);
344         EditorOperator eoPage = new EditorOperator("simpleInclude.jsp"); // NOI18N
345
final int lineJSP = Utils.setBreakpoint(eoPage, "incl/simpleInclude.jsp"); // NOI18N
346
new DebugAction().perform(pageNode);
347         Utils.waitFinished(this, SAMPLE_WEB_PROJECT_NAME, "debug");
348         Utils.reloadPage(SAMPLE_WEB_PROJECT_NAME+"/incl/simpleInclude.jsp");
349         stt.waitText("simpleInclude.jsp:"+lineJSP); //NOI18N
350

351         SessionsOperator so = SessionsOperator.invoke();
352         so.makeCurrent("MyBean"); //NOI18N
353
// wait pointer in editor (two annotations there)
354
new Waiter(new Waitable() {
355             public Object JavaDoc actionProduced(Object JavaDoc editorOper) {
356                 return ((EditorOperator)editorOper).getAnnotations(lineJavaSource).length == 2 ? Boolean.TRUE : null;
357             }
358             public String JavaDoc getDescription() {
359                 return("Wait 2 annotations in editor."); // NOI18N
360
}
361         }).waitAction(eoBean);
362         // when issue 52506 fixed use proper name
363
so.makeCurrent("name");
364         // wait pointer in editor (two annotations there)
365
new Waiter(new Waitable() {
366             public Object JavaDoc actionProduced(Object JavaDoc editorOper) {
367                 return ((EditorOperator)editorOper).getAnnotations(lineJSP).length == 2 ? Boolean.TRUE : null;
368             }
369             public String JavaDoc getDescription() {
370                 return("Wait 2 annotations in editor."); // NOI18N
371
}
372         }).waitAction(eoPage);
373         ContainerOperator debugToolbarOper = Utils.getDebugToolbar();
374         so.finishAll();
375         // wait until Debug toolbar dismiss
376
debugToolbarOper.waitComponentVisible(false);
377         so.close();
378     }
379     
380     /** Stop server just for clean-up.
381      * - stop server and wait until it finishes
382      */

383     public void testStopServer() {
384         J2eeServerNode serverNode = new J2eeServerNode(Utils.DEFAULT_SERVER);
385         serverNode.stop();
386     }
387 }
388
Popular Tags