1 19 20 package org.netbeans.test.web; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.net.ConnectException ; 25 import java.net.MalformedURLException ; 26 import java.net.URL ; 27 import java.net.URLConnection ; 28 import javax.swing.JComboBox ; 29 import javax.swing.SwingUtilities ; 30 import junit.framework.AssertionFailedError; 31 import org.netbeans.jellytools.Bundle; 32 import org.netbeans.jellytools.EditorOperator; 33 import org.netbeans.jellytools.EditorWindowOperator; 34 import org.netbeans.jellytools.JellyTestCase; 35 import org.netbeans.jellytools.MainWindowOperator; 36 import org.netbeans.jellytools.NbDialogOperator; 37 import org.netbeans.jellytools.NewFileWizardOperator; 38 import org.netbeans.jellytools.actions.BuildProjectAction; 39 import org.netbeans.jellytools.actions.EditAction; 40 import org.netbeans.jellytools.modules.web.NewJspFileNameStepOperator; 41 import org.netbeans.jellytools.nodes.SourcePackagesNode; 42 import org.netbeans.jemmy.EventTool; 43 import org.netbeans.jemmy.JemmyException; 44 import org.netbeans.jemmy.JemmyProperties; 45 import org.netbeans.jemmy.TimeoutExpiredException; 46 import org.netbeans.jellytools.WizardOperator; 47 import org.netbeans.jellytools.nodes.Node; 48 import org.netbeans.jellytools.actions.ActionNoBlock; 49 import org.netbeans.jellytools.actions.Action; 50 import org.netbeans.jellytools.NewProjectWizardOperator; 51 import org.netbeans.jellytools.NewWebProjectNameLocationStepOperator; 52 import org.netbeans.jellytools.OptionsOperator; 53 import org.netbeans.jellytools.OutputTabOperator; 54 import org.netbeans.jellytools.ProjectsTabOperator; 55 import org.netbeans.jellytools.RuntimeTabOperator; 56 import org.netbeans.jellytools.modules.j2ee.nodes.J2eeServerNode; 57 import org.netbeans.jellytools.modules.web.nodes.WebPagesNode; 58 import org.netbeans.jemmy.QueueTool; 59 import org.netbeans.jemmy.Timeouts; 60 import org.netbeans.jemmy.operators.JButtonOperator; 61 import org.netbeans.jemmy.operators.JCheckBoxOperator; 62 import org.netbeans.jemmy.operators.JComboBoxOperator; 63 import org.netbeans.jemmy.operators.JLabelOperator; 64 import org.netbeans.jemmy.operators.JListOperator; 65 import org.netbeans.jemmy.operators.JRadioButtonOperator; 66 import org.netbeans.jemmy.operators.JTextFieldOperator; 67 import org.netbeans.jemmy.operators.JTreeOperator; 68 import org.netbeans.jemmy.operators.Operator; 69 import org.netbeans.junit.NbTestSuite; 70 import org.netbeans.junit.ide.ProjectSupport; 71 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceCreationException; 72 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 73 74 76 public class WebProjectValidation extends JellyTestCase { 77 protected static ProjectHelper phelper = new ProjectHelper() { 78 public Node getSourceNode() { 79 return new SourcePackagesNode(PROJECT_NAME); 80 } 81 }; 82 protected static final String PROJECT_LOCATION = 84 System.getProperty("xtest.data"); 85 protected static String PROJECT_NAME = "SampleProject"; protected static String PROJECT_FOLDER = 89 PROJECT_LOCATION+File.separator+PROJECT_NAME; 90 protected TestURLDisplayer urlDisplayer; 91 private static final String BUILD_SUCCESSFUL = "BUILD SUCCESSFUL"; 92 private ServerInstance server; 93 94 95 public WebProjectValidation(String name) { 96 super(name); 97 } 98 99 public static NbTestSuite suite() { 100 NbTestSuite suite = new NbTestSuite(); 101 suite.addTest(new WebProjectValidation("testPreconditions")); 102 suite.addTest(new WebProjectValidation("testNewWebProject")); 103 suite.addTest(new WebProjectValidation("testNewJSP")); 104 suite.addTest(new WebProjectValidation("testNewJSP2")); 105 suite.addTest(new WebProjectValidation("testNewServlet")); 106 suite.addTest(new WebProjectValidation("testNewServlet2")); 107 suite.addTest(new WebProjectValidation("testBuildProject")); 108 suite.addTest(new WebProjectValidation("testCompileAllJSP")); 109 suite.addTest(new WebProjectValidation("testCompileJSP")); 110 suite.addTest(new WebProjectValidation("testCleanProject")); 111 suite.addTest(new WebProjectValidation("testRunProject")); 112 suite.addTest(new WebProjectValidation("testRunJSP")); 113 suite.addTest(new WebProjectValidation("testViewServlet")); 114 suite.addTest(new WebProjectValidation("testRunServlet")); 115 suite.addTest(new WebProjectValidation("testCreateTLD")); 116 suite.addTest(new WebProjectValidation("testCreateTagHandler")); 117 suite.addTest(new WebProjectValidation("testRunTag")); 118 suite.addTest(new WebProjectValidation("testNewHTML")); 119 suite.addTest(new WebProjectValidation("testRunHTML")); 120 suite.addTest(new WebProjectValidation("testNewSegment")); 121 suite.addTest(new WebProjectValidation("testNewDocument")); 122 suite.addTest(new WebProjectValidation("testStopServer")); 123 suite.addTest(new WebProjectValidation("testStartServer")); 124 suite.addTest(new WebProjectValidation("testBrowserSettings")); 125 suite.addTest(new WebProjectValidation("testFinish")); 126 return suite; 127 } 128 129 130 public static void main(java.lang.String [] args) { 131 junit.textui.TestRunner.run(suite()); 133 } 136 137 public void setUp() { 138 System.out.println("######## "+getName()+" #######"); 139 initDisplayer(); 140 JemmyProperties.setCurrentTimeout( 141 "ComponentOperator.WaitComponentTimeout", 180000); 142 JemmyProperties.setCurrentTimeout( 143 "FrameWaiter.WaitFrameTimeout", 180000); 144 JemmyProperties.setCurrentTimeout( 145 "DialogWaiter.WaitDialogTimeout",180000); 146 server = ServerInstance.getDefault(); 147 148 } 153 154 public void tearDown() throws IOException { 155 logAndCloseOutputs(); 156 } 157 158 public void testRegisterTomcat() { 159 String tomcatHome = System.getProperty("tomcat.home"); 161 try { 162 InstanceProperties.createInstanceProperties("tomcat55:home="+tomcatHome+":base="+tomcatHome, 163 "tomcat", "tomcat", "Testing Tomcat"); 164 } catch(InstanceCreationException ice) { 165 fail(ice); 166 } 167 J2eeServerNode.invoke("Testing Tomcat"); 168 RuntimeTabOperator.invoke(); 169 sleep(30000); 170 171 } 172 173 174 public void testPreconditions() throws Exception { 175 URLConnection connection = server.getServerURL().openConnection(); 176 try { 177 connection.connect(); 178 fail("Port: "+server.getServerURL()+" is used by different server."); 179 } catch (ConnectException e) { } 180 URL url = new URL ("http://localhost:8025"); 181 connection = url.openConnection(); 182 try { 183 connection.connect(); 184 fail("Connection to http://localhost:8025 established, but tomcat should not be running."); 185 } catch (ConnectException e) { } 186 } 187 188 196 public void testNewWebProject() throws IOException { 197 installJemmyQueue(); 198 NewProjectWizardOperator projectWizard = NewProjectWizardOperator.invoke(); 199 String category = Bundle.getStringTrimmed( 200 "org.netbeans.modules.web.core.Bundle", 201 "Templates/JSP_Servlet"); 202 projectWizard.selectCategory(category); 203 projectWizard.next(); 204 NewWebProjectNameLocationStepOperator nameStep = 205 new NewWebProjectNameLocationStepOperator(); 206 nameStep.txtProjectName().setText(""); 207 nameStep.txtProjectName().typeText(PROJECT_NAME); 208 nameStep.txtProjectLocation().setText(""); 209 nameStep.txtProjectLocation().typeText(PROJECT_LOCATION); 210 nameStep.finish(); 211 Timeouts timeouts = nameStep.getTimeouts().cloneThis(); 212 nameStep.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 60000); 213 nameStep.waitClosed(); 214 nameStep.setTimeouts(timeouts); 215 sleep(5000); 217 ProjectSupport.waitScanFinished(); 218 new EditorWindowOperator().getEditor("index.jsp"); ProjectSupport.waitScanFinished(); 220 WebPagesNode webPages = new WebPagesNode(PROJECT_NAME); 222 new Node(webPages,"index.jsp"); new Node(webPages,"WEB-INF|web.xml"); new Node(webPages,"META-INF|context.xml"); ref(Util.dumpProjectView(PROJECT_NAME)); 226 compareReferenceFiles(); 227 } 228 229 237 public void testNewJSP() throws IOException { 238 new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME).select(); 240 NewJspFileNameStepOperator nameStep = NewJspFileNameStepOperator.invoke(); 241 nameStep.setJSPFileName("page1"); 242 nameStep.finish(); 243 new EditorOperator("page1.jsp").close(); 245 ref(Util.dumpProjectView(PROJECT_NAME)); 246 } 248 249 256 public void testNewJSP2() throws IOException { 257 Node webPages = new WebPagesNode(PROJECT_NAME); 258 new ActionNoBlock(null, "New|JSP").perform(webPages); 260 NewJspFileNameStepOperator nameStep = new NewJspFileNameStepOperator(); 261 nameStep.setJSPFileName("page2"); 262 nameStep.finish(); 263 new EditorOperator("page2.jsp").close(); 265 ref(Util.dumpProjectView(PROJECT_NAME)); 266 } 269 270 278 public void testNewServlet() throws IOException { 279 new ActionNoBlock("File|New File", null).perform(); 281 new EventTool().waitNoEvent(1000); 283 WizardOperator newFileWizard = new WizardOperator("New File"); 284 new JComboBoxOperator(newFileWizard).selectItem(PROJECT_NAME); 285 new Node(new JTreeOperator(newFileWizard), "Java Classes").select(); 287 new Node(new JTreeOperator(newFileWizard), "Web").select(); 288 new JListOperator(newFileWizard, 1).selectItem("Servlet"); 289 newFileWizard.next(); 290 JTextFieldOperator txtPackageName = new JTextFieldOperator(newFileWizard); 291 txtPackageName.setText(""); 293 txtPackageName.typeText("Servlet1"); 294 JComboBoxOperator txtPackage = new JComboBoxOperator(newFileWizard,1); 295 txtPackage.clearText(); 297 txtPackage.typeText("test1"); 298 newFileWizard.next(); 299 newFileWizard.finish(); 300 new EditorOperator("Servlet1.java").close(); 302 WebPagesNode webPages = new WebPagesNode(PROJECT_NAME); 304 webPages.setComparator(new Operator.DefaultStringComparator(true, true)); 305 Node webXml = new Node(webPages, "WEB-INF|web.xml"); 306 new EditAction().performPopup(webXml); 307 String xmlText = new EditorOperator("web.xml").getText(); 308 new EditorOperator("web.xml").closeAllDocuments(); 309 String [] content = new String [] { 310 "<servlet-name>Servlet1</servlet-name>", 311 "<servlet-class>test1.Servlet1</servlet-class>", 312 "<url-pattern>/Servlet1</url-pattern>" 313 }; 314 for (int i=0; i<content.length; i++) { 315 assertTrue("Servlet is not correctly specifeid in web.xml." + 316 " Following line is missing in the web.xml:\n"+content[i], 317 xmlText.indexOf(content[i]) != -1); 318 } 319 ref(Util.dumpProjectView(PROJECT_NAME)); 320 } 323 324 336 public void testNewServlet2() throws IOException { 337 NewFileWizardOperator.create(PROJECT_NAME, "Java Classes", "Java Package", 338 null, "test2"); 339 Node sample1Node = new Node(phelper.getSourceNode(), "test2"); 340 new ActionNoBlock(null, "New|Servlet").perform(sample1Node); 342 WizardOperator newFileWizard = new WizardOperator("New Servlet"); 343 new JTextFieldOperator(newFileWizard).typeText("Servlet2"); 344 newFileWizard.next(); 345 new JTextFieldOperator(newFileWizard,1).setText(""); 346 new JTextFieldOperator(newFileWizard,1).typeText("Servlet2Name"); 347 new JTextFieldOperator(newFileWizard,2).setText(""); 348 new JTextFieldOperator(newFileWizard,2).typeText("/Servlet2URL"); 349 newFileWizard.finish(); 350 new EditorOperator("Servlet2.java").close(); 352 ref(Util.dumpProjectView(PROJECT_NAME)); 353 } 356 357 public void testBuildProject() { 358 Node rootNode = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME); 359 new BuildProjectAction().perform(rootNode); 360 MainWindowOperator.getDefault().waitStatusText("Finished building"); 361 ref(Util.dumpFiles(new File (PROJECT_FOLDER))); 362 } 364 365 public void testCompileAllJSP() { 366 Node rootNode = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME); 367 new Action(null,"Properties").perform(rootNode); 368 NbDialogOperator properties = new NbDialogOperator("Project Properties"); 369 new Node(new JTreeOperator(properties), "Build|Compiling").select(); 370 new JCheckBoxOperator(properties,2).changeSelection(true); 371 properties.ok(); 372 373 testBuildProject(); 374 testCleanProject(); 375 376 new Action(null,"Properties").perform(rootNode); 377 properties = new NbDialogOperator("Project Properties"); 378 new Node(new JTreeOperator(properties), "Build|Compiling").select(); 379 new JCheckBoxOperator(properties,2).changeSelection(false); 380 properties.ok(); 381 } 382 383 public void testCompileJSP() { 384 Node rootNode = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME); 385 Node jspNode = new Node(rootNode,"Web Pages|page2.jsp"); 386 new Action(null,"Compile File").perform(jspNode); 387 MainWindowOperator.getDefault().waitStatusText("Finished building"); 388 ref(Util.dumpFiles(new File (PROJECT_FOLDER))); 389 } 391 392 public void testCleanProject() { 393 Node rootNode = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME); 394 new Action(null,"Clean Project").perform(rootNode); 395 MainWindowOperator.getDefault().waitStatusText("Finished building"); 396 ref(Util.dumpFiles(new File (PROJECT_FOLDER))); 397 } 399 400 public void testRunProject() throws Exception { 401 Node rootNode = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME); 402 new Node(rootNode,"Web Pages|index.jsp").performPopupAction("Open"); 403 EditorOperator editor = new EditorOperator("index.jsp"); 404 editor.replace("<title>JSP Page</title>", 405 "<title>SampleProject Index Page</title>"); 406 editor.insert("Running Project\n",23,1); 407 new Action(null,"Run Project").perform(rootNode); 408 waitBuildSuccessful(); 409 assertDisplayerContent("<title>SampleProject Index Page</title>"); 410 editor.deleteLine(23); 411 editor.save(); 412 editor.close(); 413 } 414 415 public void testRunJSP() { 416 Node rootNode = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME); 417 new Node(rootNode,"Web Pages|page2.jsp").performPopupAction("Open"); 418 EditorOperator editor = new EditorOperator("page2.jsp"); 419 editor.replace("<title>JSP Page</title>", "<title>Page 2</title>"); 420 editor.insert("Running JSP\n",6,1); 421 new Action("Run|Run File|Run \"page2.jsp\"",null).perform(); 422 waitBuildSuccessful(); 423 assertDisplayerContent("<title>Page 2</title>"); 424 editor.deleteLine(6); 425 editor.save(); 426 editor.close(); 427 } 428 429 public void testViewServlet(){ 430 String jspCode ="new String().toString();"; 431 String runningViewServlet = "Running View Servlet"; 432 String newTitle = "<h1>View Page"; 433 Node rootNode = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME); 434 new Node(rootNode,"Web Pages|page2.jsp").performPopupAction("Open"); 435 EditorOperator editor = new EditorOperator("page2.jsp"); 436 editor.replace("<h1>", newTitle); 437 editor.insert(runningViewServlet+"\n", 21, 6); 438 editor.insert("<% " + jspCode + " %>\n" , 24, 6); 439 new Action("Run|Run File|Run \"page2.jsp\"",null).perform(); 440 waitBuildSuccessful(); 441 assertDisplayerContent("<title>Page 2</title>"); 442 new Node(rootNode,"Web Pages|page2.jsp").performPopupAction("View Servlet"); 443 EditorOperator servlet = new EditorOperator("page2_jsp.java"); 444 assertNotNull("SERVLET CONTEXT SHOULD BE SHOWN", servlet); 445 assertTrue("SERVLET SHOULD CONTAIN ", servlet.contains("<h1>")); 446 assertTrue("SERVLET SHOULD CONTAIN ", servlet.contains(runningViewServlet)); 447 assertTrue("SERVLET SHOULD CONTAIN ", servlet.contains("JspWriter out")); 448 assertTrue("SERVLET SHOULD CONTAIN ", servlet.contains(jspCode)); 449 editor.replace(newTitle, "<h1>"); 450 editor.deleteLine(24); 451 editor.deleteLine(21); 452 editor.save(); 453 editor.close(); 454 servlet.close(); 455 } 456 457 public void testRunServlet() { 458 Node sourceNode = phelper.getSourceNode(); 459 new Node(sourceNode,"test1|Servlet1.java").performPopupAction("Open"); 460 EditorOperator editor = new EditorOperator("Servlet1.java"); 461 if (!editor.getText(29).equals(" /* TODO output your page here\n")) 464 throw new AssertionFailedError("Servlet1.java:30 Other content than expected.\n"+ 465 "was >"+editor.getText(29)+"<, expected > /* TODO output your page here\n<"); 466 if (!editor.getText(38).equals(" */\n")) 467 throw new AssertionFailedError("Servlet1.java:39 Other content than expected.\n"+ 468 "was >"+editor.getText(3)+"<, expected > */\n<"); 469 editor.deleteLine(38); 470 editor.deleteLine(29); 471 editor.replace("out.println(\"<title>Servlet Servlet1</title>\");", 472 "out.println(\"<title>Servlet with name=\"+request.getParameter(\"name\")+\"</title>\");"); 473 new ActionNoBlock("Run|Run File|Run \"Servlet1.java\"",null).perform(); 474 NbDialogOperator dialog = new NbDialogOperator("Set Servlet Execution Uri"); 475 JComboBoxOperator combo = new JComboBoxOperator(dialog); 476 combo.setSelectedItem(combo.getSelectedItem()+"?name=Servlet1"); 477 dialog.ok(); 478 editor.close(); 480 assertDisplayerContent("<title>Servlet with name=Servlet1</title>"); 481 } 482 483 public void testCreateTLD() { 484 new Node(new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME), "Web Pages|WEB-INF").expand(); 486 487 new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME).select(); 489 490 new ActionNoBlock("File|New File", null).perform(); 491 new EventTool().waitNoEvent(1000); 493 WizardOperator newFileWizard = new WizardOperator("New File"); 494 new JComboBoxOperator(newFileWizard).selectItem(PROJECT_NAME); 495 new Node(new JTreeOperator(newFileWizard), "Java Classes").select(); 497 new Node(new JTreeOperator(newFileWizard), "Web").select(); 498 new JListOperator(newFileWizard, 1).selectItem("Tag Library Descriptor"); 499 newFileWizard.next(); 500 JTextFieldOperator txtName = new JTextFieldOperator(newFileWizard); 501 txtName.setText(""); 503 txtName.typeText("MyTags"); 504 newFileWizard.finish(); 505 new Node(new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME), "Web Pages|WEB-INF|tlds|MyTags.tld"); 508 new EditorOperator("MyTags.tld").close(); 510 ref(Util.dumpProjectView(PROJECT_NAME)); 511 } 513 514 public void testCreateTagHandler() { 515 new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME).select(); 517 518 new ActionNoBlock("File|New File", null).perform(); 519 new EventTool().waitNoEvent(1000); 521 WizardOperator newFileWizard = new WizardOperator("New File"); 522 new JComboBoxOperator(newFileWizard).selectItem(PROJECT_NAME); 523 new Node(new JTreeOperator(newFileWizard), "Java Classes").select(); 525 new Node(new JTreeOperator(newFileWizard), "Web").select(); 526 new JListOperator(newFileWizard, 1).selectItem("Tag Handler"); 527 newFileWizard.next(); 528 JTextFieldOperator txtName = new JTextFieldOperator(newFileWizard); 529 txtName.setText(""); 531 txtName.typeText("MyTag"); 532 JComboBoxOperator pkg = new JComboBoxOperator(newFileWizard,1); 533 pkg.clearText(); 534 pkg.typeText("tags"); 535 newFileWizard.next(); 536 new JButtonOperator(newFileWizard).push(); 537 NbDialogOperator dialog = new NbDialogOperator("Browse Files"); 538 new Node(new JTreeOperator(dialog),"Web Pages|WEB-INF|tlds|MyTags.tld").select(); 539 new JButtonOperator(dialog,"Select File").push(); 540 newFileWizard.finish(); 541 new Node(phelper.getSourceNode(), "tags|MyTag.java"); 543 EditorOperator editor = new EditorOperator("MyTag.java"); 545 editor.insert(getTagHandlerCode(),43,1); 546 editor.saveDocument(); 547 editor.close(); 548 ref(Util.dumpProjectView(PROJECT_NAME)); 549 } 551 552 protected String getTagHandlerCode() { 553 return "out.print(\"TagOutput\"); \n"; 554 } 555 556 public void testRunTag() throws Throwable { 557 Node rootNode = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME); 558 Node jspNode = new Node(rootNode,"Web Pages|page2.jsp"); 559 jspNode.performPopupAction("Open"); 560 EditorOperator editor = new EditorOperator("page2.jsp"); 561 editor.replace("<title>Page 2</title>", 562 "<title><my:MyTag/></title>"); 563 editor.insert("<%@taglib prefix=\"my\" uri=\"/WEB-INF/tlds/MyTags\"%>\n", 3, 1); 564 565 new Action(null,"Run File").perform(jspNode); 566 waitBuildSuccessful(); 567 editor.close(); 568 assertDisplayerContent("<title>TagOutput</title>"); 569 } 570 571 public void testNewHTML() throws IOException { 572 new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME).select(); 574 575 new ActionNoBlock("File|New File", null).perform(); 576 new EventTool().waitNoEvent(1000); 578 WizardOperator newFileWizard = new WizardOperator("New File"); 579 new JComboBoxOperator(newFileWizard).selectItem(PROJECT_NAME); 580 new Node(new JTreeOperator(newFileWizard), "Java Classes").select(); 582 new Node(new JTreeOperator(newFileWizard), "Web").select(); 583 new JListOperator(newFileWizard, 1).selectItem("HTML"); 584 newFileWizard.next(); 585 JTextFieldOperator txtPackageName = new JTextFieldOperator(newFileWizard); 586 txtPackageName.setText(""); 588 txtPackageName.typeText("HTML"); 589 newFileWizard.finish(); 590 new EditorOperator("HTML.html").close(); 592 ref(Util.dumpProjectView(PROJECT_NAME)); 593 new Node(new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME),"Web Pages|HTML.html"); 594 } 597 598 public void testRunHTML() { 599 Node rootNode = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME); 600 new Node(rootNode,"Web Pages|HTML.html").performPopupAction("Open"); 601 new EditorOperator("HTML.html").replace("<title></title>", 602 "<title>HTML Page</title>"); 603 new Action("Run|Run File|Run \"HTML.html\"",null).perform(); 604 new EditorOperator("HTML.html").close(); 606 assertDisplayerContent("<title>HTML Page</title>"); 607 } 608 609 public void testNewSegment() throws IOException { 610 Node sample1Node = new Node(new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME),"Web Pages"); 611 new ActionNoBlock(null, "New|JSP").perform(sample1Node); 613 new EventTool().waitNoEvent(1000); 615 WizardOperator newFileWizard = new WizardOperator("New JSP File"); 616 new JTextFieldOperator(newFileWizard).typeText("segment"); 617 new JCheckBoxOperator(newFileWizard).changeSelection(true); 618 newFileWizard.finish(); 619 new EditorOperator("segment.jspf").close(); 621 ref(Util.dumpProjectView(PROJECT_NAME)); 622 new Node(new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME),"Web Pages|segment.jspf"); 623 } 626 627 public void testNewDocument() throws IOException { 628 Node sample1Node = new Node(new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME),"Web Pages"); 629 new ActionNoBlock(null, "New|JSP").perform(sample1Node); 631 new EventTool().waitNoEvent(1000); 633 WizardOperator newFileWizard = new WizardOperator("New JSP File"); 634 new JTextFieldOperator(newFileWizard).typeText("document"); 635 new JRadioButtonOperator(newFileWizard,1).changeSelection(true); 636 newFileWizard.finish(); 637 new EditorOperator("document.jspx").close(); 639 ref(Util.dumpProjectView(PROJECT_NAME)); 640 new Node(new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME),"Web Pages|document.jspx"); 641 } 644 645 public void testStopServer() throws Exception { 646 server.stop(); 647 URL url = server.getServerURL(); 649 URLConnection connection = url.openConnection(); 650 try { 651 connection.connect(); 652 fail("Connection to: "+url+" established, but the server" + 653 " should not be running."); 654 } catch (ConnectException e) { } 655 } 656 657 public void testStartServer() throws Exception { 658 server.start(); 659 URL url = server.getServerURL(); 660 URLConnection connection = url.openConnection(); 661 connection.connect(); 662 } 663 664 public void testBrowserSettings() { 665 OptionsOperator optionsOper = OptionsOperator.invoke(); 666 optionsOper.selectGeneral(); 667 String webBrowserLabel = Bundle.getStringTrimmed( 669 "org.netbeans.modules.options.general.Bundle", 670 "CTL_Web_Browser"); 671 JLabelOperator jloWebBrowser = new JLabelOperator(optionsOper, webBrowserLabel); 672 JComboBoxOperator combo = new JComboBoxOperator((JComboBox )jloWebBrowser.getLabelFor()); 673 for (int i=0; i<combo.getItemCount(); i++) { 674 String item = combo.getItemAt(i).toString(); 675 log("Browser: "+item); 676 if (!item.equals("<Default System Browser>") && 677 !item.equals("Mozilla") && 678 !item.equals("Netscape") && 679 !item.equals("Swing HTML Browser") && 680 !item.equals("Internet Explorer") && 681 !item.equals("Firefox") && 682 !item.equals("External Browser (command-line)")) 683 fail("Unrecognized settings in Web Browser Options"); 684 } 685 optionsOper.close(); 686 } 687 688 public void testFinish() { 689 server.stop(); 690 ProjectSupport.closeProject(PROJECT_NAME); 691 } 692 693 695 protected void sleep(int milis) { 696 try { 697 Thread.sleep(milis); 698 } catch (InterruptedException ex) { 699 throw new JemmyException("Interrupted", ex); 700 } 701 } 702 703 private void logAndCloseOutputs() throws IOException { 704 long timeout = JemmyProperties.getCurrentTimeout( 705 "ComponentOperator.WaitComponentTimeout"); 706 JemmyProperties.setCurrentTimeout( 707 "ComponentOperator.WaitComponentTimeout", 3000); 708 try { 709 for (int i=0; i<10; i++) { 710 OutputTabOperator output = new OutputTabOperator(""); 711 String log_name = "Output"+i+".log"; 712 int index = 0; 713 while (new File (getWorkDir(),log_name).exists()) { 714 log_name = "Output"+i+"_"+(++index)+".log"; 715 } 716 log(log_name,output.getName()+"\n-------------\n\n"+ 717 output.getText()); 718 output.close(); 719 } 720 } catch (TimeoutExpiredException e) { } catch (IOException e) { throw e; } finally { 721 JemmyProperties.setCurrentTimeout( 722 "ComponentOperator.WaitComponentTimeout", timeout); 723 } 724 } 725 726 private void waitBuildSuccessful() { 727 OutputTabOperator console = new OutputTabOperator(PROJECT_NAME); 728 console.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 180000); 729 console.waitText(BUILD_SUCCESSFUL); 730 } 731 732 738 private void initDisplayer() { 739 if (urlDisplayer == null) { 740 urlDisplayer = TestURLDisplayer.getInstance(); 741 } 742 urlDisplayer.invalidateURL(); 743 } 744 745 private void assertDisplayerContent(String substr) { 746 try { 747 urlDisplayer.waitURL(); 748 } catch (InterruptedException ex) { 749 throw new JemmyException("Waiting interrupted.", ex); 750 } 751 String page = urlDisplayer.readURL(); 752 boolean contains = page.indexOf(substr) > -1; 753 if (!contains) { 754 log("DUMP OF: "+urlDisplayer.getURL()+"\n"); 755 log(page); 756 } 757 assertTrue("The '"+urlDisplayer.getURL()+"' page does not contain '"+substr+"'", contains); 758 } 759 760 protected void installJemmyQueue() { 761 try { 762 SwingUtilities.invokeAndWait(new Runnable () { 763 public void run() { 764 QueueTool.installQueue(); 765 } 766 }); 767 } catch (Exception ex) { 768 throw new JemmyException("Cannot install Jemmy Queue.", ex); 769 } 770 } 771 772 private static class ServerInstance { 773 private String host; 774 private int serverPort; 775 private String nodeName; 776 private String userName; 777 private String password; 778 private URL serverURL; 779 private static ServerInstance instance; 780 781 private ServerInstance() { 782 } 783 784 public static ServerInstance getDefault() { 785 if (instance == null) { 786 instance = new ServerInstance(); 787 instance.host = "localhost"; 788 instance.serverPort = 8080; 789 instance.nodeName = "Bundled Tomcat"; 790 instance.userName = "tomcat"; 791 instance.password = "tomcat"; 792 } 793 return instance; 794 } 795 796 public URL getServerURL() { 797 if (serverURL == null) { 798 try { 799 serverURL = new URL ("http",host,serverPort,""); 800 } catch (MalformedURLException mue) { 801 throw new JemmyException("Cannot create server URL.", mue); 802 } 803 } 804 return serverURL; 805 } 806 807 public J2eeServerNode getServerNode() { 808 return J2eeServerNode.invoke(nodeName); 809 } 810 811 public void stop() { 812 getServerNode().stop(); 813 } 814 815 public void start() { 816 getServerNode().start(); 817 } 818 } 819 } 820 821 | Popular Tags |