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.web;
043:
044: import java.io.File;
045: import java.io.IOException;
046: import org.netbeans.jellytools.*;
047: import org.netbeans.jellytools.actions.ActionNoBlock;
048: import org.netbeans.jellytools.actions.EditAction;
049: import org.netbeans.jellytools.actions.NewProjectAction;
050: import org.netbeans.jellytools.modules.web.nodes.WebPagesNode;
051: import org.netbeans.jellytools.nodes.Node;
052: import org.netbeans.jellytools.nodes.SourcePackagesNode;
053: import org.netbeans.jemmy.EventTool;
054: import org.netbeans.jemmy.QueueTool;
055: import org.netbeans.jemmy.Timeouts;
056: import org.netbeans.jemmy.operators.*;
057: import org.netbeans.jemmy.util.PNGEncoder;
058: import org.netbeans.junit.NbTestSuite;
059: import org.netbeans.junit.ide.ProjectSupport;
060:
061: /**
062: *
063: * @author lm97939
064: */
065: public class WebProjectValidationNb36WebModule extends
066: WebProjectValidation {
067:
068: static {
069: PROJECT_NAME = "WebModuleNB36"; // NOI18N
070: PROJECT_FOLDER = PROJECT_LOCATION + File.separator
071: + PROJECT_NAME;
072: }
073:
074: /** Need to be defined because of JUnit */
075: public WebProjectValidationNb36WebModule(String name) {
076: super (name);
077: }
078:
079: /** Use for execution inside IDE */
080: public static void main(java.lang.String[] args) {
081: // run whole suite
082: junit.textui.TestRunner.run(suite());
083: // run only selected test case
084: //junit.textui.TestRunner.run(new MyModuleValidation("testT2"));
085: }
086:
087: public static NbTestSuite suite() {
088: NbTestSuite suite = new NbTestSuite();
089: suite.addTest(new WebProjectValidationNb36WebModule(
090: "testNewWebProject"));
091: suite.addTest(new WebProjectValidationNb36WebModule(
092: "testNewJSP"));
093: suite.addTest(new WebProjectValidationNb36WebModule(
094: "testNewJSP2"));
095: suite.addTest(new WebProjectValidationNb36WebModule(
096: "testNewServlet"));
097: suite.addTest(new WebProjectValidationNb36WebModule(
098: "testNewServlet2"));
099: suite.addTest(new WebProjectValidationNb36WebModule(
100: "testBuildProject"));
101: suite.addTest(new WebProjectValidationNb36WebModule(
102: "testCompileAllJSP"));
103: suite.addTest(new WebProjectValidationNb36WebModule(
104: "testCompileJSP"));
105: suite.addTest(new WebProjectValidationNb36WebModule(
106: "testCleanProject"));
107: suite.addTest(new WebProjectValidationNb36WebModule(
108: "testRunProject"));
109: suite.addTest(new WebProjectValidationNb36WebModule(
110: "testRunJSP"));
111: suite.addTest(new WebProjectValidationNb36WebModule(
112: "testRunServlet"));
113: suite.addTest(new WebProjectValidationNb36WebModule(
114: "testCreateTLD"));
115: suite.addTest(new WebProjectValidationNb36WebModule(
116: "testCreateTagHandler"));
117: suite.addTest(new WebProjectValidationNb36WebModule(
118: "testRunTag"));
119: suite.addTest(new WebProjectValidationNb36WebModule(
120: "testNewHTML"));
121: suite.addTest(new WebProjectValidationNb36WebModule(
122: "testRunHTML"));
123: suite.addTest(new WebProjectValidationNb36WebModule(
124: "testNewSegment"));
125: suite.addTest(new WebProjectValidationNb36WebModule(
126: "testNewDocument"));
127: suite.addTest(new WebProjectValidationNb36WebModule(
128: "testStopServer"));
129: suite.addTest(new WebProjectValidationNb36WebModule(
130: "testStartServer"));
131: suite.addTest(new WebProjectValidationNb36WebModule(
132: "testFinish"));
133:
134: return suite;
135: }
136:
137: /** Test creation of web application.
138: * - open New Project wizard from main menu (File|New Project)
139: * - select Web|Web Application
140: * - in the next panel type project name and project location
141: * - finish the wizard
142: * - wait until scanning of java files is finished
143: * - check index.jsp is opened
144: */
145: public void testNewWebProject() throws IOException {
146: installJemmyQueue();
147: new NewProjectAction().perform();
148: NewProjectWizardOperator projectWizard = new NewProjectWizardOperator();
149: projectWizard.selectCategory("Web");
150: projectWizard
151: .selectProject("Web Application with Existing Sources");
152: projectWizard.next();
153: NewWebProjectNameLocationStepOperator nameStep = new NewWebProjectNameLocationStepOperator();
154: nameStep.txtLocation().setText(
155: getDataDir().getAbsolutePath() + File.separator
156: + PROJECT_NAME);
157: nameStep.txtProjectName().setText(PROJECT_NAME);
158: nameStep.txtProjectFolder().setText(
159: System.getProperty("xtest.data") + File.separator
160: + PROJECT_NAME + "Prj");
161: nameStep.next();
162: NewWebProjectSourcesStepOperator srcStep = new NewWebProjectSourcesStepOperator();
163: srcStep.finish();
164: Timeouts timeouts = nameStep.getTimeouts().cloneThis();
165: srcStep.getTimeouts().setTimeout(
166: "ComponentOperator.WaitStateTimeout", 90000);
167: srcStep.waitClosed();
168: srcStep.setTimeouts(timeouts);
169: sleep(5000);
170: // wait for project creation
171: ProjectSupport.waitScanFinished();
172: //new EditorWindowOperator().getEditor("index.jsp");
173: // HACK
174: Node prjNode = ProjectsTabOperator.invoke().getProjectRootNode(
175: PROJECT_NAME);
176: new Node(prjNode, "Configuration Files|web.xml");
177: new Node(prjNode, "Web Pages|META-INF|context.xml");
178: new Node(new SourcePackagesNode(PROJECT_NAME),
179: "<default package>|dummy");
180: ref(Util.dumpProjectView(PROJECT_NAME));
181: compareReferenceFiles();
182: //compareDD();
183: }
184:
185: /** Test new JSP wizard.
186: * - open New File wizard from main menu (File|New File)
187: * - select sample project as target
188: * - select Web|JSP file type
189: * - in the next panel type name
190: * - finish the wizard
191: * - check file is open in editor and close all opened documents
192: */
193: public void testNewJSP() throws IOException {
194: // workaround due to issue #46073
195: new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME)
196: .select();
197:
198: new ActionNoBlock("File|New File", null).perform();
199: // WORKAROUND
200: new EventTool().waitNoEvent(1000);
201: WizardOperator newFileWizard = new WizardOperator("New File");
202: new JComboBoxOperator(newFileWizard).selectItem(PROJECT_NAME);
203: new Node(new JTreeOperator(newFileWizard), "Web").select();
204: new JListOperator(newFileWizard, 1).selectItem("JSP");
205: newFileWizard.next();
206: JTextFieldOperator txtPackageName = new JTextFieldOperator(
207: newFileWizard);
208: // clear text field
209: //XXX <workaround issue='#61034 - wrond default destination'>
210: txtPackageName.setText("index1");
211: JTextFieldOperator txtProjectFolder = new JTextFieldOperator(
212: newFileWizard, 2);
213: txtProjectFolder.setText("");
214: //</workaround>
215: newFileWizard.finish();
216: // check class is opened in Editor and then close it
217: new EditorOperator("index1.jsp").close();
218: ref(Util.dumpProjectView(PROJECT_NAME));
219: new Node(new ProjectsTabOperator()
220: .getProjectRootNode(PROJECT_NAME),
221: "Web Pages|index1.jsp");
222: //compareReferenceFiles();
223: //compareDD();
224: }
225:
226: public void testCreateTLD() {
227: //HACK
228: new Node(new ProjectsTabOperator()
229: .getProjectRootNode(PROJECT_NAME), "WEB-INF").expand();
230:
231: // workaround due to issue #46073
232: new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME)
233: .select();
234:
235: new ActionNoBlock("File|New File", null).perform();
236: // WORKAROUND
237: new EventTool().waitNoEvent(1000);
238: WizardOperator newFileWizard = new WizardOperator("New File");
239: new JComboBoxOperator(newFileWizard).selectItem(PROJECT_NAME);
240: new Node(new JTreeOperator(newFileWizard), "Web").select();
241: new JListOperator(newFileWizard, 1)
242: .selectItem("Tag Library Descriptor");
243: newFileWizard.next();
244: JTextFieldOperator txtName = new JTextFieldOperator(
245: newFileWizard);
246: // clear text field
247: txtName.setText("");
248: txtName.typeText("MyTags");
249: newFileWizard.finish();
250: //XXX try { Thread.currentThread().sleep(5000); } catch (InterruptedException e) {}
251: //XXX HACK #48865
252: new Node(new ProjectsTabOperator()
253: .getProjectRootNode(PROJECT_NAME),
254: "Web|WEB-INF|tlds|MyTags.tld");
255: // check class is opened in Editor and then close it
256: new EditorOperator("MyTags.tld").close();
257: ref(Util.dumpProjectView(PROJECT_NAME));
258: //compareReferenceFiles();
259: }
260:
261: public void testNewServlet() throws IOException {
262: // create a new package
263: new ActionNoBlock("File|New File", null).perform();
264: // WORKAROUND
265: new EventTool().waitNoEvent(1000);
266: WizardOperator newFileWizard = new WizardOperator("New File");
267: new JComboBoxOperator(newFileWizard).selectItem(PROJECT_NAME);
268: new Node(new JTreeOperator(newFileWizard), "Web").select();
269: new JListOperator(newFileWizard, 1).selectItem("Servlet");
270: newFileWizard.next();
271: JTextFieldOperator txtPackageName = new JTextFieldOperator(
272: newFileWizard);
273: // clear text field
274: txtPackageName.setText("");
275: txtPackageName.typeText("Servlet1");
276: JComboBoxOperator txtPackage = new JComboBoxOperator(
277: newFileWizard, 1);
278: // clear text field
279: txtPackage.clearText();
280: txtPackage.typeText("test1");
281: newFileWizard.next();
282: newFileWizard.finish();
283: // check class is opened in Editor and close it
284: new EditorOperator("Servlet1.java").close();
285: // check the servlet is specified in web.xml
286: Node rootNode = new ProjectsTabOperator()
287: .getProjectRootNode(PROJECT_NAME);
288: rootNode.setComparator(new Operator.DefaultStringComparator(
289: true, true));
290: Node webXml = new Node(rootNode, "WEB-INF|web.xml");
291: new EditAction().performPopup(webXml);
292: String xmlText = new EditorOperator("web.xml").getText();
293: new EditorOperator("web.xml").closeAllDocuments();
294: String[] content = new String[] {
295: "<servlet-name>Servlet1</servlet-name>",
296: "<servlet-class>test1.Servlet1</servlet-class>",
297: "<url-pattern>/Servlet1</url-pattern>" };
298: for (int i = 0; i < content.length; i++) {
299: assertTrue("Servlet is not correctly specifeid in web.xml."
300: + " Following line is missing in the web.xml:\n"
301: + content[i], xmlText.indexOf(content[i]) != -1);
302: }
303: ref(Util.dumpProjectView(PROJECT_NAME));
304: //compareReferenceFiles();
305: //compareDD();
306: }
307:
308: }
|