1 19 20 package org.netbeans.test.gui.web.extbrowser.execution; 21 22 import org.netbeans.jellytools.JellyTestCase; 23 import org.netbeans.jellytools.Bundle; 24 import org.netbeans.jellytools.ExplorerOperator; 25 import org.netbeans.jellytools.NbFrameOperator; 26 27 28 29 import org.netbeans.jellytools.nodes.FolderNode; 30 import org.netbeans.jellytools.nodes.JavaNode; 31 import org.netbeans.jellytools.nodes.HTMLNode; 32 33 34 import org.netbeans.jellytools.actions.ExecuteAction; 35 36 import org.netbeans.junit.NbTestSuite; 37 38 39 40 import org.netbeans.jemmy.Waiter; 41 42 import org.netbeans.web.test.nodes.JSPNode; 43 import org.netbeans.web.test.nodes.ServletNode; 44 import org.netbeans.test.gui.web.util.JSPServletResponseWaitable; 45 import org.netbeans.test.gui.web.util.HttpRequestWaitable; 46 import org.netbeans.test.gui.web.util.BrowserUtils; 47 48 49 50 import org.netbeans.jemmy.operators.JTextFieldOperator; 51 import org.netbeans.jemmy.operators.JTextComponentOperator; 52 53 public class ExecuteSwingBrowser extends JellyTestCase { 54 private static String workDir = null; 55 private static String webModule = null; 56 private static String wmName = "wm1"; 57 private static String fSep = System.getProperty("file.separator"); 58 private static String iSep = "|"; 59 private static String classes = "Classes"; 60 private static String servletForExecution = "ServletForExecution"; 61 private static String htmlForExecution = null;; 62 private static String wmForExecution = "wmForExecution"; 63 private static String urlToRedirectFromHTML = "RedirectFromHtmlForExecution.html"; 64 private static String jspForExecution = null; 65 private static String pkg = "execution"; 66 private static ExplorerOperator explorer = null; 67 private String servletId = "cebde3e2-e8f1-4421-8a1c-df11dcc6e79a"; 68 private String jspId = "c78eae2b-39f2-4b41-b2be-032e5373d7f4"; 69 private String wmId = "9bc4ac0b-0a21-452a-9e51-ca9df3c2fa04"; 70 private int defaultPort = 1357; 71 private int port = 2468; 72 private String defaultAnswer = "HTTP/1.0 200 OK\nServer: FFJ Automated Tests SimpleServ\nLast-Modified: Fri, 12 Jul 2002 09:53:56 GMT\nContent-Length: 281\nConnection: close\nContent-Type: text/html\n\n<html>\n<head>\n <title>Tests passed</title>\n</head>\n<body>\n<center><H1>Request Accepted</H1></center>\n</body>\n</html>"; 73 74 75 76 public ExecuteSwingBrowser(java.lang.String testName) { 77 super(testName); 78 } 79 80 public static void main(java.lang.String [] args) { 81 junit.textui.TestRunner.run(suite()); 82 } 83 84 public static junit.framework.Test suite() { 86 workDir = System.getProperty("extbrowser.workdir").replace('/', fSep.charAt(0)); 87 webModule = workDir + fSep + wmName; 88 htmlForExecution = webModule + iSep + "html" + iSep + "HtmlFileForExecution"; 89 jspForExecution = webModule + iSep + "jsp" + iSep + "JSPForExecution"; 90 pkg = webModule + iSep + "WEB-INF" + iSep + classes + iSep + pkg; 91 return new NbTestSuite(ExecuteSwingBrowser.class); 92 } 93 94 public void testExecuteHtml() { 95 NbFrameOperator fo = null; 96 HTMLNode node1 = null; 97 BrowserUtils.setSwingBrowser(); 98 try { 99 node1 = new HTMLNode(htmlForExecution); 100 }catch(Exception e) { 101 fail("Not found: " + htmlForExecution); 102 } 103 new ExecuteAction().perform(node1); 104 BrowserUtils.handleSwingBrowserDialog(); 105 try { 106 fo = new NbFrameOperator("Web Browser"); 107 }catch(Exception e) { 108 e.printStackTrace(); 109 fail("Looks like browser not started."); 110 } 111 JTextFieldOperator tf = new JTextFieldOperator(fo,0); 112 if(tf.getText().indexOf("HtmlFileForExecution")==-1) { 113 fail("Wrong URL in SWING browser: " + tf.getText()); 114 } 115 JTextComponentOperator tf1 = new JTextComponentOperator(fo,0); 116 System.out.println("TEXTFIELD 1: " + tf1.getText()); 117 if(tf1.getText().indexOf("Html file executed correctly")==-1) { 118 fail("Wrong CONTENT shown in SWING browser: " + tf1.getText()); 119 } 120 } 121 122 public void testExecuteSevlet() { 123 ServletNode node1 = null; 124 BrowserUtils.setSwingBrowser(); 125 try { 126 node1 = new ServletNode(pkg + iSep + servletForExecution); 127 }catch(Exception e) { 128 fail("Not found: " + servletForExecution); 129 } 130 JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(servletId, defaultAnswer, port); 131 node1.execute(); 132 BrowserUtils.handleSwingBrowserDialog(); 133 Waiter w = new Waiter(jsrw); 134 try { 135 w.waitAction(jsrw); 136 } catch (Exception e) { 137 e.printStackTrace(); 138 fail("Looks like browser not started or URL not loaded"); 139 } 140 } 141 142 public void testExecuteJSP() { 143 JSPNode node1 = null; 144 BrowserUtils.setSwingBrowser(); 145 try { 146 node1 = new JSPNode(jspForExecution); 147 }catch(Exception e) { 148 fail("Not found: " + jspForExecution); 149 } 150 JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(jspId, defaultAnswer, port); 151 node1.execute(); 152 BrowserUtils.handleSwingBrowserDialog(); 153 Waiter w = new Waiter(jsrw); 154 try { 155 w.waitAction(jsrw); 156 } catch (Exception e) { 157 e.printStackTrace(); 158 fail("Looks like browser not started or URL not loaded"); 159 } 160 } 161 162 public void testExecuteWebModule() { 163 FolderNode node1 = null; 164 BrowserUtils.setSwingBrowser(); 165 try { 166 node1 = new FolderNode(workDir + fSep + wmForExecution + iSep + "WEB-INF"); 167 }catch(Exception e) { 168 fail("Web Module for execution not found"); 169 } 170 JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(wmId, defaultAnswer, port); 171 new ExecuteAction().perform(node1); 172 BrowserUtils.handleSwingBrowserDialog(); 173 Waiter w = new Waiter(jsrw); 174 try { 175 w.waitAction(jsrw); 176 } catch (Exception e) { 177 e.printStackTrace(); 178 fail("Looks like browser not started or URL not loaded"); 179 } 180 } 181 182 183 } 184 | Popular Tags |