KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > debuggercore > StartDebugger


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  * The Original Software is NetBeans.
15  * The Initial Developer of the Original Software is Sun Microsystems, Inc.
16  * Portions created by Sun Microsystems, Inc. are Copyright (C) 2003
17  * All Rights Reserved.
18  *
19  * Contributor(s): Sun Microsystems, Inc.
20  */

21
22 package gui.debuggercore;
23
24 import java.io.File JavaDoc;
25 import junit.textui.TestRunner;
26 import org.netbeans.jellytools.*;
27 import org.netbeans.jellytools.actions.Action;
28 import org.netbeans.jellytools.actions.DebugProjectAction;
29 import org.netbeans.jellytools.actions.OpenAction;
30 import org.netbeans.jellytools.nodes.Node;
31 import org.netbeans.jellytools.nodes.SourcePackagesNode;
32 import org.netbeans.jemmy.JemmyProperties;
33 import org.netbeans.jemmy.util.PNGEncoder;
34 import org.netbeans.junit.NbTestSuite;
35
36 public class StartDebugger extends JellyTestCase {
37     
38     public StartDebugger(String JavaDoc name) {
39         super(name);
40     }
41     
42     public static void main(String JavaDoc[] args) {
43         TestRunner.run(suite());
44     }
45     
46     public static NbTestSuite suite() {
47         NbTestSuite suite = new NbTestSuite();
48         suite.addTest(new StartDebugger("testDebugMainProject"));
49         suite.addTest(new StartDebugger("testDebugProject"));
50         suite.addTest(new StartDebugger("testDebugFile"));
51         suite.addTest(new StartDebugger("testRunDebuggerStepInto"));
52         suite.addTest(new StartDebugger("testRunDebuggerRunToCursor"));
53         return suite;
54     }
55     
56     public void setUp() {
57         System.out.println("######## " + getName() + " #######");
58     }
59     
60     public void tearDown() {
61         JemmyProperties.getCurrentOutput().printTrace("\nteardown\n");
62         Utilities.endAllSessions();
63     }
64     
65     public void testDebugMainProject() throws Throwable JavaDoc {
66         try {
67             new Action(Utilities.runMenu+"|"+Utilities.debugMainProjectItem, null).perform();
68             Utilities.getDebugToolbar().waitComponentVisible(true);
69             Utilities.waitDebuggerConsole(Utilities.runningStatusBarText, 0);
70         } catch (Throwable JavaDoc th) {
71             try {
72                 // capture screen before cleanup in finally clause is completed
73
PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png");
74             } catch (Exception JavaDoc e1) {
75                 // ignore it
76
}
77             throw th;
78         }
79     }
80     
81     public void testDebugProject() throws Throwable JavaDoc {
82         try {
83             Node projectNode = ProjectsTabOperator.invoke().getProjectRootNode(Utilities.testProjectName);
84             new DebugProjectAction().perform(projectNode);
85             Utilities.getDebugToolbar().waitComponentVisible(true);
86             Utilities.waitDebuggerConsole(Utilities.runningStatusBarText, 0);
87         } catch (Throwable JavaDoc th) {
88             try {
89                 // capture screen before cleanup in finally clause is completed
90
PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png");
91             } catch (Exception JavaDoc e1) {
92                 // ignore it
93
}
94             throw th;
95         }
96     }
97     
98     public void testDebugFile() throws Throwable JavaDoc {
99         try {
100             //open source
101
Node beanNode = new Node(new SourcePackagesNode(Utilities.testProjectName), "examples.advanced|MemoryView.java"); //NOI18N
102
new OpenAction().performAPI(beanNode); // NOI18N
103
EditorOperator eo = new EditorOperator("MemoryView.java");
104             new Action(null, null, Utilities.debugFileShortcut).performShortcut();
105             Utilities.getDebugToolbar().waitComponentVisible(true);
106             Utilities.waitDebuggerConsole(Utilities.runningStatusBarText, 0);
107         } catch (Throwable JavaDoc th) {
108             try {
109                 // capture screen before cleanup in finally clause is completed
110
PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png");
111             } catch (Exception JavaDoc e1) {
112                 // ignore it
113
}
114             throw th;
115         }
116     }
117     
118     public void testRunDebuggerStepInto() throws Throwable JavaDoc {
119         try {
120             EditorOperator eo = new EditorOperator("MemoryView.java");
121             new Action(null, null, Utilities.stepIntoShortcut).performShortcut();
122             Utilities.getDebugToolbar().waitComponentVisible(true);
123             Utilities.waitDebuggerConsole("Thread main stopped at MemoryView.java:", 0);
124         } catch (Throwable JavaDoc th) {
125             try {
126                 // capture screen before cleanup in finally clause is completed
127
PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png");
128             } catch (Exception JavaDoc e1) {
129                 // ignore it
130
}
131             throw th;
132         }
133     }
134     
135     public void testRunDebuggerRunToCursor() throws Throwable JavaDoc {
136         try {
137             EditorOperator eo = new EditorOperator("MemoryView.java");
138             Utilities.setCaret(eo, 75);
139             new Action(null, null, Utilities.runToCursorShortcut).performShortcut();
140             Utilities.getDebugToolbar().waitComponentVisible(true);
141             Utilities.waitDebuggerConsole("Thread main stopped at MemoryView.java:75", 0);
142         } catch (Throwable JavaDoc th) {
143             try {
144                 // capture screen before cleanup in finally clause is completed
145
PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png");
146             } catch (Exception JavaDoc e1) {
147                 // ignore it
148
}
149             throw th;
150         }
151     }
152 }
153
Popular Tags