|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.test.gui.web.servletexec.execution; import org.netbeans.jellytools.JellyTestCase; import org.netbeans.jellytools.Bundle; import org.netbeans.web.test.nodes.ServletNode; import org.netbeans.web.test.actions.ExecuteForceReloadAction; import org.netbeans.web.test.util.Utils; import org.netbeans.web.test.util.EditorPageWaitable; import org.netbeans.web.test.SwingBrowserOperator; import org.netbeans.web.test.PropertyTableDialogOperator; import org.netbeans.jellytools.nodes.FolderNode; import org.netbeans.jellytools.nodes.HTMLNode; import org.netbeans.jellytools.nodes.Node; import org.netbeans.jellytools.OutputWindowOperator; import org.netbeans.jellytools.NbDialogOperator; import org.netbeans.jellytools.RuntimeTabOperator; import org.netbeans.jellytools.ExplorerOperator; import org.netbeans.jellytools.OptionsOperator; import org.netbeans.jellytools.MainWindowOperator; import org.netbeans.jellytools.actions.NewTemplateAction; import org.netbeans.jellytools.actions.ExecuteAction; import org.netbeans.jellytools.actions.CompileAction; import org.netbeans.jellytools.actions.CleanAction; import org.netbeans.jellytools.actions.OpenAction; import org.netbeans.jellytools.actions.Action; //import org.netbeans.jellytools.properties.editors.StringArrayCustomEditorOperator; import org.netbeans.jellytools.properties.PropertySheetTabOperator; import org.netbeans.jellytools.properties.PropertySheetOperator; import org.netbeans.jellytools.properties.ComboBoxProperty; import org.netbeans.jellytools.properties.TextFieldProperty; import org.netbeans.jellytools.properties.Property; import org.netbeans.junit.NbTestSuite; import org.netbeans.jemmy.operators.JTreeOperator; import org.netbeans.jemmy.operators.JTextFieldOperator; import org.netbeans.jemmy.operators.JButtonOperator; import org.netbeans.jemmy.operators.Operator; import org.netbeans.jemmy.Waiter; import org.netbeans.jemmy.Waitable; import org.netbeans.jemmy.TimeoutExpiredException; import org.netbeans.jellytools.EditorOperator; import org.netbeans.jellytools.EditorWindowOperator; import org.netbeans.jellytools.ChooseTemplateStepOperator; import org.netbeans.jellytools.NewWizardOperator; import org.netbeans.jellytools.TargetLocationStepOperator; public class Execution extends JellyTestCase { private static String workDir = null; private static String webModule = null; private static String wmName = "wm3"; private static String iSep = "|"; private static String fSep = System.getProperty("file.separator"); private static String classes = null; private static String pkg = null; private static String updatedLine = "Updated_LINE"; private static int updateCount = 0; private static String okApp = " HTTP/1.0\" 200"; private static String okPre = "\"GET "; private static String uri1 = "/servlet/execution.Servlet1"; private static String servlet1 = "Servlet1"; private static String servletRp = "RequestParamsServlet"; private static String servletCp = "ContextParamsServlet"; private static String servletMap = "MappingServlet"; private static String servlet1CheckString = "Servlet 1. Test Passed"; private static String servlet2CheckString = "Servlet 2. Test Passed"; private static String uri2 = "/servlet/execution.Servlet2"; private static String servlet2 = "Servlet2"; private static boolean first = true; //constructor required by JUnit public Execution(java.lang.String testName) { super(testName); } //from IDE for debugging public static void main(java.lang.String[] args) { junit.textui.TestRunner.run(suite()); } //method required by JUnit public static junit.framework.Test suite() { workDir = System.getProperty("servletexec.workdir").replace('/', fSep.charAt(0)); webModule = workDir + fSep + wmName; classes = webModule + iSep + "WEB-INF" + iSep + "Classes"; pkg = classes + iSep + "execution"; String wmc = System.getProperty("servletexec.mountcount"); int count = 0; if(wmc != null) { count = new Integer(wmc).intValue(); } if(first) { while(count >0) { Utils.handleDialogAfterNewWebModule(); count--; } first = false; } setSimpleBrowser(); new ExecuteAction().perform(new HTMLNode(webModule + iSep + "empty")); if(!handleSwingBrowserDialog()) { //Try to hadle it in the first tests. } return new NbTestSuite(Execution.class); } /** Execute newly created servlet */ public void testExecuteNewServlet() { ServletNode node = null; FolderNode node1 = null; NewWizardOperator wizard = null; String servletTreePath = Bundle.getString("org.netbeans.modules.web.core.Bundle", "Templates/JSP_Servlet") + iSep + Bundle.getString("org.netbeans.modules.web.core.Bundle", "Templates/JSP_Servlet/Servlet.java"); String name = "NewServlet"; try { node1 = new FolderNode(pkg); node1.select(); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } try { new NewTemplateAction().performMenu(); wizard = new NewWizardOperator(); new ChooseTemplateStepOperator().selectTemplate(servletTreePath); wizard.next(); new TargetLocationStepOperator().setName(name); wizard.finish(); }catch(Exception e1) { if(wizard != null) wizard.cancel(); e1.printStackTrace(); fail("Exception during servlet creation"); } try { node = new ServletNode(pkg + iSep + name); }catch(Exception e) { fail("Servlet for execution was not created."); } //node.open(); EditorPageWaitable epw = new EditorPageWaitable(name); Waiter w = new Waiter(epw); try { w.waitAction(epw); } catch (Exception e) { e.printStackTrace(); fail("Servlet was not opened in editor."); } EditorOperator editor = epw.getEditorOperator(); editor.setCaretPosition("/* output your page",true); editor.insert("\nout.println(\"\");\n"); editor.insert("\nout.println(\"OutputLine\");\n"); editor.insert("\nout.println(\"\");\n"); node.execute(); checkExecutionResults("/servlet/execution." + name, "OutputLine"); } /** Execute servlet with server restarting via popup menu */ public void testExecuteForceReloadServletViaPopup() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet1); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } new ExecuteAction().performPopup(node); checkExecutionResults(uri1, servlet1CheckString);//Just to be sure, that servlet was loaded before FR new ExecuteForceReloadAction().performPopup(node); checkExecutionResults(uri1, servlet1CheckString, 1); } /** Execute servlet via popup menu */ public void testExecuteServletViaPopup() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet1); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } new ExecuteAction().performPopup(node); checkExecutionResults(uri1, servlet1CheckString); } /** Execute servlet via main menu */ public void testExecuteServletViaMain() { ServletNode node = null; try { node = new ServletNode(pkg + iSep + servlet1); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } new ExecuteAction().performMenu(node); checkExecutionResults(uri1, servlet1CheckString); } /** Execute servlet via hotkey */ public void testExecuteServletViaShortcut() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet1); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } node.select(); new ExecuteAction().performShortcut(node); checkExecutionResults(uri1, servlet1CheckString); } /** Execute servlet via toolbar button */ public void testExecuteServletViaToolbar() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet1); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } node.select(); MainWindowOperator mainWindow = MainWindowOperator.getDefault(); mainWindow.getToolbarButton(mainWindow.getToolbar("Build"), "Execute").push(); //NOI18N checkExecutionResults(uri1, servlet1CheckString); } /*End: execute servlet*/ /*Begin: deploy servlet */ public void testDeployServlet() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet1); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } node.deploy(); checkDeployResults(uri1, servlet1CheckString); } /*End: deploy servlet*/ /*Begin: autocompilation */ /** Execute / Execute (Force Reload) / Deploy servlet after clean up (auto compilation) */ /** t1 */ public void testCleanDeploy() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet1); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } node.clean(); waitForClean(); node.deploy(); checkDeployResults(uri1, servlet1CheckString); } /** t2 */ public void testCleanExecuteMain() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet1); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } node.clean(); waitForClean(); node.deploy(); checkDeployResults(uri1, servlet1CheckString); node.clean(); waitForClean(); node.execute(); //Menu checkExecutionResults(uri1, servlet1CheckString); } /** t3 */ public void testCleanExecutePopup() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet1); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } node.clean(); waitForClean(); node.execute(); //Popup checkExecutionResults(uri1, servlet1CheckString); } /** t4 */ public void testCleanExecuteToolbar() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet1); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } node.clean(); waitForClean(); MainWindowOperator mainWindow = MainWindowOperator.getDefault(); mainWindow.getToolbarButton(mainWindow.getToolbar("Build"), "Execute").push(); //NOI18N checkExecutionResults(uri1, servlet1CheckString); } /** t5 */ public void testCleanExecuteForceReloadPopup() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet1); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } node.execute(); checkExecutionResults(uri1, servlet1CheckString); //To be sure that servlet loaded before FR node.clean(); waitForClean(); node.executeForceReload(); checkExecutionResults(uri1, servlet1CheckString, 1); } /*End: autocompilation */ /*Begin: autosave/autocompilation */ /** Execute / Execute (Force Reload) / Deploy servlet after servlet modification (auto save and auto compilation) */ /** t1 */ public void testModifiedDeploy() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet2); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } updateServlet(node, servlet2); node.deploy(); checkDeployResults(uri2, updatedLine + updateCount); } /** t2 */ public void testModifiedExecuteMain() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet2); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } updateServlet(node, servlet2); new ExecuteAction().performMenu(node); checkExecutionResults(uri2, updatedLine + updateCount); } /** t3 */ public void testModifiedExecutePopup() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet2); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } updateServlet(node,servlet2); new ExecuteAction().performPopup(node); //Popup checkExecutionResults(uri2, updatedLine + updateCount); } /** t4 */ public void testModifiedExecuteToolbar() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet2); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } updateServlet(node,servlet2); MainWindowOperator mainWindow = MainWindowOperator.getDefault(); mainWindow.getToolbarButton(mainWindow.getToolbar("Build"), "Execute").push(); //NOI18N checkExecutionResults(uri2, updatedLine + updateCount); } /** t5 */ public void testModifiedExecuteForceReloadPopup() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet2); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } node.execute(); //To be sure, that servlet loaded before FR checkExecutionResults(uri2, servlet2CheckString); updateServlet(node,servlet2); node.executeForceReload(); checkExecutionResults(uri2, updatedLine + updateCount, 1); } /** Execute servlet after modification of web module Context Root Looks like obsolete. */ /* public void testModifiedContextRoot() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servlet2); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } node.properties(); PropertySheetOperator pso = PropertySheetOperator.invoke(); PropertySheetTabOperator psto = new PropertySheetTabOperator(pso, "Execution"); TextFieldProperty pr = new TextFieldProperty(psto, "Context Root"); pr.setValue("/newroot"); checkExecutionResults("/newroot" + uri1, servlet1CheckString); } */ /** Execute servlet with Context Parameters set */ public void testContextParams() { ServletNode node = null; Node node1 = null; try { node = new ServletNode(pkg + "|" + servletCp); node1 = new ServletNode(webModule + iSep + "WEB-INF" + iSep + "web"); //NB $%#$ ServletNode MUST be replaced by Web.xml node }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } node1.select(); PropertySheetOperator pso = PropertySheetOperator.invoke(); PropertySheetTabOperator psto = new PropertySheetTabOperator(pso, "Deployment"); //NOI18N Property pr = new Property(psto, "Context Parameters"); pr.openEditor(); PropertyTableDialogOperator dialog = new PropertyTableDialogOperator("Context Parameters"); dialog.add(); NbDialogOperator dialog1 = new NbDialogOperator("Add Context Parameter"); JTextFieldOperator tf = new JTextFieldOperator(dialog1, 0); JTextFieldOperator tf1 = new JTextFieldOperator(dialog1, 1); tf.setText("context_parameter"); tf1.setText("parameter_value"); dialog1.ok(); dialog.ok(); node.execute(); checkExecutionResults("/servlet/execution."+servletCp, "context_parameter==parameter_value"); } /** Execute servlet with Request Parameters set via popup menu */ public void testRequestParamsPopup() { String title = Bundle.getString("org.netbeans.modules.web.core.Bundle","CTL_QueryStringTitle"); ServletNode node = null; try { node = new ServletNode(pkg + "|" + servletRp); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } new Action(null, "Tools|Set Request Parameters...").performPopup(node); NbDialogOperator dialog = new NbDialogOperator(title); JTextFieldOperator tf = new JTextFieldOperator(dialog, 0); tf.setText("param1=val1śm2=val2"); dialog.ok(); node.execute(); checkExecutionResults("/servlet/execution."+servletRp + "?param1=val1śm2=val2", "param1==val1"); } /** Execute servlet with Request Parameters set via properties */ public void testRequestParamsProps() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servletRp); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } PropertySheetOperator pso = PropertySheetOperator.invoke(); PropertySheetTabOperator psto = new PropertySheetTabOperator(pso, "Execution"); //NOI18N TextFieldProperty pr = new TextFieldProperty(psto, "Request Parameters"); pr.setValue("param1=val1śm2=val2"); node.execute(); checkExecutionResults("/servlet/execution."+servletRp+"?param1=val1śm2=val2", "param1==val1"); } /** Execute servlet after adding new mapping for it */ public void testNewMappingExact() { ServletNode node = null; try { node = new ServletNode(pkg + "|" + servletMap); }catch(Exception e) { e.printStackTrace(); fail("Please check, that all mounts are done properly"); } node.select(); PropertySheetTabOperator psto = new PropertySheetTabOperator(PropertySheetOperator.invoke(), "Properties"); //NOI18N new Property(psto, "Deployment Entries").openEditor(); //NOI18N PropertyTableDialogOperator deDialog = new PropertyTableDialogOperator("Deployment Entries"); deDialog.selectCell(servletMap);//Just to select deDialog.edit(); NbDialogOperator esDialog = new NbDialogOperator("Edit Servlet"); new JButtonOperator(esDialog, "Edit", 0).push(); //NB PropertyTableDialogOperator esmDialog = new PropertyTableDialogOperator("Edit Servlet Mappings"); esmDialog.add(); NbDialogOperator dialog3 = new NbDialogOperator("Add Servlet Mapping"); JTextFieldOperator name = new JTextFieldOperator(dialog3, 0); JTextFieldOperator uri = new JTextFieldOperator(dialog3, 1); name.setText(servletMap); uri.setText("/newUri"); dialog3.ok(); esmDialog.ok(); esDialog.ok(); deDialog.ok(); node.select(); psto = new PropertySheetTabOperator(PropertySheetOperator.invoke(), "Properties"); new TextFieldProperty(psto, "URI").setValue("/newUri"); node.execute(); checkExecutionResults("newUri", "MappingServlet PASSED"); } public void testNewMappingWildCard() { } /* Private methods */ private boolean waitForTomcatStartup() { String tomcatPath = "Server Registry|Installed Servers|Tomcat"; String stoppedPath = tomcatPath + "|" + "Internal Tomcat (JWSDP 1.0_01) [Not Running]"; String runningPath = tomcatPath + "|" + "Internal Tomcat (JWSDP 1.0_01) [Running]"; NodeWaitable nw = new NodeWaitable(runningPath); Waiter w = new Waiter(nw); try { w.waitAction(nw); return true; } catch (InterruptedException e) { e.printStackTrace(); fail("Exception while waiting for tomcat startup"); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); fail("Tomcat not started in reasonable time "); } return false; } private boolean waitForTomcatShutdown() { String tomcatPath = "Server Registry|Installed Servers|Tomcat"; String stoppedPath = tomcatPath + "|" + "Internal Tomcat (JWSDP 1.0_01) [Not Running]"; String runningPath = tomcatPath + "|" + "Internal Tomcat (JWSDP 1.0_01) [Running]"; NodeWaitable nw = new NodeWaitable(stoppedPath); Waiter w = new Waiter(nw); try { w.waitAction(nw); return true; } catch (InterruptedException e) { e.printStackTrace(); fail("Exception while waiting for tomcat shutdown"); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); fail("Tomcat not stoppedin reasonable time "); } return false; } private boolean tomcatIntStatus() { String tomcatPath = "Server Registry|Installed Servers|Tomcat"; String stoppedPath = tomcatPath + "|" + "Internal Tomcat (JWSDP 1.0_01) [Not Running]"; String runningPath = tomcatPath + "|" + "Internal Tomcat (JWSDP 1.0_01) [Running]"; boolean stopped = true; boolean running = true; ExplorerOperator explorer = ExplorerOperator.invoke(); //select "Runtime" page RuntimeTabOperator runtimeOp = explorer.runtimeTab(); explorer.selectPageRuntime(); JTreeOperator to = runtimeOp.tree(); try { new Node(to,stoppedPath); stopped = true; }catch(Exception e) { stopped = false; } try { new Node(to, runningPath); running = true; }catch(Exception e) { running = false; } if(running == stopped) { fail("Some missconfiguration :("); } return running; } private void checkExecutionResultsTomcat(String uri) { if(!waitForTomcatStartup()) { fail("Tomcat internal not started(according to runtime tab)"); return; } String access = "localhost_access_log."; OutputPageWaitable opw = new OutputPageWaitable(access); Waiter w = new Waiter(opw); try { w.waitAction(opw); } catch (InterruptedException e) { e.printStackTrace(); fail("Exception while waiting for access log"); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); fail("Access log not opened "); } String output = opw.getText(); String logEntry = okPre + uri + okApp; try { opw.getOutput().getTerm(access).waitText(logEntry); }catch(Exception e2) { fail("Log Entry " + logEntry + " not found in access.log"); } } private void checkExecutionResults(String uri, String checkString) { checkExecutionResults(uri, checkString, -1); } private void checkExecutionResults(String uri, String checkString, int count) { SwingBrowserOperator browser = null; try { browser = new SwingBrowserOperator(); }catch(Exception e) { e.printStackTrace(); fail("Browser not opened."); } UriWaitable uriw = new UriWaitable(uri, browser); Waiter w = new Waiter(uriw); try { w.waitAction(uriw); } catch (Exception e) { String locator = browser.locator().getText(); System.out.println("LOCATOR: " + locator); fail("URI: " + uri + " was not opened in browser. Current uri is " + locator); } ContentWaitable cw = new ContentWaitable(checkString, browser); w = new Waiter(cw); try { w.waitAction(cw); } catch (Exception e) { String window = browser.window().getDisplayedText(); fail("Text " + checkString + " was not displayed in browser. Current text is " + window); } if (count!=-1) { cw = new ContentWaitable("COUNT:" + count + ":", browser); w = new Waiter(cw); try { w.waitAction(cw); } catch (Exception e) { String window = browser.window().getDisplayedText(); fail("Text " + "COUNT:" + count + ":" + " was not displayed in browser. Current text is " + window); } } browser.close(); } private void checkDeployResults(String uri, String checkString) { if(!waitForTomcatStartup()) { fail("Tomcat internal not started(according to runtime tab)"); return; } String access = "localhost_access_log."; OutputPageWaitable opw = new OutputPageWaitable(access); Waiter w = new Waiter(opw); try { w.waitAction(opw); } catch (InterruptedException e) { e.printStackTrace(); fail("Exception while waiting for access log"); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); return; } String output = opw.getText(); String logEntry = okPre + uri + okApp; try { opw.getOutput().getTerm(access).waitText(logEntry); fail("Log Entry " + logEntry + " found in access.log"); }catch(Exception e2) { } } private void checkExecutionForceReloadResults(String uri, String checkString) { checkExecutionResults(uri, checkString, 1); } private void waitForClean() { String compilerPage = Bundle.getString("org.netbeans.core.compiler.Bundle", "CTL_CompileTab"); OutputWindowOperator output = OutputWindowOperator.invoke(); output.getTerm(compilerPage).waitText("Finished"); } private void checkExecutionFRResults(String uri) { if(!waitForTomcatShutdown()) { fail("Tomcat internal not stopped(according to runtime tab)"); return; } if(!waitForTomcatStartup()) { fail("Tomcat internal not started(according to runtime tab)"); return; } String access = "localhost_access_log."; OutputPageWaitable opw = new OutputPageWaitable(access); Waiter w = new Waiter(opw); try { w.waitAction(opw); } catch (InterruptedException e) { e.printStackTrace(); fail("Exception while waiting for access log"); } catch (TimeoutExpiredException e1) { e1.printStackTrace(); fail("Access log not opened "); } String output = opw.getText(); String logEntry = okPre + uri + okApp; try { opw.getOutput().getTerm(access).waitText(logEntry); }catch(Exception e2) { fail("Log Entry " + logEntry + " not found in access.log"); } } private void clearAccessLog() { try { OutputWindowOperator output = OutputWindowOperator.invoke(); output.selectPage("localhost_access_log."); output.clearOutput(); }catch(Exception e) { } } private void updateServlet(Node s, String name) { new OpenAction().performPopup(s); EditorWindowOperator editorWindow = new EditorWindowOperator(); EditorOperator editor = editorWindow.selectPage(name); editor.setCaretPosition("/*please add strings above*/",true); updateCount++; editor.insert("\nout.println(\"" + updatedLine + updateCount + " |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.