KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > debuggercore > Views


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.OpenAction;
28 import org.netbeans.jellytools.nodes.Node;
29 import org.netbeans.jellytools.nodes.SourcePackagesNode;
30 import org.netbeans.jemmy.JemmyProperties;
31 import org.netbeans.jemmy.operators.JTableOperator;
32 import org.netbeans.jemmy.util.PNGEncoder;
33 import org.netbeans.junit.NbTestSuite;
34
35
36 public class Views extends JellyTestCase {
37     
38     public Views(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 Views("testViewsDefaultOpen"));
49         suite.addTest(new Views("testViewsCallStack"));
50         suite.addTest(new Views("testViewsClasses"));
51         suite.addTest(new Views("testViewsThreads"));
52         suite.addTest(new Views("testViewsSessions"));
53         suite.addTest(new Views("testViewsSources"));
54         suite.addTest(new Views("testViewsClose"));
55         return suite;
56     }
57     
58     public void setUp() {
59         System.out.println("######## " + getName() + " #######");
60         if ("testViewsDefaultOpen".equals(getName())) {
61             //open source
62
Node beanNode = new Node(new SourcePackagesNode(Utilities.testProjectName), "examples.advanced|MemoryView.java"); //NOI18N
63
new OpenAction().performAPI(beanNode); // NOI18N
64
EditorOperator op = new EditorOperator("MemoryView.java");
65             Utilities.toggleBreakpoint(op, 92);
66             Utilities.startDebugger();
67             Utilities.waitDebuggerConsole("Thread main stopped at MemoryView.java:92", 0);
68         }
69     }
70     
71     public void tearDown() {
72         JemmyProperties.getCurrentOutput().printTrace("\nteardown\n");
73         if ("testViewsClose".equals(getName())) {
74             Utilities.endAllSessions();
75             Utilities.deleteAllBreakpoints();
76         }
77     }
78     
79     public void testViewsDefaultOpen() throws Throwable JavaDoc {
80         try {
81             assertNotNull("Local variables view was not opened after debugger start", TopComponentOperator.findTopComponent(Utilities.localVarsViewTitle, 0));
82             assertNotNull("Call stack view was not opened after debugger start", TopComponentOperator.findTopComponent(Utilities.callStackViewTitle, 0));
83             assertNotNull("Watches view was not opened after debugger start", TopComponentOperator.findTopComponent(Utilities.watchesViewTitle, 0));
84         } catch (Throwable JavaDoc th) {
85             try {
86                 // capture screen before cleanup in finally clause is completed
87
PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png");
88             } catch (Exception JavaDoc e1) {
89                 // ignore it
90
}
91             throw th;
92         }
93     }
94     
95     public void testViewsCallStack() throws Throwable JavaDoc {
96         try {
97             Utilities.showDebuggerView(Utilities.callStackViewTitle);
98             JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(Utilities.callStackViewTitle));
99             assertEquals("MemoryView.updateStatus:92", Utilities.removeTags(jTableOperator.getValueAt(0,0).toString()));
100             assertEquals("MemoryView.updateConsumption:80", Utilities.removeTags(jTableOperator.getValueAt(1,0).toString()));
101             assertEquals("MemoryView.main:117", Utilities.removeTags(jTableOperator.getValueAt(2,0).toString()));
102         } catch (Throwable JavaDoc th) {
103             try {
104                 // capture screen before cleanup in finally clause is completed
105
PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png");
106             } catch (Exception JavaDoc e1) {
107                 // ignore it
108
}
109             throw th;
110         }
111     }
112     
113     public void testViewsClasses() throws Throwable JavaDoc {
114         try {
115             Utilities.showDebuggerView(Utilities.classesViewTitle);
116             JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(Utilities.classesViewTitle));
117             TreeTableOperator treeTableOperator = new TreeTableOperator((javax.swing.JTable JavaDoc) jTableOperator.getSource());
118             new org.netbeans.jellytools.nodes.Node(treeTableOperator.tree(), "Application Class Loader|examples.advanced|MemoryView|1").expand();
119             String JavaDoc[] entries = {"System Class Loader", "Application Class Loader", "examples.advanced", "Helper", "MemoryView", "1"};
120             for (int i = 0; i < entries.length; i++) {
121                 assertTrue("Node " + entries[i] + " not displayed in Classes view", entries[i].equals(Utilities.removeTags(treeTableOperator.getValueAt(i, 0).toString())));
122             }
123         } catch (Throwable JavaDoc th) {
124             try {
125                 // capture screen before cleanup in finally clause is completed
126
PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png");
127             } catch (Exception JavaDoc e1) {
128                 // ignore it
129
}
130             throw th;
131         }
132     }
133     
134     public void testViewsThreads() throws Throwable JavaDoc {
135         try {
136             Utilities.showDebuggerView(Utilities.threadsViewTitle);
137             JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(Utilities.threadsViewTitle));
138             assertTrue("Thread group system is not shown in threads view", "system".equals(Utilities.removeTags(jTableOperator.getValueAt(0,0).toString())));
139             assertTrue("Thread group main is not shown in threads view", "main".equals(Utilities.removeTags(jTableOperator.getValueAt(1,0).toString())));
140             assertTrue("Thread main is not shown in threads view", "main".equals(Utilities.removeTags(jTableOperator.getValueAt(2,0).toString())));
141             assertTrue("Thread Reference Handler is not shown in threads view", "Reference Handler".equals(Utilities.removeTags(jTableOperator.getValueAt(3,0).toString())));
142             assertTrue("Thread Finalizer is not shown in threads view", "Finalizer".equals(Utilities.removeTags(jTableOperator.getValueAt(4,0).toString())));
143             assertTrue("Thread Signal Dispatcher is not shown in threads view", "Signal Dispatcher".equals(Utilities.removeTags(jTableOperator.getValueAt(5,0).toString())));
144         } catch (Throwable JavaDoc th) {
145             try {
146                 // capture screen before cleanup in finally clause is completed
147
PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png");
148             } catch (Exception JavaDoc e1) {
149                 // ignore it
150
}
151             throw th;
152         }
153     }
154     
155     public void testViewsSessions() throws Throwable JavaDoc {
156         try {
157             Utilities.showDebuggerView(Utilities.sessionsViewTitle);
158             JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(Utilities.sessionsViewTitle));
159             assertEquals("examples.advanced.MemoryView", Utilities.removeTags(jTableOperator.getValueAt(0,0).toString()));
160             try {
161                 org.openide.nodes.Node.Property property = (org.openide.nodes.Node.Property)jTableOperator.getValueAt(0,1);
162                 assertEquals("Stopped", Utilities.removeTags(property.getValue().toString()));
163                 property = (org.openide.nodes.Node.Property)jTableOperator.getValueAt(0,2);
164                 assertEquals("org.netbeans.api.debugger.Session localhost:examples.advanced.MemoryView", Utilities.removeTags(property.getValue().toString()));
165             } catch (Exception JavaDoc ex) {
166                 ex.printStackTrace();
167                 assertTrue(ex.getClass()+": "+ex.getMessage(), false);
168             }
169         } catch (Throwable JavaDoc th) {
170             try {
171                 // capture screen before cleanup in finally clause is completed
172
PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png");
173             } catch (Exception JavaDoc e1) {
174                 // ignore it
175
}
176             throw th;
177         }
178     }
179     
180     public void testViewsSources() throws Throwable JavaDoc {
181         try {
182             Utilities.showDebuggerView(Utilities.sourcesViewTitle);
183             JTableOperator jTableOperator = new JTableOperator(new TopComponentOperator(Utilities.sourcesViewTitle));
184             String JavaDoc debugAppSource = "debugTestProject" + java.io.File.separator + "src (Project debugTestProject)";
185             boolean jdk = false, project = false;
186             for (int i=0;i < jTableOperator.getRowCount();i++) {
187                 String JavaDoc src = Utilities.removeTags(jTableOperator.getValueAt(i,0).toString());
188                 if (src.endsWith("src.zip")) {
189                     jdk=true;
190                 } else if (src.endsWith(debugAppSource)) {
191                     project = true;
192                 }
193             }
194             assertTrue("JDK source root is not shown in threads view", jdk);
195             assertTrue("MemoryView source root is not shown in threads view", project);
196         } catch (Throwable JavaDoc th) {
197             try {
198                 // capture screen before cleanup in finally clause is completed
199
PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png");
200             } catch (Exception JavaDoc e1) {
201                 // ignore it
202
}
203             throw th;
204         }
205     }
206     
207     public void testViewsClose() throws Throwable JavaDoc {
208         try {
209             //new TopComponentOperator(Utilities.localVarsViewTitle).close();
210
//new TopComponentOperator(Utilities.watchesViewTitle).close();
211
//new TopComponentOperator(Utilities.callStackViewTitle).close();
212
new TopComponentOperator(Utilities.classesViewTitle).close();
213             new TopComponentOperator(Utilities.sessionsViewTitle).close();
214             new TopComponentOperator(Utilities.threadsViewTitle).close();
215             new TopComponentOperator(Utilities.sourcesViewTitle).close();
216         } catch (Throwable JavaDoc th) {
217             try {
218                 // capture screen before cleanup in finally clause is completed
219
PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png");
220             } catch (Exception JavaDoc e1) {
221                 // ignore it
222
}
223             throw th;
224         }
225     }
226 }
227
Popular Tags