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:
007: The contents of this file are subject to the terms of either the GNU
008: General Public License Version 2 only ("GPL") or the Common
009: Development and Distribution License("CDDL") (collectively, the
010: "License"). You may not use this file except in compliance with the
011: License. You can obtain a copy of the License at
012: http://www.netbeans.org/cddl-gplv2.html
013: or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
014: specific language governing permissions and limitations under the
015: License. When distributing the software, include this License Header
016: Notice in each file and include the License file at
017: nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
018: particular file as subject to the "Classpath" exception as provided
019: by Sun in the GPL Version 2 section of the License file that
020: accompanied this code. If applicable, add the following below the
021: License Header, with the fields enclosed by brackets [] replaced by
022: your own identifying information:
023: "Portions Copyrighted [year] [name of copyright owner]"
024:
025: Contributor(s):
026:
027: The Original Software is NetBeans. The Initial Developer of the Original
028: Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
029: Microsystems, Inc. All Rights Reserved.
030:
031: If you wish your version of this file to be governed by only the CDDL
032: or only the GPL Version 2, indicate your decision by adding
033: "[Contributor] elects to include this software in this distribution
034: under the [CDDL or GPL Version 2] license." If you do not indicate a
035: single choice of license, a recipient has the option to distribute
036: your version of this file under either the CDDL, the GPL Version 2 or
037: to extend the choice of license to its licensees as provided above.
038: However, if you add GPL Version 2 code and therefore, elected the GPL
039: Version 2 license, then the option applies only if the new code is
040: made subject to such option by the copyright holder.
041: */
042: package org.netbeans.test.dataprovider.common;
043:
044: import java.awt.event.*;
045: import java.io.*;
046: import java.util.*;
047: import java.util.Map.*;
048: import java.awt.*;
049: import java.util.regex.*;
050: import javax.swing.*;
051: import javax.swing.tree.*;
052: import javax.swing.text.*;
053: import org.netbeans.modules.visualweb.gravy.dataconnectivity.*;
054: import org.netbeans.modules.visualweb.gravy.model.deployment.*;
055: import org.netbeans.modules.visualweb.gravy.designer.*;
056: import org.netbeans.modules.visualweb.gravy.toolbox.*;
057: import org.netbeans.modules.visualweb.gravy.*;
058: import org.netbeans.jellytools.TopComponentOperator;
059: import org.netbeans.jemmy.*;
060: import org.netbeans.jemmy.operators.*;
061: import org.netbeans.jellytools.actions.*;
062: import org.netbeans.jemmy.drivers.*;
063: import org.netbeans.jemmy.drivers.input.MouseRobotDriver;
064: import org.netbeans.modules.visualweb.gravy.properties.*;
065:
066: public class Utils implements Constants {
067: public static PrintStream logStream;
068:
069: private static final long WAIT_NEXT_NODE_TIMEOUT = 1500; // milliseconds
070:
071: public static void openLog() {
072: closeLog();
073: String logFilePath = TEST_LOG_FILE_PATH + "/"
074: + TEST_LOG_FILE_NAME;
075: try {
076: File logFile = new File(logFilePath);
077: if (logFile.exists()) {
078: logFile.delete();
079: }
080: FileOutputStream logFileStream = new FileOutputStream(
081: logFile, true);
082: logStream = new PrintStream(logFileStream);
083: } catch (Exception e) {
084: e.printStackTrace();
085: logStream = null;
086: throw new RuntimeException(e);
087: }
088: }
089:
090: public static void closeLog() {
091: if (logStream != null) {
092: try {
093: logStream.flush();
094: logStream.close();
095: } catch (Exception e) {
096: e.printStackTrace();
097: } finally {
098: logStream = null;
099: }
100: }
101: }
102:
103: public static void logMsg(String msg) {
104: logMsg(msg, true, true);
105: }
106:
107: public static void logMsg(String msg, boolean spaceBefore,
108: boolean spaceAfter) {
109: logMsg(logStream, msg, spaceBefore, spaceAfter);
110: }
111:
112: public static void logMsg(PrintStream out, String msg,
113: boolean spaceBefore, boolean spaceAfter) {
114: if (spaceBefore) {
115: out.println();
116: }
117: out.println(msg);
118: if (spaceAfter) {
119: out.println();
120: }
121: }
122:
123: public static void logMsg(Object... dataArray) {
124: debugOutput(logStream, dataArray);
125: }
126:
127: public static void debugOutput(Object... dataArray) {
128: debugOutput(logStream, dataArray);
129: }
130:
131: public static void debugOutput(PrintStream out, Object... dataArray) {
132: out.println();
133: for (Object obj : dataArray) {
134: out.println(obj.toString());
135: }
136: out.println();
137: }
138:
139: public static void doSaveAll() {
140: Util.getMainMenu().pushMenuNoBlock(
141: MAIN_MENU_ITEM_WINDOW_SAVE_ALL);
142: Util.wait(1000);
143: new QueueTool().waitEmpty();
144: logMsg("+++ [Save All] action has been performed");
145: }
146:
147: public static void doCloseWindow() {
148: Util.getMainMenu().pushMenuNoBlock(
149: MAIN_MENU_ITEM_WINDOW_CLOSE_WINDOW);
150: Util.wait(1000);
151: new QueueTool().waitEmpty();
152: logMsg("+++ [Close Window] action has been performed");
153: }
154:
155: public static void doResetWindows() {
156: Util.getMainMenu().pushMenuNoBlock(
157: MAIN_MENU_ITEM_WINDOW_RESET_WINDOWS);
158: Util.wait(2500);
159: new QueueTool().waitEmpty();
160: logMsg("+++ [Reset Windows] action has been performed");
161: }
162:
163: public static String setDeploymentTargetProperties(
164: DeploymentTargetDescriptor deploymentTargetDescriptor) {
165: String errMsg = null;
166:
167: String appServerType = TestPropertiesHandler
168: .getServerProperty("Application_Server_Type");
169: if (appServerType == null) {
170: errMsg = "--- Deployment Target (application server) isn't defined ---";
171: return errMsg;
172: }
173: if (ServerExplorerOperator.STR_NAME_APPSERVER.toLowerCase()
174: .contains(appServerType.toLowerCase())) {
175: return setSunAppServerProperties(deploymentTargetDescriptor);
176: } else if ((ServerExplorerOperator.STR_NAME_TOMCAT50 + ServerExplorerOperator.STR_NAME_TOMCAT55)
177: .toLowerCase().contains(appServerType.toLowerCase())) {
178: return setTomcatAppServerProperties(deploymentTargetDescriptor);
179: } else {
180: errMsg = "--- Unknown Deployment Target (application server): ["
181: + appServerType + "] ---";
182: }
183: return errMsg;
184: }
185:
186: public static String setSunAppServerProperties(
187: DeploymentTargetDescriptor deploymentTargetDescriptor) {
188: String errMsg = null, serverType = ServerExplorerOperator.STR_NAME_APPSERVER, appServerAbsPath = TestPropertiesHandler
189: .getServerProperty("Application_Server_AbsPath");
190:
191: Hashtable deploymentTargetProperties = deploymentTargetDescriptor
192: .getProperties();
193: deploymentTargetProperties.put(
194: DeploymentTargetDescriptor.SERVER_TYPE_KEY, serverType);
195: deploymentTargetProperties.put(
196: DeploymentTargetDescriptor.NAME_KEY + serverType,
197: TestPropertiesHandler
198: .getServerProperty("Application_Server_Name"));
199: deploymentTargetProperties.put(
200: DeploymentTargetDescriptor.PATH_KEY + serverType,
201: appServerAbsPath);
202: deploymentTargetProperties
203: .put(
204: DeploymentTargetDescriptor.DOMAIN_KEY
205: + serverType,
206: appServerAbsPath
207: + "/"
208: + TestPropertiesHandler
209: .getServerProperty("Application_Server_Domain_Dir"));
210: deploymentTargetProperties.put(
211: DeploymentTargetDescriptor.LOGIN_KEY + serverType,
212: TestPropertiesHandler
213: .getServerProperty("Application_Server_Login"));
214: deploymentTargetProperties
215: .put(
216: DeploymentTargetDescriptor.PASSWORD_KEY
217: + serverType,
218: TestPropertiesHandler
219: .getServerProperty("Application_Server_Password"));
220:
221: printDeploymentTargetProperties(deploymentTargetDescriptor);
222:
223: return errMsg;
224: }
225:
226: public static String setTomcatAppServerProperties(
227: DeploymentTargetDescriptor deploymentTargetDescriptor) {
228: String errMsg = "--- Deployment Target [Tomcat] isn't implemented yet ---";
229: return errMsg;
230: }
231:
232: private static void printDeploymentTargetProperties(
233: DeploymentTargetDescriptor deploymentTargetDescriptor) {
234: Hashtable deploymentTargetProperties = deploymentTargetDescriptor
235: .getProperties();
236: Set entrySet = deploymentTargetProperties.entrySet();
237: logMsg(
238: "Property of Deployment Target ["
239: + deploymentTargetProperties
240: .get(DeploymentTargetDescriptor.SERVER_TYPE_KEY)
241: + "]", true, false);
242: for (Object entryKeyValue : entrySet) {
243: Map.Entry mapEntry = (Map.Entry) entryKeyValue;
244: logMsg(" Property [" + mapEntry.getKey() + "] = ["
245: + mapEntry.getValue() + "]", false, false);
246: }
247: }
248:
249: public static void putFocusOnWindowServices() {
250: putFocusOnWindow(MAIN_MENU_ITEM_WINDOW_SERVICES);
251: }
252:
253: public static void putFocusOnWindowPalette() {
254: putFocusOnWindow(MAIN_MENU_ITEM_WINDOW_PALETTE);
255: }
256:
257: public static void putFocusOnWindowNavigator() {
258: putFocusOnWindow(MAIN_MENU_ITEM_WINDOW_NAVIGATOR);
259: }
260:
261: public static void putFocusOnWindowProperties() {
262: putFocusOnWindow(MAIN_MENU_ITEM_WINDOW_PROPERTIES);
263: }
264:
265: public static void putFocusOnWindowProjects() {
266: putFocusOnWindow(MAIN_MENU_ITEM_WINDOW_PROJECTS);
267: }
268:
269: private static void putFocusOnWindow(String windowMenuItem) {
270: JMenuBarOperator menuBarOp = Util.getMainMenu();
271: Util.wait(1500);
272: new QueueTool().waitEmpty();
273: menuBarOp.clickMouse(1, 1);
274: Util.wait(1000);
275: menuBarOp.pressKey(KeyEvent.VK_ESCAPE);
276: Util.wait(1000);
277: new QueueTool().waitEmpty();
278: menuBarOp.pushMenuNoBlock(windowMenuItem);
279: Util.wait(1000);
280: new QueueTool().waitEmpty();
281: }
282:
283: private static TreePath findTreeNode(JTreeOperator jTreeOp,
284: String treeNodeLabel, long waitTimeout, boolean setSelected) {
285: TreePath treePath = null;
286: try {
287: jTreeOp.getTimeouts().setTimeout(
288: "JTreeOperator.WaitNextNodeTimeout", waitTimeout);
289: treePath = jTreeOp.findPath(treeNodeLabel);
290: if (setSelected) {
291: //jTreeOp.setVerification(use_JTreeOperator_Verification);
292: Util.wait(500);
293: new QueueTool().waitEmpty();
294: jTreeOp.selectPath(treePath);
295: }
296: } catch (TimeoutExpiredException tee) {
297: tee.printStackTrace(Utils.logStream);
298: return null;
299: } finally {
300: Util.wait(500);
301: new QueueTool().waitEmpty();
302: }
303: return treePath;
304: }
305:
306: public static TreePath findDBConnectionTreeNode() {
307: String dbURL = TestPropertiesHandler
308: .getDatabaseProperty("DB_URL");
309:
310: //return findServicesTreeNode(SERVICES_TREE_NODE_DATABASES + "|" + dbURL, false);
311: JTree jTree = (JTree) new ServerNavigatorOperator().getTree()
312: .getSource();
313: return selectChildOfTreeNode(jTree,
314: SERVICES_TREE_NODE_DATABASES, dbURL);
315: }
316:
317: public static TreePath findServicesTreeNode(String treeNodeLabel,
318: boolean setSelected) {
319: return (findServicesTreeNode(treeNodeLabel,
320: WAIT_NEXT_NODE_TIMEOUT, setSelected));
321: }
322:
323: public static TreePath findServicesTreeNode(String treeNodeLabel,
324: long waitTimeout, boolean setSelected) {
325: ServerNavigatorOperator serverNavigatorOp = null;
326: for (int i = 0; i < 3; i++) {
327: try {
328: serverNavigatorOp = new ServerNavigatorOperator();
329: if (serverNavigatorOp != null)
330: break;
331: Util.wait(500);
332: new QueueTool().waitEmpty();
333: } catch (TimeoutExpiredException e) {
334: e.printStackTrace(logStream);
335: }
336: }
337: JTreeOperator jTreeOp = null;
338: for (int i = 0; i < 3; i++) {
339: try {
340: jTreeOp = serverNavigatorOp.getTree();
341: if (jTreeOp != null)
342: break;
343: Util.wait(500);
344: new QueueTool().waitEmpty();
345: } catch (TimeoutExpiredException e) {
346: e.printStackTrace(logStream);
347: }
348: }
349: return (findTreeNode(jTreeOp, treeNodeLabel, waitTimeout,
350: setSelected));
351: }
352:
353: public static void callPopupMenuOnProjectsTreeNode(
354: String treeNodeLabel, String popupMenuItem) {
355: callPopupMenuOnTreeNode(new ProjectNavigatorOperator().tree(),
356: treeNodeLabel, popupMenuItem);
357: }
358:
359: public static void callPopupMenuOnServicesTreeNode(
360: String treeNodeLabel, String popupMenuItem) {
361: callPopupMenuOnTreeNode(
362: new ServerNavigatorOperator().getTree(), treeNodeLabel,
363: popupMenuItem);
364: }
365:
366: public static void callPopupMenuOnNavigatorTreeNode(
367: String treeNodeLabel, String popupMenuItem) {
368: callPopupMenuOnTreeNode(getNavigatorTreeOperator(),
369: treeNodeLabel, popupMenuItem);
370: }
371:
372: public static JPopupMenuOperator invokePopupMenuOnTreeNode(
373: JTreeOperator jTreeOp, String treeNodeLabel) {
374: JPopupMenuOperator popupMenuOp = new JPopupMenuOperator(jTreeOp
375: .callPopupOnPath(findTreeNode(jTreeOp, treeNodeLabel,
376: WAIT_NEXT_NODE_TIMEOUT, true)));
377: Util.wait(500);
378: new QueueTool().waitEmpty();
379: return popupMenuOp;
380: }
381:
382: private static void callPopupMenuOnTreeNode(JTreeOperator jTreeOp,
383: String treeNodeLabel, String popupMenuItem) {
384: JPopupMenuOperator popupMenuOp = invokePopupMenuOnTreeNode(
385: jTreeOp, treeNodeLabel);
386: popupMenuOp.pushMenuNoBlock(popupMenuItem);
387: Util.wait(500);
388: new QueueTool().waitEmpty();
389: /*
390: JMenuItem menuItem = TestUtils.findPopupMenuItemByLabel(popupMenuOp,
391: strMenuItem, false, false);
392: new JMenuItemOperator(menuItem).pushNoBlock();
393: Util.wait(500);
394: new QueueTool().waitEmpty();
395: */
396: }
397:
398: public static JPopupMenuOperator callPopupOnPath(
399: JTreeOperator treeOp, TreePath treePath) {
400: int row = treeOp.getRowForPath(treePath);
401: Rectangle rowRect = treeOp.getRowBounds(row);
402: int x = rowRect.x + rowRect.width / 2, y = rowRect.y
403: + rowRect.height / 2;
404: treeOp.clickMouse(x, y, 1, InputEvent.BUTTON3_MASK);
405: Util.wait(500);
406: new QueueTool().waitEmpty();
407: return (new JPopupMenuOperator());
408: }
409:
410: public static TreePath findNavigatorTreeNode(String treeNodeLabel,
411: boolean setSelected) {
412: return (findNavigatorTreeNode(treeNodeLabel,
413: WAIT_NEXT_NODE_TIMEOUT, setSelected));
414: }
415:
416: public static TreePath findNavigatorTreeNode(String treeNodeLabel,
417: long waitTimeout, boolean setSelected) {
418: JTreeOperator jTreeOp = getNavigatorTreeOperator();
419: return (findTreeNode(jTreeOp, treeNodeLabel, waitTimeout,
420: setSelected));
421: }
422:
423: public static TopComponentOperator getNavigatorOperator() {
424: DesignerPaneOperator designPaneOp = new DesignerPaneOperator(
425: RaveWindowOperator.getDefaultRave());
426: DesignerPaneOperator.switchToDesignerPane();
427:
428: putFocusOnWindowNavigator();
429: TopComponentOperator topComponentOp = new TopComponentOperator(
430: WINDOW_NAVIGATOR_TITLE);
431: return topComponentOp;
432: }
433:
434: public static JTreeOperator getNavigatorTreeOperator() {
435: TopComponentOperator topComponentOp = getNavigatorOperator();
436: /*
437: topComponentOp.getTimeouts().setTimeout("ComponentOperator.WaitComponentTimeout", 1000);
438: try {
439: JComboBoxOperator comboBoxOp = new JComboBoxOperator(topComponentOp);
440: comboBoxOp.selectItem(NAVIGATOR_COMBOBOX_ITEM_NAVIGATOR);
441: } catch (TimeoutExpiredException e) {
442: e.printStackTrace(logStream);
443: }
444: */
445: JTreeOperator treeOp = new JTreeOperator(topComponentOp);
446: return treeOp;
447: }
448:
449: public static JTreeOperator getServerNavigatorTreeOperator() {
450: putFocusOnWindowServices();
451: JTreeOperator jTreeOp = new ServerNavigatorOperator().getTree();
452: return jTreeOp;
453: }
454:
455: public static TreePath selectChildOfTreeNode(JTree jTree,
456: String treeNodeName, String childNodeName) {
457: TreePath treePath = jTree.getNextMatch(treeNodeName, 0,
458: Position.Bias.Forward);
459: return selectChildOfTreeNode(jTree, treePath, childNodeName);
460: }
461:
462: public static TreePath selectChildOfTreeNode(JTree jTree,
463: TreePath startTreePath, String childNodeName) {
464: if (startTreePath == null)
465: throw new RuntimeException("Start tree path is null");
466:
467: jTree.expandPath(startTreePath);
468: Util.wait(500);
469: new QueueTool().waitEmpty();
470: logMsg("+++ Expanded treePath = [" + startTreePath.toString()
471: + "]");
472:
473: int row = jTree.getRowForPath(startTreePath);
474:
475: TreePath treePath = jTree.getNextMatch(childNodeName, row,
476: Position.Bias.Forward);
477: if (treePath == null)
478: return null;
479:
480: jTree.setSelectionPath(treePath);
481: logMsg("+++ Selected treePath = [" + treePath.toString() + "]");
482: Util.wait(500);
483: new QueueTool().waitEmpty();
484:
485: treePath = jTree.getSelectionPath();
486: return treePath;
487: }
488:
489: public static TreePath selectChildOfTreeNode(JTree jTree,
490: TreePath parentTreePath, int childNumber) {
491: jTree.expandPath(parentTreePath);
492: Util.wait(500);
493: new QueueTool().waitEmpty();
494: logMsg("+++ Expanded treePath = [" + parentTreePath.toString()
495: + "]");
496:
497: TreeModel treeModel = jTree.getModel();
498: Object objChild = treeModel.getChild(parentTreePath
499: .getLastPathComponent(), childNumber);
500: // String childName = objChild.toString();
501: TreePath childTreePath = parentTreePath
502: .pathByAddingChild(objChild);
503:
504: jTree.setSelectionPath(childTreePath);
505: logMsg("+++ Selected treePath = [" + childTreePath.toString()
506: + "]");
507:
508: Util.wait(500);
509: new QueueTool().waitEmpty();
510: return childTreePath;
511: }
512:
513: public static void putComponentOnDesigner(String paletteName,
514: String componentName, String componentID, int x, int y,
515: String navigatorTreeNodePrefix) {
516: Utils.putFocusOnWindowPalette();
517: Util.wait(500);
518: new QueueTool().waitEmpty();
519:
520: DesignerPaneOperator designPaneOp = new DesignerPaneOperator(
521: RaveWindowOperator.getDefaultRave());
522:
523: PaletteContainerOperator paletteContainerOp = new PaletteContainerOperator(
524: paletteName);
525:
526: paletteContainerOp.addComponent(componentName, designPaneOp,
527: new Point(x, y));
528: Util.wait(2000);
529: new QueueTool().waitEmpty();
530:
531: logMsg("+++ Component [" + componentName
532: + "] has been placed on Design View");
533:
534: String treeNodeLabel = navigatorTreeNodePrefix + componentID;
535: TreePath treePath = Utils.findNavigatorTreeNode(treeNodeLabel,
536: true);
537: Util.wait(500);
538: new QueueTool().waitEmpty();
539: if (treePath == null) {
540: throw new RuntimeException("The tree node ["
541: + treeNodeLabel
542: + "] isn't found in the window [Navigator]");
543: }
544: logMsg("The tree node [" + treeNodeLabel
545: + "] is found in the window [Navigator]");
546: }
547:
548: public static void setTextPropertyValue(String propertyName,
549: String propertyValue) {
550: putFocusOnWindowProperties();
551: SheetTableOperator propTableOp = new SheetTableOperator();
552: propTableOp.setTextValue(propertyName, propertyValue);
553: Util.wait(1000);
554: new QueueTool().waitEmpty();
555: }
556:
557: public static void setComboboxPropertyValue(String propertyName,
558: String propertyValue) {
559: putFocusOnWindowProperties();
560: SheetTableOperator propTableOp = new SheetTableOperator();
561: int rowNumber = propTableOp.findCellRow(propertyName);
562: Util.wait(1000);
563: new QueueTool().waitEmpty();
564:
565: propTableOp.clickOnCell(rowNumber, 1);
566: Util.wait(1000);
567: new QueueTool().waitEmpty();
568:
569: JComboBoxOperator comboboxOp = new JComboBoxOperator(
570: propTableOp);
571: comboboxOp.selectItem(propertyValue);
572: Util.wait(1000);
573: new QueueTool().waitEmpty();
574: }
575:
576: public static Point getSelectedComponentLeftUpperPoint() {
577: Point componentPoint = null;
578: int x = -1, y = -1;
579: String valuePropertyStyle = getSelectedComponentProperty(PROPERTY_NAME_STYLE);
580:
581: // style="position: absolute; left: 48px; top: 96px"
582: x = extractComponentCoordinate(valuePropertyStyle, "left"); // get coordinate X
583: y = extractComponentCoordinate(valuePropertyStyle, "top"); // get coordinate Y
584: if ((x > -1) && (y > -1)) {
585: componentPoint = new Point(x, y);
586: }
587: return componentPoint;
588: }
589:
590: public static String getSelectedComponentProperty(
591: String propertyName) {
592: putFocusOnWindowProperties();
593: SheetTableOperator propTableOp = new SheetTableOperator();
594: Util.wait(500);
595: new QueueTool().waitEmpty();
596: String propertyValue = propTableOp.getValue(propertyName);
597: logMsg("+++ Value of property [" + propertyName
598: + "] for selected component = [" + propertyValue + "]");
599: return propertyValue;
600: }
601:
602: private static int extractComponentCoordinate(
603: String valuePropertyStyle, String coordPosition) {
604: int coordValue = -1;
605:
606: // style="position: absolute; left: 48px; top: 96px"
607: String patternPrefix = "[:;\\w\\s]*", patternSuffix = "[\\s]*:[\\s]*(\\d*)[:;\\w\\s]*";
608:
609: Pattern pattern = Pattern.compile(patternPrefix + coordPosition
610: + patternSuffix);
611: Matcher matcher = pattern.matcher(valuePropertyStyle);
612: try {
613: matcher.matches();
614: coordValue = Integer.parseInt(matcher.group(1));
615: } catch (Exception e) {
616: logMsg("+++ Problem with getting [" + coordPosition
617: + "] coordinate of selected component: "
618: + e.getMessage());
619: e.printStackTrace(logStream);
620: }
621: return coordValue;
622: }
623:
624: public static void createSessionBeanDataProvider(String dbURL,
625: String dbTableName) {
626: createSessionBeanDataProvider(dbURL, dbTableName, null, -1, -1);
627: }
628:
629: public static void createSessionBeanDataProvider(String dbURL,
630: String dbTableName, String rowSetName,
631: int radioButtonIndex, int textFieldIndex) {
632: createDataProvider(dbURL, dbTableName,
633: NAVIGATOR_TREE_NODE_SESSION_PREFIX.replace("|", ""),
634: rowSetName, radioButtonIndex, textFieldIndex);
635: }
636:
637: public static void createDataProvider(String dbURL,
638: String dbTableName, String beanNodeName, String rowSetName,
639: int radioButtonIndex, int textFieldIndex) {
640: //dndDBTableOnManagedBean(dbURL, dbTableName, beanNodeName);
641: copyPasteDBTableOnManagedBean(dbURL, dbTableName, beanNodeName);
642: if (rowSetName != null) {
643: Utils.defineSessionRowSetNameInDialog(rowSetName,
644: radioButtonIndex, textFieldIndex);
645: }
646: Util.wait(2000);
647: new QueueTool().waitEmpty();
648: Utils.doSaveAll();
649: }
650:
651: public static void copyPasteDBTableOnManagedBean(String dbURL,
652: final String dbTableName, final String beanNodeName) {
653: selectDBTable(dbURL, dbTableName);
654: Util.wait(500);
655: new QueueTool().waitEmpty();
656:
657: Util.getMainMenu().pushMenuNoBlock(MAIN_MENU_ITEM_EDIT_COPY);
658: Util.wait(1000);
659: new QueueTool().waitEmpty();
660:
661: Thread pasteThread = new Thread(new Runnable() {
662: public void run() {
663: callPopupMenuOnNavigatorTreeNode(beanNodeName,
664: POPUP_MENU_ITEM_PASTE);
665: logMsg("+++ DB table [" + dbTableName
666: + "] is copied on managed bean ["
667: + beanNodeName + "]");
668: }
669: });
670: pasteThread.start();
671: try {
672: logMsg("+++ Wait until paste thread is died...");
673: pasteThread.join(3000);
674: } catch (Exception e) {
675: e.printStackTrace(logStream);
676: }
677: Util.wait(1000);
678: new QueueTool().waitEmpty();
679: }
680:
681: public static void dndDBTableOnManagedBean(String dbURL,
682: final String dbTableName, final String beanNodeName) {
683: final JTreeOperator navigatorTreeOp = getNavigatorTreeOperator();
684: TreePath beanTreePath = findNavigatorTreeNode(beanNodeName,
685: true);
686: if (beanTreePath == null) {
687: throw new RuntimeException("The tree node [" + beanNodeName
688: + "] isn't found in the window [Navigator]");
689: }
690: final Point beanNodePoint = navigatorTreeOp
691: .getPointToClick(beanTreePath);
692: logMsg("+++ Point of bean node [" + beanNodeName
693: + "] in the window [Navigator] = [" + beanNodePoint
694: + "]");
695:
696: final JTreeOperator serverNavigatorTreeOp = getServerNavigatorTreeOperator();
697: TreePath dbTableTreePath = selectDBTable(dbURL, dbTableName);
698: if (dbTableTreePath == null) {
699: throw new RuntimeException("The tree node [" + dbTableName
700: + "] isn't found in the window [Services]");
701: }
702: final Point dbTableNodePoint = serverNavigatorTreeOp
703: .getPointToClick(dbTableTreePath);
704: logMsg("+++ Point of DB table node [" + dbTableName
705: + "] in the window [Services] = [" + dbTableNodePoint
706: + "]");
707:
708: Thread dndThread = new Thread(new Runnable() {
709: public void run() {
710: dndFromTo(serverNavigatorTreeOp, dbTableNodePoint,
711: navigatorTreeOp, beanNodePoint);
712: logMsg("+++ DnD is performed: DB table [" + dbTableName
713: + "] => on managed bean [" + beanNodeName + "]");
714: }
715: });
716: dndThread.start();
717: try {
718: logMsg("+++ Wait until DnD mouse thread is died...");
719: dndThread.join(3000);
720: } catch (Exception e) {
721: e.printStackTrace(logStream);
722: }
723: Util.wait(1000);
724: new QueueTool().waitEmpty();
725: }
726:
727: public static void dndFromTo(ComponentOperator sourceComponent,
728: Point sourcePoint, ComponentOperator targetComponent,
729: Point targetPoint) {
730: dndFromTo(sourceComponent, sourcePoint, targetComponent,
731: targetPoint, InputEvent.BUTTON1_MASK, 0);
732: }
733:
734: public static void dndFromTo(ComponentOperator sourceComponent,
735: Point sourcePoint, ComponentOperator targetComponent,
736: Point targetPoint, int mouseButton, int keyModifiers) {
737: Timeout dndTimeout = new Timeout(
738: "MouseRobotDriver timeout for Drag-n-Drop", 1000);
739: MouseRobotDriver mouseRobotDriver = new MouseRobotDriver(
740: dndTimeout);
741: int startX = sourceComponent.getSource().getLocationOnScreen().x
742: + sourcePoint.x + 1, startY = sourceComponent
743: .getSource().getLocationOnScreen().y
744: + sourcePoint.y + 1, endX = targetComponent.getSource()
745: .getLocationOnScreen().x
746: + targetPoint.x + 1, endY = targetComponent.getSource()
747: .getLocationOnScreen().y
748: + targetPoint.y + 1;
749: mouseRobotDriver.dragNDrop(startX, startY, endX, endY,
750: mouseButton, keyModifiers, dndTimeout, dndTimeout);
751:
752: Util.wait(500);
753: new QueueTool().waitEmpty();
754: }
755:
756: public static TreePath selectDBTable(String dbURL,
757: String dbTableName) {
758: //TreePath treePath = findServicesTreeNode(SERVICES_TREE_NODE_DATABASES + "|" + dbURL + "|" +
759: // DB_TREE_NODE_TABLES + "|" + dbTableName, true);
760: JTree jTree = (JTree) getServerNavigatorTreeOperator()
761: .getSource();
762: TreePath treePath = selectChildOfTreeNode(jTree, dbURL,
763: DB_TREE_NODE_TABLES);
764: jTree.expandPath(treePath);
765: Util.wait(500);
766: new QueueTool().waitEmpty();
767:
768: TreeModel treeModel = jTree.getModel();
769: int childCount = treeModel.getChildCount(treePath
770: .getLastPathComponent());
771: // wait until childCount (amount of available DB tables) is greater than 1 because
772: // several seconds only one child exists - the subnode with text "Please, wait..."
773: for (int i = 0; i < 10; i++) {
774: if (childCount > 1)
775: break;
776: childCount = treeModel.getChildCount(treePath
777: .getLastPathComponent());
778: Util.wait(1000);
779: new QueueTool().waitEmpty();
780: }
781: TreePath dbTableTreePath = null;
782: for (int i = 0; i < childCount; i++) {
783: Object objDBTable = treeModel.getChild(treePath
784: .getLastPathComponent(), i);
785: if (objDBTable.toString().equalsIgnoreCase(dbTableName)) {
786: dbTableTreePath = treePath
787: .pathByAddingChild(objDBTable);
788: jTree.setSelectionPath(dbTableTreePath);
789: break;
790: }
791: }
792: return dbTableTreePath;
793: }
794:
795: public static void callPopupMenuForDBTable(String dbURL,
796: String dbTableName, String popupMenuItem) {
797: TreePath treePath = selectDBTable(dbURL, dbTableName);
798: Util.wait(1000);
799: new QueueTool().waitEmpty();
800:
801: JPopupMenuOperator popupMenuOp = callPopupOnPath(
802: getServerNavigatorTreeOperator(), treePath);
803: Util.wait(1000);
804: new QueueTool().waitEmpty();
805:
806: popupMenuOp.pushMenuNoBlock(popupMenuItem);
807: Util.wait(1000);
808: new QueueTool().waitEmpty();
809: }
810:
811: public static void putDBTableOnComponent(String dbURL,
812: String dbTableName, Point componentPoint) {
813: putDBTableOnComponent(dbURL, dbTableName, componentPoint, null,
814: -1, -1);
815: }
816:
817: public static void putDBTableOnComponent(String dbURL,
818: String dbTableName, final Point componentPoint,
819: String rowSetName, int radioButtonIndex, int textFieldIndex) {
820: final DesignerPaneOperator designPaneOp = new DesignerPaneOperator(
821: RaveWindowOperator.getDefaultRave());
822: DesignerPaneOperator.switchToDesignerPane();
823: TreePath dbTableTreePath = selectDBTable(dbURL, dbTableName);
824: if (dbTableTreePath != null) {
825: Thread mouseThread = new Thread(new Runnable() {
826: public void run() {
827: designPaneOp.clickMouse(componentPoint.x + 5,
828: componentPoint.y + 5, 1);
829: logMsg("+++ Mouse thread has been finished.");
830: }
831: });
832: mouseThread.start();
833: try {
834: logMsg("+++ Wait until mouse thread is died...");
835: mouseThread.join(6000);
836: } catch (Exception e) {
837: e.printStackTrace(logStream);
838: }
839: if (rowSetName != null) {
840: defineSessionRowSetNameInDialog(rowSetName,
841: radioButtonIndex, textFieldIndex);
842: }
843: Util.wait(2000);
844: new QueueTool().waitEmpty();
845: logMsg("+++ DB table [" + dbTableName
846: + "] is bound to component with point ["
847: + componentPoint + "]");
848: }
849: }
850:
851: public static void defineSessionRowSetNameInDialog(
852: String rowSetName, int radioButtonIndex, int textFieldIndex) {
853: String timeoutName = "DialogWaiter.WaitDialogTimeout";
854: long previousTimeoutValue = JemmyProperties
855: .getCurrentTimeout(timeoutName), newTimeoutValue = 10000;
856: JemmyProperties.getCurrentTimeouts().setTimeout(timeoutName,
857: newTimeoutValue);
858: try {
859: JDialogOperator dialogOp = new JDialogOperator(
860: DIALOG_TITLE_ADD_NEW_DATAPROVIDER_WITH_ROWSET);
861: if (dialogOp != null) {
862: logMsg("+++ Dialog ["
863: + DIALOG_TITLE_ADD_NEW_DATAPROVIDER_WITH_ROWSET
864: + "] is found (RowSet name: [" + rowSetName
865: + "])");
866:
867: new JRadioButtonOperator(dialogOp, radioButtonIndex)
868: .doClick();
869: Util.wait(1000);
870: new QueueTool().waitEmpty();
871:
872: new JTextFieldOperator(dialogOp, textFieldIndex)
873: .setText(rowSetName);
874: Util.wait(1000);
875: new QueueTool().waitEmpty();
876:
877: new JButtonOperator(dialogOp, BUTTON_LABEL_OK)
878: .pushNoBlock();
879: Util.wait(1000);
880: new QueueTool().waitEmpty();
881: }
882: } catch (TimeoutExpiredException tee) {
883: Util.wait(500);
884: new QueueTool().waitEmpty();
885: throw new RuntimeException("Dialog ["
886: + DIALOG_TITLE_ADD_NEW_DATAPROVIDER_WITH_ROWSET
887: + "] isn't found " + "(RowSet name: [" + rowSetName
888: + "])");
889: } catch (Exception e) {
890: e.printStackTrace(System.out);
891: throw new RuntimeException(e);
892: } finally {
893: JemmyProperties.getCurrentTimeouts().setTimeout(
894: timeoutName, previousTimeoutValue);
895: }
896: }
897:
898: private static void selectComponentOnDesigner(
899: DesignerPaneOperator designPaneOp, Point componentPoint) {
900: designPaneOp.clickMouse(componentPoint.x + 3,
901: componentPoint.y + 3, 1);
902: Util.wait(1000);
903: new QueueTool().waitEmpty();
904: }
905:
906: public static String getBaseRowSetName(String dbTableName) {
907: return (dbTableName.toLowerCase() + ROW_SET_SUFFIX);
908: }
909:
910: public static String getBaseDataProviderName(String dbTableName) {
911: return (dbTableName.toLowerCase() + DATA_PROVIDER_SUFFIX);
912: }
913:
914: public static EditorOperator getJavaEditor() {
915: EditorOperator editor = new EditorOperator(
916: Util.getMainWindow(), JAVA_EDITOR_TITLE);
917: Util.wait(1000);
918: new QueueTool().waitEmpty();
919: logMsg("+++ Source editor for [" + JAVA_EDITOR_TITLE
920: + "] found");
921: return editor;
922: }
923:
924: public static boolean isUsedJ2EELevel_14() {
925: String j2EE_Level = TestPropertiesHandler
926: .getServerProperty("J2EE_Level");
927: return (j2EE_Level.equalsIgnoreCase(J2EE_LEVEL_14));
928: }
929:
930: public static boolean isUsedJ2EELevel_5() {
931: String j2EE_Level = TestPropertiesHandler
932: .getServerProperty("J2EE_Level");
933: return (j2EE_Level.equalsIgnoreCase(J2EE_LEVEL_5));
934: }
935:
936: public static boolean isUsedDBDerby() {
937: String database = TestPropertiesHandler.getDatabaseProperty(
938: "Database").trim();
939: return (database.equalsIgnoreCase(DB_NAME_DERBY));
940: }
941:
942: public static boolean isUsedDBOracle() {
943: String database = TestPropertiesHandler.getDatabaseProperty(
944: "Database").trim();
945: return (database.equalsIgnoreCase(DB_NAME_ORACLE));
946: }
947:
948: public static boolean isUsedDBMySQL() {
949: String database = TestPropertiesHandler.getDatabaseProperty(
950: "Database").trim();
951: return (database.equalsIgnoreCase(DB_NAME_MYSQL));
952: }
953:
954: public static boolean isUsedDBPostgres() {
955: String database = TestPropertiesHandler.getDatabaseProperty(
956: "Database").trim();
957: return (database.equalsIgnoreCase(DB_NAME_POSTGRES));
958: }
959:
960: public static boolean isStringEmpty(String s) {
961: return ((s == null) || (s.trim().length() == 0));
962: }
963: }
|