Source Code Cross Referenced for Utilities.java in  » IDE-Netbeans » performance » gui » 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 » performance » gui 
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:        package gui;
043:
044:        import javax.swing.tree.TreePath;
045:        import java.text.SimpleDateFormat;
046:        import java.util.Date;
047:        import java.util.Locale;
048:
049:        import org.netbeans.jellytools.Bundle;
050:        import org.netbeans.jellytools.NbDialogOperator;
051:        import org.netbeans.jellytools.EditorOperator;
052:        import org.netbeans.jellytools.MainWindowOperator;
053:        import org.netbeans.jellytools.NewProjectNameLocationStepOperator;
054:        import org.netbeans.jellytools.NewProjectWizardOperator;
055:        import org.netbeans.jellytools.ProjectsTabOperator;
056:        import org.netbeans.jellytools.RuntimeTabOperator;
057:        import org.netbeans.jellytools.TopComponentOperator;
058:        import org.netbeans.jellytools.actions.ActionNoBlock;
059:        import org.netbeans.jellytools.actions.CloseAllDocumentsAction;
060:        import org.netbeans.jellytools.actions.DeleteAction;
061:        import org.netbeans.jellytools.actions.EditAction;
062:        import org.netbeans.jellytools.actions.OpenAction;
063:        import org.netbeans.jellytools.actions.Action;
064:        import org.netbeans.jellytools.modules.form.FormDesignerOperator;
065:        import org.netbeans.jellytools.nodes.Node;
066:        import org.netbeans.jellytools.nodes.ProjectRootNode;
067:        import org.netbeans.jellytools.nodes.SourcePackagesNode;
068:
069:        import org.netbeans.jemmy.EventTool;
070:        import org.netbeans.jemmy.QueueTool;
071:        import org.netbeans.jemmy.TimeoutExpiredException;
072:        import org.netbeans.jemmy.operators.JButtonOperator;
073:        import org.netbeans.jemmy.operators.JCheckBoxOperator;
074:        import org.netbeans.jemmy.operators.JListOperator;
075:        import org.netbeans.jemmy.operators.JMenuBarOperator;
076:        import org.netbeans.jemmy.operators.JMenuItemOperator;
077:        import org.netbeans.jemmy.operators.JPopupMenuOperator;
078:        import org.netbeans.jemmy.operators.JTextFieldOperator;
079:        import org.netbeans.jemmy.operators.JTreeOperator;
080:
081:        import org.netbeans.jemmy.util.Dumper;
082:        import org.netbeans.junit.ide.ProjectSupport;
083:        import org.netbeans.performance.test.utilities.PerformanceTestCase;
084:
085:        import org.netbeans.progress.module.Controller;
086:        import org.netbeans.progress.spi.InternalHandle;
087:        import org.netbeans.progress.spi.TaskModel;
088:
089:        /**
090:         * Utilities for Performance tests, workarrounds, often used methods, ...
091:         *
092:         * @author  mmirilovic@netbeans.org, mrkam@netbeans.org
093:         */
094:        public class Utilities {
095:
096:            public static final String SOURCE_PACKAGES = Bundle
097:                    .getStringTrimmed(
098:                            "org.netbeans.modules.java.j2seproject.Bundle",
099:                            "NAME_src.dir");
100:            public static final String TEST_PACKAGES = Bundle.getStringTrimmed(
101:                    "org.netbeans.modules.java.j2seproject.Bundle",
102:                    "NAME_test.src.dir");
103:            public static final String WEB_PAGES = Bundle.getStringTrimmed(
104:                    "org.netbeans.modules.web.project.ui.Bundle",
105:                    "LBL_Node_DocBase");
106:            private static PerformanceTestCase test = null;
107:
108:            /** Creates a new instance of Utilities */
109:            public Utilities() {
110:            }
111:
112:            public static String getTimeIndex() {
113:                return new SimpleDateFormat("HHmmssS", Locale.US)
114:                        .format(new Date());
115:            }
116:
117:            /**
118:             * Close Welcome.
119:             */
120:            public static void closeWelcome() {
121:                String TCOName = Bundle.getStringTrimmed(
122:                        "org.netbeans.modules.welcome.Bundle", "LBL_Tab_Title");
123:                TopComponentOperator tComponent = null;
124:                try {
125:                    tComponent = new TopComponentOperator(
126:                            org.netbeans.jellytools.Bundle.getString(
127:                                    "org.netbeans.modules.welcome.Bundle",
128:                                    "LBL_Tab_Title"));
129:                } catch (TimeoutExpiredException tex) {
130:                    // Do nothing
131:                    try {
132:                        tComponent = new TopComponentOperator("Welcome");
133:                    } catch (TimeoutExpiredException tex2) {
134:                        // Do nothing
135:                    }
136:                }
137:
138:                if (tComponent == null) {
139:                    return;
140:                }
141:                new JCheckBoxOperator(tComponent, Bundle.getStringTrimmed(
142:                        "org.netbeans.modules.welcome.resources.Bundle",
143:                        "LBL_ShowOnStartup")).changeSelection(false);
144:                tComponent.close();
145:            }
146:
147:            /**
148:             * Close BluePrints.
149:             */
150:            public static void closeBluePrints() {
151:                new TopComponentOperator(Bundle.getStringTrimmed(
152:                        "org.netbeans.modules.j2ee.blueprints.Bundle",
153:                        "LBL_Tab_Title")).close();
154:            }
155:
156:            /**
157:             * Close All Documents.
158:             */
159:            public static void closeAllDocuments() {
160:                if (new Action("Window|Close All Documents", null).isEnabled())
161:                    new CloseAllDocumentsAction().perform();
162:            }
163:
164:            /**
165:             * Close Memory Toolbar.
166:             */
167:            public static void closeMemoryToolbar() {
168:                closeToolbar(Bundle.getStringTrimmed(
169:                        "org.netbeans.core.Bundle", "Menu/View")
170:                        + "|"
171:                        + Bundle.getStringTrimmed(
172:                                "org.netbeans.core.windows.actions.Bundle",
173:                                "CTL_ToolbarsListAction")
174:                        + "|"
175:                        + Bundle.getStringTrimmed("org.netbeans.core.Bundle",
176:                                "Toolbars/Memory"));
177:            }
178:
179:            private static void closeToolbar(String menu) {
180:                MainWindowOperator mainWindow = MainWindowOperator.getDefault();
181:                JMenuBarOperator menuBar = new JMenuBarOperator(mainWindow
182:                        .getJMenuBar());
183:                JMenuItemOperator menuItem = menuBar.showMenuItem(menu, "|");
184:
185:                if (menuItem.isSelected())
186:                    menuItem.push();
187:                else {
188:                    menuItem.pushKey(java.awt.event.KeyEvent.VK_ESCAPE);
189:                    mainWindow.pushKey(java.awt.event.KeyEvent.VK_ESCAPE);
190:                }
191:            }
192:
193:            /**
194:             * Work around issue 35962 (Main menu popup accidentally rolled up)
195:             * Issue has been fixed for JDK 1.5, so we will use it only for JDK 1.4.X
196:             */
197:            public static void workarroundMainMenuRolledUp() {
198:                if (System.getProperty("java.version").indexOf("1.4") != -1) {
199:                    String helpMenu = Bundle.getStringTrimmed(
200:                            "org.netbeans.core.Bundle", "Menu/Help")
201:                            + "|"
202:                            + Bundle
203:                                    .getStringTrimmed(
204:                                            "org.netbeans.core.actions.Bundle",
205:                                            "About");
206:                    String about = Bundle.getStringTrimmed(
207:                            "org.netbeans.core.Bundle_nb", "CTL_About_Title");
208:
209:                    new ActionNoBlock(helpMenu, null).perform();
210:                    new NbDialogOperator(about).close();
211:                }
212:            }
213:
214:            /**
215:             * Open files
216:             *
217:             * @param project project which will be used as source for files to be opened
218:             * @param files_path path to the files to be opened
219:             */
220:            public static void openFiles(String project, String[][] files_path) {
221:                Node[] openFileNodes = new Node[files_path.length];
222:
223:                SourcePackagesNode sourcePackagesNode = new SourcePackagesNode(
224:                        project);
225:
226:                for (int i = 0; i < files_path.length; i++) {
227:                    openFileNodes[i] = new Node(sourcePackagesNode,
228:                            files_path[i][0] + '|' + files_path[i][1]);
229:
230:                    // open file one by one, opening all files at once causes never ending loop (java+mdr)
231:                    // new OpenAction().performAPI(openFileNodes[i]);
232:                }
233:
234:                // try to come back and open all files at-once, rises another problem with refactoring, if you do open file and next expand folder,
235:                // it doesn't finish in the real-time -> hard to reproduced by hand
236:                new OpenAction().performAPI(openFileNodes);
237:            }
238:
239:            /**
240:             * Copy file f1 to f2
241:             * @param f1 file 1
242:             * @param f2 file 2
243:             * @throws java.io.FileNotFoundException
244:             * @throws java.io.IOException
245:             */
246:            public static void copyFile(java.io.File f1, java.io.File f2)
247:                    throws java.io.FileNotFoundException, java.io.IOException {
248:                int data;
249:                java.io.InputStream fis = new java.io.BufferedInputStream(
250:                        new java.io.FileInputStream(f1));
251:                java.io.OutputStream fos = new java.io.BufferedOutputStream(
252:                        new java.io.FileOutputStream(f2));
253:
254:                while ((data = fis.read()) != -1) {
255:                    fos.write(data);
256:                }
257:            }
258:
259:            /**
260:             * Invoke open action on file and wait for editor
261:             * @param filename
262:             * @param waitforeditor
263:             * @return
264:             */
265:            public static EditorOperator openFile(Node fileNode,
266:                    String filename, boolean waitforeditor) {
267:                new OpenAction().performAPI(fileNode);
268:
269:                if (waitforeditor) {
270:                    EditorOperator editorOperator = new EditorOperator(filename);
271:                    return editorOperator;
272:                } else
273:                    return null;
274:            }
275:
276:            public static EditorOperator openFile(String project,
277:                    String filepackage, String filename, boolean waitforeditor) {
278:                return openFile(new Node(new SourcePackagesNode(project),
279:                        filepackage + "|" + filename), filename, waitforeditor);
280:            }
281:
282:            /**
283:             * Invoke Edit Action on file and wait for editor
284:             * @param project
285:             * @param filepackage
286:             * @param filename
287:             * @return
288:             */
289:            public static EditorOperator editFile(String project,
290:                    String filepackage, String filename) {
291:                Node filenode = new Node(new SourcePackagesNode(project),
292:                        filepackage + "|" + filename);
293:                new EditAction().performAPI(filenode);
294:                EditorOperator editorOperator = new EditorOperator(filename);
295:                return editorOperator;
296:            }
297:
298:            /**
299:             * open small form file in the editor
300:             * @return Form Designer
301:             */
302:            public static FormDesignerOperator openSmallFormFile() {
303:                Node openFile = new Node(new SourcePackagesNode(
304:                        "PerformanceTestData"),
305:                        "org.netbeans.test.performance|JFrame20kB.java");
306:                new OpenAction().performAPI(openFile);
307:                return new FormDesignerOperator("JFrame20kB");
308:
309:            }
310:
311:            /**
312:             * Edit file and type there a text
313:             * @param filename file that will be eddited
314:             * @param line line where put the text
315:             * @param text write the text
316:             * @param save save at the and
317:             */
318:            public static void insertToFile(String filename, int line,
319:                    String text, boolean save) {
320:                EditorOperator editorOperator = new EditorOperator(filename);
321:                editorOperator.setCaretPositionToLine(line);
322:                editorOperator.insert(text);
323:
324:                if (save)
325:                    editorOperator.save();
326:            }
327:
328:            /**
329:             * Create project
330:             * @param category project's category
331:             * @param project type of the project
332:             * @param wait wait for background tasks
333:             * @return name of recently created project
334:             */
335:            public static String createproject(String category, String project,
336:                    boolean wait) {
337:                // select Projects tab
338:                ProjectsTabOperator.invoke();
339:
340:                // create a project
341:                NewProjectWizardOperator wizard = NewProjectWizardOperator
342:                        .invoke();
343:                wizard.selectCategory(category);
344:                wizard.selectProject(project);
345:                wizard.next();
346:
347:                NewProjectNameLocationStepOperator wizard_location = new NewProjectNameLocationStepOperator();
348:                wizard_location.txtProjectLocation().clearText();
349:                wizard_location.txtProjectLocation().typeText(
350:                        System.getProperty("xtest.tmpdir"));
351:                String pname = wizard_location.txtProjectName().getText();
352:
353:                // if the project exists, try to generate new name
354:                for (int i = 0; i < 5 && !wizard.btFinish().isEnabled(); i++) {
355:                    pname = pname + "1";
356:                    wizard_location.txtProjectName().clearText();
357:                    wizard_location.txtProjectName().typeText(pname);
358:                }
359:                wizard.finish();
360:
361:                // wait 10 seconds
362:                waitForProjectCreation(10000, wait);
363:
364:                return pname;
365:            }
366:
367:            protected static void waitForProjectCreation(int delay, boolean wait) {
368:                try {
369:                    Thread.currentThread().sleep(delay);
370:                } catch (InterruptedException exc) {
371:                    exc.printStackTrace(System.err);
372:                }
373:
374:                // wait for classpath scanning finish
375:                if (wait) {
376:                    waitScanFinished();
377:                    waitForPendingBackgroundTasks();
378:                }
379:            }
380:
381:            /**
382:             * Delete project
383:             * @param project project to be deleted
384:             */
385:            public static void deleteProject(String project) {
386:                deleteProject(project, false);
387:            }
388:
389:            public static void deleteProject(String project, boolean waitStatus) {
390:                new DeleteAction().performAPI(ProjectsTabOperator.invoke()
391:                        .getProjectRootNode(project));
392:
393:                //delete project
394:                NbDialogOperator deleteProject = new NbDialogOperator(
395:                        "Delete Project"); // NOI18N
396:                JCheckBoxOperator delete_sources = new JCheckBoxOperator(
397:                        deleteProject);
398:
399:                if (delete_sources.isEnabled())
400:                    delete_sources.changeSelection(true);
401:
402:                deleteProject.yes();
403:
404:                waitForPendingBackgroundTasks();
405:
406:                if (waitStatus)
407:                    MainWindowOperator.getDefault().waitStatusText(
408:                            "Finished building " + project + " (clean)"); // NOI18N
409:
410:                try {
411:                    //sometimes dialog rises
412:                    new NbDialogOperator("Question").yes(); // NOI18N
413:                } catch (Exception exc) {
414:                    System.err
415:                            .println("No Question dialog rises - no problem this is just workarround!");
416:                    exc.printStackTrace(System.err);
417:                }
418:
419:            }
420:
421:            /**
422:             * Build project and wait for finish
423:             * @param project
424:             */
425:            public static void buildproject(String project) {
426:                ProjectRootNode prn = ProjectsTabOperator.invoke()
427:                        .getProjectRootNode(project);
428:                prn.buildProject();
429:                MainWindowOperator.getDefault().waitStatusText(
430:                        "Finished building " + project); // NOI18N
431:            }
432:
433:            /**
434:             * Invoke action on project node from popup menu
435:             * @param project
436:             * @param pushAction
437:             */
438:            public static void actionOnProject(String project, String pushAction) {
439:                ProjectRootNode prn = ProjectsTabOperator.invoke()
440:                        .getProjectRootNode(project);
441:                prn.callPopup().pushMenuNoBlock(pushAction);
442:            }
443:
444:            /**
445:             * Run project
446:             * @param project
447:             */
448:            public static void runProject(String project) {
449:                actionOnProject(project, "Run Project"); // NOI18N
450:                // TODO MainWindowOperator.getDefault().waitStatusText("run"); // NOI18N
451:            }
452:
453:            /**
454:             * Debug project
455:             * @param project
456:             */
457:            public static void debugProject(String project) {
458:                actionOnProject(project, "Debug Project"); // NOI18N
459:                // TODO MainWindowOperator.getDefault().waitStatusText("debug"); // NOI18N
460:            }
461:
462:            /**
463:             * Test project
464:             * @param project
465:             */
466:            public static void testProject(String project) {
467:                actionOnProject(project, "Test Project"); // NOI18N
468:                // TODO MainWindowOperator.getDefault().waitStatusText("test"); // NOI18N
469:            }
470:
471:            /**
472:             * Deploy project and wait for finish
473:             * @param project
474:             */
475:            public static void deployProject(String project) {
476:                actionOnProject(project, "Deploy Project"); // NOI18N
477:                waitForPendingBackgroundTasks();
478:                MainWindowOperator.getDefault().waitStatusText(
479:                        "Finished building " + project + " (run-deploy)"); // NOI18N
480:            }
481:
482:            /**
483:             * Verify project and wait for finish
484:             * @param project
485:             */
486:            public static void verifyProject(String project) {
487:                actionOnProject(project, "Verify Project"); // NOI18N
488:                MainWindowOperator.getDefault().waitStatusText(
489:                        "Finished building " + project + " (verify)"); // NOI18N
490:            }
491:
492:            /**
493:             * Open project and wait until it's scanned
494:             * @param projectFolder Project's location
495:             */
496:            public static void waitProjectOpenedScanFinished(
497:                    String projectFolder) {
498:                ProjectSupport.openProject(projectFolder);
499:                waitScanFinished();
500:            }
501:
502:            public static void waitForPendingBackgroundTasks() {
503:                waitForPendingBackgroundTasks(5);
504:            }
505:
506:            public static void waitForPendingBackgroundTasks(int n) {
507:                // wait maximum n minutes
508:                for (int i = 0; i < n * 60; i++) {
509:                    if (org.netbeans.progress.module.Controller.getDefault()
510:                            .getModel().getSize() == 0)
511:                        return;
512:                    try {
513:                        Thread.sleep(1000);
514:                    } catch (InterruptedException exc) {
515:                        exc.printStackTrace(System.err);
516:                        return;
517:                    }
518:                }
519:            }
520:
521:            /**
522:             * Adds GlassFish V2 using path from com.sun.aas.installRoot property
523:             */
524:            public static void addApplicationServer() {
525:
526:                String appServerPath = System
527:                        .getProperty("com.sun.aas.installRoot");
528:
529:                if (appServerPath == null) {
530:                    throw new Error(
531:                            "Can't add application server. com.sun.aas.installRoot property is not set.");
532:                }
533:
534:                String addServerMenuItem = Bundle
535:                        .getStringTrimmed(
536:                                "org.netbeans.modules.j2ee.deployment.impl.ui.actions.Bundle",
537:                                "LBL_Add_Server_Instance"); // Add Server...
538:                String addServerInstanceDialogTitle = Bundle
539:                        .getStringTrimmed(
540:                                "org.netbeans.modules.j2ee.deployment.impl.ui.wizard.Bundle",
541:                                "LBL_ASIW_Title"); //"Add Server Instance"
542:                String glassFishV2ListItem = Bundle.getStringTrimmed(
543:                        "org.netbeans.modules.j2ee.sun.ide.Bundle",
544:                        "LBL_GlassFishV2");
545:                String nextButtonCaption = Bundle.getStringTrimmed(
546:                        "org.openide.Bundle", "CTL_NEXT");
547:                String finishButtonCaption = Bundle.getStringTrimmed(
548:                        "org.openide.Bundle", "CTL_FINISH");
549:
550:                RuntimeTabOperator rto = RuntimeTabOperator.invoke();
551:                JTreeOperator runtimeTree = rto.tree();
552:
553:                long oldTimeout = runtimeTree.getTimeouts().getTimeout(
554:                        "JTreeOperator.WaitNextNodeTimeout");
555:                runtimeTree.getTimeouts().setTimeout(
556:                        "JTreeOperator.WaitNextNodeTimeout", 60000);
557:
558:                TreePath path = runtimeTree.findPath("Servers");
559:                runtimeTree.selectPath(path);
560:
561:                try {
562:                    //log("Let's check whether GlassFish V2 is already added");
563:                    runtimeTree.findPath("Servers|GlassFish V2");
564:                } catch (TimeoutExpiredException tee) {
565:                    //log("There is no GlassFish V2 node so we'll add it");
566:
567:                    new JPopupMenuOperator(runtimeTree.callPopupOnPath(path))
568:                            .pushMenuNoBlock(addServerMenuItem);
569:
570:                    NbDialogOperator addServerInstanceDialog = new NbDialogOperator(
571:                            addServerInstanceDialogTitle);
572:
573:                    new JListOperator(addServerInstanceDialog, 1)
574:                            .selectItem(glassFishV2ListItem);
575:
576:                    new JButtonOperator(addServerInstanceDialog,
577:                            nextButtonCaption).push();
578:
579:                    new JTextFieldOperator(addServerInstanceDialog)
580:                            .enterText(appServerPath);
581:
582:                    new JButtonOperator(addServerInstanceDialog,
583:                            finishButtonCaption).push();
584:                }
585:
586:                runtimeTree.getTimeouts().setTimeout(
587:                        "JTreeOperator.WaitNextNodeTimeout", oldTimeout);
588:            }
589:
590:            public static Node getApplicationServerNode() {
591:                RuntimeTabOperator rto = RuntimeTabOperator.invoke();
592:
593:                TreePath path = null;
594:
595:                // create exactly (full match) and case sensitively comparing comparator
596:                //        Operator.DefaultStringComparator comparator = new Operator.DefaultStringComparator(false, false);
597:                //        StringComparator previousComparator = rto.tree().getComparator();
598:                //        rto.setComparator(comparator);
599:                JTreeOperator runtimeTree = rto.tree();
600:                long oldTimeout = runtimeTree.getTimeouts().getTimeout(
601:                        "JTreeOperator.WaitNextNodeTimeout");
602:                runtimeTree.getTimeouts().setTimeout(
603:                        "JTreeOperator.WaitNextNodeTimeout", 60000);
604:                try {
605:                    log("Looking path = Servers");
606:                    path = runtimeTree.findPath("Servers");
607:                    runtimeTree.selectPath(path);
608:                    log("Looking path = Servers|GlassFish V2");
609:                    path = runtimeTree.findPath("Servers|GlassFish V2"); // NOI18N
610:                    runtimeTree.selectPath(path);
611:                } catch (Exception exc) {
612:                    exc.printStackTrace(System.err);
613:                    throw new Error("Cannot find Application Server Node", exc);
614:                }
615:                runtimeTree.getTimeouts().setTimeout(
616:                        "JTreeOperator.WaitNextNodeTimeout", oldTimeout);
617:                //        rto.setComparator(previousComparator);
618:                return new Node(runtimeTree, path);
619:            }
620:
621:            public static Node startApplicationServer() {
622:                Node node = performApplicationServerAction("Start", "Starting"); // NOI18N
623:                new EventTool().waitNoEvent(80000);
624:                return node;
625:            }
626:
627:            public static Node stopApplicationServer() {
628:                Node node = performApplicationServerAction("Stop", "Stopping"); // NOI18N
629:                new EventTool().waitNoEvent(50000);
630:                return node;
631:            }
632:
633:            /**
634:             * Invoke action on Application server node (start/stop/...)
635:             * @param action Action to be invoked on the Application server node
636:             */
637:            private static Node performApplicationServerAction(String action,
638:                    String message) {
639:                Node asNode = getApplicationServerNode();
640:                asNode.select();
641:
642:                String serverIDEName = asNode.getText();
643:                log("ServerNode name = " + serverIDEName);
644:                JPopupMenuOperator popup = asNode.callPopup();
645:                if (popup == null) {
646:                    throw new Error(
647:                            "Cannot get context menu for Application server node ");
648:                }
649:                boolean startEnabled = popup.showMenuItem(action).isEnabled();
650:                if (startEnabled) {
651:                    popup.pushMenuNoBlock(action);
652:                }
653:
654:                waitForAppServerTask(message, serverIDEName);
655:
656:                return asNode;
657:            }
658:
659:            private static void waitForAppServerTask(String taskName,
660:                    String serverIDEName) {
661:                Controller controller = Controller.getDefault();
662:                TaskModel model = controller.getModel();
663:
664:                InternalHandle task = waitServerTaskHandle(model, taskName
665:                        + " " + serverIDEName);
666:                long taskTimestamp = task.getTimeStampStarted();
667:
668:                log("task started at : " + taskTimestamp);
669:                int i = 0;
670:                while (i < 12000) { // max 12000*50=600000=10 min
671:                    i++;
672:                    int state = task.getState();
673:                    if (state == task.STATE_FINISHED) {
674:                        return;
675:                    }
676:                    try {
677:                        Thread.sleep(50);
678:                    } catch (InterruptedException exc) {
679:                        exc.printStackTrace(System.err);
680:                        return;
681:                    }
682:                }
683:            }
684:
685:            private static InternalHandle waitServerTaskHandle(TaskModel model,
686:                    String serverIDEName) {
687:                for (int i = 0; i < 12000; i++) { // max 12000*50=600000=10 min
688:                    InternalHandle[] handles = model.getHandles();
689:                    InternalHandle serverTask = getServerTaskHandle(handles,
690:                            serverIDEName);
691:                    if (serverTask != null) {
692:                        log("Returning task handle");
693:                        return serverTask;
694:                    }
695:
696:                    try {
697:                        Thread.sleep(50);
698:                    } catch (InterruptedException exc) {
699:                        exc.printStackTrace(System.err);
700:                    }
701:                }
702:
703:                return null;
704:            }
705:
706:            private static InternalHandle getServerTaskHandle(
707:                    InternalHandle[] handles, String taskName) {
708:                if (handles.length == 0) {
709:                    log("Empty tasks queue");
710:                    return null;
711:                }
712:
713:                for (InternalHandle internalHandle : handles) {
714:                    if (internalHandle.getDisplayName().equals(taskName)) {
715:                        log("Expected task found...");
716:                        return internalHandle;
717:                    }
718:                }
719:                return null;
720:            }
721:
722:            /**
723:             * Wait finished scan - repeatedly
724:             */
725:            public static void waitScanFinished() {
726:                ProjectSupport.waitScanFinished();
727:                new QueueTool().waitEmpty(1000);
728:                ProjectSupport.waitScanFinished();
729:            }
730:
731:            public static void initLog(PerformanceTestCase testCase) {
732:                test = testCase;
733:            }
734:
735:            public static void closeLog() {
736:                test = null;
737:            }
738:
739:            private static void log(String logMessage) {
740:                System.out.println("Utilities::" + logMessage);
741:                if (test != null) {
742:                    test.log("Utilities::" + logMessage);
743:                }
744:            }
745:
746:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.