001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.test.gui.web.extbrowser.execution;
043:
044: import org.netbeans.jellytools.JellyTestCase;
045: import org.netbeans.jellytools.Bundle;
046: import org.netbeans.jellytools.ExplorerOperator;
047:
048: import org.netbeans.jellytools.nodes.FolderNode;
049: import org.netbeans.jellytools.nodes.JavaNode;
050: import org.netbeans.jellytools.nodes.HTMLNode;
051:
052: import org.netbeans.jellytools.actions.ExecuteAction;
053:
054: import org.netbeans.junit.NbTestSuite;
055:
056: import org.netbeans.jemmy.Timeouts;
057: import org.netbeans.jemmy.Waiter;
058:
059: import org.netbeans.web.test.nodes.JSPNode;
060: import org.netbeans.web.test.nodes.ServletNode;
061: import org.netbeans.web.test.util.Utils;
062: import org.netbeans.test.gui.web.util.JSPServletResponseWaitable;
063: import org.netbeans.test.gui.web.util.HttpRequestWaitable;
064: import org.netbeans.test.gui.web.util.BrowserUtils;
065:
066: public class ExecuteExternalUnixBrowser extends JellyTestCase {
067: private static String workDir = null;
068: private static String webModule = null;
069: private static String wmName = "wm1";
070: private static String fSep = System.getProperty("file.separator");
071: private static String iSep = "|";
072: private static Timeouts tm = null;
073: private static boolean first = true;
074: private static String classes = "Classes";
075: private static String servletForExecution = "ServletForExecution";
076: private static String htmlForExecution = null;;
077: private static String wmForExecution = "wmForExecution";
078: private static String urlToRedirectFromHTML = "RedirectFromHtmlForExecution.html";
079: private static String jspForExecution = null;
080: private static String pkg = "execution";
081: private static ExplorerOperator explorer = null;
082: private String servletId = "cebde3e2-e8f1-4421-8a1c-df11dcc6e79a";
083: private String jspId = "c78eae2b-39f2-4b41-b2be-032e5373d7f4";
084: private String wmId = "9bc4ac0b-0a21-452a-9e51-ca9df3c2fa04";
085: private int defaultPort = 1357;
086: private int port = 2468;
087: 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>";
088:
089: public ExecuteExternalUnixBrowser(java.lang.String testName) {
090: super (testName);
091: }
092:
093: public static void main(java.lang.String[] args) {
094: junit.textui.TestRunner.run(suite());
095: }
096:
097: //method required by JUnit
098: public static junit.framework.Test suite() {
099: workDir = System.getProperty("extbrowser.workdir").replace('/',
100: fSep.charAt(0));
101: webModule = workDir + fSep + wmName;
102: htmlForExecution = webModule + iSep + "html" + iSep
103: + "HtmlFileForExecution";
104: jspForExecution = webModule + iSep + "jsp" + iSep
105: + "JSPForExecution";
106: pkg = webModule + iSep + "WEB-INF" + iSep + classes + iSep
107: + pkg;
108: String wmc = System.getProperty("extbrowser.mountcount");
109: int count = 0;
110: if (wmc != null) {
111: count = new Integer(wmc).intValue();
112: }
113: if (first) {
114: while (count > 0) {
115: Utils.handleDialogAfterNewWebModule();
116: count--;
117: }
118: first = false;
119: }
120: tm = new Timeouts();
121: tm.initTimeout("Waiter.WaitingTime", 300000); //5 minutes
122:
123: BrowserUtils.setExternalUnixBrowser();
124: return new NbTestSuite(ExecuteExternalUnixBrowser.class);
125: }
126:
127: public void testExecuteHtml() {
128: HTMLNode node1 = null;
129:
130: try {
131: node1 = new HTMLNode(htmlForExecution);
132: } catch (Exception e) {
133: fail("Not found: " + htmlForExecution);
134: }
135: new ExecuteAction().perform(node1);
136: HttpRequestWaitable hrw = new HttpRequestWaitable(
137: urlToRedirectFromHTML, defaultAnswer, defaultPort);
138: Waiter w = new Waiter(hrw);
139: w.setTimeouts(tm);
140: try {
141: w.waitAction(hrw);
142: } catch (Exception e) {
143: e.printStackTrace();
144: fail("Looks like browser not started or URL not loaded");
145: }
146: }
147:
148: public void testExecuteSevlet() {
149: ServletNode node1 = null;
150: try {
151: node1 = new ServletNode(pkg + iSep + servletForExecution);
152: } catch (Exception e) {
153: fail("Not found: " + servletForExecution);
154: }
155: node1.execute();
156: JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(
157: servletId, defaultAnswer, port);
158: Waiter w = new Waiter(jsrw);
159: w.setTimeouts(tm);
160: try {
161: w.waitAction(jsrw);
162: } catch (Exception e) {
163: e.printStackTrace();
164: fail("Looks like browser not started or URL not loaded");
165: }
166: }
167:
168: public void testExecuteJSP() {
169: JSPNode node1 = null;
170: try {
171: node1 = new JSPNode(jspForExecution);
172: } catch (Exception e) {
173: fail("Not found: " + jspForExecution);
174: }
175: node1.execute();
176: JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(
177: jspId, defaultAnswer, port);
178: Waiter w = new Waiter(jsrw);
179: w.setTimeouts(tm);
180: try {
181: w.waitAction(jsrw);
182: } catch (Exception e) {
183: e.printStackTrace();
184: fail("Looks like browser not started or URL not loaded");
185: }
186: }
187:
188: public void testExecuteWebModule() {
189: FolderNode node1 = null;
190: try {
191: node1 = new FolderNode(workDir + fSep + wmForExecution
192: + iSep + "WEB-INF");
193: } catch (Exception e) {
194: fail("Web Module for execution not found");
195: }
196: new ExecuteAction().perform(node1);
197: JSPServletResponseWaitable jsrw = new JSPServletResponseWaitable(
198: wmId, defaultAnswer, port);
199: Waiter w = new Waiter(jsrw);
200: w.setTimeouts(tm);
201: try {
202: w.waitAction(jsrw);
203: } catch (Exception e) {
204: e.printStackTrace();
205: fail("Looks like browser not started or URL not loaded");
206: }
207: }
208:
209: }
|