001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans.
026: * The Initial Developer of the Original Software is Sun Microsystems, Inc.
027: * Portions created by Sun Microsystems, Inc. are Copyright (C) 2003
028: * All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: *
041: * Contributor(s): Sun Microsystems, Inc.
042: */
043:
044: package gui.debuggercore;
045:
046: import java.awt.event.KeyEvent;
047: import java.io.File;
048: import junit.textui.TestRunner;
049: import org.netbeans.jellytools.*;
050: import org.netbeans.jellytools.actions.OpenAction;
051: import org.netbeans.jellytools.nodes.Node;
052: import org.netbeans.jellytools.nodes.SourcePackagesNode;
053: import org.netbeans.jemmy.EventTool;
054: import org.netbeans.jemmy.JemmyProperties;
055: import org.netbeans.jemmy.operators.JComboBoxOperator;
056: import org.netbeans.jemmy.operators.JPopupMenuOperator;
057: import org.netbeans.jemmy.operators.JTableOperator;
058: import org.netbeans.jemmy.util.PNGEncoder;
059: import org.netbeans.junit.NbTestSuite;
060:
061: public class Views extends JellyTestCase {
062:
063: public Views(String name) {
064: super (name);
065: }
066:
067: public static void main(String[] args) {
068: TestRunner.run(suite());
069: }
070:
071: public static NbTestSuite suite() {
072: NbTestSuite suite = new NbTestSuite();
073: String vers = System.getProperty("java.version");
074:
075: suite.addTest(new Views("testViewsDefaultOpen"));
076: suite.addTest(new Views("testViewsCallStack"));
077: if (vers.startsWith("1.6")) { //heapwalker
078: suite.addTest(new Views("testViewsHeapWalker1"));
079: } else { // old classes view
080: suite.addTest(new Views("testViewsClasses"));
081: }
082: suite.addTest(new Views("testViewsThreads"));
083: suite.addTest(new Views("testViewsSessions"));
084: suite.addTest(new Views("testViewsSources"));
085: suite.addTest(new Views("testViewsClose"));
086: return suite;
087: }
088:
089: public void setUp() {
090: System.out.println("######## " + getName() + " #######");
091: if ("testViewsDefaultOpen".equals(getName())) {
092: //open source
093: Node beanNode = new Node(new SourcePackagesNode(
094: Utilities.testProjectName),
095: "examples.advanced|MemoryView.java"); //NOI18N
096: new OpenAction().performAPI(beanNode); // NOI18N
097: EditorOperator op = new EditorOperator("MemoryView.java");
098: Utilities.toggleBreakpoint(op, 92);
099: Utilities.startDebugger();
100: Utilities.waitDebuggerConsole(
101: "Thread main stopped at MemoryView.java:92", 0);
102: }
103: }
104:
105: public void tearDown() {
106: JemmyProperties.getCurrentOutput().printTrace("\nteardown\n");
107: if ("testViewsClose".equals(getName())) {
108: Utilities.endAllSessions();
109: Utilities.deleteAllBreakpoints();
110: }
111: }
112:
113: public void testViewsDefaultOpen() throws Throwable {
114: try {
115: assertNotNull(
116: "Local variables view was not opened after debugger start",
117: TopComponentOperator.findTopComponent(
118: Utilities.localVarsViewTitle, 0));
119: assertNotNull(
120: "Call stack view was not opened after debugger start",
121: TopComponentOperator.findTopComponent(
122: Utilities.callStackViewTitle, 0));
123: assertNotNull(
124: "Watches view was not opened after debugger start",
125: TopComponentOperator.findTopComponent(
126: Utilities.watchesViewTitle, 0));
127: } catch (Throwable th) {
128: Utilities.captureScreen(this );
129: throw th;
130: }
131: }
132:
133: public void testViewsCallStack() throws Throwable {
134: try {
135: Utilities.showDebuggerView(Utilities.callStackViewTitle);
136: JTableOperator jTableOperator = new JTableOperator(
137: new TopComponentOperator(
138: Utilities.callStackViewTitle));
139: assertEquals("MemoryView.updateStatus:92", Utilities
140: .removeTags(jTableOperator.getValueAt(0, 0)
141: .toString()));
142: assertEquals("MemoryView.updateConsumption:80", Utilities
143: .removeTags(jTableOperator.getValueAt(1, 0)
144: .toString()));
145: assertEquals("MemoryView.main:117", Utilities
146: .removeTags(jTableOperator.getValueAt(2, 0)
147: .toString()));
148: } catch (Throwable th) {
149: Utilities.captureScreen(this );
150: throw th;
151: }
152: }
153:
154: public void testViewsClasses() throws Throwable {
155: try {
156: Utilities.showDebuggerView(Utilities.classesViewTitle);
157: JTableOperator jTableOperator = new JTableOperator(
158: new TopComponentOperator(Utilities.classesViewTitle));
159: TreeTableOperator treeTableOperator = new TreeTableOperator(
160: (javax.swing.JTable) jTableOperator.getSource());
161: new org.netbeans.jellytools.nodes.Node(treeTableOperator
162: .tree(),
163: "Application Class Loader|examples.advanced|MemoryView|1")
164: .expand();
165: String[] entries = { "System Class Loader",
166: "Application Class Loader", "examples.advanced",
167: "Helper", "MemoryView", "1" };
168: for (int i = 0; i < entries.length; i++) {
169: assertTrue("Node " + entries[i]
170: + " not displayed in Classes view", entries[i]
171: .equals(Utilities.removeTags(treeTableOperator
172: .getValueAt(i, 0).toString())));
173: }
174: } catch (Throwable th) {
175: Utilities.captureScreen(this );
176: throw th;
177: }
178: }
179:
180: public void testViewsHeapWalker1() throws Throwable {
181: try {
182: Utilities.showDebuggerView(Utilities.classesViewTitle);
183:
184: TopComponentOperator tco = new TopComponentOperator(
185: Utilities.classesViewTitle);
186: JTableOperator jTableOperator = new JTableOperator(tco);
187: JComboBoxOperator filter = new JComboBoxOperator(tco);
188: filter.clearText();
189: filter.enterText("example");
190: filter.pushKey(KeyEvent.VK_ENTER);
191: new EventTool().waitNoEvent(500);
192: assertEquals("MemoryView class is not in classes",
193: "examples.advanced.MemoryView", Utilities
194: .removeTags(jTableOperator.getValueAt(0, 0)
195: .toString()));
196: assertEquals("Instances number is wrong", "1 (0%)",
197: Utilities.removeTags(jTableOperator
198: .getValueAt(0, 2).toString()));
199: } catch (Throwable th) {
200: Utilities.captureScreen(this );
201: throw th;
202: }
203: }
204:
205: public void testViewsHeapWalker2() throws Throwable {
206: try {
207: Utilities.showDebuggerView(Utilities.classesViewTitle);
208:
209: TopComponentOperator tco = new TopComponentOperator(
210: Utilities.classesViewTitle);
211: JTableOperator jTableOperator = new JTableOperator(tco);
212: JComboBoxOperator filter = new JComboBoxOperator(tco);
213: JPopupMenuOperator popup = new JPopupMenuOperator(
214: jTableOperator.callPopupOnCell(0, 0));
215: popup.pushMenuNoBlock("Show in Instances View");
216: filter.clearText();
217: filter.pushKey(KeyEvent.VK_ENTER);
218: new EventTool().waitNoEvent(500);
219: } catch (Throwable th) {
220: Utilities.captureScreen(this );
221: throw th;
222: }
223: }
224:
225: public void testViewsThreads() throws Throwable {
226: try {
227: Utilities.showDebuggerView(Utilities.threadsViewTitle);
228: JTableOperator jTableOperator = new JTableOperator(
229: new TopComponentOperator(Utilities.threadsViewTitle));
230: assertTrue(
231: "Thread group system is not shown in threads view",
232: "system".equals(Utilities.removeTags(jTableOperator
233: .getValueAt(0, 0).toString())));
234: assertTrue(
235: "Thread group main is not shown in threads view",
236: "main".equals(Utilities.removeTags(jTableOperator
237: .getValueAt(1, 0).toString())));
238: assertTrue("Thread main is not shown in threads view",
239: "main".equals(Utilities.removeTags(jTableOperator
240: .getValueAt(2, 0).toString())));
241: assertTrue(
242: "Thread Reference Handler is not shown in threads view",
243: "Reference Handler".equals(Utilities
244: .removeTags(jTableOperator.getValueAt(3, 0)
245: .toString())));
246: assertTrue("Thread Finalizer is not shown in threads view",
247: "Finalizer".equals(Utilities
248: .removeTags(jTableOperator.getValueAt(4, 0)
249: .toString())));
250: assertTrue(
251: "Thread Signal Dispatcher is not shown in threads view",
252: "Signal Dispatcher".equals(Utilities
253: .removeTags(jTableOperator.getValueAt(5, 0)
254: .toString())));
255: } catch (Throwable th) {
256: Utilities.captureScreen(this );
257: throw th;
258: }
259: }
260:
261: public void testViewsSessions() throws Throwable {
262: try {
263: Utilities.showDebuggerView(Utilities.sessionsViewTitle);
264: JTableOperator jTableOperator = new JTableOperator(
265: new TopComponentOperator(
266: Utilities.sessionsViewTitle));
267: assertEquals("examples.advanced.MemoryView", Utilities
268: .removeTags(jTableOperator.getValueAt(0, 0)
269: .toString()));
270: try {
271: org.openide.nodes.Node.Property property = (org.openide.nodes.Node.Property) jTableOperator
272: .getValueAt(0, 1);
273: assertEquals("Stopped", Utilities.removeTags(property
274: .getValue().toString()));
275: property = (org.openide.nodes.Node.Property) jTableOperator
276: .getValueAt(0, 2);
277: assertEquals(
278: "org.netbeans.api.debugger.Session localhost:examples.advanced.MemoryView",
279: Utilities.removeTags(property.getValue()
280: .toString()));
281: } catch (Exception ex) {
282: ex.printStackTrace();
283: assertTrue(ex.getClass() + ": " + ex.getMessage(),
284: false);
285: }
286: } catch (Throwable th) {
287: Utilities.captureScreen(this );
288: throw th;
289: }
290: }
291:
292: public void testViewsSources() throws Throwable {
293: try {
294: Utilities.showDebuggerView(Utilities.sourcesViewTitle);
295: JTableOperator jTableOperator = new JTableOperator(
296: new TopComponentOperator(Utilities.sourcesViewTitle));
297: String debugAppSource = "debugTestProject"
298: + java.io.File.separator
299: + "src (Project debugTestProject)";
300: boolean jdk = false, project = false;
301: for (int i = 0; i < jTableOperator.getRowCount(); i++) {
302: String src = Utilities.removeTags(jTableOperator
303: .getValueAt(i, 0).toString());
304: if (src.endsWith("src.zip")) {
305: jdk = true;
306: } else if (src.endsWith(debugAppSource)) {
307: project = true;
308: }
309: }
310: assertTrue("JDK source root is not shown in threads view",
311: jdk);
312: assertTrue(
313: "MemoryView source root is not shown in threads view",
314: project);
315: } catch (Throwable th) {
316: Utilities.captureScreen(this );
317: throw th;
318: }
319: }
320:
321: public void testViewsClose() throws Throwable {
322: try {
323: //new TopComponentOperator(Utilities.localVarsViewTitle).close();
324: //new TopComponentOperator(Utilities.watchesViewTitle).close();
325: //new TopComponentOperator(Utilities.callStackViewTitle).close();
326: new TopComponentOperator(Utilities.classesViewTitle)
327: .close();
328: new TopComponentOperator(Utilities.sessionsViewTitle)
329: .close();
330: new TopComponentOperator(Utilities.threadsViewTitle)
331: .close();
332: new TopComponentOperator(Utilities.sourcesViewTitle)
333: .close();
334: } catch (Throwable th) {
335: Utilities.captureScreen(this);
336: throw th;
337: }
338: }
339: }
|