Source Code Cross Referenced for ComponentUtils.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » test » components » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » visualweb.api.designer » org.netbeans.modules.visualweb.test.components.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. 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:
042:        /*
043:         * ComponentUtils.java
044:         *
045:         * Created on June 20, 2006, 9:57 AM
046:         *
047:         * Common code used in component testcases.
048:         */
049:
050:        package org.netbeans.modules.visualweb.test.components.util;
051:
052:        import java.io.ByteArrayInputStream;
053:        import org.netbeans.jellytools.nodes.Node;
054:        import org.netbeans.modules.visualweb.gravy.DocumentOutlineOperator;
055:        import org.netbeans.modules.visualweb.gravy.ProjectNavigatorOperator;
056:        import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
057:        import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
058:        import org.netbeans.modules.visualweb.gravy.navigation.NavigatorOperator;
059:        import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
060:        import org.netbeans.modules.visualweb.gravy.toolbox.PaletteContainerOperator;
061:        import org.netbeans.modules.visualweb.gravy.model.IDE;
062:        import java.awt.event.KeyEvent;
063:        import java.io.File;
064:        import java.io.IOException;
065:        import java.util.Properties;
066:        import java.util.regex.Matcher;
067:        import java.util.regex.Pattern;
068:        import org.netbeans.jemmy.drivers.text.SwingTextKeyboardDriver;
069:        import org.netbeans.jemmy.operators.*;
070:        import org.netbeans.jellytools.NewProjectWizardOperator;
071:        import org.netbeans.jemmy.Waiter;
072:        import org.netbeans.jemmy.Waitable;
073:        import javax.swing.JList;
074:        import org.netbeans.jemmy.JemmyProperties;
075:        import org.netbeans.modules.visualweb.gravy.actions.ActionNoBlock;
076:        import org.netbeans.jellytools.WizardOperator;
077:        import javax.swing.JTextField;
078:        import javax.swing.JComboBox;
079:        import javax.swing.tree.TreePath;
080:        import org.netbeans.jemmy.JemmyException;
081:        import org.netbeans.jemmy.TimeoutExpiredException;
082:        import org.netbeans.modules.visualweb.gravy.Bundle;
083:        import org.netbeans.modules.visualweb.gravy.EditorOperator;
084:        import org.netbeans.modules.visualweb.gravy.NbDialogOperator;
085:        import org.netbeans.modules.visualweb.gravy.RaveWindowOperator;
086:        import org.netbeans.modules.visualweb.gravy.TestUtils;
087:        import org.netbeans.modules.visualweb.gravy.Util;
088:
089:        /**
090:         *
091:         * @author Sherry Zhou
092:         * @author Lark Fitzgerald
093:         */
094:        public class ComponentUtils {
095:
096:            public static String _bundle = getBundle();
097:
098:            public static String _projects = Bundle.getStringTrimmed(_bundle,
099:                    "projects");
100:            public static String _projectType = Bundle.getStringTrimmed(
101:                    _bundle, "projectType");
102:            public static String _projectServer = Bundle.getStringTrimmed(
103:                    _bundle, "projectServer");
104:            public static String _projectServerLocation = Bundle
105:                    .getStringTrimmed(_bundle, "projectServerLocation");
106:            public static String _projectServerPassword = Bundle
107:                    .getStringTrimmed(_bundle, "projectServerPassword");
108:            public static String _projectSourceLevel = Bundle.getStringTrimmed(
109:                    _bundle, "projectSourceLevel");
110:            public static String _projectJ2EEVersion = Bundle.getStringTrimmed(
111:                    _bundle, "projectJ2EEVersion");
112:            //    public static String _projectSourceStructure = Bundle.getStringTrimmed(_bundle,"projectSourceStructure");
113:            public static String _projectCategory = System
114:                    .getProperty("xtest.project.category");
115:
116:            public static String _dataBindingMenu = Bundle.getStringTrimmed(
117:                    _bundle, "Designer_Menu_DataBinding");
118:            public static String _dataBindingDialog = Bundle.getStringTrimmed(
119:                    _bundle, "Dialog_DataBinding");
120:            public static String _dataProviderTab = Bundle.getStringTrimmed(
121:                    _bundle, "DataProviderTab");
122:            public static String _objectTab = Bundle.getStringTrimmed(_bundle,
123:                    "ObjectTab");
124:            public static String _okButton = Bundle.getStringTrimmed(_bundle,
125:                    "Button_OK");
126:            public static String _applyButton = Bundle.getStringTrimmed(
127:                    _bundle, "Button_Apply");
128:            public static String _closeButton = Bundle.getStringTrimmed(
129:                    _bundle, "Button_Close");
130:            public static ActionNoBlock srv;
131:            private static String pathLastCreatedProject;
132:
133:            /** Creates a new instance of Util */
134:            public ComponentUtils() {
135:            }
136:
137:            /**
138:             * Selects a component in the Navigator view specified by string <code>path</code>
139:             * @param path string path delimited by |
140:             */
141:            public static void selectComponentByPath(String path) {
142:                DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
143:                        .getMainWindow());
144:                JTreeOperator jto = doo.getStructTreeOperator();
145:                new Node(jto, path).select();
146:            }
147:
148:            /**
149:             * Selects a component in the Navigator view specified by relative path to
150:             * <code>Page1|page1|html1|body1|form1|</code> component.
151:             * @param a relative path delimited by |
152:             */
153:            public static void selectForm1Component(String name) {
154:                /*TODO should be replaced by selectComponent(String name) which find the component
155:                  by it's name somwhere in the tree */
156:                DocumentOutlineOperator doo = new DocumentOutlineOperator(Util
157:                        .getMainWindow());
158:                JTreeOperator jto = doo.getStructTreeOperator();
159:                selectComponentByPath("Page1|page1|html1|body1|form1|" + name);
160:            }
161:
162:            /**
163:             * Reads a property list (key and element pairs) from the String.
164:             * @param src properties string in format described at
165:             * <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Properties.html#load(java.io.InputStream
166:             * Properties.load(java.io.InputStream)</a> method.
167:             * @return the <code>Properties</code> object holding the properties represented by the string argument
168:             */
169:            public static Properties parseProperties(String src) {
170:                Properties properties = new Properties();
171:                try {
172:                    properties.load(new ByteArrayInputStream(src
173:                            .getBytes("ISO-8859-1")));
174:                } catch (IOException ex) {
175:                    new JemmyException("Failed to parse properties:\n" + src,
176:                            ex);
177:                }
178:                return properties;
179:            }
180:
181:            /*
182:             * Get bundle property file based on commandline option j2ee.version
183:             * if j2ee.version=Java EE 5, return ComponentJEE5.properties
184:             * otherwise return Component.properties
185:             */
186:            public static String getBundle() {
187:                /*String j2eeVersion=System.getProperty("j2ee.version");
188:                 
189:                if (j2eeVersion.equals("JEE5"))
190:                    return "org.netbeans.modules.visualweb.test.components.ComponentJEE5";
191:                else */
192:                return "org.netbeans.modules.visualweb.test.components.Component";
193:
194:            }
195:
196:            /*
197:             *  get project path
198:             */
199:            public static String getProjectPath(String projectName) {
200:                String basePath = System.getProperty("xtest.workdir");
201:                //String basePath = System.getProperty("xtest.sketchpad") ;
202:                String projectPath = basePath + File.separator + "projects";
203:                File folder = new File(projectPath);
204:                if (!folder.exists()) {
205:                    folder.mkdirs();
206:                }
207:                return projectPath;
208:            }
209:
210:            /*
211:             * set component's property via property sheet
212:             */
213:            public static void setProperty(SheetTableOperator sheet,
214:                    String propertyName, String propertyValue) {
215:                int row = sheet.findCellRow(propertyName);
216:                sheet.clickForEdit(row, 1);
217:                sheet.clickForEdit(row, 1);
218:                new JTextComponentOperator(sheet).enterText(propertyValue);
219:                //        sheet.clickForEdit(sheet.findCell(propertyName, 2).y, 1);
220:                //        sheet.clickForEdit(sheet.findCell(propertyName, 2).y, 1);
221:                //        new JTextComponentOperator(sheet).enterText(propertyValue);
222:            }
223:
224:            /*
225:             * return runtime data directory
226:             */
227:            public static String getDataDir() {
228:                String path = System.getProperty("xtest.workdir")
229:                        + File.separator + "sys" + File.separator + "tests"
230:                        + File.separator + "components" + File.separator
231:                        + "classes" + File.separator + "com" + File.separator
232:                        + "sun" + File.separator + "rave" + File.separator
233:                        + "components" + File.separator + "data"
234:                        + File.separator;
235:                return path;
236:            }
237:
238:            /*
239:             * Add bean property from project window
240:             * @objName Application Bean, Session Bean, or Request Bean
241:             * @propertyName Property Name
242:             * @propertyType Property type
243:             * @propertyMode Property mode
244:             *
245:             */
246:
247:            public static void addObjectProperty(String objectPath,
248:                    String propertyName, String propertyType,
249:                    String propertyMode) {
250:                ProjectNavigatorOperator prjNav = ProjectNavigatorOperator
251:                        .showProjectNavigator();
252:
253:                String popupMenuItem = "Add|Property";
254:                prjNav.selectNode(objectPath);
255:                Util.wait(2000);
256:                prjNav.pressPopupItemOnNode(objectPath, popupMenuItem);
257:                prjNav.selectNode(objectPath);
258:                JDialogOperator dialog = new JDialogOperator(Bundle
259:                        .getStringTrimmed(_bundle, "Dialog_BeanPattern_Title"));
260:                Util.wait(500);
261:                JTextFieldOperator tf_Name = new JTextFieldOperator(dialog, 0);
262:                tf_Name.setText(propertyName);
263:                Util.wait(500);
264:                JTextFieldOperator tf_Type = new JTextFieldOperator(dialog, 1);
265:                tf_Type.setText(propertyType);
266:                //        JComboBoxOperator cmbx_Type = new JComboBoxOperator(dialog, 0);
267:                //        cmbx_Type.setSelectedItem(propertyType);
268:                Util.wait(1000);
269:                JComboBoxOperator cmbx_Mode = new JComboBoxOperator(dialog, 1);
270:                cmbx_Mode.setSelectedItem(propertyMode);
271:                Util.wait(1000);
272:
273:                new JButtonOperator(dialog, _okButton).pushNoBlock();
274:                dialog.waitClosed();
275:                Util.wait(1000);
276:                Util.saveAllAPICall();
277:            }
278:
279:            /*
280:             * Connect sample database
281:             */
282:            public static void connectDB(String dbName, String passwd) {
283:                ServerNavigatorOperator explorer = ServerNavigatorOperator
284:                        .showNavigatorOperator();
285:                JTreeOperator tree = explorer.getTree();
286:                tree.callPopupOnPath(tree.findPath(dbName));
287:                new JPopupMenuOperator().pushMenuNoBlock(Bundle
288:                        .getStringTrimmed(_bundle, "Database_Menu_Connect"));
289:                //        JDialogOperator dialog = new JDialogOperator("Connect");
290:                //        Util.wait(1000);
291:                //        JTextFieldOperator tf_Name = new JTextFieldOperator(dialog, 1);
292:                //        tf_Name.setText(passwd);
293:                //        Util.wait(1000);
294:                //        new JButtonOperator(dialog, "OK").pushNoBlock();
295:                //        dialog.waitClosed();
296:                TestUtils.wait(15000);
297:            }
298:
299:            /*
300:             * Bind component to specific data provider
301:             */
302:            public static void bindToDataProvider(int x, int y, String dbTable,
303:                    String dataProviderName, String displayField,
304:                    String valueField) {
305:                //D&D database table to component
306:                ServerNavigatorOperator explorer = ServerNavigatorOperator
307:                        .showNavigatorOperator();
308:                JTreeOperator tree = explorer.getTree();
309:                TreePath path = tree.findPath(dbTable);
310:                TestUtils.wait(5000);
311:                tree.clickOnPath(path);
312:                TestUtils.wait(1000);
313:                tree.selectPath(path);
314:                TestUtils.wait(1000);
315:
316:                DesignerPaneOperator designer = new DesignerPaneOperator(
317:                        RaveWindowOperator.getDefaultRave());
318:                designer.clickMouse(x, y, 1);
319:                TestUtils.wait(10000);
320:
321:                designer.requestFocus();
322:                designer.clickForPopup(x, y);
323:
324:                //Bring up Data binding dialog. Setup data provider binding
325:                JPopupMenuOperator popup = null;
326:                popup = new JPopupMenuOperator();
327:                popup.pushMenuNoBlock(_dataBindingMenu);
328:
329:                JDialogOperator dataBind = new JDialogOperator(
330:                        _dataBindingDialog);
331:                // new JTabbedPaneOperator(dataBind).selectPage(_dataProviderTab);
332:                TestUtils.wait(8000);
333:                // Place cursor to PERSON.NAME in value field
334:                new JTabbedPaneOperator(dataBind).selectPage(_dataProviderTab);
335:                TestUtils.wait(1000);
336:
337:                //Select data provider
338:                JComboBoxOperator comb = new JComboBoxOperator(dataBind, 0);
339:                comb.setSelectedItem(dataProviderName);
340:                Util.wait(1000);
341:
342:                //Set Display field and Value field
343:
344:                if (valueField != null) {
345:                    JListOperator valueList = new JListOperator(dataBind, 0);
346:                    TestUtils.wait(1000);
347:                    valueList.selectItem(valueField);
348:                    TestUtils.wait(1000);
349:                }
350:
351:                if (displayField != null) {
352:                    JListOperator displayList = new JListOperator(dataBind, 1);
353:                    TestUtils.wait(1000);
354:                    displayList.selectItem(displayField);
355:                    TestUtils.wait(1000);
356:                }
357:
358:                new JButtonOperator(dataBind, _okButton).pushNoBlock();
359:            }
360:
361:            /*
362:             * Bind component to specific data provider 
363:             * Can be used for Table component where Name and Value fields do not need to be specified.
364:             * This will bind the component to the DB table with default settings.
365:             */
366:            public static void bindToDataProvider(int x, int y, String dbTable) {
367:                //D&D database table to component
368:                ServerNavigatorOperator explorer = ServerNavigatorOperator
369:                        .showNavigatorOperator();
370:                JTreeOperator tree = explorer.getTree();
371:                TreePath path = tree.findPath(dbTable);
372:                TestUtils.wait(5000);
373:                tree.clickOnPath(path);
374:                TestUtils.wait(1000);
375:                tree.selectPath(path);
376:                TestUtils.wait(1000);
377:
378:                DesignerPaneOperator designer = new DesignerPaneOperator(
379:                        RaveWindowOperator.getDefaultRave());
380:                designer.clickMouse(x, y, 1);
381:                TestUtils.wait(20000);
382:
383:            }
384:
385:            /*
386:             * Bind component to an object property
387:             */
388:            public static void bindToObject(int x, int y, String propertyPath) {
389:                //Open Bind to Data dialog vai context menu
390:                DesignerPaneOperator designer = new DesignerPaneOperator(
391:                        RaveWindowOperator.getDefaultRave());
392:                designer.clickMouse(x, y, 1);
393:                TestUtils.wait(1000);
394:                designer.requestFocus();
395:                designer.clickForPopup(x, y);
396:                JPopupMenuOperator popup = null;
397:                popup = new JPopupMenuOperator();
398:                popup.pushMenuNoBlock(_dataBindingMenu);
399:                Util.wait(1000);
400:                JDialogOperator dialog = new JDialogOperator(_dataBindingDialog);
401:                Util.wait(1000);
402:
403:                // Select object to bind
404:                new JTabbedPaneOperator(dialog).selectPage(_objectTab);
405:                TestUtils.wait(1000);
406:                TestUtils.printComponentList(dialog);
407:                JTreeOperator tree = new JTreeOperator(dialog);
408:                TestUtils.printComponentList(tree);
409:                tree.selectPath(tree.findPath(propertyPath));
410:                Util.wait(1000);
411:
412:                new JButtonOperator(dialog, _applyButton).pushNoBlock();
413:                Util.wait(1000);
414:
415:                new JButtonOperator(dialog, _okButton).pushNoBlock();
416:                dialog.waitClosed();
417:                Util.wait(1000);
418:            }
419:
420:            /* public static void bindToObject(int x, int y,  String[] treeNodeTexts) {
421:             
422:                 DesignerPaneOperator designer = new DesignerPaneOperator(RaveWindowOperator.getDefaultRave());
423:                 designer.clickForPopup(x, y);
424:                 Util.wait(1000);
425:                 new QueueTool().waitEmpty();
426:             
427:                 JPopupMenuOperator popupMenu = new JPopupMenuOperator();
428:                 popupMenu.pushMenuNoBlock(_dataBindingMenu);
429:                 Util.wait(1000);
430:                 new QueueTool().waitEmpty();
431:             
432:                 JDialogOperator dialog = new JDialogOperator(_dataBindingDialog);
433:                 Util.wait(1000);
434:                 new QueueTool().waitEmpty();
435:             
436:                 JTreeOperator treeOperator = new JTreeOperator(dialog);
437:                 JTree tree = (JTree) treeOperator.getSource();
438:                 TreeModel treeModel = tree.getModel();
439:                 TreeNode rootNode = (TreeNode) treeModel.getRoot();
440:             
441:                 Object[] treeNodePaths = new Object[treeNodeTexts.length + 1];
442:                 treeNodePaths[0] = rootNode;
443:                 TreeNode parentNode = rootNode;
444:                 for (int i = 0; i < treeNodeTexts.length; ++i) {
445:                     TestUtils.outMsg("+++ tree level = " + i);
446:                     TreeNode treeNode = findBindingTreeNode(parentNode, treeNodeTexts[i]);
447:                     treeNodePaths[i + 1] = treeNode;
448:                     parentNode = treeNode;
449:                 }
450:                 List treeNodeList = new ArrayList();
451:                 for (int i = 0; i < treeNodePaths.length; ++i) {
452:                     Object treeNode = treeNodePaths[i];
453:                     treeNodeList.add(treeNode);
454:                     TreePath treePath = new TreePath(treeNodeList.toArray());
455:                     tree.expandPath(treePath);
456:                     Util.wait(500);
457:                 }
458:                 tree.getSelectionModel().setSelectionPath(new TreePath(treeNodePaths));
459:                 Util.wait(1000);
460:                 new QueueTool().waitEmpty();
461:             
462:                 new JButtonOperator(dialog, _applyButton).pushNoBlock();
463:                 Util.wait(1000);
464:                 new QueueTool().waitEmpty();
465:             
466:                 new JButtonOperator(dialog, _okButton).pushNoBlock();
467:                 dialog.waitClosed();
468:                 Util.wait(1000);
469:                 new QueueTool().waitEmpty();
470:             }
471:             
472:             public static TreeNode findBindingTreeNode(TreeNode parentNode, String treeNodeText) {
473:                 TreeNode treeNode = null;
474:                 int childCount = parentNode.getChildCount();
475:                 for (int i = 0; i < childCount; ++i) {
476:                     treeNode = (TreeNode) parentNode.getChildAt(i);
477:                     TestUtils.outMsg("+++ tree node class = " + treeNode.getClass().getName());
478:                     try {
479:                         // find and invoke the method public String getBindingExpressionPart() on a tree node
480:                         Method method = treeNode.getClass().getMethod("getBindingExpressionPart", null);
481:                         Object methodInvocationResult = method.invoke(treeNode, new Object[] {});
482:                         String text = methodInvocationResult.toString();
483:                         TestUtils.outMsg("+++ treeNodeText = " + text);
484:                         if (treeNodeText.equals(text)) {
485:                             return treeNode;
486:                         }
487:                     } catch(Throwable t) {
488:                         JemmyException e = new JemmyException("Problem with a method of a tree node class", t);
489:                         e.printStackTrace();
490:                         if ((t instanceof NoSuchMethodException) &&
491:                                 ((treeNode.getClass().getName().equals("com.sun.rave.propertyeditors.binding.nodes.ContextTargetNode"))
492:                                 ||
493:                                 (treeNode.getClass().getName().equals("com.sun.rave.propertyeditors.binding.nodes.PropertyTargetNode")))) {
494:                             throw e;
495:                         }
496:                     }
497:                 }
498:                 return null;
499:             }*/
500:
501:            /*
502:             * set component's property via property bindling dialog
503:             * @designer
504:             * @component Component ID
505:             * @x The component xcoordinate
506:             * @y The component y coordinate
507:             * @property Property name
508:             * @value Prtoperty value
509:             */
510:            public static void setPropertyBinding(
511:                    DesignerPaneOperator designer, int x, int y,
512:                    String property, String value) {
513:                designer.clickForPopup(x, y);
514:                Util.wait(500);
515:                new JPopupMenuOperator().pushMenuNoBlock(Bundle
516:                        .getStringTrimmed(_bundle,
517:                                "Designer_Menu_PropertyBindings"));
518:                JDialogOperator dialog = new JDialogOperator(Bundle
519:                        .getStringTrimmed(_bundle, "Dialog_PropertyBindings"));
520:                JListOperator list = new JListOperator(dialog, 0);
521:                list.selectItem(property);
522:                Util.wait(1000);
523:                JTextFieldOperator tf_Name = new JTextFieldOperator(dialog, 1);
524:                tf_Name.setText(value);
525:                Util.wait(1000);
526:                new JButtonOperator(dialog, _applyButton).pushNoBlock();
527:                Util.wait(1000);
528:                new JButtonOperator(dialog, _closeButton).pushNoBlock();
529:                dialog.waitClosed();
530:                Util.wait(1000);
531:            }
532:
533:            public static void loadImageFile(String imageFile) {
534:                // Select menu File>Add existing items>image
535:                String menuItem = Bundle.getStringTrimmed(_bundle, "Menu_File")
536:                        + "|"
537:                        + Bundle.getStringTrimmed(_bundle,
538:                                "Menu_AddExistingItem") + "|"
539:                        + Bundle.getStringTrimmed(_bundle, "Menu_ImageFile");
540:
541:                Util.getMainMenu().pushMenuNoBlock(menuItem);
542:                JDialogOperator dialog = new JDialogOperator(Bundle
543:                        .getStringTrimmed(_bundle, "Dialog_AddExistingItem"));
544:                (new JTextFieldOperator(dialog, 0)).typeText(imageFile);
545:                TestUtils.wait(1000);
546:                (new JButtonOperator(dialog, Bundle.getStringTrimmed(_bundle,
547:                        "Button_Add"))).pushNoBlock();
548:            }
549:
550:            public static void setButtonTextInLine(
551:                    DesignerPaneOperator designer, int x, int y, String text) {
552:                // click component to get inline mode
553:                TestUtils.printComponentList(new RaveWindowOperator());
554:                designer.clickMouse(x, y, 1);
555:                TestUtils.wait(1500);
556:                designer.clickMouse(x, y, 1);
557:                TestUtils.wait(1500);
558:                //Enter the text
559:                JTextFieldOperator field = new JTextFieldOperator(designer);
560:                SwingTextKeyboardDriver keyboard = new SwingTextKeyboardDriver();
561:                keyboard.enterText(field, text);
562:                TestUtils.wait(100);
563:            }
564:
565:            /*
566:             * Create navigation link
567:             */
568:            public static void linkWebPages(DesignerPaneOperator designer,
569:                    String startPage, String endPage, String linkName) {
570:                // Start Page Navigation Editor via designer context menu
571:                designer.clickForPopup(1, 1);
572:                Util.wait(500);
573:                new JPopupMenuOperator().pushMenuNoBlock(Bundle
574:                        .getStringTrimmed(_bundle,
575:                                "Designer_Menu_PageNavigation"));
576:
577:                NavigatorOperator navigation = new NavigatorOperator();
578:                Util.wait(500);
579:                navigation.linkUsingXmlSource(startPage + ".jsp", endPage
580:                        + ".jsp", linkName);
581:                TestUtils.wait(500);
582:            }
583:
584:            public static void insertJavaCode(EditorOperator editor,
585:                    String[] javaCodeLines) {
586:                for (int i = 0; i < javaCodeLines.length; ++i) {
587:                    editor.insert(javaCodeLines[i]);
588:                    Util.wait(1000);
589:
590:                    if (i < javaCodeLines.length - 1) {
591:                        editor.pushKey(KeyEvent.VK_ENTER);
592:                        Util.wait(1000);
593:
594:                    }
595:                }
596:            }
597:
598:            /*
599:             * Create New Project
600:             */
601:            public static void createNewProject(String _projectName) {
602:                String _projectPath = getProjectPath(_projectName);
603:                //  createNewProjectLoc(_projectPath, _projectName, true, _projectType, _projectCategory, _projectServer, _projectServerLocation, _projectServerPassword, _projectSourceLevel, _projectJ2EEVersion, _projectSourceStructure);
604:                createProject(_projectName);
605:
606:                // Wait until designer appear
607:                TestUtils.wait(50000);
608:            }
609:
610:            /* 
611:             * Use the method in gravy. similar to sanity tests
612:             */
613:            public static void createProject(String _projectName) {
614:                // Add appserver
615:                IDE.getIDE();
616:
617:                // Create a project
618:                String _projectPath = getProjectPath(_projectName);
619:                if (_projectJ2EEVersion.equals("Java EE 5")) {
620:                    // Create Java EE 5 project
621:                    TestUtils.createJavaEE5ProjectLoc(_projectPath,
622:                            _projectName, true, _projectType, _projectCategory);
623:                } else {
624:                    // Create J2EE 1.4 project
625:                    TestUtils.createNewProjectLoc(_projectPath, _projectName,
626:                            true, _projectType, _projectCategory);
627:                }
628:
629:                //Bring up palette. Workaround for issue http://www.netbeans.org/issues/show_bug.cgi?id=105200
630:                PaletteContainerOperator.showPalette();
631:                TestUtils.wait(1000);
632:            }
633:
634:            /*
635:             * Create New Project & Configure Web Server
636:             * This method should be temporary until alexey fixes the
637:             * original utilities.
638:             */
639:            public static String createNewProjectLoc(String location,
640:                    String projectName, boolean absoluteLocation,
641:                    String projectCategory, String projectType,
642:                    String projectServer, String projectServerLocation,
643:                    String projectServerPassword, String projectSourceLevel,
644:                    String projectJ2EEVersion, String projectSourceStructure) {
645:                NewProjectWizardOperator po = NewProjectWizardOperator.invoke();
646:
647:                //need to wait for a list containing project
648:                Waiter projectListWaiter = new Waiter(new Waitable() {
649:                    public Object actionProduced(Object po) {
650:                        JList projList = (JList) ((ContainerOperator) po)
651:                                .findSubComponent(
652:                                        new JListOperator.JListFinder(), 1);
653:                        JListOperator projListOper = new JListOperator(projList);
654:                        projListOper.copyEnvironment((ComponentOperator) po);
655:                        /*return((projListOper.findItemIndex(_bundle.getString(
656:                                "com.sun.rave.project.nbbridge.Bundle",
657:                                "Templates/Project/Web/raveform.xml")) == -1) ? null : "");*/
658:                        //return((projListOper.findItemIndex("Application") == -1) ? null : "");
659:                        if ((projListOper.findItemIndex("Application") == -1)
660:                                && (projListOper.findItemIndex("Travel") == -1))
661:                            return null;
662:                        else
663:                            return "";
664:                    }
665:
666:                    public String getDescription() {
667:                        return ("Project list to be displayed");
668:                    }
669:                });
670:                TestUtils.wait(1000);
671:
672:                /* select Web categroy */
673:                po.selectCategory(projectCategory);
674:                projectListWaiter.getTimeouts().setTimeout(
675:                        "Waiter.WaitingTime", 180000);
676:                try {
677:                    projectListWaiter.waitAction(po);
678:                } catch (InterruptedException e) {
679:                }
680:
681:                /* Select project type */
682:                //po.selectProject(_bundle.getString("com.sun.rave.project.nbbridge.Bundle", "Templates/Project/Web/raveform.xml"));
683:                po.selectProject(projectType);
684:                TestUtils.wait(1000);
685:                po.next();
686:                TestUtils.wait(2000);
687:                if (projectName != null) {
688:                    new JTextFieldOperator(po).setText(projectName);
689:                } else {
690:                    projectName = new JTextFieldOperator(po).getText();
691:                }
692:                if (location != null) {
693:                    if (!absoluteLocation) {
694:                        location = new JTextFieldOperator(po, 1).getText()
695:                                + "/" + location;
696:                    }
697:                    new JTextFieldOperator(po, 1).setText(location);
698:                } else {
699:                    location = new JTextFieldOperator(po, 1).getText();
700:                }
701:                pathLastCreatedProject = location;
702:
703:                //Configure projectServer if not default (Tomcat (5.5.17)
704:                //        if (projectServer == "Sun Java System Application Server") {
705:                JButtonOperator manage = new JButtonOperator(po, "Manage...");
706:                manage.press();
707:                manage.release();
708:                configureSunServer(projectServerLocation, projectServerPassword);
709:                /*
710:                 //Set project Source Structure
711:                 JLabelOperator sourceStructure = new JLabelOperator(po, "Source Structure:");
712:                 java.awt.Component c = sourceStructure.getLabelFor();
713:                 JComboBox cb = (JComboBox)c;
714:                 JComboBoxOperator structure = new JComboBoxOperator(cb);
715:                 structure.selectItem(projectSourceStructure);
716:                 */
717:                JLabelOperator server = new JLabelOperator(po, "Server:");
718:                java.awt.Component c = server.getLabelFor();
719:                JComboBox cb = (JComboBox) c;
720:                JComboBoxOperator sunServer = new JComboBoxOperator(cb);
721:                sunServer.selectItem(projectServer);
722:                //        }
723:
724:                //Set J2EE Version
725:                JLabelOperator j2eeVersion = new JLabelOperator(po,
726:                        "Java EE Version:");
727:                c = j2eeVersion.getLabelFor();
728:                cb = (JComboBox) c;
729:                JComboBoxOperator version = new JComboBoxOperator(cb);
730:                version.selectItem(projectJ2EEVersion);
731:
732:                //Set Source Level to 1.4
733:
734:                //Set as Main Project
735:
736:                if (new JButtonOperator(po, "Next").isEnabled()) {
737:                    po.next();
738:                    //TODO clicked on Down button and then Brake Space pressed to select needed checkbox
739:                    po.pushKey(KeyEvent.VK_DOWN);
740:                    TestUtils.wait(2000);
741:                    po.pushKey(KeyEvent.VK_SPACE);
742:                    TestUtils.wait(2000);
743:                }
744:                po.finish();
745:
746:                String timeoutName = "DialogWaiter.WaitDialogTimeout";
747:                long timeoutValue = JemmyProperties
748:                        .getCurrentTimeout(timeoutName);
749:                JemmyProperties.getCurrentTimeouts().setTimeout(timeoutName,
750:                        10000);
751:                Waiter waitProjectPropertiesDialog = new Waiter(new Waitable() {
752:                    public Object actionProduced(Object obj) {
753:                        try {
754:                            new JButtonOperator(new JDialogOperator(
755:                                    "Edit Project Properties"), "Regenerate")
756:                                    .push();
757:                            return null;
758:                        } catch (TimeoutExpiredException e) {
759:                            return true;
760:                        }
761:
762:                    }
763:
764:                    public String getDescription() {
765:                        return "Wait all dialogs";
766:                    }
767:                });
768:                waitProjectPropertiesDialog.getTimeouts().setTimeout(
769:                        "Waiter.WaitingTime", 60000);
770:                try {
771:                    waitProjectPropertiesDialog.waitAction(null);
772:                } catch (Exception e) {
773:                    e.printStackTrace();
774:                } finally {
775:                    JemmyProperties.getCurrentTimeouts().setTimeout(
776:                            timeoutName, timeoutValue);
777:                }
778:
779:                //wait(20000);
780:                Util.getMainWindow().getTimeouts().setTimeout(
781:                        "ComponentOperator.WaitComponentTimeout", 60000);//project creation time
782:                //        new TopComponentOperator("Page1");
783:                //        TestUtils.disableBrowser(projectName, location, true);
784:                return projectName;
785:            }
786:
787:            /*
788:             * Configure Sun One Application Server
789:             */
790:            public static void configureSunServer(String projectServerLocation,
791:                    String projectServerPassword) {
792:                NbDialogOperator serverManager = new NbDialogOperator("Servers");
793:                JButtonOperator addServer = new JButtonOperator(serverManager,
794:                        "Add Server...");
795:                addServer.pushNoBlock();
796:
797:                WizardOperator serverInstance = new WizardOperator(
798:                        "Add Server Instance");
799:                serverInstance.next();
800:                JButtonOperator browse = new JButtonOperator(serverInstance,
801:                        "Browse...");
802:                browse.press();
803:                browse.release();
804:
805:                NbDialogOperator installLocation = new NbDialogOperator(
806:                        "Choose Application Server's Install Location");
807:                //There's only 1 textField on page so this works.
808:                JTextFieldOperator fileName = new JTextFieldOperator(
809:                        installLocation);
810:                fileName.enterText(projectServerLocation);
811:                JButtonOperator choose = new JButtonOperator(installLocation,
812:                        "Choose");
813:                choose.pushNoBlock();
814:                try {
815:                    Thread.sleep(2000);
816:                } catch (Exception e) {
817:                }
818:
819:                serverInstance.next();
820:                try {
821:                    Thread.sleep(2000);
822:                } catch (Exception e) {
823:                }
824:                JLabelOperator la = new JLabelOperator(serverInstance,
825:                        "Admin Password:");
826:                java.awt.Component c = la.getLabelFor();
827:                JTextField jtf = (JTextField) c;
828:                JTextFieldOperator adminPassword = new JTextFieldOperator(jtf);
829:                adminPassword.setText(projectServerPassword);
830:                serverInstance.finish();
831:
832:                JButtonOperator close = new JButtonOperator(serverManager,
833:                        "Close");
834:                close.pushNoBlock();
835:            }
836:
837:            /*
838:             * Used to check the ide log file for exceptions.
839:             * This method was taken from the sanity test and modified to return a string.
840:             */
841:            public static String hasUnexpectedException() throws IOException {
842:                String[] knownException = {
843:                        "import javax.faces.FacesException",
844:                        "java.lang.IllegalStateException",
845:                        "java.lang.IllegalArgumentException: Expected scheme-specific part at index",
846:                        "java.lang.IllegalArgumentException: Cannot get BASE revision,",
847:                        "java.net.UnknownHostException: www.netbeans.org",
848:                        "org.netbeans.modules.uihandler.exceptionreporter" };
849:
850:                String logFile = System.getProperty("xtest.workdir")
851:                        + File.separator
852:                        + Bundle.getStringTrimmed(_bundle, "LogFile");
853:                String lineSep = System.getProperty("line.separator");
854:                StringBuffer sb = new StringBuffer();
855:                String nextLine = "";
856:                boolean isUnexpectedException;
857:
858:                //Get lines that has word "Exceptions" from message.log
859:                String exceptions = TestUtils.parseLogs(logFile, "Exception");
860:                if (exceptions.equals("")) {
861:                    return ""; //No exceptions found
862:                } else {
863:                    //            log("Exceptions found in message.log:\n"+exceptions);         
864:                    // Compile the pattern
865:                    String patternStr = "^(.*)$";
866:                    Pattern pattern = Pattern.compile(patternStr,
867:                            Pattern.MULTILINE);
868:                    Matcher matcher = pattern.matcher(exceptions);
869:
870:                    // Read exceptions line by line to determine if it is unexpected
871:                    while (matcher.find()) {
872:                        isUnexpectedException = true;
873:                        nextLine = matcher.group(1);
874:                        for (int i = 0; i < knownException.length; i++) {
875:                            if (nextLine.indexOf(knownException[i]) != -1)
876:                                isUnexpectedException = false;
877:                        }
878:                        if (isUnexpectedException) {
879:                            sb.append(nextLine);
880:                            sb.append(lineSep);
881:                        }
882:                    }
883:                    if (!sb.toString().equals("")) {
884:                        return "Unexpected exceptions: \n" + sb.toString();
885:                    } else
886:                        return "";
887:                }
888:            }
889:        }
w___w__w___.j__a__va___2_s.___c___o__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.