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.Component;
047: import java.awt.event.KeyEvent;
048: import java.io.File;
049: import javax.swing.KeyStroke;
050: import org.netbeans.jellytools.*;
051: import org.netbeans.jellytools.actions.Action;
052: import org.netbeans.jellytools.actions.DebugProjectAction;
053: import org.netbeans.jellytools.modules.debugger.actions.FinishDebuggerAction;
054: import org.netbeans.jellytools.modules.debugger.actions.NewBreakpointAction;
055: import org.netbeans.jellytools.modules.debugger.actions.ToggleBreakpointAction;
056: import org.netbeans.jellytools.nodes.Node;
057: import org.netbeans.jemmy.ComponentChooser;
058: import org.netbeans.jemmy.EventTool;
059: import org.netbeans.jemmy.JemmyException;
060: import org.netbeans.jemmy.JemmyProperties;
061: import org.netbeans.jemmy.TimeoutExpiredException;
062: import org.netbeans.jemmy.Waitable;
063: import org.netbeans.jemmy.Waiter;
064: import org.netbeans.jemmy.operators.ContainerOperator;
065: import org.netbeans.jemmy.operators.JPopupMenuOperator;
066: import org.netbeans.jemmy.operators.JTableOperator;
067: import org.netbeans.jemmy.util.PNGEncoder;
068: import org.openide.awt.StatusDisplayer;
069:
070: public class Utilities {
071:
072: public static String windowMenu = Bundle.getStringTrimmed(
073: "org.netbeans.core.Bundle", "Menu/Window");
074: public static String runMenu = Bundle
075: .getStringTrimmed("org.netbeans.modules.project.ui.Bundle",
076: "Menu/RunProject");
077: public static String debugMenu = Bundle.getStringTrimmed(
078: "org.netbeans.modules.debugger.resources.Bundle",
079: "Menu/Window/Debug");
080: public static String runFileMenu = Bundle.getStringTrimmed(
081: "org.netbeans.modules.java.project.Bundle",
082: "LBL_RunFile_Action");
083: public static String debugToolbarLabel = Bundle.getStringTrimmed(
084: "org.netbeans.modules.debugger.jpda.ui.Bundle",
085: "Toolbars/Debug");
086:
087: public static String toggleBreakpointItem = Bundle
088: .getStringTrimmed(
089: "org.netbeans.modules.debugger.ui.actions.Bundle",
090: "CTL_Toggle_breakpoint");
091: public static String newBreakpointItem = Bundle.getStringTrimmed(
092: "org.netbeans.modules.debugger.ui.actions.Bundle",
093: "CTL_AddBreakpoint");
094: public static String newWatchItem = Bundle.getStringTrimmed(
095: "org.netbeans.modules.debugger.ui.actions.Bundle",
096: "CTL_New_Watch");
097: public static String debugMainProjectItem = Bundle
098: .getStringTrimmed(
099: "org.netbeans.modules.debugger.ui.actions.Bundle",
100: "LBL_DebugMainProjectAction_Name");
101: public static String stepIntoItem = Bundle.getStringTrimmed(
102: "org.netbeans.modules.debugger.ui.actions.Bundle",
103: "CTL_Step_into_action_name");
104: public static String stepOverItem = Bundle.getStringTrimmed(
105: "org.netbeans.modules.debugger.jpda.ui.Bundle",
106: "CTL_Step_Over");
107: public static String stepOutItem = Bundle.getStringTrimmed(
108: "org.netbeans.modules.debugger.jpda.ui.Bundle",
109: "CTL_Step_Out");
110: public static String stepOverExpresItem = Bundle.getStringTrimmed(
111: "org.netbeans.modules.debugger.ui.actions.Bundle",
112: "CTL_Step_operation_action_name");
113: public static String runIntoMethodItem = Bundle.getStringTrimmed(
114: "org.netbeans.modules.debugger.ui.actions.Bundle",
115: "CTL_Run_into_method_action_name");
116: public static String continueItem = Bundle.getStringTrimmed(
117: "org.netbeans.modules.debugger.ui.actions.Bundle",
118: "CTL_Continue_action_name");
119: public static String pauseItem = Bundle.getStringTrimmed(
120: "org.netbeans.modules.debugger.ui.actions.Bundle",
121: "CTL_Pause_action_name");
122: public static String finishSessionsItem = Bundle.getStringTrimmed(
123: "org.netbeans.modules.debugger.ui.actions.Bundle",
124: "CTL_KillAction_name");
125: public static String runToCursorItem = Bundle.getStringTrimmed(
126: "org.netbeans.modules.debugger.ui.actions.Bundle",
127: "CTL_Run_to_cursor_action_name");
128: public static String applyCodeChangesItem = Bundle
129: .getStringTrimmed(
130: "org.netbeans.modules.debugger.ui.actions.Bundle",
131: "CTL_Fix_action_name");
132: public static String evaluateExpressionItem = Bundle
133: .getStringTrimmed(
134: "org.netbeans.modules.debugger.jpda.ui.actions.Bundle",
135: "CTL_Evaluate");
136:
137: public static String localVarsItem = Bundle.getStringTrimmed(
138: "org.netbeans.modules.debugger.ui.actions.Bundle",
139: "CTL_LocalVariablesAction");
140: public static String watchesItem = Bundle.getStringTrimmed(
141: "org.netbeans.modules.debugger.ui.actions.Bundle",
142: "CTL_WatchesAction");
143: public static String callStackItem = Bundle.getStringTrimmed(
144: "org.netbeans.modules.debugger.ui.actions.Bundle",
145: "CTL_CallStackAction");
146: public static String classesItem = Bundle.getStringTrimmed(
147: "org.netbeans.modules.debugger.jpda.heapwalk.views.Bundle",
148: "CTL_Classes_view");
149: public static String sourcesItem = Bundle.getStringTrimmed(
150: "org.netbeans.modules.debugger.jpda.ui.actions.Bundle",
151: "CTL_SourcesViewAction");
152: public static String breakpointsItem = Bundle.getStringTrimmed(
153: "org.netbeans.modules.debugger.ui.actions.Bundle",
154: "CTL_BreakpointsAction");
155: public static String sessionsItem = Bundle.getStringTrimmed(
156: "org.netbeans.modules.debugger.ui.actions.Bundle",
157: "CTL_SessionsAction");
158: public static String threadsItem = Bundle.getStringTrimmed(
159: "org.netbeans.modules.debugger.ui.actions.Bundle",
160: "CTL_ThreadsAction");
161:
162: public static String localVarsViewTitle = Bundle.getStringTrimmed(
163: "org.netbeans.modules.debugger.ui.views.Bundle",
164: "CTL_Variables_view");
165: public static String watchesViewTitle = Bundle.getStringTrimmed(
166: "org.netbeans.modules.debugger.ui.views.Bundle",
167: "CTL_Watches_view");
168: public static String callStackViewTitle = Bundle.getStringTrimmed(
169: "org.netbeans.modules.debugger.ui.views.Bundle",
170: "CTL_Call_stack_view");
171: public static String classesViewTitle = Bundle.getStringTrimmed(
172: "org.netbeans.modules.debugger.jpda.heapwalk.views.Bundle",
173: "CTL_Classes_view");
174: public static String sourcesViewTitle = Bundle.getStringTrimmed(
175: "org.netbeans.modules.debugger.jpda.ui.views.Bundle",
176: "CTL_Sourcess_view");
177: public static String breakpointsViewTitle = Bundle
178: .getStringTrimmed(
179: "org.netbeans.modules.debugger.ui.views.Bundle",
180: "CTL_Breakpoints_view");
181: public static String sessionsViewTitle = Bundle.getStringTrimmed(
182: "org.netbeans.modules.debugger.ui.views.Bundle",
183: "CTL_Sessions_view");
184: public static String threadsViewTitle = Bundle.getStringTrimmed(
185: "org.netbeans.modules.debugger.ui.views.Bundle",
186: "CTL_Threads_view");
187:
188: public static String customizeBreakpointTitle = Bundle.getString(
189: "org.netbeans.modules.debugger.jpda.ui.models.Bundle",
190: "CTL_Breakpoint_Customizer_Title");
191: public static String newBreakpointTitle = Bundle.getStringTrimmed(
192: "org.netbeans.modules.debugger.ui.actions.Bundle",
193: "CTL_Breakpoint_Title");
194: public static String newWatchTitle = Bundle.getStringTrimmed(
195: "org.netbeans.modules.debugger.ui.actions.Bundle",
196: "CTL_WatchDialog_Title");
197: public static String debuggerConsoleTitle = Bundle.getString(
198: "org.netbeans.modules.debugger.jpda.ui.Bundle",
199: "CTL_DebuggerConsole_Title");
200:
201: public static String runningStatusBarText = Bundle
202: .getStringTrimmed(
203: "org.netbeans.modules.debugger.jpda.ui.Bundle",
204: "CTL_Debugger_running");
205: public static String stoppedStatusBarText = Bundle
206: .getStringTrimmed(
207: "org.netbeans.modules.debugger.jpda.ui.Bundle",
208: "CTL_Debugger_stopped");
209: public static String finishedStatusBarText = Bundle
210: .getStringTrimmed(
211: "org.netbeans.modules.debugger.jpda.ui.Bundle",
212: "CTL_Debugger_finished");
213: public static String buildCompleteStatusBarText = "Finished building";
214: public static String evaluatingPropertyText = Bundle.getString(
215: "org.netbeans.modules.viewmodel.Bundle", "EvaluatingProp");
216:
217: public static String openSourceAction = Bundle.getStringTrimmed(
218: "org.openide.actions.Bundle", "Open");
219: public static String setMainProjectAction = Bundle
220: .getStringTrimmed(
221: "org.netbeans.modules.project.ui.actions.Bundle",
222: "LBL_SetAsMainProjectAction_Name");
223: public static String projectPropertiesAction = Bundle
224: .getStringTrimmed(
225: "org.netbeans.modules.project.ui.actions.Bundle",
226: "LBL_CustomizeProjectAction_Popup_Name");
227: public static String projectPropertiesTitle = Bundle
228: .getStringTrimmed(
229: "org.netbeans.modules.java.j2seproject.ui.Bundle",
230: "LBL_Customizer_Title");
231: // public static String runningProjectTreeItem = Bundle.getStringTrimmed("org.netbeans.modules.java.j2seproject.ui.customizer.Bundle", "LBL_Config_Run");
232: public static String testProjectName = "debugTestProject";
233:
234: public static KeyStroke toggleBreakpointShortcut = KeyStroke
235: .getKeyStroke(KeyEvent.VK_F8, KeyEvent.CTRL_MASK);
236: public static KeyStroke newBreakpointShortcut = KeyStroke
237: .getKeyStroke(KeyEvent.VK_F8, KeyEvent.CTRL_MASK
238: | KeyEvent.SHIFT_MASK);
239: public static KeyStroke newWatchShortcut = KeyStroke.getKeyStroke(
240: KeyEvent.VK_F7, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK);
241: public static KeyStroke debugProjectShortcut = KeyStroke
242: .getKeyStroke(KeyEvent.VK_F5, 0);
243: public static KeyStroke debugFileShortcut = KeyStroke.getKeyStroke(
244: KeyEvent.VK_F5, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK);
245: public static KeyStroke runToCursorShortcut = KeyStroke
246: .getKeyStroke(KeyEvent.VK_F4, 0);
247: public static KeyStroke stepIntoShortcut = KeyStroke.getKeyStroke(
248: KeyEvent.VK_F7, 0);
249: public static KeyStroke stepOutShortcut = KeyStroke.getKeyStroke(
250: KeyEvent.VK_F7, KeyEvent.CTRL_MASK);
251: public static KeyStroke stepOverShortcut = KeyStroke.getKeyStroke(
252: KeyEvent.VK_F8, 0);
253: public static KeyStroke continueShortcut = KeyStroke.getKeyStroke(
254: KeyEvent.VK_F5, KeyEvent.CTRL_MASK);
255: public static KeyStroke killSessionShortcut = KeyStroke
256: .getKeyStroke(KeyEvent.VK_F5, KeyEvent.SHIFT_MASK);
257: public static KeyStroke buildProjectShortcut = KeyStroke
258: .getKeyStroke(KeyEvent.VK_F11, 0);
259: public static KeyStroke openBreakpointsShortcut = KeyStroke
260: .getKeyStroke(KeyEvent.VK_5, KeyEvent.ALT_MASK
261: | KeyEvent.SHIFT_MASK);
262:
263: public Utilities() {
264: }
265:
266: public static boolean verifyMainMenu(String actionPath,
267: boolean expected) {
268: if (expected == MainWindowOperator.getDefault().menuBar()
269: .showMenuItem(actionPath).isEnabled()) {
270: return MainWindowOperator.getDefault().menuBar()
271: .showMenuItem(actionPath).isEnabled();
272: } else {
273: for (int i = 0; i < 10; i++) {
274: if (MainWindowOperator.getDefault().menuBar()
275: .showMenuItem(actionPath).isEnabled() == expected) {
276: MainWindowOperator.getDefault().menuBar()
277: .closeSubmenus();
278: return expected;
279: }
280: MainWindowOperator.getDefault().menuBar()
281: .closeSubmenus();
282: new EventTool().waitNoEvent(500);
283: System.err.println("waiting on " + actionPath);
284: }
285: return MainWindowOperator.getDefault().menuBar()
286: .showMenuItem(actionPath).isEnabled();
287: }
288: }
289:
290: public static boolean verifyPopup(Node node, String[] menus) {
291: //invocation of root popup
292: JPopupMenuOperator popup = node.callPopup();
293: return verifyPopup(popup, menus);
294: }
295:
296: public static boolean verifyPopup(final JPopupMenuOperator popup,
297: String[] menus) {
298: for (int i = 0; i < menus.length; i++) {
299: try {
300: popup.showMenuItem(menus[i]);
301: } catch (NullPointerException npe) {
302: throw new JemmyException("Popup path [" + menus[i]
303: + "] not found.");
304: }
305: }
306: //close popup and wait until is not visible
307: popup.waitState(new ComponentChooser() {
308:
309: public boolean checkComponent(Component comp) {
310: popup.pushKey(KeyEvent.VK_ESCAPE);
311: return !popup.isVisible();
312: }
313:
314: public String getDescription() {
315: return "Popup menu closed";
316: }
317: });
318: return true;
319: }
320:
321: public static boolean checkAnnotation(EditorOperator operator,
322: int line, String annotationType) {
323: new EventTool().waitNoEvent(500);
324: Object[] annotations = operator.getAnnotations(line);
325: boolean found = false;
326: JemmyProperties.getProperties().getOutput().print(
327: ">>>>> Annotations on line: " + line + "\n");
328: for (int i = 0; i < annotations.length; i++) {
329: JemmyProperties.getProperties().getOutput().print(
330: " " + operator.getAnnotationType(annotations[i])
331: + "\n");
332: if (annotationType.equals(operator
333: .getAnnotationType(annotations[i]))) {
334: found = true;
335: }
336: }
337: return found;
338: }
339:
340: public static void deleteAllBreakpoints() {
341: showDebuggerView(breakpointsViewTitle);
342: JTableOperator jTableOperator = new JTableOperator(
343: new TopComponentOperator(breakpointsViewTitle));
344: if (jTableOperator.getRowCount() > 0) {
345: new JPopupMenuOperator(jTableOperator.callPopupOnCell(0, 0))
346: .pushMenu(Bundle
347: .getString(
348: "org.netbeans.modules.debugger.ui.models.Bundle",
349: "CTL_BreakpointAction_DeleteAll_Label"));
350: }
351: }
352:
353: public static void deleteAllWatches() {
354: showDebuggerView(watchesViewTitle);
355: JTableOperator jTableOperator = new JTableOperator(
356: new TopComponentOperator(watchesViewTitle));
357: if (jTableOperator.getRowCount() > 0) {
358: new JPopupMenuOperator(jTableOperator.callPopupOnCell(0, 0))
359: .pushMenu(Bundle
360: .getString(
361: "org.netbeans.modules.debugger.ui.models.Bundle",
362: "CTL_WatchAction_DeleteAll"));
363: }
364: }
365:
366: public static void showDebuggerView(String viewName) {
367: new Action(windowMenu + "|" + debugMenu + "|" + viewName, null)
368: .perform();
369: new TopComponentOperator(viewName);
370: new EventTool().waitNoEvent(500);
371: }
372:
373: public static String removeTags(String in) {
374: String out = "";
375: in = in.trim();
376: if (in.indexOf('<') == -1) {
377: out = in;
378: } else {
379: while (in.indexOf('<') >= 0) {
380: if (in.indexOf('<') == 0) {
381: in = in.substring(in.indexOf('>') + 1, in.length());
382: } else {
383: out += in.substring(0, in.indexOf('<'));
384: in = in.substring(in.indexOf('<'), in.length());
385: }
386: }
387: }
388: return out;
389: }
390:
391: public static void endAllSessions() {
392: showDebuggerView(sessionsViewTitle);
393: JTableOperator jTableOperator = new JTableOperator(
394: new TopComponentOperator(sessionsViewTitle));
395: if (jTableOperator.getRowCount() > 0) {
396: new JPopupMenuOperator(jTableOperator.callPopupOnCell(0, 0))
397: .pushMenu(Bundle
398: .getString(
399: "org.netbeans.modules.debugger.ui.models.Bundle",
400: "CTL_SessionAction_FinishAll_Label"));
401: }
402: }
403:
404: public static void startDebugger() {
405: // "Set as Main Project"
406: String setAsMainProjectItem = Bundle.getStringTrimmed(
407: "org.netbeans.modules.project.ui.actions.Bundle",
408: "LBL_SetAsMainProjectAction_Name");
409: new Action(null, setAsMainProjectItem)
410: .perform(new ProjectsTabOperator()
411: .getProjectRootNode(testProjectName));
412: new DebugProjectAction().performShortcut();
413: getDebugToolbar().waitComponentVisible(true);
414: }
415:
416: public static ContainerOperator getDebugToolbar() {
417: return MainWindowOperator.getDefault().getToolbar(
418: debugToolbarLabel);
419: }
420:
421: public static void setCaret(EditorOperator eo, final int line) {
422: eo.makeComponentVisible();
423: eo.setCaretPositionToLine(line);
424: new EventTool().waitNoEvent(500);
425:
426: try {
427: new Waiter(new Waitable() {
428:
429: public Object actionProduced(Object editorOper) {
430: EditorOperator op = (EditorOperator) editorOper;
431: if (op.getLineNumber() == line) {
432: return Boolean.TRUE;
433: }
434: return null;
435: }
436:
437: public String getDescription() {
438: return "Wait caret position on line " + line;
439: }
440: }).waitAction(eo);
441: } catch (InterruptedException ex) {
442: ex.printStackTrace();
443: }
444: }
445:
446: public static NbDialogOperator newBreakpoint(int line, int column) {
447: EditorOperator eo = new EditorOperator("MemoryView.java");
448: eo.setCaretPosition(line, column);
449: new NewBreakpointAction().perform();
450: NbDialogOperator dialog = new NbDialogOperator(
451: newBreakpointTitle);
452: new EventTool().waitNoEvent(1000l);
453: return dialog;
454: }
455:
456: public static NbDialogOperator newBreakpoint(int line) {
457: Node projectNode = ProjectsTabOperator.invoke()
458: .getProjectRootNode(testProjectName);
459: EditorOperator eo = new EditorOperator("MemoryView.java");
460: setCaret(eo, line);
461: new NewBreakpointAction().perform();
462: NbDialogOperator dialog = new NbDialogOperator(
463: newBreakpointTitle);
464: new EventTool().waitNoEvent(1000l);
465: return dialog;
466: }
467:
468: public static void toggleBreakpoint(EditorOperator eo,
469: final int line) {
470: toggleBreakpoint(eo, line, true);
471: }
472:
473: public static void toggleBreakpoint(EditorOperator eo,
474: final int line, final boolean newBreakpoint) {
475: setCaret(eo, line);
476:
477: new ToggleBreakpointAction().perform();
478: try {
479: new Waiter(new Waitable() {
480:
481: public Object actionProduced(Object editorOper) {
482: Object[] annotations = ((EditorOperator) editorOper)
483: .getAnnotations(line);
484: boolean found = false;
485: for (int i = 0; i < annotations.length; i++) {
486: if (((EditorOperator) editorOper)
487: .getAnnotationType(annotations[i])
488: .startsWith("Breakpoint")) {
489: found = true;
490: if (newBreakpoint) {
491: return Boolean.TRUE;
492: }
493: }
494: }
495: if (!found && !newBreakpoint) {
496: return Boolean.TRUE;
497: }
498: return null;
499: }
500:
501: public String getDescription() {
502: return "Wait breakpoint established on line "
503: + line;
504: }
505: }).waitAction(eo);
506: } catch (InterruptedException ex) {
507: ex.printStackTrace();
508: }
509: }
510:
511: public static void waitFinished(JellyTestCase test,
512: String projectName, String target) {
513: long oldTimeout = MainWindowOperator.getDefault().getTimeouts()
514: .getTimeout("Waiter.WaitingTime");
515: try {
516: // increase time to wait to 240 second (it fails on slower machines)
517: MainWindowOperator.getDefault().getTimeouts().setTimeout(
518: "Waiter.WaitingTime", 240000);
519: MainWindowOperator.getDefault().waitStatusText(
520: "Finished building " + projectName + " (" + target
521: + ")");
522: } finally {
523: // start status text tracer again because we use it further
524: MainWindowOperator.getDefault().getStatusTextTracer()
525: .start();
526: // restore default timeout
527: MainWindowOperator.getDefault().getTimeouts().setTimeout(
528: "Waiter.WaitingTime", oldTimeout);
529: // log messages from output
530: test.getLog("RunOutput").print(
531: new OutputTabOperator(projectName).getText()); // NOI18N
532: }
533: }
534:
535: public static void waitStatusText(String text) {
536: long oldTimeout = MainWindowOperator.getDefault().getTimeouts()
537: .getTimeout("Waiter.WaitingTime");
538: try {
539: // increase time to wait to 240 second (it fails on slower machines)
540: MainWindowOperator.getDefault().getTimeouts().setTimeout(
541: "Waiter.WaitingTime", 240000);
542: MainWindowOperator.getDefault().waitStatusText(text);
543: } finally {
544: // start status text tracer again because we use it further
545: MainWindowOperator.getDefault().getStatusTextTracer()
546: .start();
547: // restore default timeout
548: MainWindowOperator.getDefault().getTimeouts().setTimeout(
549: "Waiter.WaitingTime", oldTimeout);
550: }
551: }
552:
553: public static void waitStatusTextPrefix(final String text) {
554: try {
555: new Waiter(new Waitable() {
556:
557: public Object actionProduced(Object anObject) {
558: JemmyProperties.getProperties().getOutput().print(
559: ">>>>> status text: "
560: + StatusDisplayer.getDefault()
561: .getStatusText() + " > "
562: + anObject + "\n");
563: if (StatusDisplayer.getDefault().getStatusText()
564: .startsWith(text)) {
565: return Boolean.TRUE;
566: }
567: return null;
568: }
569:
570: public String getDescription() {
571: return "Wait status text prefix: " + text;
572: }
573: }).waitAction(StatusDisplayer.getDefault());
574: } catch (InterruptedException ex) {
575: ex.printStackTrace();
576: }
577: }
578:
579: public static int getDebuggerConsoleStatus() {
580: return new OutputTabOperator(debuggerConsoleTitle)
581: .getLineCount();
582: }
583:
584: public static int waitDebuggerConsole(final String text,
585: final int status) {
586: OutputTabOperator op = new OutputTabOperator(
587: debuggerConsoleTitle);
588: ConsoleChooser cch = new ConsoleChooser(op, text, status);
589: JemmyProperties.getCurrentOutput().printLine(
590: "Waiting on text in debugger console '" + text
591: + "' from line " + status);
592: JemmyProperties.setCurrentTimeout(
593: "ComponentOperator.WaitStateTimeout", 30000l);
594: try {
595: op.waitState(cch);
596: } catch (TimeoutExpiredException ex) {
597: JemmyProperties.getCurrentOutput().printLine(
598: "Not found text in debugger console:");
599: JemmyProperties.getCurrentOutput().printLine(op.getText());
600: throw ex;
601: }
602: JemmyProperties.getCurrentOutput().printLine(
603: "Found text in debugger console '" + text
604: + "' at line " + cch.getLastIndex());
605: return cch.getLastIndex();
606: }
607:
608: public static boolean checkConsoleForText(String text, int startLine) {
609: OutputTabOperator op = new OutputTabOperator(
610: debuggerConsoleTitle);
611: for (int i = startLine; i < op.getLineCount(); i++) {
612: if (op.getLine(i).startsWith(text)) {
613: return true;
614: }
615: }
616: return false;
617: }
618:
619: public static void captureScreen(JellyTestCase testCase) {
620: try {
621: PNGEncoder.captureScreen(testCase.getWorkDir()
622: .getAbsolutePath()
623: + File.separator + "screenBeforeCleanup.png");
624: } catch (Exception e1) {
625: // ignore it
626: }
627: }
628:
629: static class ConsoleChooser implements ComponentChooser {
630:
631: int lastIndex = 0;
632: OutputTabOperator op;
633: String text;
634: int status;
635:
636: public ConsoleChooser(OutputTabOperator op, String text,
637: int status) {
638: this .op = op;
639: this .text = text;
640: this .status = status;
641: }
642:
643: public boolean checkComponent(Component comp) {
644: for (int i = status; i < op.getLineCount(); i++) {
645: if (op.getLine(i).startsWith(text)) {
646: lastIndex = i;
647: return true;
648: }
649: }
650: return false;
651: }
652:
653: public String getDescription() {
654: return "\"" + text + "\" text";
655: }
656:
657: public int getLastIndex() {
658: return lastIndex;
659: }
660: }
661: }
|