|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.test.gui.web.util; import javax.swing.tree.TreePath; import javax.swing.JPopupMenu; import org.netbeans.jellytools.Bundle; import org.netbeans.jellytools.EditorOperator; import org.netbeans.jellytools.EditorWindowOperator; import org.netbeans.jellytools.ExplorerOperator; import org.netbeans.jellytools.MainWindowOperator; import org.netbeans.jellytools.OptionsOperator; import org.netbeans.jellytools.OutputWindowOperator; import org.netbeans.jellytools.TreeTableOperator; import org.netbeans.jellytools.nodes.FilesystemNode; import org.netbeans.jellytools.nodes.FormNode; import org.netbeans.jellytools.properties.ComboBoxProperty; import org.netbeans.jellytools.properties.PropertySheetOperator; import org.netbeans.jellytools.properties.PropertySheetTabOperator; import org.netbeans.jellytools.properties.TextFieldProperty; import org.netbeans.jemmy.Timeouts; import org.netbeans.jemmy.TimeoutExpiredException; import org.netbeans.jemmy.Waiter; import org.netbeans.jemmy.operators.DialogOperator; import org.netbeans.jemmy.operators.JButtonOperator; import org.netbeans.jemmy.operators.JComboBoxOperator; import org.netbeans.jemmy.operators.JCheckBoxOperator; import org.netbeans.jemmy.operators.JPopupMenuOperator; import org.netbeans.jemmy.operators.JTextFieldOperator; import org.netbeans.jemmy.operators.JTreeOperator; import org.netbeans.web.test.util.StatusWaitable; import org.netbeans.web.test.actions.ToggleBreakpointAction; public class CommonUtils { private static String breakpointsPath = "Debugger|Breakpoint"; private static String delim = "|"; public CommonUtils() { } public static EditorOperator openFile(String workDir, String file) { MainWindowOperator.getDefault().switchToEditingWorkspace(); ExplorerOperator explorer = ExplorerOperator.invoke(); explorer.selectPageFilesystems(); FilesystemNode tmpNode = null; tmpNode = new FilesystemNode(workDir); FormNode fNode = new FormNode(tmpNode, file); fNode.edit(); EditorWindowOperator editorWindow = new EditorWindowOperator(file); EditorOperator editor = editorWindow.selectPage(file); editor.requestFocus(); return editor; } public static boolean isLineBreakpointExist(String name, int lineNumber) { boolean result = true; String breakpointName = "Line "+name+".java:"+lineNumber; ExplorerOperator explorer = ExplorerOperator.invoke(); JTreeOperator jTreeOper = explorer.runtimeTab().tree(); Timeouts.initDefault("JTreeOperator.WaitNodeExpandedTimeout", 3000); try{ String breakpointNode = "Debugger"+delim+"Breakpoints"+delim+breakpointName; System.out.println("Try to find: "+breakpointNode); TreePath treePath = jTreeOper.findPath(breakpointNode, delim); JPopupMenu popupMenu = jTreeOper.callPopupOnPath(treePath); JPopupMenuOperator popupOper = new JPopupMenuOperator(popupMenu); popupOper.pushMenu("Properties", "|"); PropertySheetOperator properties = PropertySheetOperator.invoke(); PropertySheetTabOperator propertiesSheet = new PropertySheetTabOperator(properties, "Properties"); TextFieldProperty lineProperty = new TextFieldProperty(propertiesSheet, "Line Number"); ComboBoxProperty stateProperty = new ComboBoxProperty(propertiesSheet, "Enabled"); String line = lineProperty.getValue(); String state = stateProperty.getValue(); if(state.equals("False") | !line.equals((new Integer(lineNumber)).toString())){ result = false; } properties.close(); }catch(Exception e){ e.printStackTrace(); result = false; } return result; } public static void checkBreakpointExist(String name, String breakpointFileName, int line, String workDir) { String fullName = null; fullName = "Line "+breakpointFileName+".java:"+line; if(!isExplorerItemExist("Debugger"+delim+"Breakpoints"+delim+fullName)){ EditorOperator editor = openFile(workDir, name); editor.setCaretPositionToLine(line); (new ToggleBreakpointAction()).performShortcut(); return; } } public static boolean isExplorerItemExist(String path) { ExplorerOperator explorer = ExplorerOperator.invoke(); explorer.selectPageRuntime(); try { JTreeOperator jTreeOper = explorer.runtimeTab().tree(); jTreeOper.findPath(path,delim); }catch(TimeoutExpiredException tee) { return false; } return true; } public static void fillAddBreakpointLine(String type, String name, int line){ DialogOperator dialog = new DialogOperator(Bundle.getStringTrimmed("org.netbeans.modules.debugger.support.actions.Bundle", "CTL_Breakpoint_Title")); if(type!=null){ if(type=="jsp/servlet"){ (new JComboBoxOperator(dialog, 0)).selectItem(Bundle.getStringTrimmed("org.netbeans.modules.web.debug.Bundle", "CTL_JSP_SERVLET_DEBUGGER_NAME")); }else{ (new JComboBoxOperator(dialog, 0)).selectItem(Bundle.getStringTrimmed("org.netbeans.modules.web.debug.Bundle", "CTL_JSP_DEBUGGER_NAME")); } new JButtonOperator(dialog, "OK").doClick(); }else{ (new JComboBoxOperator(dialog, 1)).selectItem(Bundle.getStringTrimmed("org.netbeans.modles.debugger.support.java.Bundle", "CTL_Line_event_type_name")); JTextFieldOperator lineField = new JTextFieldOperator(dialog, 0); if(line!=0){ lineField.setText((new Integer(line)).toString()); } if(name!=null){ JTextFieldOperator fileField = new JTextFieldOperator(dialog, 1); fileField.setText(name); } new JButtonOperator(dialog, "OK").doClick(); } } private static void wait(int millisec) { try { Thread.sleep(millisec); } catch(Exception e) {} } private static String waitStop(StatusWaitable csw){ Waiter w = new Waiter(csw); try { w.waitAction(csw); } catch (InterruptedException e) { e.printStackTrace(); return("Exception while waiting debugger stop:" + e); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); return("Exception while waiting debugger stop:" + e1); } return null; } public static String waitDebuggerStoppedOnBreakpoint(String className, int line) { String[] variants = {"Breakpoint reached at line " + line + " in class "+className}; StatusWaitable csw = new StatusWaitable(variants, false); return waitStop(csw); } public static String waitDebuggerStoppedOnMethod(String className, String methodName, int line) { String[] variants = {"Method "+methodName+" reached at line " + line + " in class "+className}; StatusWaitable csw = new StatusWaitable(variants, false); return waitStop(csw); } public static String waitDebuggerStoppedOnVariable(String variableName, String accessName, String number) { String[] variants = {"Variable "+variableName+" "+accessName+ " ("+number+")."}; StatusWaitable csw = new StatusWaitable(variants, true); return waitStop(csw); } public static String waitDebuggerStoppedOnExceptionCaught(String className, String exceptionName, int line) { String[] variants = {"Exception "+exceptionName+" reached at line " + line + " in class "+className}; StatusWaitable csw = new StatusWaitable(variants, false); return waitStop(csw); } public static String waitDebuggerStoppedOnHiddenBreakpoint(String className, int line) { String[] variants = {className + ".class stopped at debug." + className + ".sendOK line "+line}; StatusWaitable csw = new StatusWaitable(variants, false); return waitStop(csw); } public static String waitDebuggerStoppedInInit(String className, int line) { String[] variants = {"stopped at " + className + ". |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.