Source Code Cross Referenced for TestUtils.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » gravy » 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.gravy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:
0042:        package org.netbeans.modules.visualweb.gravy;
0043:
0044:        import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
0045:        import java.nio.charset.MalformedInputException;
0046:        import javax.swing.tree.TreePath;
0047:        import org.netbeans.jellytools.Bundle;
0048:        import org.netbeans.jellytools.NewProjectWizardOperator;
0049:        import org.netbeans.jellytools.TopComponentOperator;
0050:        import org.netbeans.modules.visualweb.gravy.debugger.BuildOutputOperator;
0051:        import org.netbeans.modules.visualweb.gravy.welcome.WelcomeOperator;
0052:        import org.netbeans.modules.visualweb.gravy.actions.CloseProjectAction;
0053:        import java.awt.*;
0054:        import java.awt.event.*;
0055:        import java.io.*;
0056:        import java.util.Date;
0057:        import java.util.Properties;
0058:        import java.text.SimpleDateFormat;
0059:        import java.net.URL;
0060:        import org.netbeans.modules.visualweb.gravy.properties.Property;
0061:        import org.netbeans.modules.visualweb.gravy.properties.PropertySheetTabOperator;
0062:        import org.netbeans.modules.visualweb.gravy.properties.PropertySheetOperator;
0063:        import org.netbeans.modules.visualweb.gravy.designer.*;
0064:        import javax.swing.*;
0065:        import org.netbeans.jemmy.*;
0066:        import org.netbeans.jemmy.drivers.*;
0067:        import org.netbeans.jemmy.drivers.input.*;
0068:        import org.netbeans.jemmy.operators.*;
0069:        import com.meterware.httpunit.*;
0070:        import java.util.Enumeration;
0071:        import java.util.zip.ZipEntry;
0072:        import java.util.zip.ZipFile;
0073:        import org.netbeans.core.windows.view.ui.tabcontrol.TabbedAdapter;
0074:        import org.netbeans.jellytools.OutputOperator;
0075:        import org.openide.windows.TopComponent;
0076:
0077:        /**
0078:         * TestUtils class
0079:         * @author Vladimir Strigun (sva@sparc.spb.su)
0080:         */
0081:
0082:        public class TestUtils {
0083:            public static final String KEY_STRING_AFTER_PRJ_NAME_J2EE = "src",
0084:                    KEY_STRING_AFTER_PRJ_NAME_JSF = "web";
0085:            private static final String SAVE_DIALOG_TITLE = "Save";
0086:            private static final String SAVE_ALL = "Save All";
0087:            //public static final String SAVE_ALL = Bundle.getStringTrimmed("com.sun.rave.project.actions.Bundle", "LBL_SaveAllAction");
0088:            private static final String CLOSE_PROJECT = "Close";
0089:            //public static final String CLOSE_PROJECT = Bundle.getStringTrimmed("com.sun.rave.project.actions.Bundle", "LBL_CloseProjectAction");
0090:
0091:            private static String delim = "|";
0092:            private static String fSep = System.getProperty("file.separator");
0093:
0094:            private static String pathLastCreatedProject;
0095:
0096:            /** Create new Project with given name
0097:             *   @param projectName - Project's name
0098:             */
0099:            public static void createNewProject(String projectName) {
0100:
0101:                createNewProjectAbsoluteLocation(null, projectName);
0102:            }
0103:
0104:            /** Create new Project with name included time stamp
0105:             *   @param projectName - Project's name
0106:             */
0107:            public static void createNewProjectTimeStamped(String projectName) {
0108:                createNewProject(projectName + "_"
0109:                        + getCurrentDateAndTimeAsString());
0110:            }
0111:
0112:            /** Create new Project with given name and relative location
0113:             *   @param location - relative location
0114:             *   @param projectName - Project's name
0115:             */
0116:
0117:            public static void createNewProjectLocation(String location,
0118:                    String projectName) {
0119:
0120:                createNewProjectLoc(location, projectName, false);
0121:            }
0122:
0123:            /** Create new Project with given name and absolute location
0124:             *   @param location - absolute location
0125:             *   @param projectName - Project's name
0126:             */
0127:
0128:            public static void createNewProjectAbsoluteLocation(
0129:                    String location, String projectName) {
0130:
0131:                createNewProjectLoc(location, projectName, true);
0132:            }
0133:
0134:            public static String createNewPortletProjectLoc(String location,
0135:                    String projectName, boolean absoluteLocation,
0136:                    String projectCategory, String projectType) {
0137:                NewProjectWizardOperator po = NewProjectWizardOperator.invoke();
0138:
0139:                //need to wait for a list containing project
0140:                Waiter projectListWaiter = new Waiter(new Waitable() {
0141:                    public Object actionProduced(Object po) {
0142:                        JList projList = (JList) ((ContainerOperator) po)
0143:                                .findSubComponent(
0144:                                        new JListOperator.JListFinder(), 1);
0145:                        JListOperator projListOper = new JListOperator(projList);
0146:                        projListOper.copyEnvironment((ComponentOperator) po);
0147:                        /*return((projListOper.findItemIndex(Bundle.getString(
0148:                                "com.sun.rave.project.nbbridge.Bundle",
0149:                                "Templates/Project/Web/raveform.xml")) == -1) ? null : "");*/
0150:                        //return((projListOper.findItemIndex("Application") == -1) ? null : "");
0151:                        if ((projListOper.findItemIndex("Application") == -1)
0152:                                && (projListOper.findItemIndex("Travel") == -1))
0153:                            return null;
0154:                        else
0155:                            return "";
0156:                    }
0157:
0158:                    public String getDescription() {
0159:                        return ("Project list to be displayed");
0160:                    }
0161:                });
0162:                wait(1000);
0163:
0164:                /* select the categroy */
0165:                po.selectCategory(projectCategory);
0166:                projectListWaiter.getTimeouts().setTimeout(
0167:                        "Waiter.WaitingTime", 180000);
0168:                try {
0169:                    projectListWaiter.waitAction(po);
0170:                } catch (InterruptedException e) {
0171:                }
0172:                /* Select project type */
0173:                //po.selectProject(Bundle.getString("com.sun.rave.project.nbbridge.Bundle", "Templates/Project/Web/raveform.xml"));
0174:                po.selectProject(projectType);
0175:                wait(1000);
0176:                po.next();
0177:                wait(2000);
0178:                if (projectName != null) {
0179:                    new JTextFieldOperator(po).setText(projectName);
0180:                } else {
0181:                    projectName = new JTextFieldOperator(po).getText();
0182:                }
0183:                if (location != null) {
0184:                    if (!absoluteLocation) {
0185:                        location = new JTextFieldOperator(po, 1).getText()
0186:                                + "/" + location;
0187:                    }
0188:                    new JTextFieldOperator(po, 1).setText(location);
0189:                } else {
0190:                    location = new JTextFieldOperator(po, 1).getText();
0191:                }
0192:                pathLastCreatedProject = location;
0193:
0194:                wait(1000);
0195:                po.next();
0196:                wait(2000);
0197:
0198:                po.finish();
0199:
0200:                String timeoutName = "DialogWaiter.WaitDialogTimeout";
0201:                long timeoutValue = JemmyProperties
0202:                        .getCurrentTimeout(timeoutName);
0203:                JemmyProperties.getCurrentTimeouts().setTimeout(timeoutName,
0204:                        8000);
0205:                try {
0206:                    new JButtonOperator(new JDialogOperator("Question"), "Yes")
0207:                            .pushNoBlock();
0208:                } catch (Exception e) {
0209:                } finally {
0210:                    JemmyProperties.getCurrentTimeouts().setTimeout(
0211:                            timeoutName, timeoutValue);
0212:                }
0213:
0214:                Util.getMainWindow().getTimeouts().setTimeout(
0215:                        "ComponentOperator.WaitComponentTimeout", 60000);//project creation time
0216:                //disableBrowser(projectName, true);
0217:
0218:                disableBrowser(projectName, location, true);
0219:                return projectName;
0220:            }
0221:
0222:            @Deprecated
0223:            public static String createNewJSFProject() {
0224:                return createNewJSFProject(null); // use default name
0225:            }
0226:
0227:            @Deprecated
0228:            public static String createNewJSFProject(String projectName) {
0229:                return createNewProjectLoc(null, projectName, true, "Web"/*Bundle.getStringTrimmed("com.sun.rave.jsf.project.Bundle",
0230:                                "OpenIDE-Module-Display-Category")*/,
0231:                        "Web Application"/*Bundle.getStringTrimmed("com.sun.rave.jsf.project.ui.wizards.Bundle",
0232:                                        "Templates/Project/Web/emptyJsf.xml")*/);
0233:            }
0234:
0235:            /**
0236:             * Creates project with J2EE 1.4 and default source structure
0237:             * @param location Project's location, if null then default location used
0238:             * @param projectName Project's name, if null then default name used
0239:             * @param absoluteLocation absolute or relative location
0240:             * @param projectCategory Category of the project (General, Web, etc.)
0241:             * @param projectType Type of the project of the given category
0242:             * @return Name of the Created project
0243:             *
0244:             */
0245:            public static String createNewProjectLoc(String location,
0246:                    String projectName, boolean absoluteLocation,
0247:                    String projectCategory, String projectType) {
0248:                projectName = createNewProject(location, projectName,
0249:                        absoluteLocation, projectCategory, projectType, null,
0250:                        "J2EE 1.4");
0251:                return projectName;
0252:            }
0253:
0254:            /**
0255:             * Creates JAVA EE 5 project with default source level
0256:             * @param location Project's location, if null then default location used
0257:             * @param projectName Project's name, if null then default name used
0258:             * @param absoluteLocation absolute or relative location
0259:             * @param projectCategory Category of the project (General, Web, etc.)
0260:             * @param projectType Type of the project of the given category
0261:             * @return Name of the Created project
0262:             */
0263:            public static String createJavaEE5ProjectLoc(String location,
0264:                    String projectName, boolean absoluteLocation,
0265:                    String projectCategory, String projectType) {
0266:                projectName = createNewProject(location, projectName,
0267:                        absoluteLocation, projectCategory, projectType, null,
0268:                        "Java EE 5");
0269:                return projectName;
0270:            }
0271:
0272:            /**
0273:             * Creating project
0274:             * @param location Project's location, if null then default location used
0275:             * @param projectName Project's name, if null then default name used
0276:             * @param absoluteLocation absolute or relative location
0277:             * @param projectCategory Category of the project (General, Web, etc.)
0278:             * @param projectType Type of the project of the given category, i.e. Web Application
0279:             * @param sourceStructure source structure (Java BluePrints, Jakarta), if null
0280:             * then currently selected used
0281:             * @param J2EELevel (Java EE 5, J2EE 1.4, J2EE 1.3), if null then currently selected used
0282:             * @return Name of the Created project
0283:             */
0284:            public static String createNewProject(String location,
0285:                    String projectName, boolean absoluteLocation,
0286:                    String projectCategory, String projectType,
0287:                    String sourceStructure, String J2EELevel) {
0288:                projectName = createNewProject(location, projectName,
0289:                        absoluteLocation, projectCategory, projectType,
0290:                        sourceStructure, J2EELevel, null);
0291:                return projectName;
0292:            }
0293:
0294:            /**
0295:             * Creating project
0296:             * @param location Project's location, if null then default location used
0297:             * @param projectName Project's name, if null then default name used
0298:             * @param absoluteLocation absolute or relative location
0299:             * @param projectCategory Category of the project (General, Web, etc.)
0300:             * @param projectType Type of the project of the given category, i.e. Web Application
0301:             * @param sourceStructure source structure (Java BluePrints, Jakarta), if null
0302:             * then currently selected used
0303:             * @param J2EELevel (Java EE 5, J2EE 1.4, J2EE 1.3), if null then currently selected used
0304:             * @param server deployment target, if null then default application server used
0305:             * @return Name of the Created project
0306:             */
0307:            public static String createNewProject(String location,
0308:                    String projectName, boolean absoluteLocation,
0309:                    String projectCategory, String projectType,
0310:                    String sourceStructure, String J2EELevel, String server) {
0311:                new Operator.DefaultStringComparator(true, true);
0312:                NewProjectWizardOperator po = NewProjectWizardOperator.invoke();
0313:
0314:                //need to wait for a list containing project
0315:                Waiter projectListWaiter = new Waiter(new Waitable() {
0316:                    public Object actionProduced(Object po) {
0317:                        JList projList = (JList) ((ContainerOperator) po)
0318:                                .findSubComponent(
0319:                                        new JListOperator.JListFinder(), 1);
0320:                        JListOperator projListOper = new JListOperator(projList);
0321:                        projListOper.copyEnvironment((ComponentOperator) po);
0322:                        /*return((projListOper.findItemIndex(Bundle.getString(
0323:                                "com.sun.rave.project.nbbridge.Bundle",
0324:                                "Templates/Project/Web/raveform.xml")) == -1) ? null : "");*/
0325:                        //return((projListOper.findItemIndex("Application") == -1) ? null : "");
0326:                        if ((projListOper.findItemIndex("Application") == -1)
0327:                                && (projListOper.findItemIndex("Travel") == -1))
0328:                            return null;
0329:                        else
0330:                            return "";
0331:                    }
0332:
0333:                    public String getDescription() {
0334:                        return ("Project list to be displayed");
0335:                    }
0336:                });
0337:                wait(1000);
0338:
0339:                /* select Web categroy */
0340:                po.selectCategory(projectCategory);
0341:                projectListWaiter.getTimeouts().setTimeout(
0342:                        "Waiter.WaitingTime", 180000);
0343:                try {
0344:                    projectListWaiter.waitAction(po);
0345:                } catch (InterruptedException e) {
0346:                }
0347:                /* Select project type */
0348:                //po.selectProject(Bundle.getString("com.sun.rave.project.nbbridge.Bundle", "Templates/Project/Web/raveform.xml"));
0349:                Operator.StringComparator comparator = po.getComparator();
0350:                Operator.StringComparator stringComparator = new Operator.DefaultStringComparator(
0351:                        true, true);
0352:                po.setComparator(stringComparator);
0353:                wait(1000);
0354:                po.selectProject(projectType);
0355:                wait(2000);
0356:                po.setComparator(comparator);
0357:                wait(1000);
0358:
0359:                po.next();
0360:                wait(2000);
0361:                if (projectName != null) {
0362:                    new JTextFieldOperator(po).setText(projectName);
0363:                } else {
0364:                    projectName = new JTextFieldOperator(po).getText();
0365:                }
0366:                if (location != null) {
0367:                    if (!absoluteLocation) {
0368:                        location = new JTextFieldOperator(po, 1).getText()
0369:                                + "/" + location;
0370:                    }
0371:                    new JTextFieldOperator(po, 1).setText(location);
0372:                } else {
0373:                    location = new JTextFieldOperator(po, 1).getText();
0374:                }
0375:                pathLastCreatedProject = location;
0376:
0377:                //Setting source structure (Blue Prints or Jakarta)
0378:                //if (sourceStructure!=null) {
0379:                //   new JComboBoxOperator(po, 0).selectItem(sourceStructure);
0380:                //}
0381:
0382:                wait(1000);
0383:                //Setting Server
0384:                if (server != null) {
0385:                    new JComboBoxOperator(po, 1).selectItem(server);
0386:                }
0387:
0388:                wait(1000);
0389:                //Setting level of J2EE
0390:                if (J2EELevel != null) {
0391:                    new JComboBoxOperator(po, 2).selectItem(J2EELevel);
0392:                }
0393:                wait(1000);
0394:                if (new JButtonOperator(po, "Next").isEnabled()) {
0395:                    po.next();
0396:                    wait(1000);
0397:                    po.next();
0398:                    wait(1000);
0399:                    //TODO clicked on Down button and then Brake Space pressed to select needed checkbox
0400:                    po.pushKey(KeyEvent.VK_DOWN);
0401:                    wait(2000);
0402:                    po.pushKey(KeyEvent.VK_SPACE);
0403:                    wait(2000);
0404:                }
0405:                po.finish();
0406:                String timeoutName = "DialogWaiter.WaitDialogTimeout";
0407:                long timeoutValue = JemmyProperties
0408:                        .getCurrentTimeout(timeoutName);
0409:                JemmyProperties.getCurrentTimeouts().setTimeout(timeoutName,
0410:                        10000);
0411:                Waiter waitProjectPropertiesDialog = new Waiter(new Waitable() {
0412:                    public Object actionProduced(Object obj) {
0413:                        try {
0414:                            new JButtonOperator(new JDialogOperator(
0415:                                    "Edit Project Properties"), "Regenerate")
0416:                                    .push();
0417:                            return null;
0418:                        } catch (TimeoutExpiredException e) {
0419:                            return true;
0420:                        }
0421:
0422:                    }
0423:
0424:                    public String getDescription() {
0425:                        return "Wait all dialogs";
0426:                    }
0427:                });
0428:                waitProjectPropertiesDialog.getTimeouts().setTimeout(
0429:                        "Waiter.WaitingTime", 60000);
0430:                try {
0431:                    waitProjectPropertiesDialog.waitAction(null);
0432:                } catch (Exception e) {
0433:                    e.printStackTrace();
0434:                } finally {
0435:                    JemmyProperties.getCurrentTimeouts().setTimeout(
0436:                            timeoutName, timeoutValue);
0437:                }
0438:                /*
0439:                try {
0440:                    for (int i = 0 ;i<5; i++) {
0441:                        new JButtonOperator(new JDialogOperator("Edit Project Properties"), "Cancel").pushNoBlock();
0442:                    }
0443:                } catch(Exception e) {
0444:                } finally {
0445:                    JemmyProperties.getCurrentTimeouts().setTimeout(timeoutName,
0446:                            timeoutValue);
0447:                }
0448:                 */
0449:                //wait(20000);
0450:                //Util.getMainWindow().getTimeouts().setTimeout("ComponentOperator.WaitComponentTimeout", 60000);//project creation time
0451:
0452:                //new TopComponentOperator("Page1");
0453:                disableBrowser(projectName, location, true);
0454:
0455:                Waiter projectCreationWaiter = new Waiter(new Waitable() {
0456:                    public Object actionProduced(Object po) {
0457:                        try {
0458:                            int i = 0;
0459:                            PageTopComponentOperator page;
0460:                            while (((String) (page = new PageTopComponentOperator(
0461:                                    "Page1", i++)).getDump()
0462:                                    .get("Tooltip text")).indexOf("web"
0463:                                    + File.separator + "Page1.jsp") == -1)
0464:                                ;
0465:                            new DesignerPaneOperator(page);
0466:                            return "";
0467:                        } catch (TimeoutExpiredException e) {
0468:                            return null;
0469:                        }
0470:                    }
0471:
0472:                    public String getDescription() {
0473:                        return ("Project list to be displayed");
0474:                    }
0475:                });
0476:                wait(1000);
0477:                projectCreationWaiter.getTimeouts().setTimeout(
0478:                        "Waiter.WaitingTime", 600000);
0479:                System.out.println("TRACE: Start waiting: "
0480:                        + getCurrentDateAndTimeAsString());
0481:                try {
0482:                    projectCreationWaiter.waitAction(null);
0483:                } catch (Exception e) {
0484:                    //            e.printStackTrace();
0485:                    throw new JemmyException(
0486:                            "Exception when waiting Page1 opened", e);
0487:                }
0488:                System.out.println("TRACE: Stop waiting: "
0489:                        + getCurrentDateAndTimeAsString());
0490:                return projectName;
0491:            }
0492:
0493:            public static String getPathLastCreatedProject() {
0494:                return pathLastCreatedProject;
0495:            }
0496:
0497:            public static void openProject(String projectPath,
0498:                    boolean welcomeOperator) {
0499:                if (welcomeOperator)
0500:                    WelcomeOperator.getWelcomeButton(
0501:                            Bundle.getStringTrimmed(
0502:                                    "com.sun.rave.welcome.Bundle",
0503:                                    "LBL_OpenProject")).pushNoBlock();
0504:                else
0505:                    Util
0506:                            .getMainMenu()
0507:                            .pushMenuNoBlock(
0508:                                    Bundle.getStringTrimmed(
0509:                                            "org.netbeans.core.Bundle",
0510:                                            "Menu/File")
0511:                                            + "|"
0512:                                            + Bundle
0513:                                                    .getStringTrimmed(
0514:                                                            "com.sun.rave.project.actions.Bundle",
0515:                                                            "LBL_OpenProjectAction"));
0516:                //        String workDir = System.getProperty("scratch.dir").replace('/',File.separatorChar);
0517:                //        workDir+=File.separatorChar+"Creator"+File.separatorChar+projectPath;
0518:                Util.wait(3000);
0519:                //        (new JTextFieldOperator(new JDialogOperator("Open"))).typeText(workDir);
0520:                //        (new JButtonOperator(new JDialogOperator("Open"), "Open")).push();
0521:                (new JTextFieldOperator(new JDialogOperator(Bundle
0522:                        .getStringTrimmed(
0523:                                "org.netbeans.modules.project.ui.Bundle",
0524:                                "LBL_PrjChooser_Title")), 1))
0525:                        .typeText(projectPath);
0526:                (new JButtonOperator(new JDialogOperator(Bundle
0527:                        .getStringTrimmed(
0528:                                "org.netbeans.modules.project.ui.Bundle",
0529:                                "LBL_PrjChooser_Title")), Bundle
0530:                        .getStringTrimmed(
0531:                                "org.netbeans.modules.project.ui.Bundle",
0532:                                "BTN_PrjChooser_ApproveButtonText"))).push();
0533:                //        DesignerPaneOperator des = new DesignerPaneOperator(Util.getMainTab());
0534:                //        DesignerPaneOperator des = new DesignerPaneOperator();
0535:                Util.wait(3000);
0536:            }
0537:
0538:            public static void openProject(String projectPath) {
0539:                /*
0540:                Util.getMainMenu().pushMenuNoBlock(Bundle.getStringTrimmed("org.netbeans.core.Bundle",
0541:                        "Menu/File")+"|"
0542:                        +Bundle.getStringTrimmed("com.sun.rave.project.actions.Bundle",
0543:                        "LBL_OpenProjectAction"));
0544:                 */
0545:                Util.getMainMenu().pushMenuNoBlock(
0546:                        Bundle.getStringTrimmed("org.netbeans.core.Bundle",
0547:                                "Menu/File")
0548:                                + "|" + "Open Project");
0549:
0550:                Util.wait(3000);
0551:                //(new JTextFieldOperator(new JDialogOperator(Bundle.getStringTrimmed("org.netbeans.modules.project.ui.Bundle", "LBL_PrjChooser_Title")), 1)).typeText(projectPath);
0552:                JDialogOperator openPrjDialog = new JDialogOperator(
0553:                        "Open Project");
0554:                //        if (System.getProperty("os.name").equals("Mac OS X")) {
0555:                //            String[] splittedPath = projectPath.substring(1, projectPath.length()).split(File.separator);
0556:                //            TestUtils.wait(1000);
0557:                //            JComboBoxOperator cbRoot = new JComboBoxOperator(openPrjDialog);
0558:                //            for (int i = 0; i < cbRoot.getItemCount(); i++) {
0559:                //                System.out.println("cbRoot.getItemAt(i).toString()=" + cbRoot.getItemAt(i).toString());
0560:                //                TestUtils.wait(500);
0561:                //                if (cbRoot.getItemAt(i).toString().equals(File.separator)) {
0562:                //                    cbRoot.setSelectedIndex(i);
0563:                //                    break;
0564:                //                }
0565:                //            }
0566:                //            String toCompare = "";
0567:                //            for (int i = 0; i < splittedPath.length; i++) {
0568:                //                JTableOperator jtoPath = new JTableOperator(openPrjDialog);
0569:                //                toCompare += "/" + splittedPath[i];
0570:                //                System.out.println("toComapre="+toCompare);
0571:                //                TestUtils.wait(500);
0572:                //                Point cell = jtoPath.findCell(toCompare, new Operator.DefaultStringComparator(true, true), 0);
0573:                //                jtoPath.clickOnCell((int) cell.getY(), (int) cell.getX());
0574:                //                TestUtils.wait(500);
0575:                //                if (i != splittedPath.length - 1) jtoPath.clickOnCell((int) cell.getY(), (int) cell.getX(), 2);
0576:                //                else new JButtonOperator(openPrjDialog, "Open Project Folder").pushNoBlock();
0577:                //                TestUtils.wait(500);
0578:                //            }
0579:                //        } else {
0580:                new JTextFieldOperator(openPrjDialog, 1).setText(projectPath);
0581:                new JButtonOperator(openPrjDialog, "Open Project").push();
0582:                //        }
0583:                //        (new JButtonOperator(new JDialogOperator("Open"), "Open")).push();
0584:                //(new JButtonOperator(new JDialogOperator(Bundle.getStringTrimmed("org.netbeans.modules.project.ui.Bundle", "LBL_PrjChooser_Title")), Bundle.getStringTrimmed("org.netbeans.modules.project.ui.Bundle", "BTN_PrjChooser_ApproveButtonText"))).push();
0585:                //(new JButtonOperator(openPrjDialog, "Open Project Folder")).push();
0586:                //        DesignerPaneOperator des = new DesignerPaneOperator(Util.getMainTab());
0587:                //        DesignerPaneOperator des = new DesignerPaneOperator();
0588:                Util.wait(3000);
0589:            }
0590:
0591:            public static void openWebFormJavaFile(String projectName) {
0592:                //        Util.getMainMenu().pushMenu(Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/View")+delim+Bundle.getStringTrimmed("com.sun.rave.project.Bundle", "LBL_Projects"));
0593:                Util.getMainMenu()
0594:                        .pushMenu(
0595:                                Bundle
0596:                                        .getStringTrimmed(
0597:                                                "org.netbeans.core.Bundle",
0598:                                                "Menu/View")
0599:                                        + delim
0600:                                        + Bundle.getStringTrimmed(
0601:                                                "org.netbeans.core.Bundle",
0602:                                                "Projects"));
0603:                final JTreeOperator tree = new JTreeOperator(
0604:                        new ProjectNavigatorOperator());
0605:                //        TreePath treePath = tree.findPath(projectName, "|");
0606:                //        tree.expandPath(treePath);
0607:                String path = projectName + "|Java Sources|"
0608:                        + projectName.toLowerCase() + "|Page1.java";
0609:                TreePath treePath = tree.findPath(path, "|");
0610:                (new JPopupMenuOperator(tree.callPopupOnPath(treePath)))
0611:                        .pushMenu("Open");
0612:            }
0613:
0614:            public static void closeCurrentProject() {
0615:                try {
0616:                    Util.getMainMenu().pushMenu(
0617:                            Bundle.getStringTrimmed("org.netbeans.core.Bundle",
0618:                                    "Menu/File")
0619:                                    + delim + CLOSE_PROJECT);
0620:                } catch (TimeoutExpiredException e) {
0621:                    System.out
0622:                            .println("Can't close current project. May be project doesn't exist");
0623:                    e.printStackTrace();
0624:                }
0625:            }
0626:
0627:            public static void closeCurrentProjectSaveAll() {
0628:                try {
0629:                    try {
0630:                        /*
0631:                        Util.getMainMenu().pushMenu(
0632:                                Bundle.getStringTrimmed("org.netbeans.core.Bundle",
0633:                                                        "Menu/File")
0634:                                +delim
0635:                                + CLOSE_PROJECT);
0636:                         */
0637:                        new CloseProjectAction().perform();
0638:                    } catch (TimeoutExpiredException e) {
0639:                    }
0640:                    JDialogOperator saveAll = new JDialogOperator(
0641:                            SAVE_DIALOG_TITLE);
0642:                    new JButtonOperator(saveAll, SAVE_ALL).pushNoBlock();
0643:                } catch (TimeoutExpiredException e) {
0644:                    System.out
0645:                            .println("Can't close current project. May be project doesn't exist");
0646:                    e.printStackTrace();
0647:                }
0648:            }
0649:
0650:            /**
0651:             *  Closes project <code>prjName</code> if it is currently selected
0652:             *  @param prjName Project Name
0653:             *  @deprecated Use closeCurrentProject or closeProjectByName instead
0654:             */
0655:            public static void closeProject(String prjName) {
0656:                try {
0657:                    try {
0658:                        Util.getMainMenu().pushMenu(
0659:                                Bundle
0660:                                        .getStringTrimmed(
0661:                                                "org.netbeans.core.Bundle",
0662:                                                "Menu/File")
0663:                                        + delim
0664:                                        + CLOSE_PROJECT
0665:                                        + " \""
0666:                                        + prjName + "\"");
0667:                    } catch (TimeoutExpiredException e) {
0668:                    }
0669:                    JDialogOperator saveAll = new JDialogOperator(
0670:                            SAVE_DIALOG_TITLE);
0671:                    new JButtonOperator(saveAll, SAVE_ALL).pushNoBlock();
0672:                } catch (org.netbeans.jemmy.TimeoutExpiredException e) {
0673:                    System.out
0674:                            .println("Can't close current project. May be project doesn't exist");
0675:                    e.printStackTrace();
0676:                }
0677:            }
0678:
0679:            /**
0680:             *  Closes project <code>prjName</code>. Saves all if Save Dialog is shown
0681:             *  @param prjName Project Name
0682:             */
0683:            public static void closeProjectByName(String prjName) {
0684:
0685:                try {
0686:                    ProjectNavigatorOperator pno = new ProjectNavigatorOperator()
0687:                            .switchToProjects();
0688:                    pno.pressPopupItemOnNode(prjName, "Close");
0689:                } catch (TimeoutExpiredException e) {
0690:                    throw new RuntimeException("Failed to close project", e);
0691:                }
0692:
0693:                JDialogOperator saveAll = null;
0694:
0695:                try {
0696:                    saveAll = new JDialogOperator(SAVE_DIALOG_TITLE);
0697:                    new JButtonOperator(saveAll, SAVE_ALL).pushNoBlock();
0698:                } catch (org.netbeans.jemmy.TimeoutExpiredException e) {
0699:                    if (saveAll == null)
0700:                        System.out.println("No Save Dialog is shown");
0701:                    else {
0702:                        System.out.println("Failed to save all");
0703:                        e.printStackTrace();
0704:                    }
0705:                }
0706:            }
0707:
0708:            /**
0709:             *  Checks whether project <code>prjName</code> is opened
0710:             *  @param prjName Project Name to check
0711:             *  @return Returns true if project name is shown in Projects tree
0712:             */
0713:            public static boolean isProjectOpened(String prjName) {
0714:                ProjectNavigatorOperator pno = null;
0715:                try {
0716:                    pno = new ProjectNavigatorOperator().switchToProjects();
0717:                    JTreeOperator jto = pno.tree();
0718:                    Timeouts timeouts = jto.getTimeouts().cloneThis();
0719:                    jto.getTimeouts().setTimeout(
0720:                            "JTreeOperator.WaitNextNodeTimeout", 3000);
0721:                    try {
0722:                        jto.findPath(prjName);
0723:                    } finally {
0724:                        jto.setTimeouts(timeouts);
0725:                    }
0726:                } catch (TimeoutExpiredException e) {
0727:                    if (pno == null) {
0728:                        //                    e.printStackTrace();
0729:                        throw new RuntimeException(
0730:                                "Failed to open Project Navigator", e);
0731:                    } else {
0732:                        return false;
0733:                    }
0734:                }
0735:                return true;
0736:            }
0737:
0738:            public static void closeProjectSaveAll(String prjName) {
0739:                try {
0740:                    try {
0741:                        /*
0742:                        Util.getMainMenu().pushMenu(
0743:                                Bundle.getStringTrimmed("org.netbeans.core.Bundle",
0744:                                "Menu/File") + delim
0745:                                + CLOSE_PROJECT
0746:                                + " \"" + prjName + "\"");
0747:                         */
0748:                        new CloseProjectAction().perform();
0749:                    } catch (TimeoutExpiredException e) {
0750:                    }
0751:                    JDialogOperator saveAll = new JDialogOperator(
0752:                            SAVE_DIALOG_TITLE);
0753:                    new JButtonOperator(saveAll, SAVE_ALL).push();
0754:                } catch (org.netbeans.jemmy.TimeoutExpiredException e) {
0755:                    System.out
0756:                            .println("Can't close current project. May be project doesn't exist");
0757:                    e.printStackTrace();
0758:                }
0759:            }
0760:
0761:            public static void closeProjectAfterSaveAll(String prjName) {
0762:                try {
0763:                    Util.getMainMenu().pushMenu(
0764:                            Bundle.getStringTrimmed("org.netbeans.core.Bundle",
0765:                                    "Menu/File")
0766:                                    + delim + SAVE_ALL);
0767:                    Util.getMainMenu().pushMenu(
0768:                            Bundle.getStringTrimmed("org.netbeans.core.Bundle",
0769:                                    "Menu/File")
0770:                                    + delim
0771:                                    + CLOSE_PROJECT
0772:                                    + " \""
0773:                                    + prjName
0774:                                    + "\"");
0775:                } catch (Exception e) {
0776:                    e.printStackTrace();
0777:                }
0778:            }
0779:
0780:            public static void pushPopupMenuItemOnMainDesignerTab(
0781:                    DesignerPaneOperator designerOperator, String menuItem) {
0782:                clickMainDesignerTabForPopup(designerOperator);
0783:                JPopupMenuOperator popupMenu = new JPopupMenuOperator();
0784:                Util.wait(1000);
0785:                popupMenu
0786:                        .setComparator(new ComponentOperator.DefaultStringComparator(
0787:                                false, false));
0788:                popupMenu.pushMenu(menuItem);
0789:                Util.wait(2000);
0790:            }
0791:
0792:            public static void createNewProjectLoc(String location,
0793:                    String projectName, boolean absoluteLocation) {
0794:
0795:                createNewProjectLoc(location, projectName, absoluteLocation,
0796:                        "Web", "Visual Web Application");
0797:            }
0798:
0799:            private static void clickMainDesignerTabForPopup(
0800:                    DesignerPaneOperator designerOperator) {
0801:                TabbedAdapter tabbedAdapter = getTabbedAdapter(designerOperator);
0802:
0803:                int selectedIndex = tabbedAdapter.getSelectionModel()
0804:                        .getSelectedIndex();
0805:                Rectangle tabRect = tabbedAdapter.getTabBounds(selectedIndex);
0806:                int clickX = tabRect.x + (tabRect.width / 2), clickY = tabRect.y
0807:                        + (tabRect.height / 2);
0808:
0809:                ComponentOperator componentOperator = new ComponentOperator(
0810:                        (Component) tabbedAdapter);
0811:                MouseDriver mouseDriver = new MouseRobotDriver(new Timeout("",
0812:                        300));
0813:                mouseDriver.clickMouse(componentOperator, clickX, clickY, 1,
0814:                        InputEvent.BUTTON3_MASK, 0, new Timeout("", 10));
0815:                Util.wait(1000);
0816:            }
0817:
0818:            public static String getCurrentProjectName() {
0819:                // JSF-project is used by default
0820:                return getCurrentProjectName(KEY_STRING_AFTER_PRJ_NAME_JSF);
0821:            }
0822:
0823:            public static String getCurrentProjectName(
0824:                    String keyStringAfterPrjName) {
0825:                DesignerPaneOperator designerOperator = new DesignerPaneOperator();
0826:                TopComponent topComponent = getSelectedTopComponent(designerOperator);
0827:                String toolTip = topComponent.getToolTipText();
0828:
0829:                System.out.println();
0830:                System.out.println("+++ TopComconent's tooltip = [" + toolTip
0831:                        + "]");
0832:
0833:                String prjName = toolTip.replace(File.separatorChar, '/');
0834:                int substrIndex = prjName.lastIndexOf("/"
0835:                        + keyStringAfterPrjName);
0836:                prjName = prjName.substring(0, substrIndex);
0837:
0838:                substrIndex = prjName.lastIndexOf("/");
0839:                prjName = prjName.substring(substrIndex + 1);
0840:
0841:                System.out.println("+++ Current project name = " + prjName);
0842:                System.out.println();
0843:
0844:                return prjName;
0845:            }
0846:
0847:            public static boolean isMainTabOfDesignerSelected(
0848:                    DesignerPaneOperator designerOperator, String tabTitle) {
0849:                TopComponent topComponent = getSelectedTopComponent(designerOperator);
0850:                String name = getTopComponentName(topComponent).trim();
0851:
0852:                System.out.println("+++ Tab Title = [" + tabTitle + "]");
0853:                System.out.println("+++ TopComconent name = [" + name + "]");
0854:                System.out.println();
0855:
0856:                return (name.equals(tabTitle.trim()));
0857:            }
0858:
0859:            private static TabbedAdapter getTabbedAdapter(
0860:                    ContainerOperator containerOperator) {
0861:                if (containerOperator == null)
0862:                    return null;
0863:                Container container = containerOperator.getParent();
0864:                while (container != null) {
0865:                    if (container instanceof  TabbedAdapter) {
0866:                        System.out.println();
0867:                        System.out.println("+++ Tabbed Adapter found = "
0868:                                + container);
0869:                        System.out.println();
0870:                        return ((TabbedAdapter) container);
0871:                    }
0872:                    container = container.getParent();
0873:                }
0874:                return null;
0875:            }
0876:
0877:            public static TopComponent[] getTabTopComponents(
0878:                    ContainerOperator containerOperator) {
0879:                TabbedAdapter tabbedAdapter = getTabbedAdapter(containerOperator);
0880:                if (tabbedAdapter == null) {
0881:                    return null;
0882:                }
0883:                TopComponent[] topComponents = tabbedAdapter.getTopComponents();
0884:                return topComponents;
0885:            }
0886:
0887:            public static TopComponent getTabSelectedTopComponent(
0888:                    ContainerOperator containerOperator) {
0889:                TabbedAdapter tabbedAdapter = getTabbedAdapter(containerOperator);
0890:                if (tabbedAdapter == null) {
0891:                    return null;
0892:                }
0893:                int selectedIndex = tabbedAdapter.getSelectionModel()
0894:                        .getSelectedIndex();
0895:                TopComponent topComponent = tabbedAdapter
0896:                        .getSelectedTopComponent();
0897:                return topComponent;
0898:            }
0899:
0900:            private static TopComponent getSelectedTopComponent(
0901:                    DesignerPaneOperator designerOperator) {
0902:                TopComponent topComponent = getTabSelectedTopComponent(designerOperator);
0903:
0904:                System.out.println();
0905:                System.out.println("+++ TopComconent found = " + topComponent);
0906:                System.out.println();
0907:                return topComponent;
0908:            }
0909:
0910:            public static String getTopComponentName(TopComponent topComponent) {
0911:                String name = topComponent.getDisplayName();
0912:                if ((name == null) || (name.length() < 1)) {
0913:                    name = topComponent.getName();
0914:                }
0915:                return name;
0916:            }
0917:
0918:            public static boolean checkProjectBuilded() {
0919:                BuildOutputOperator console = new BuildOutputOperator();
0920:                if ((console.getTextOutput()).indexOf("BUILD SUCCESSFUL") != -1)
0921:                    return true;
0922:                return false;
0923:            }
0924:
0925:            public static void wait(int millisec) {
0926:                Util.wait(millisec);
0927:                //System.out.println("sleep to "+millisec/1000+" seconds");
0928:                //try { Thread.sleep(millisec); } catch(Exception e) {}
0929:            }
0930:
0931:            public static void waitStatusText(String line) {
0932:                String[] variants = { line };
0933:                StatusWaitable csw = new StatusWaitable(variants, false);
0934:                String result = waitStatus(csw);
0935:                if (result != null) {
0936:                    System.out.println("Error while waiting status text: "
0937:                            + result);
0938:                }
0939:            }
0940:
0941:            public static String waitStatus(StatusWaitable csw) {
0942:                Waiter w = new Waiter(csw);
0943:                try {
0944:                    w.waitAction(csw);
0945:                } catch (InterruptedException e) {
0946:                    e.printStackTrace();
0947:                    return ("Exception while waiting status text:" + e);
0948:                } catch (TimeoutExpiredException e1) {
0949:                    e1.printStackTrace();
0950:                    return ("Exception while waiting status text:" + e1);
0951:                }
0952:                return null;
0953:            }
0954:
0955:            public static void waitDeployed(OutputOperator output,
0956:                    int maxTimeout) throws InterruptedException {
0957:                Waiter deploymentWaiter = new Waiter(new Waitable() {
0958:                    public Object actionProduced(Object output) {
0959:                        String text = ((OutputOperator) output).getText();
0960:                        if (text.indexOf("BUILD FAILED") != -1)
0961:                            throw new RuntimeException(
0962:                                    new InterruptedException(
0963:                                            "BUILD FAILED String found in Output Window"));
0964:                        if (text.indexOf("BUILD SUCCESSFUL") != -1)
0965:                            return "true";
0966:                        return null;
0967:
0968:                    }
0969:
0970:                    public String getDescription() {
0971:                        return ("Waiting Project Deployed");
0972:                    }
0973:                });
0974:                //Waiter deploymentWaiter = new Waiter(new WaitDeploymentCompleted());
0975:                deploymentWaiter.getTimeouts().setTimeout("Waiter.WaitingTime",
0976:                        maxTimeout);
0977:                deploymentWaiter.waitAction(output);
0978:                output.close();
0979:            }
0980:
0981:            /** getting coords of selected component from "style" property
0982:             *
0983:             *
0984:             */
0985:
0986:            public static Point getComponentCoords() {
0987:                PropertySheetOperator pso = new PropertySheetOperator(Util
0988:                        .getMainWindow());
0989:                PropertySheetTabOperator psto = new PropertySheetTabOperator(
0990:                        pso);
0991:                psto.setComparator(new Operator.DefaultStringComparator(true,
0992:                        true));
0993:                Property pr = new Property(psto, "style");
0994:                String propValue = pr.getValue();
0995:
0996:                int xLoc = new Integer(propValue.substring(propValue
0997:                        .indexOf("left: ") + 6, propValue.indexOf("px",
0998:                        propValue.indexOf("left: ")))).intValue();
0999:                int yLoc = new Integer(propValue.substring(propValue
1000:                        .indexOf("top: ") + 5, propValue.indexOf("px",
1001:                        propValue.indexOf("top: ")))).intValue();
1002:
1003:                return new Point(xLoc, yLoc);
1004:            }
1005:
1006:            /** getting current Date and Time as one string ( YYYYMMDDHHMMSS )
1007:             *
1008:             *
1009:             */
1010:            public static String getCurrentDateAndTimeAsString() {
1011:                return (new SimpleDateFormat("yyyyMMddHHmmss"))
1012:                        .format(new Date());
1013:            }
1014:
1015:            /** export WAR file
1016:             *
1017:             *
1018:             */
1019:            public static void exportWAR(String projectName, String pathToWAR,
1020:                    boolean platform) {
1021:                //        ProjectNavigatorOperator.pressPopupItemOnNode("ROOT", "Export WAR File");
1022:                ProjectNavigatorOperator.pressPopupItemOnNode(projectName,
1023:                        "Export WAR File");
1024:                wait(2000);
1025:                JDialogOperator newWF = new JDialogOperator("Export WAR");
1026:                new JTextFieldOperator(newWF, 0).setText(pathToWAR + fSep
1027:                        + projectName + ".war");
1028:                wait(1000);
1029:                new JRadioButtonOperator(newWF, platform ? 0 : 1)
1030:                        .setSelected(true);
1031:                wait(1000);
1032:                new JButtonOperator(newWF, "OK").pushNoBlock();
1033:                newWF.waitClosed();
1034:                wait(2000);
1035:                long oldWaitTime = Util.getMainWindow().getTimeouts()
1036:                        .getTimeout("DialogWaiter.WaitDialogTimeout");
1037:                try {
1038:                    Util.getMainWindow().getTimeouts().setTimeout(
1039:                            "DialogWaiter.WaitDialogTimeout", 5000);
1040:                    JDialogOperator owdo = new JDialogOperator("Question");
1041:                    new JButtonOperator(owdo, "Yes").pushNoBlock();
1042:                    Util.getMainWindow().getTimeouts().setTimeout(
1043:                            "DialogWaiter.WaitDialogTimeout", oldWaitTime);
1044:                } catch (Exception e) {
1045:                    Util.getMainWindow().getTimeouts().setTimeout(
1046:                            "DialogWaiter.WaitDialogTimeout", oldWaitTime);
1047:                }
1048:                System.out.println("WAR File exported in " + pathToWAR + fSep
1049:                        + projectName + ".war");
1050:                while (new JLabelOperator(Util.getMainWindow(), 0).getText()
1051:                        .indexOf("Finished") == -1
1052:                        && new JLabelOperator(Util.getMainWindow(), 0)
1053:                                .getText().indexOf("(export.war)") == -1) {
1054:                }
1055:                wait(2000);
1056:            }
1057:
1058:            public static void exportWAR(String projectName, String pathToWAR) {
1059:                exportWAR(projectName, pathToWAR, true);
1060:            }
1061:
1062:            /**
1063:             * Prints list of all child components of container
1064:             * @param op - container
1065:             */
1066:            public static void printComponentList(ComponentOperator op) {
1067:                Component cmp = op.getSource();
1068:                if (cmp instanceof  Container) {
1069:                    printComponentList((Container) cmp);
1070:                } else {
1071:                    System.out.println("Not a container");
1072:                }
1073:            }
1074:
1075:            public static void printComponentList(Container container) {
1076:                printComponentList(container, 0);
1077:            }
1078:
1079:            private static void printComponentList(Container container,
1080:                    int tabCount) {
1081:                printComponentList(System.out, container, tabCount);
1082:            }
1083:
1084:            public static void printComponentList(String fileName,
1085:                    Container container) {
1086:                PrintStream printOut = null;
1087:                try {
1088:                    printOut = new PrintStream(new FileOutputStream(fileName,
1089:                            true));
1090:                    printComponentList(printOut, container, 0);
1091:                } catch (Exception e) {
1092:                    e.printStackTrace();
1093:                } finally {
1094:                    try {
1095:                        printOut.flush();
1096:                        printOut.close();
1097:                    } catch (Exception e) {
1098:                        e.printStackTrace();
1099:                    }
1100:                }
1101:            }
1102:
1103:            private static void printComponentList(PrintStream out,
1104:                    Container container, int tabCount) {
1105:                Component[] components = container.getComponents();
1106:                for (int i = 0; i < components.length; i++) {
1107:                    Component component = components[i];
1108:
1109:                    out.println();
1110:                    out.println();
1111:                    for (int j = 0; j < tabCount; j++) {
1112:                        out.print("\t");
1113:                    }
1114:                    out.print("+++ COMPONENT = " + component);
1115:                    out.println();
1116:                    // print next level
1117:                    if (component instanceof  Container) {
1118:                        printComponentList(out, (Container) component,
1119:                                tabCount + 1);
1120:                    }
1121:                }
1122:            }
1123:
1124:            private static final String CREATOR_SYSTEM_DIR = "visualweb1"
1125:                    + File.separator + "config",
1126:                    CREATOR_INSTALL_PROPERTIES_FILE_NAME = "com-sun-rave-install.properties";
1127:            //            CREATOR_SYSTEM_DIR = "system",
1128:            //            CREATOR_INSTALL_PROPERTIES_FILE_NAME = "install.properties";
1129:
1130:            private static final String HTTP_PROTOCOL = "http",
1131:                    WEB_PORT_PROPERTY_NAME = "webPort",
1132:                    ADMIN_PORT_PROPERTY_NAME = "adminPort",
1133:                    LOCALHOST = "localhost";
1134:
1135:            public static URL getJ2EEApplicationURL(String projectName) {
1136:                String webPort = getWebPortFromProperties(), unsensitiveProjectName = projectName
1137:                        .toLowerCase();
1138:                try {
1139:                    return (new URL(HTTP_PROTOCOL, LOCALHOST, Integer
1140:                            .parseInt(webPort), File.separator
1141:                            + unsensitiveProjectName));
1142:                } catch (Exception e) {
1143:                    e.printStackTrace();
1144:                    return null;
1145:                }
1146:            }
1147:
1148:            public static String getWebPortFromProperties() {
1149:                Properties installProperties = getCreatorInstallProperties();
1150:                return ((installProperties == null) ? null : installProperties
1151:                        .getProperty(WEB_PORT_PROPERTY_NAME));
1152:            }
1153:
1154:            public static String getAdminPortFromProperties() {
1155:                Properties installProperties = getCreatorInstallProperties();
1156:                return ((installProperties == null) ? null : installProperties
1157:                        .getProperty(ADMIN_PORT_PROPERTY_NAME));
1158:            }
1159:
1160:            public static Properties getCreatorInstallProperties() {
1161:                // ak153254: Fixed the name of installation properties file due to the fact
1162:                // that netbeans.dest.dir property doesn't exist any more
1163:                String installPropertiesFileName = System
1164:                        .getProperty("netbeans.home")
1165:                        + File.separator
1166:                        + ".."
1167:                        + File.separator
1168:                        + CREATOR_SYSTEM_DIR
1169:                        + File.separator
1170:                        + CREATOR_INSTALL_PROPERTIES_FILE_NAME;
1171:                try {
1172:                    Properties installProperties = new Properties();
1173:                    installProperties.load(new FileInputStream(
1174:                            installPropertiesFileName));
1175:                    return installProperties;
1176:                } catch (Exception e) {
1177:                    e.printStackTrace();
1178:                    return null;
1179:                }
1180:            }
1181:
1182:            public static void outMsg(String msg) {
1183:                outMsg(msg, true, true);
1184:            }
1185:
1186:            public static void outMsg(String msg, boolean spaceBefore,
1187:                    boolean spaceAfter) {
1188:                outMsg(System.out, msg, spaceBefore, spaceAfter);
1189:            }
1190:
1191:            public static void outMsg(String fileName, String msg) {
1192:                outMsg(fileName, msg, true, true);
1193:            }
1194:
1195:            public static void outMsg(String fileName, String msg,
1196:                    boolean spaceBefore, boolean spaceAfter) {
1197:                PrintStream printOut = null;
1198:                try {
1199:                    printOut = new PrintStream(new FileOutputStream(fileName,
1200:                            true));
1201:                    outMsg(printOut, msg, spaceBefore, spaceAfter);
1202:                } catch (Exception e) {
1203:                    e.printStackTrace();
1204:                } finally {
1205:                    try {
1206:                        printOut.flush();
1207:                        printOut.close();
1208:                    } catch (Exception e) {
1209:                        e.printStackTrace();
1210:                    }
1211:                }
1212:            }
1213:
1214:            private static void outMsg(PrintStream out, String msg,
1215:                    boolean spaceBefore, boolean spaceAfter) {
1216:                if (spaceBefore) {
1217:                    out.println();
1218:                }
1219:                out.println(msg);
1220:                if (spaceAfter) {
1221:                    out.println();
1222:                }
1223:            }
1224:
1225:            public static boolean isServerStarted() {
1226:                String adminPort = "24848";//getAdminPortFromProperties();
1227:                System.out.println("adminPort = " + adminPort);
1228:                return isServerStarted(LOCALHOST, adminPort);
1229:            }
1230:
1231:            public static boolean isServerStarted(String host, String port) {
1232:                return isServerStarted(host, port, null, null);
1233:            }
1234:
1235:            public static boolean isServerStarted(String host, String port,
1236:                    String userName, String userPassword) {
1237:                try {
1238:                    WebConversation conversation = new WebConversation();
1239:                    HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
1240:                    HttpUnitOptions.setExceptionsThrownOnScriptError(false);
1241:                    if ((userName != null) && (userPassword != null)) {
1242:                        conversation.setAuthorization(userName, userPassword);
1243:                    }
1244:                    String url = HTTP_PROTOCOL + "://" + host + ":" + port;
1245:                    try {
1246:                        WebResponse response = conversation.getResponse(url);
1247:                    } catch (java.io.EOFException e) {
1248:                        // workaround: handle an exception from Web Server 6.1
1249:                        outMsg("+++ Method [isServerStarted(...)]: an exception ["
1250:                                + e
1251:                                + "] after attempt to receive a response "
1252:                                + "from server [" + url + "]");
1253:                        e.printStackTrace();
1254:                    }
1255:                } catch (Throwable t) {
1256:                    t.printStackTrace();
1257:                    System.out.println("Exception in HTTP check : " + t);
1258:                    return false;
1259:                }
1260:                return true;
1261:            }
1262:
1263:            public static String getRequestPrefix(long timeout) {
1264:                Waiter waiter = new Waiter(new Waitable() {
1265:                    public Object actionProduced(Object p) {
1266:                        String _requestPrefix = "";
1267:                        _requestPrefix = System
1268:                                .getProperty("test.netbeans.j2eeserver.clienturl");
1269:                        if (_requestPrefix != null
1270:                                && _requestPrefix.length() > 0) {
1271:                            return (_requestPrefix);
1272:                        } else {
1273:                            return (null);
1274:                        }
1275:                    }
1276:
1277:                    public String getDescription() {
1278:                        return ("URL to be set");
1279:                    }
1280:                });
1281:                waiter.getTimeouts().setTimeout("Waiter.WaitingTime", timeout);
1282:                try {
1283:                    return ((String) waiter.waitAction(null));
1284:                } catch (java.lang.InterruptedException e) {
1285:                    return ("");
1286:                }
1287:            }
1288:
1289:            public static void disableBrowser(String prjName, boolean dis) {
1290:                ProjectNavigatorOperator.pressPopupItemOnNode(prjName,
1291:                        "Properties");
1292:                JDialogOperator propertiesDialog = new JDialogOperator(
1293:                        "Project Properties - " + prjName);
1294:                wait(1000);
1295:                JTreeOperator tree = new JTreeOperator(propertiesDialog);
1296:                tree.selectPath(tree.findPath("Run"));
1297:                wait(2000);
1298:                JCheckBoxOperator checkBox = new JCheckBoxOperator(
1299:                        propertiesDialog);
1300:                checkBox.setSelected(!dis);
1301:                wait(1000);
1302:                new JButtonOperator(propertiesDialog, "OK").pushNoBlock();
1303:                wait(1000);
1304:            }
1305:
1306:            public static void disableBrowser(String prjName, String prjLoc,
1307:                    boolean dis) {
1308:                final String propFileStr = prjLoc + File.separator + prjName
1309:                        + File.separator + "nbproject" + File.separator
1310:                        + "project.properties";
1311:                FileInputStream propIn = null;
1312:
1313:                //need to wait property file to be created
1314:                Waiter propertyFileWaiter = new Waiter(new Waitable() {
1315:                    public Object actionProduced(Object path) {
1316:                        File file = new File((String) path);
1317:                        if (file.exists()) {
1318:                            return file;
1319:                        } else
1320:                            return null;
1321:                    }
1322:
1323:                    public String getDescription() {
1324:                        return ("\"" + propFileStr + "\" property file to be created");
1325:                    }
1326:                });
1327:
1328:                propertyFileWaiter.getTimeouts().setTimeout(
1329:                        "Waiter.WaitingTime", 20000);
1330:                File propFile = null;
1331:                try {
1332:                    propFile = (File) propertyFileWaiter
1333:                            .waitAction(propFileStr);
1334:                } catch (InterruptedException e) {
1335:                }
1336:
1337:                wait(1000);
1338:                try {
1339:                    Properties prop = new Properties();
1340:                    wait(1000);
1341:                    propIn = new FileInputStream(propFile);
1342:                    wait(1000);
1343:                    prop.load(propIn);
1344:                    //wait(2000);
1345:                    Boolean newVal = new Boolean(!dis);
1346:                    prop.setProperty("display.browser", newVal.toString());
1347:                    //System.out.println("TRACE        Property set : display.browser = "+prop.getProperty("display.browser"));
1348:                    //wait(2000);
1349:                    prop.store(new FileOutputStream(propFileStr), null);
1350:                    //wait(5000);
1351:                } catch (Exception e) {
1352:                    e.printStackTrace();
1353:                    System.out.println("Exception occured " + e);
1354:                }
1355:            }
1356:
1357:            public static JMenuItem findPopupMenuItemByLabel(
1358:                    JPopupMenuOperator menuOperator, String menuItemLabel) {
1359:                return findPopupMenuItemByLabel(menuOperator, menuItemLabel,
1360:                        true, false);
1361:            }
1362:
1363:            public static JMenuItem findPopupMenuItemByLabel(
1364:                    JPopupMenuOperator menuOperator, String menuItemLabel,
1365:                    boolean equalsMode, boolean ignoreCaseMode) {
1366:                String labelText = (ignoreCaseMode ? menuItemLabel
1367:                        .toUpperCase() : menuItemLabel);
1368:
1369:                MenuElement[] menuItems = menuOperator.getSubElements();
1370:                for (int i = 0; i < menuItems.length; i++) {
1371:                    JMenuItem menuItem = (JMenuItem) menuItems[i];
1372:                    String menuItemText = (ignoreCaseMode ? menuItem.getText()
1373:                            .toUpperCase() : menuItem.getText());
1374:                    if (equalsMode) {
1375:                        if (menuItemText.equals(labelText)) {
1376:                            return menuItem;
1377:                        }
1378:                    } else {
1379:                        if (menuItemText.indexOf(labelText) > -1) {
1380:                            return menuItem;
1381:                        }
1382:                    }
1383:                }
1384:                return null;
1385:            }
1386:
1387:            /**
1388:             * @param destinationUrl - url with zip file
1389:             * @param srcFile - file in which downloaded file will be saved
1390:             */
1391:
1392:            public static void downloadFile(String destinationUrl,
1393:                    String srcFile) throws MalformedInputException, IOException {
1394:
1395:                // try {
1396:                // Create an URL instance
1397:                URL url = new URL(destinationUrl);
1398:
1399:                // Get an input stream for reading
1400:                InputStream in = url.openStream();
1401:
1402:                // Create a buffered input stream for efficency
1403:                BufferedInputStream bufIn = new BufferedInputStream(in);
1404:                OutputStream outStr = new FileOutputStream(srcFile);
1405:
1406:                // Repeat until end of file
1407:                for (;;) {
1408:                    int data = bufIn.read();
1409:
1410:                    // Check for EOF
1411:                    if (data == -1)
1412:                        break;
1413:                    else
1414:                        outStr.write(data);
1415:                    //System.out.print ( (char) data);
1416:                }
1417:                outStr.close();
1418:                /*
1419:                } catch(MalformedURLException mue) {
1420:                    System.err.println("Invalid URL");
1421:                    System.out.println("Invalid URL :" + mue);
1422:                    fail("Invalid URL");
1423:                } catch (IOException ioe) {
1424:                    System.err.println("I/O Error - " + ioe);
1425:                    fail("I/O Error - " + ioe);
1426:                }
1427:                 */
1428:            }
1429:
1430:            public static String unzip(String file) throws IOException {
1431:                String projectName;
1432:                Enumeration entries;
1433:                ZipFile zipFile;
1434:                //try {
1435:                zipFile = new ZipFile(file);
1436:                entries = zipFile.entries();
1437:                System.out.println("Extracting from: " + zipFile.getName());
1438:                //TODO:
1439:                String firstEntry = ((ZipEntry) zipFile.entries().nextElement())
1440:                        .getName();
1441:                System.out.println("FIRST ENTRY = " + firstEntry);
1442:                String startDir = firstEntry;
1443:                if (firstEntry.indexOf('/') != -1) {
1444:                    startDir = firstEntry.substring(0, firstEntry.indexOf('/'));
1445:                    System.out.println("dir = " + startDir);
1446:                    (new File(startDir)).mkdir();
1447:                }
1448:                projectName = startDir;
1449:                //_projectPath = (new File(startDir)).getAbsolutePath();
1450:                while (entries.hasMoreElements()) {
1451:                    ZipEntry entry = (ZipEntry) entries.nextElement();
1452:
1453:                    if (entry.isDirectory()) {
1454:                        // Assume directories are stored parents first then children.
1455:                        System.out.println("Extracting directory: "
1456:                                + entry.getName());
1457:                        // This is not robust, just for demonstration purposes.
1458:                        (new File(entry.getName())).mkdir();
1459:                        //continue;
1460:                    } else {
1461:                        System.out.println("Extracting file: "
1462:                                + entry.getName());
1463:                        copyInputStream(zipFile.getInputStream(entry),
1464:                                new BufferedOutputStream(new FileOutputStream(
1465:                                        entry.getName())));
1466:                    }
1467:
1468:                }
1469:                zipFile.close();
1470:                return projectName;
1471:                /*
1472:                } catch (IOException ioe) {
1473:                System.err.println("Unhandled exception:");
1474:                ioe.printStackTrace();
1475:                fail();
1476:                }
1477:                 */
1478:            }
1479:
1480:            protected static final void copyInputStream(InputStream in,
1481:                    OutputStream out) throws IOException {
1482:                byte[] buffer = new byte[1024];
1483:                int len;
1484:
1485:                while ((len = in.read(buffer)) >= 0)
1486:                    out.write(buffer, 0, len);
1487:
1488:                in.close();
1489:                out.close();
1490:            }
1491:
1492:            /**
1493:             * Parse logs for exceptions
1494:             *
1495:             */
1496:            public static String parseLogs(String pathToFile, String strToFind)
1497:                    throws IOException {
1498:                String lineSep = System.getProperty("line.separator");
1499:                BufferedReader br = new BufferedReader(new FileReader(
1500:                        pathToFile));
1501:                String nextLine = "";
1502:                StringBuffer sb = new StringBuffer();
1503:                while ((nextLine = br.readLine()) != null) {
1504:                    if (nextLine.indexOf(strToFind) != -1) {
1505:                        sb.append(nextLine);
1506:                        sb.append(lineSep);
1507:                    }
1508:                }
1509:                return sb.toString();
1510:            }
1511:
1512:            public static void setHTTPProxy(String proxyHost, String proxyPort) {
1513:                OptionsOperator opOper = OptionsOperator.invoke();
1514:                opOper.selectOption("General Settings|System Settings");
1515:                SheetTableOperator props = new SheetTableOperator(opOper);
1516:                props.setComboBoxValue("Type of proxy configuration",
1517:                        "Use HTTP Proxy");
1518:                props.setTextValue("Proxy Host", proxyHost);
1519:                props.setTextValue("Proxy Port", proxyPort);
1520:                opOper.close();
1521:            }
1522:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.