Source Code Cross Referenced for WebProjectValidation.java in  » IDE-Netbeans » web.core » org » netbeans » test » web » 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 » web.core » org.netbeans.test.web 
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.test.web;
0043:
0044:        import java.io.File;
0045:        import java.io.IOException;
0046:        import java.net.ConnectException;
0047:        import java.net.MalformedURLException;
0048:        import java.net.URL;
0049:        import java.net.URLConnection;
0050:        import javax.swing.JComboBox;
0051:        import javax.swing.SwingUtilities;
0052:        import javax.swing.tree.TreePath;
0053:        import org.netbeans.jellytools.Bundle;
0054:        import org.netbeans.jellytools.EditorOperator;
0055:        import org.netbeans.jellytools.EditorWindowOperator;
0056:        import org.netbeans.jellytools.JellyTestCase;
0057:        import org.netbeans.jellytools.MainWindowOperator;
0058:        import org.netbeans.jellytools.NbDialogOperator;
0059:        import org.netbeans.jellytools.NewFileNameLocationStepOperator;
0060:        import org.netbeans.jellytools.NewFileWizardOperator;
0061:        import org.netbeans.jellytools.actions.BuildProjectAction;
0062:        import org.netbeans.jellytools.actions.EditAction;
0063:        import org.netbeans.jellytools.modules.web.NewJspFileNameStepOperator;
0064:        import org.netbeans.jellytools.nodes.SourcePackagesNode;
0065:        import org.netbeans.jemmy.EventTool;
0066:        import org.netbeans.jemmy.JemmyException;
0067:        import org.netbeans.jemmy.JemmyProperties;
0068:        import org.netbeans.jemmy.TimeoutExpiredException;
0069:        import org.netbeans.jellytools.WizardOperator;
0070:        import org.netbeans.jellytools.nodes.Node;
0071:        import org.netbeans.jellytools.actions.ActionNoBlock;
0072:        import org.netbeans.jellytools.actions.Action;
0073:        import org.netbeans.jellytools.NewProjectWizardOperator;
0074:        import org.netbeans.jellytools.NewWebProjectNameLocationStepOperator;
0075:        import org.netbeans.jellytools.OptionsOperator;
0076:        import org.netbeans.jellytools.OutputTabOperator;
0077:        import org.netbeans.jellytools.ProjectsTabOperator;
0078:        import org.netbeans.jellytools.RuntimeTabOperator;
0079:        import org.netbeans.jellytools.actions.PropertiesAction;
0080:        import org.netbeans.jellytools.modules.j2ee.nodes.J2eeServerNode;
0081:        import org.netbeans.jellytools.modules.web.NavigatorOperator;
0082:        import org.netbeans.jellytools.modules.web.nodes.WebPagesNode;
0083:        import org.netbeans.jemmy.QueueTool;
0084:        import org.netbeans.jemmy.Timeouts;
0085:        import org.netbeans.jemmy.operators.JButtonOperator;
0086:        import org.netbeans.jemmy.operators.JCheckBoxOperator;
0087:        import org.netbeans.jemmy.operators.JComboBoxOperator;
0088:        import org.netbeans.jemmy.operators.JLabelOperator;
0089:        import org.netbeans.jemmy.operators.JListOperator;
0090:        import org.netbeans.jemmy.operators.JRadioButtonOperator;
0091:        import org.netbeans.jemmy.operators.JTextFieldOperator;
0092:        import org.netbeans.jemmy.operators.JTreeOperator;
0093:        import org.netbeans.jemmy.operators.Operator;
0094:        import org.netbeans.jemmy.util.PNGEncoder;
0095:        import org.netbeans.junit.NbTestSuite;
0096:        import org.netbeans.junit.ide.ProjectSupport;
0097:        import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceCreationException;
0098:        import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
0099:        import org.openide.cookies.EditorCookie;
0100:        import org.openide.filesystems.FileUtil;
0101:        import org.openide.loaders.DataObject;
0102:
0103:        /**
0104:         */
0105:        public class WebProjectValidation extends JellyTestCase {
0106:            protected static ProjectHelper phelper = new ProjectHelper() {
0107:                public Node getSourceNode() {
0108:                    return new SourcePackagesNode(PROJECT_NAME);
0109:                }
0110:            };
0111:            // location of sample project (parent of PROJECT_FOLDER)
0112:            protected static final String PROJECT_LOCATION = System
0113:                    .getProperty("xtest.data");
0114:            // name of sample project
0115:            protected static String PROJECT_NAME = "SampleProject"; // NOI18N
0116:            // foloder of sample project
0117:            protected static String PROJECT_FOLDER = PROJECT_LOCATION
0118:                    + File.separator + PROJECT_NAME;
0119:            protected TestURLDisplayer urlDisplayer;
0120:            private static final String BUILD_SUCCESSFUL = "BUILD SUCCESSFUL";
0121:            private ServerInstance server;
0122:            protected static int logIdx = 0;
0123:
0124:            /** Need to be defined because of JUnit */
0125:            public WebProjectValidation(String name) {
0126:                super (name);
0127:            }
0128:
0129:            public static NbTestSuite suite() {
0130:                NbTestSuite suite = new NbTestSuite();
0131:                suite.addTest(new WebProjectValidation("testPreconditions"));
0132:                suite.addTest(new WebProjectValidation("testNewWebProject"));
0133:                //suite.addTest(new WebProjectValidation("testRegisterTomcat"));
0134:                suite.addTest(new WebProjectValidation("testNewJSP"));
0135:                suite.addTest(new WebProjectValidation("testNewJSP2"));
0136:                suite.addTest(new WebProjectValidation("testJSPNavigator"));
0137:                suite.addTest(new WebProjectValidation("testNewServlet"));
0138:                suite.addTest(new WebProjectValidation("testNewServlet2"));
0139:                suite.addTest(new WebProjectValidation("testBuildProject"));
0140:                suite.addTest(new WebProjectValidation("testCompileAllJSP"));
0141:                suite.addTest(new WebProjectValidation("testCompileJSP"));
0142:                suite.addTest(new WebProjectValidation("testCleanProject"));
0143:                suite.addTest(new WebProjectValidation("testRunProject"));
0144:                suite.addTest(new WebProjectValidation("testRunJSP"));
0145:                suite.addTest(new WebProjectValidation("testViewServlet"));
0146:                suite.addTest(new WebProjectValidation("testRunServlet"));
0147:                suite.addTest(new WebProjectValidation("testCreateTLD"));
0148:                suite.addTest(new WebProjectValidation("testCreateTagHandler"));
0149:                suite.addTest(new WebProjectValidation("testRunTag"));
0150:                suite.addTest(new WebProjectValidation("testNewHTML"));
0151:                suite.addTest(new WebProjectValidation("testHTMLNavigator"));
0152:                suite.addTest(new WebProjectValidation("testRunHTML"));
0153:                suite.addTest(new WebProjectValidation("testNewSegment"));
0154:                suite.addTest(new WebProjectValidation("testNewDocument"));
0155:                suite.addTest(new WebProjectValidation("testStopServer"));
0156:                suite.addTest(new WebProjectValidation("testStartServer"));
0157:                suite.addTest(new WebProjectValidation("testBrowserSettings"));
0158:                suite.addTest(new WebProjectValidation("testFinish"));
0159:                return suite;
0160:            }
0161:
0162:            /** Use for execution inside IDE */
0163:            public static void main(java.lang.String[] args) {
0164:                // run whole suite
0165:                //junit.textui.TestRunner.run(suite());
0166:                //WebProjectValidation val = new WebProjectValidation("test");
0167:                //val.setUp();
0168:                //val.testStartServer();
0169:
0170:                // run only selected test case
0171:                //junit.textui.TestRunner.run(new MyModuleValidation("testT2"));
0172:            }
0173:
0174:            @Override
0175:            public void setUp() {
0176:                System.out.println("########  " + getName() + "  #######");
0177:                JemmyProperties.setCurrentTimeout(
0178:                        "ComponentOperator.WaitComponentTimeout", 180000);
0179:                JemmyProperties.setCurrentTimeout(
0180:                        "FrameWaiter.WaitFrameTimeout", 180000);
0181:                JemmyProperties.setCurrentTimeout(
0182:                        "DialogWaiter.WaitDialogTimeout", 180000);
0183:                server = ServerInstance.getDefault();
0184:
0185:                // extend Tomcat running check timeout
0186:                //        TomcatManager tomcatManager = getTomcatManager();
0187:                //        tomcatManager.getInstanceProperties().setProperty(
0188:                //                TomcatProperties.PROP_RUNNING_CHECK_TIMEOUT, "8000");
0189:            }
0190:
0191:            @Override
0192:            public void tearDown() {
0193:                logAndCloseOutputs();
0194:            }
0195:
0196:            public void testRegisterTomcat() {
0197:                // register Tomcat
0198:                String tomcatHome = System.getProperty("tomcat.home");
0199:                try {
0200:                    InstanceProperties.createInstanceProperties(
0201:                            "tomcat55:home=" + tomcatHome + ":base="
0202:                                    + tomcatHome, "tomcat", "tomcat",
0203:                            "Testing Tomcat");
0204:                } catch (InstanceCreationException ice) {
0205:                    fail(ice);
0206:                }
0207:                J2eeServerNode.invoke("Testing Tomcat");
0208:                RuntimeTabOperator.invoke();
0209:                sleep(30000);
0210:
0211:            }
0212:
0213:            /** checks if the Server ports are not used */
0214:            public void testPreconditions() throws Exception {
0215:                URLConnection connection = server.getServerURL()
0216:                        .openConnection();
0217:                try {
0218:                    connection.connect();
0219:                    fail("Port: " + server.getServerURL()
0220:                            + " is used by different server.");
0221:                } catch (ConnectException e) {
0222:                }
0223:                URL url = new URL("http://localhost:8025");
0224:                connection = url.openConnection();
0225:                try {
0226:                    connection.connect();
0227:                    fail("Connection to http://localhost:8025 established, but tomcat should not be running.");
0228:                } catch (ConnectException e) {
0229:                }
0230:            }
0231:
0232:            /** Test creation of web project.
0233:             * - open New Project wizard from main menu (File|New Project)
0234:             * - select Web|Web Application
0235:             * - in the next panel type project name and project location
0236:             * - finish the wizard
0237:             * - wait until scanning of java files is finished
0238:             * - check index.jsp is opened
0239:             */
0240:            public void testNewWebProject() throws IOException {
0241:                installJemmyQueue();
0242:                NewProjectWizardOperator projectWizard = NewProjectWizardOperator
0243:                        .invoke();
0244:                String category = Bundle.getStringTrimmed(
0245:                        "org.netbeans.modules.web.core.Bundle",
0246:                        "Templates/JSP_Servlet");
0247:                projectWizard.selectCategory(category);
0248:                projectWizard.next();
0249:                NewWebProjectNameLocationStepOperator nameStep = new NewWebProjectNameLocationStepOperator();
0250:                nameStep.txtProjectName().setText("");
0251:                nameStep.txtProjectName().typeText(PROJECT_NAME);
0252:                nameStep.txtProjectLocation().setText("");
0253:                nameStep.txtProjectLocation().typeText(PROJECT_LOCATION);
0254:                nameStep.finish();
0255:                Timeouts timeouts = nameStep.getTimeouts().cloneThis();
0256:                nameStep.getTimeouts().setTimeout(
0257:                        "ComponentOperator.WaitStateTimeout", 60000);
0258:                nameStep.waitClosed();
0259:                nameStep.setTimeouts(timeouts);
0260:                // wait for project creation
0261:                sleep(5000);
0262:                ProjectSupport.waitScanFinished();
0263:                EditorWindowOperator.getEditor("index.jsp");//NOI18N
0264:                ProjectSupport.waitScanFinished();
0265:                // XXX HACK
0266:                WebPagesNode webPages = new WebPagesNode(PROJECT_NAME);
0267:                new Node(webPages, "index.jsp");//NOI18N
0268:                new Node(webPages, "WEB-INF|web.xml");//NOI18N
0269:                new Node(webPages, "META-INF|context.xml");//NOI18N
0270:                ref(Util.dumpProjectView(PROJECT_NAME));
0271:                compareReferenceFiles();
0272:            }
0273:
0274:            /** Test new JSP wizard.
0275:             * - open New File wizard from main menu (File|New File)
0276:             * - select sample project as target
0277:             * - select Web|JSP file type
0278:             * - in the next panel type name
0279:             * - finish the wizard
0280:             * - check file is open in editor and close all opened documents
0281:             */
0282:            public void testNewJSP() throws IOException {
0283:                // XXX workaround due to issue #46073
0284:                new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME)
0285:                        .select();
0286:                NewJspFileNameStepOperator nameStep = NewJspFileNameStepOperator
0287:                        .invoke();
0288:                nameStep.setJSPFileName("page1");
0289:                nameStep.finish();
0290:                // check class is opened in Editor and then close it
0291:                EditorOperator jsp1Editor = new EditorOperator("page1.jsp");
0292:                jsp1Editor.save();
0293:                jsp1Editor.close();
0294:                //new EditorOperator("page1.jsp").close();
0295:                ref(Util.dumpProjectView(PROJECT_NAME));
0296:                //compareReferenceFiles();
0297:            }
0298:
0299:            /** Test new JSP wizard.
0300:             * - open New File wizard from context menu on Web Pages (New|File)
0301:             * - select JSP file type
0302:             * - in the next panel type name in
0303:             * - finish the wizard
0304:             * - check file is open in editor and close all opened documents
0305:             */
0306:            public void testNewJSP2() throws IOException {
0307:                Node webPages = new WebPagesNode(PROJECT_NAME);
0308:                // create new .jsp
0309:                new ActionNoBlock(null, "New|JSP").perform(webPages);
0310:                NewJspFileNameStepOperator nameStep = new NewJspFileNameStepOperator();
0311:                nameStep.setJSPFileName("page2");
0312:                nameStep.finish();
0313:                // check class is opened in Editor and then close the  document
0314:                new EditorOperator("page2.jsp").close();
0315:                ref(Util.dumpProjectView(PROJECT_NAME));
0316:                //compareReferenceFiles();
0317:                //compareDD();
0318:            }
0319:
0320:            /** Test new servlet wizard.
0321:             * - open New File wizard from main menu (File|New File)
0322:             * - select sample project as target
0323:             * - select Web|Servlet file type
0324:             * - in the next panel type name
0325:             * - finish the wizard
0326:             * - check file is open in editor and close it
0327:             */
0328:            public void testNewServlet() throws IOException {
0329:                // create a new package
0330:                new ActionNoBlock("File|New File", null).perform();
0331:                // WORKAROUND
0332:                new EventTool().waitNoEvent(1000);
0333:                WizardOperator newFileWizard = new WizardOperator("New File");
0334:                new JComboBoxOperator(newFileWizard).selectItem(PROJECT_NAME);
0335:                new Node(new JTreeOperator(newFileWizard), "Web").select();
0336:                new JListOperator(newFileWizard, 1).selectItem("Servlet");
0337:                newFileWizard.next();
0338:                JTextFieldOperator txtPackageName = new JTextFieldOperator(
0339:                        newFileWizard);
0340:                // clear text field
0341:                txtPackageName.setText("");
0342:                txtPackageName.typeText("Servlet1");
0343:                JComboBoxOperator txtPackage = new JComboBoxOperator(
0344:                        newFileWizard, 1);
0345:                // clear text field
0346:                txtPackage.clearText();
0347:                txtPackage.typeText("test1");
0348:                newFileWizard.next();
0349:                newFileWizard.finish();
0350:                // check class is opened in Editor and close it
0351:                new EditorOperator("Servlet1.java").close();
0352:                // check the servlet is specified in web.xml
0353:                WebPagesNode webPages = new WebPagesNode(PROJECT_NAME);
0354:                webPages.setComparator(new Operator.DefaultStringComparator(
0355:                        true, true));
0356:                Node webXml = new Node(webPages, "WEB-INF|web.xml");
0357:                new EditAction().performPopup(webXml);
0358:                String xmlText = new EditorOperator("web.xml").getText();
0359:                new EditorOperator("web.xml").closeAllDocuments();
0360:                String[] content = new String[] {
0361:                        "<servlet-name>Servlet1</servlet-name>",
0362:                        "<servlet-class>test1.Servlet1</servlet-class>",
0363:                        "<url-pattern>/Servlet1</url-pattern>" };
0364:                for (int i = 0; i < content.length; i++) {
0365:                    assertTrue("Servlet is not correctly specifeid in web.xml."
0366:                            + " Following line is missing in the web.xml:\n"
0367:                            + content[i], xmlText.indexOf(content[i]) != -1);
0368:                }
0369:                ref(Util.dumpProjectView(PROJECT_NAME));
0370:                //compareReferenceFiles();
0371:                //compareDD();
0372:            }
0373:
0374:            /** Test new Servlet wizard.
0375:             * - open New File wizard from main menu (File|New File)
0376:             * - select sample project as target
0377:             * - select Java|Package file type
0378:             * - in the next panel type package name in
0379:             * - finish the wizard
0380:             * - open New File wizard from context menu on created package node (New|File)
0381:             * - select Web|Servlet file type
0382:             * - in the next panel type class name in
0383:             * - finish the wizard
0384:             * - check class is open in editor and close it
0385:             */
0386:            public void testNewServlet2() throws IOException {
0387:                createJavaPackage(PROJECT_NAME, "test2");
0388:                Node sample1Node = new Node(phelper.getSourceNode(), "test2");
0389:                // create a new class
0390:                new ActionNoBlock(null, "New|Servlet").perform(sample1Node);
0391:                WizardOperator newFileWizard = new WizardOperator("New Servlet");
0392:                new JTextFieldOperator(newFileWizard).typeText("Servlet2");
0393:                newFileWizard.next();
0394:                new JTextFieldOperator(newFileWizard, 1).setText("");
0395:                new JTextFieldOperator(newFileWizard, 1)
0396:                        .typeText("Servlet2Name");
0397:                new JTextFieldOperator(newFileWizard, 2).setText("");
0398:                new JTextFieldOperator(newFileWizard, 2)
0399:                        .typeText("/Servlet2URL");
0400:                newFileWizard.finish();
0401:                // check class is opened in Editor and then close it
0402:                new EditorOperator("Servlet2.java").close();
0403:                ref(Util.dumpProjectView(PROJECT_NAME));
0404:                sleep(1000);
0405:                //compareReferenceFiles();
0406:                //compareDD();
0407:            }
0408:
0409:            // TODO workaround for defective:
0410:            // NewFileWizardOperator.create(PROJECT_NAME, "Java", "Java Package", null, "test2");
0411:            // Should be fixed in jemmy/jelly
0412:            private void createJavaPackage(String projectName, String pkgName) {
0413:                String wizardTitle = Bundle.getString(
0414:                        "org.netbeans.modules.project.ui.Bundle",
0415:                        "LBL_NewFileWizard_Title");
0416:                NewFileWizardOperator nfwo = NewFileWizardOperator
0417:                        .invoke(wizardTitle);
0418:                nfwo.selectProject(projectName);
0419:                nfwo.setComparator(new Operator.DefaultStringComparator(true,
0420:                        true));
0421:                nfwo.selectCategory("Java");
0422:                nfwo.selectFileType("Java Package");
0423:                nfwo.next();
0424:                NewFileNameLocationStepOperator nfnlso = new NewFileNameLocationStepOperator();
0425:                nfnlso.setObjectName(pkgName);
0426:                nfnlso.finish();
0427:            }
0428:
0429:            public void testBuildProject() {
0430:                Node rootNode = new ProjectsTabOperator()
0431:                        .getProjectRootNode(PROJECT_NAME);
0432:                Util.cleanStatusBar();
0433:                new BuildProjectAction().perform(rootNode);
0434:                MainWindowOperator.getDefault().waitStatusText(
0435:                        "Finished building");
0436:                ref(Util.dumpFiles(new File(PROJECT_FOLDER)));
0437:                //compareReferenceFiles();
0438:            }
0439:
0440:            public void testCompileAllJSP() {
0441:                Node rootNode = new ProjectsTabOperator()
0442:                        .getProjectRootNode(PROJECT_NAME);
0443:                new PropertiesAction().perform(rootNode);
0444:                NbDialogOperator properties = new NbDialogOperator(
0445:                        "Project Properties");
0446:                new Node(new JTreeOperator(properties), "Build|Compiling")
0447:                        .select();
0448:                new JCheckBoxOperator(properties, 2).changeSelection(true);
0449:                properties.ok();
0450:
0451:                testCleanProject();
0452:                logAndCloseOutputs();
0453:                testBuildProject();
0454:                logAndCloseOutputs();
0455:                testCleanProject();
0456:                logAndCloseOutputs();
0457:
0458:                new Action(null, "Properties").perform(rootNode);
0459:                properties = new NbDialogOperator("Project Properties");
0460:                new Node(new JTreeOperator(properties), "Build|Compiling")
0461:                        .select();
0462:                new JCheckBoxOperator(properties, 2).changeSelection(false);
0463:                properties.ok();
0464:            }
0465:
0466:            public void testCompileJSP() {
0467:                Node rootNode = new ProjectsTabOperator()
0468:                        .getProjectRootNode(PROJECT_NAME);
0469:                Node jspNode = new Node(rootNode, "Web Pages|page2.jsp");
0470:                Util.cleanStatusBar();
0471:                new Action(null, "Compile File").perform(jspNode);
0472:                MainWindowOperator.getDefault().waitStatusText(
0473:                        "Finished building");
0474:                ref(Util.dumpFiles(new File(PROJECT_FOLDER)));
0475:                //compareReferenceFiles();
0476:            }
0477:
0478:            public void testCleanProject() {
0479:                Node rootNode = new ProjectsTabOperator()
0480:                        .getProjectRootNode(PROJECT_NAME);
0481:                Action clean = new Action(null, "Clean");
0482:                // can clash with 'Clean and Build' action
0483:                clean.setComparator(new Operator.DefaultStringComparator(true,
0484:                        true));
0485:                Util.cleanStatusBar();
0486:                clean.perform(rootNode);
0487:                MainWindowOperator.getDefault().waitStatusText(
0488:                        "Finished building");
0489:                ref(Util.dumpFiles(new File(PROJECT_FOLDER)));
0490:                //compareReferenceFiles();
0491:            }
0492:
0493:            public void testRunProject() throws Exception {
0494:                initDisplayer();
0495:                Node rootNode = new ProjectsTabOperator()
0496:                        .getProjectRootNode(PROJECT_NAME);
0497:                new Node(rootNode, "Web Pages|index.jsp")
0498:                        .performPopupAction("Open");
0499:                EditorOperator editor = new EditorOperator("index.jsp");
0500:                editor.replace("<title>JSP Page</title>",
0501:                        "<title>SampleProject Index Page</title>");
0502:                editor.insert("Running Project\n", 12, 1);
0503:                new Action(null, "Run").perform(rootNode);
0504:                waitBuildSuccessful();
0505:                assertDisplayerContent("<title>SampleProject Index Page</title>");
0506:                editor.deleteLine(12);
0507:                editor.save();
0508:                editor.closeDiscardAll();
0509:            }
0510:
0511:            public void testRunJSP() {
0512:                initDisplayer();
0513:                Node rootNode = new ProjectsTabOperator()
0514:                        .getProjectRootNode(PROJECT_NAME);
0515:                new Node(rootNode, "Web Pages|page2.jsp")
0516:                        .performPopupAction("Open");
0517:                EditorOperator editor = new EditorOperator("page2.jsp");
0518:                //editor.replace("<title>JSP Page/title>", "<title>Page 2</title>");
0519:                editor.deleteLine(14);
0520:                editor.insert("<title>Page 2</title>\n", 14, 1);
0521:                editor.insert("Running JSP\n", 12, 1);
0522:                sleep(2000);
0523:                editor.save();
0524:                new Action("Run|Run File|Run \"page2.jsp\"", null).perform();
0525:                waitBuildSuccessful();
0526:                assertDisplayerContent("<title>Page 2</title>");
0527:                editor.deleteLine(12);
0528:                editor.save();
0529:                editor.close();
0530:            }
0531:
0532:            public void testViewServlet() throws IOException {
0533:                initDisplayer();
0534:                String jspCode = "new String().toString();";
0535:                String runningViewServlet = "Running View Servlet";
0536:                String newTitle = "<h1>View Page</h1>";
0537:                Node rootNode = new ProjectsTabOperator()
0538:                        .getProjectRootNode(PROJECT_NAME);
0539:                new Node(rootNode, "Web Pages|page2.jsp")
0540:                        .performPopupAction("Open");
0541:                EditorOperator editor = new EditorOperator("page2.jsp");
0542:                editor.insert(newTitle + "\n", 13, 6);
0543:                editor.insert(runningViewServlet + "\n", 14, 1);
0544:                editor.insert("<% " + jspCode + " %>\n", 19, 9);
0545:                sleep(5000);
0546:                PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()
0547:                        + File.separator + "screen1.png");
0548:                editor.saveDocument();
0549:                new Action("Run|Run File|Run \"page2.jsp\"", null).perform();
0550:                waitBuildSuccessful();
0551:                assertDisplayerContent("<title>Page 2</title>");
0552:                new Node(rootNode, "Web Pages|page2.jsp")
0553:                        .performPopupAction("View Servlet");
0554:                EditorOperator servlet = new EditorOperator("page2_jsp.java");
0555:                assertNotNull("SERVLET CONTEXT SHOULD BE SHOWN", servlet);
0556:                String text = "file: page2_jsp.java\n" + servlet.getText();
0557:                for (String str : new String[] { "<h1>", runningViewServlet,
0558:                        "JspWriter out", jspCode }) {
0559:                    assertContains(text, str);
0560:                }
0561:                editor.deleteLine(12);
0562:                editor.deleteLine(13);
0563:                editor.deleteLine(19);
0564:                sleep(5000);
0565:                editor.save();
0566:                PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()
0567:                        + File.separator + "screen2.png");
0568:                editor.close();
0569:                servlet.close();
0570:            }
0571:
0572:            public void testRunServlet() {
0573:                initDisplayer();
0574:                Node sourceNode = phelper.getSourceNode();
0575:                new Node(sourceNode, "test1|Servlet1.java")
0576:                        .performPopupAction("Open");
0577:                EditorOperator editor = new EditorOperator("Servlet1.java");
0578:                String expected = "response.setContentType(\"text/html;charset=UTF-8\");";
0579:                assertTrue("Servlet1.java should contain " + expected, editor
0580:                        .contains(expected));
0581:                editor.replace("/* TODO output your page here", "");
0582:                editor.replace("            */", "");
0583:                editor
0584:                        .replace(
0585:                                "out.println(\"<title>Servlet Servlet1</title>\");",
0586:                                "out.println(\"<title>Servlet with name=\"+request.getParameter(\"name\")+\"</title>\");");
0587:                new ActionNoBlock("Run|Run File|Run \"Servlet1.java\"", null)
0588:                        .perform();
0589:                NbDialogOperator dialog = new NbDialogOperator(
0590:                        "Set Servlet Execution Uri");
0591:                JComboBoxOperator combo = new JComboBoxOperator(dialog);
0592:                combo.setSelectedItem(combo.getSelectedItem()
0593:                        + "?name=Servlet1");
0594:                dialog.ok();
0595:                //waitBuildSuccessful();
0596:                editor.close();
0597:                assertDisplayerContent("<title>Servlet with name=Servlet1</title>");
0598:            }
0599:
0600:            public void testCreateTLD() {
0601:                //HACK
0602:                new Node(new ProjectsTabOperator()
0603:                        .getProjectRootNode(PROJECT_NAME), "Web Pages|WEB-INF")
0604:                        .expand();
0605:
0606:                // workaround due to issue #46073
0607:                new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME)
0608:                        .select();
0609:
0610:                new ActionNoBlock("File|New File", null).perform();
0611:                // WORKAROUND
0612:                new EventTool().waitNoEvent(1000);
0613:                WizardOperator newFileWizard = new WizardOperator("New File");
0614:                new JComboBoxOperator(newFileWizard).selectItem(PROJECT_NAME);
0615:                new Node(new JTreeOperator(newFileWizard), "Web").select();
0616:                new JListOperator(newFileWizard, 1)
0617:                        .selectItem("Tag Library Descriptor");
0618:                newFileWizard.next();
0619:                JTextFieldOperator txtName = new JTextFieldOperator(
0620:                        newFileWizard);
0621:                // clear text field
0622:                txtName.setText("");
0623:                txtName.typeText("MyTags");
0624:                newFileWizard.finish();
0625:                //XXX try { Thread.currentThread().sleep(5000); } catch (InterruptedException e) {}
0626:                //XXX HACK #48865
0627:                new Node(new ProjectsTabOperator()
0628:                        .getProjectRootNode(PROJECT_NAME),
0629:                        "Web Pages|WEB-INF|tlds|MyTags.tld");
0630:                // check class is opened in Editor and then close it
0631:                new EditorOperator("MyTags.tld").close();
0632:                ref(Util.dumpProjectView(PROJECT_NAME));
0633:                //compareReferenceFiles();
0634:            }
0635:
0636:            public void testCreateTagHandler() {
0637:                // workaround due to issue #46073
0638:                new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME)
0639:                        .select();
0640:
0641:                new ActionNoBlock("File|New File", null).perform();
0642:                // WORKAROUND
0643:                new EventTool().waitNoEvent(1000);
0644:                WizardOperator newFileWizard = new WizardOperator("New File");
0645:                new JComboBoxOperator(newFileWizard).selectItem(PROJECT_NAME);
0646:                new Node(new JTreeOperator(newFileWizard), "Web").select();
0647:                new JListOperator(newFileWizard, 1).selectItem("Tag Handler");
0648:                newFileWizard.next();
0649:                JTextFieldOperator txtName = new JTextFieldOperator(
0650:                        newFileWizard);
0651:                // clear text field
0652:                txtName.setText("");
0653:                txtName.typeText("MyTag");
0654:                JComboBoxOperator pkg = new JComboBoxOperator(newFileWizard, 1);
0655:                pkg.clearText();
0656:                pkg.typeText("tags");
0657:                newFileWizard.next();
0658:                new JButtonOperator(newFileWizard).push();
0659:                NbDialogOperator dialog = new NbDialogOperator("Browse Files");
0660:                new Node(new JTreeOperator(dialog),
0661:                        "Web Pages|WEB-INF|tlds|MyTags.tld").select();
0662:                new JButtonOperator(dialog, "Select File").push();
0663:                newFileWizard.finish();
0664:                // HACK
0665:                new Node(phelper.getSourceNode(), "tags|MyTag.java");
0666:                // check class is opened in Editor and then close it
0667:                EditorOperator editor = new EditorOperator("MyTag.java");
0668:                editor.replace("// out.println(\"    </blockquote>\");",
0669:                        getTagHandlerCode());
0670:                editor.saveDocument();
0671:                editor.close();
0672:                ref(Util.dumpProjectView(PROJECT_NAME));
0673:                //compareReferenceFiles();
0674:            }
0675:
0676:            protected String getTagHandlerCode() {
0677:                return "out.print(\"TagOutput\"); \n";
0678:            }
0679:
0680:            public void testRunTag() throws Throwable {
0681:                initDisplayer();
0682:                Node rootNode = new ProjectsTabOperator()
0683:                        .getProjectRootNode(PROJECT_NAME);
0684:                Node jspNode = new Node(rootNode, "Web Pages|page2.jsp");
0685:                jspNode.performPopupAction("Open");
0686:                EditorOperator editor = new EditorOperator("page2.jsp");
0687:                editor.replace("<title>Page 2</title>",
0688:                        "<title><my:MyTag/></title>");
0689:                editor
0690:                        .insert(
0691:                                "<%@taglib prefix=\"my\" uri=\"/WEB-INF/tlds/MyTags\"%>\n",
0692:                                6, 1);
0693:                sleep(5000);
0694:                editor.save();
0695:                new Action(null, "Run File").perform(jspNode);
0696:                waitBuildSuccessful();
0697:                editor.close();
0698:                assertDisplayerContent("<title>TagOutput</title>");
0699:            }
0700:
0701:            public void testNewHTML() throws IOException {
0702:                // workaround due to issue #46073
0703:                new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME)
0704:                        .select();
0705:
0706:                new ActionNoBlock("File|New File", null).perform();
0707:                // WORKAROUND
0708:                new EventTool().waitNoEvent(1000);
0709:                WizardOperator newFileWizard = new WizardOperator("New File");
0710:                new JComboBoxOperator(newFileWizard).selectItem(PROJECT_NAME);
0711:                new Node(new JTreeOperator(newFileWizard), "Web").select();
0712:                JListOperator fileTypeList = new JListOperator(newFileWizard, 1);
0713:                fileTypeList
0714:                        .setComparator(new Operator.DefaultStringComparator(
0715:                                true, true));
0716:                fileTypeList.selectItem("HTML");
0717:                newFileWizard.next();
0718:                JTextFieldOperator txtPackageName = new JTextFieldOperator(
0719:                        newFileWizard);
0720:                // clear text field
0721:                txtPackageName.setText("");
0722:                txtPackageName.typeText("HTML");
0723:                newFileWizard.finish();
0724:                // check class is opened in Editor and then close it
0725:                new EditorOperator("HTML.html").close();
0726:                ref(Util.dumpProjectView(PROJECT_NAME));
0727:                new Node(new ProjectsTabOperator()
0728:                        .getProjectRootNode(PROJECT_NAME),
0729:                        "Web Pages|HTML.html");
0730:                //compareReferenceFiles();
0731:                //compareDD();
0732:            }
0733:
0734:            public void testHTMLNavigator() throws Exception {
0735:                String fileName = "navigatorHTML.html";
0736:                open(fileName);
0737:                EditorOperator eop = new EditorOperator(fileName);
0738:                String htmlText = new EditorOperator(fileName).getText();
0739:                int caretPosition = verifyNavigator(eop);
0740:                assertEquals("NAVIGATION TARGET", 144, caretPosition);
0741:                openFromProject("HTML.html", htmlText);
0742:                caretPosition = verifyNavigator(new EditorOperator("HTML.html"));
0743:                assertEquals("NAVIGATION TARGET", 144, caretPosition);
0744:                EditorOperator.closeDiscardAll();
0745:            }
0746:
0747:            public void testJSPNavigator() throws Exception {
0748:                String fileName = "navigatorJSP.jsp";
0749:                open(fileName);
0750:                EditorOperator eop = new EditorOperator(fileName);
0751:                String jspText = eop.getText();
0752:                int caretPosition = verifyNavigator(eop);
0753:                assertEquals("NAVIGATION TARGET", 325, caretPosition);
0754:                openFromProject("page2.jsp", jspText);
0755:                caretPosition = verifyNavigator(new EditorOperator("page2.jsp"));
0756:                assertEquals("NAVIGATION TARGET", 325, caretPosition);
0757:                EditorOperator.closeDiscardAll();
0758:            }
0759:
0760:            private void open(String fileName) throws Exception {
0761:                DataObject dataObj = DataObject.find(FileUtil
0762:                        .toFileObject(new File(getDataDir(), fileName)));
0763:                EditorCookie ed = dataObj.getCookie(EditorCookie.class);
0764:                ed.open();
0765:            }
0766:
0767:            private void openFromProject(String fileName, String text)
0768:                    throws Exception {
0769:                Node rootNode = new ProjectsTabOperator()
0770:                        .getProjectRootNode(PROJECT_NAME);
0771:                new Node(rootNode, "Web Pages|" + fileName)
0772:                        .performPopupAction("Open");
0773:                EditorOperator eop = new EditorOperator(fileName);
0774:                eop.delete(0, eop.getText().length());
0775:                eop.insert(text);
0776:            }
0777:
0778:            private int verifyNavigator(EditorOperator eOperator)
0779:                    throws Exception {
0780:                eOperator
0781:                        .insert(
0782:                                "<h1>JSP Page</h1>\n<table border=\"1\">\n <tr> \n<td></td> \n  <td></td>\n</tr> \n"
0783:                                        + "<tr>\n<td></td>\n<td></td>\n</tr>\n</table>\n",
0784:                                10, 5);
0785:                eOperator.save();
0786:                //refresh navigator
0787:                Node rootNode = new ProjectsTabOperator()
0788:                        .getProjectRootNode(PROJECT_NAME);
0789:                new Node(rootNode, "Web Pages|index.jsp")
0790:                        .performPopupAction("Open");
0791:                new EditorOperator("index.jsp").closeDiscard();
0792:                //wait for editor update
0793:                Thread.sleep(1000);
0794:                int startCaretPos = eOperator.txtEditorPane()
0795:                        .getCaretPosition();
0796:                NavigatorOperator navigatorOperator = NavigatorOperator
0797:                        .invokeNavigator();
0798:                assertNotNull(navigatorOperator);
0799:                JTreeOperator treeOperator = navigatorOperator.getTree();
0800:                Object root = treeOperator.getRoot();
0801:                assertNotNull(root);
0802:                assertEquals(1, treeOperator.getChildCount(root));
0803:                Object htmlChild = treeOperator.getChild(root, 0);//HTML
0804:                assertNotNull(htmlChild);
0805:                assertEquals(2, treeOperator.getChildCount(htmlChild));// HEAD, BODY
0806:                Object bodyChild = treeOperator.getChild(htmlChild, 1);
0807:                assertEquals(2, treeOperator.getChildCount(bodyChild));// H1, TABLE
0808:                Object tableChild = treeOperator.getChild(bodyChild, 1);
0809:                assertEquals(2, treeOperator.getChildCount(tableChild));// 2 rows
0810:                Object[] pathObjects = { root, htmlChild, bodyChild, tableChild };
0811:                TreePath path = new TreePath(pathObjects);
0812:                treeOperator.clickOnPath(path, 2);
0813:                // wait for editor update
0814:                Thread.sleep(1000);
0815:                int finalCaretPossition = eOperator.txtEditorPane()
0816:                        .getCaretPosition();
0817:                assertFalse("move in document",
0818:                        finalCaretPossition == startCaretPos);
0819:                return finalCaretPossition;
0820:            }
0821:
0822:            public void testRunHTML() {
0823:                initDisplayer();
0824:                Node rootNode = new ProjectsTabOperator()
0825:                        .getProjectRootNode(PROJECT_NAME);
0826:                new Node(rootNode, "Web Pages|HTML.html")
0827:                        .performPopupAction("Open");
0828:                new EditorOperator("HTML.html").replace("<title></title>",
0829:                        "<title>HTML Page</title>");
0830:                new Action("Run|Run File|Run \"HTML.html\"", null).perform();
0831:                //waitBuildSuccessful();
0832:                new EditorOperator("HTML.html").close();
0833:                assertDisplayerContent("<title>HTML Page</title>");
0834:            }
0835:
0836:            public void testNewSegment() throws IOException {
0837:                Node sample1Node = new Node(new ProjectsTabOperator()
0838:                        .getProjectRootNode(PROJECT_NAME), "Web Pages");
0839:                // create a new class
0840:                new ActionNoBlock(null, "New|JSP").perform(sample1Node);
0841:                // WORKAROUND
0842:                new EventTool().waitNoEvent(1000);
0843:                WizardOperator newFileWizard = new WizardOperator(
0844:                        "New JSP File");
0845:                new JTextFieldOperator(newFileWizard).typeText("segment");
0846:                new JCheckBoxOperator(newFileWizard).changeSelection(true);
0847:                newFileWizard.finish();
0848:                // check class is opened in Editor and then close all documents
0849:                new EditorOperator("segment.jspf").close();
0850:                ref(Util.dumpProjectView(PROJECT_NAME));
0851:                new Node(new ProjectsTabOperator()
0852:                        .getProjectRootNode(PROJECT_NAME),
0853:                        "Web Pages|segment.jspf");
0854:                //compareReferenceFiles();
0855:                //compareDD();
0856:            }
0857:
0858:            public void testNewDocument() throws IOException {
0859:                Node sample1Node = new Node(new ProjectsTabOperator()
0860:                        .getProjectRootNode(PROJECT_NAME), "Web Pages");
0861:                // create a new class
0862:                new ActionNoBlock(null, "New|JSP").perform(sample1Node);
0863:                // WORKAROUND
0864:                new EventTool().waitNoEvent(1000);
0865:                WizardOperator newFileWizard = new WizardOperator(
0866:                        "New JSP File");
0867:                new JTextFieldOperator(newFileWizard).typeText("document");
0868:                new JRadioButtonOperator(newFileWizard, 1)
0869:                        .changeSelection(true);
0870:                newFileWizard.finish();
0871:                // check class is opened in Editor and then close all documents
0872:                new EditorOperator("document.jspx").close();
0873:                ref(Util.dumpProjectView(PROJECT_NAME));
0874:                new Node(new ProjectsTabOperator()
0875:                        .getProjectRootNode(PROJECT_NAME),
0876:                        "Web Pages|document.jspx");
0877:                //compareReferenceFiles();
0878:                //compareDD();
0879:            }
0880:
0881:            public void testStopServer() throws Exception {
0882:                server.stop();
0883:                //try { Thread.currentThread().sleep(5000); } catch (InterruptedException e) {}
0884:                URL url = server.getServerURL();
0885:                URLConnection connection = url.openConnection();
0886:                try {
0887:                    connection.connect();
0888:                    fail("Connection to: " + url
0889:                            + " established, but the server"
0890:                            + " should not be running.");
0891:                } catch (ConnectException e) {
0892:                }
0893:            }
0894:
0895:            public void testStartServer() throws Exception {
0896:                server.start();
0897:                URL url = server.getServerURL();
0898:                URLConnection connection = url.openConnection();
0899:                connection.connect();
0900:            }
0901:
0902:            public void testBrowserSettings() {
0903:                OptionsOperator optionsOper = OptionsOperator.invoke();
0904:                optionsOper.selectGeneral();
0905:                // "Web Browser:"
0906:                String webBrowserLabel = Bundle.getStringTrimmed(
0907:                        "org.netbeans.core.ui.options.general.Bundle",
0908:                        "CTL_Web_Browser");
0909:                JLabelOperator jloWebBrowser = new JLabelOperator(optionsOper,
0910:                        webBrowserLabel);
0911:                JComboBoxOperator combo = new JComboBoxOperator(
0912:                        (JComboBox) jloWebBrowser.getLabelFor());
0913:                for (int i = 0; i < combo.getItemCount(); i++) {
0914:                    String item = combo.getItemAt(i).toString();
0915:                    log("Browser: " + item);
0916:                    if (!item.equals("<Default System Browser>")
0917:                            && !item.equals("Mozilla")
0918:                            && !item.equals("Netscape")
0919:                            && !item.equals("Swing HTML Browser")
0920:                            && !item.equals("Internet Explorer")
0921:                            && !item.equals("Firefox")
0922:                            && !item.equals("External Browser (command-line)"))
0923:                        fail("Unrecognized settings in Web Browser Options");
0924:                }
0925:                optionsOper.close();
0926:            }
0927:
0928:            public void testFinish() {
0929:                server.stop();
0930:                ProjectSupport.closeProject(PROJECT_NAME);
0931:            }
0932:
0933:            //********************************************************
0934:
0935:            protected void sleep(int milis) {
0936:                try {
0937:                    Thread.sleep(milis);
0938:                } catch (InterruptedException ex) {
0939:                    throw new JemmyException("Interrupted", ex);
0940:                }
0941:            }
0942:
0943:            private void logAndCloseOutputs() {
0944:                OutputTabOperator outputTab;
0945:                long timeout = JemmyProperties
0946:                        .getCurrentTimeout("ComponentOperator.WaitComponentTimeout");
0947:                JemmyProperties.setCurrentTimeout(
0948:                        "ComponentOperator.WaitComponentTimeout", 3000);
0949:                try {
0950:                    do {
0951:                        try {
0952:                            outputTab = new OutputTabOperator("");
0953:                        } catch (TimeoutExpiredException e) {
0954:                            // probably no more tabs so ignore it and continue
0955:                            break;
0956:                        }
0957:                        String logName = "Output" + logIdx++ + ".log";
0958:                        log(logName, outputTab.getName()
0959:                                + "\n-------------\n\n" + outputTab.getText());
0960:                        outputTab.close();
0961:                    } while (true);
0962:                } finally {
0963:                    JemmyProperties.setCurrentTimeout(
0964:                            "ComponentOperator.WaitComponentTimeout", timeout);
0965:                }
0966:            }
0967:
0968:            private void waitBuildSuccessful() {
0969:                OutputTabOperator console = new OutputTabOperator(PROJECT_NAME);
0970:                console.getTimeouts().setTimeout(
0971:                        "ComponentOperator.WaitStateTimeout", 180000);
0972:                console.waitText(BUILD_SUCCESSFUL);
0973:            }
0974:
0975:            private void initDisplayer() {
0976:                if (urlDisplayer == null) {
0977:                    urlDisplayer = TestURLDisplayer.getInstance();
0978:                }
0979:                urlDisplayer.invalidateURL();
0980:            }
0981:
0982:            private void assertDisplayerContent(String substr) {
0983:                try {
0984:                    urlDisplayer.waitURL();
0985:                } catch (InterruptedException ex) {
0986:                    throw new JemmyException("Waiting interrupted.", ex);
0987:                }
0988:                String page = urlDisplayer.readURL();
0989:                boolean contains = page.indexOf(substr) > -1;
0990:                if (!contains) {
0991:                    log("DUMP OF: " + urlDisplayer.getURL() + "\n");
0992:                    log(page);
0993:                }
0994:                assertTrue("The '" + urlDisplayer.getURL()
0995:                        + "' page does not contain '" + substr + "'", contains);
0996:            }
0997:
0998:            private void assertContains(String text, String value) {
0999:                assertTrue("Assertation failed, cannot find:\n" + value
1000:                        + "\nin the following text:\n" + text, text
1001:                        .contains(value));
1002:            }
1003:
1004:            protected void installJemmyQueue() {
1005:                try {
1006:                    SwingUtilities.invokeAndWait(new Runnable() {
1007:                        public void run() {
1008:                            QueueTool.installQueue();
1009:                        }
1010:                    });
1011:                } catch (Exception ex) {
1012:                    throw new JemmyException("Cannot install Jemmy Queue.", ex);
1013:                }
1014:            }
1015:
1016:            private static class ServerInstance {
1017:                private String host;
1018:                private int serverPort;
1019:                private String nodeName;
1020:                private String userName;
1021:                private String password;
1022:                private URL serverURL;
1023:                private static ServerInstance instance;
1024:
1025:                private ServerInstance() {
1026:                }
1027:
1028:                public static ServerInstance getDefault() {
1029:                    if (instance == null) {
1030:                        instance = new ServerInstance();
1031:                        instance.host = "localhost";
1032:                        instance.serverPort = 8084;
1033:                        instance.nodeName = "Tomcat";
1034:                        instance.userName = "tomcat";
1035:                        instance.password = "tomcat";
1036:                    }
1037:                    return instance;
1038:                }
1039:
1040:                public URL getServerURL() {
1041:                    if (serverURL == null) {
1042:                        try {
1043:                            serverURL = new URL("http", host, serverPort, "");
1044:                        } catch (MalformedURLException mue) {
1045:                            throw new JemmyException(
1046:                                    "Cannot create server URL.", mue);
1047:                        }
1048:                    }
1049:                    System.out.println("serverurl:" + serverURL);
1050:                    return serverURL;
1051:                }
1052:
1053:                public J2eeServerNode getServerNode() {
1054:                    return J2eeServerNode.invoke(nodeName);
1055:                }
1056:
1057:                public void stop() {
1058:                    getServerNode().stop();
1059:                }
1060:
1061:                public void start() {
1062:                    getServerNode().start();
1063:                }
1064:            }
1065:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.