001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2008 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: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2007 Sun Microsystems, Inc.
038: */
039: package org.netbeans.modules.ws.qaf;
040:
041: import java.io.BufferedOutputStream;
042: import java.io.File;
043: import java.io.FileOutputStream;
044: import java.io.IOException;
045: import java.io.OutputStream;
046: import org.netbeans.api.project.Project;
047: import org.netbeans.api.project.ProjectManager;
048: import org.netbeans.jellytools.Bundle;
049: import org.netbeans.jellytools.JellyTestCase;
050: import org.netbeans.jellytools.NbDialogOperator;
051: import org.netbeans.jellytools.NewFileWizardOperator;
052: import org.netbeans.jellytools.NewProjectNameLocationStepOperator;
053: import org.netbeans.jellytools.NewProjectWizardOperator;
054: import org.netbeans.jellytools.OutputOperator;
055: import org.netbeans.jellytools.OutputTabOperator;
056: import org.netbeans.jellytools.ProjectsTabOperator;
057: import org.netbeans.jellytools.actions.Action;
058: import org.netbeans.jellytools.modules.j2ee.nodes.J2eeServerNode;
059: import org.netbeans.jellytools.nodes.Node;
060: import org.netbeans.jellytools.nodes.ProjectRootNode;
061: import org.netbeans.jemmy.EventTool;
062: import org.netbeans.jemmy.JemmyProperties;
063: import org.netbeans.jemmy.TimeoutExpiredException;
064: import org.netbeans.jemmy.operators.JComboBoxOperator;
065: import org.netbeans.jemmy.operators.JDialogOperator;
066: import org.netbeans.jemmy.operators.JTabbedPaneOperator;
067: import org.netbeans.jemmy.operators.JTreeOperator;
068: import org.netbeans.jemmy.operators.Operator;
069: import org.netbeans.junit.ide.ProjectSupport;
070: import org.openide.filesystems.FileObject;
071: import org.openide.filesystems.FileUtil;
072:
073: /**
074: * Base class for web services UI tests
075: * @author lukas
076: */
077: public abstract class WebServicesTestBase extends JellyTestCase {
078:
079: protected static final ServerType REGISTERED_SERVER;
080: private Project project;
081: private String projectName;
082: private ProjectType projectType;
083: private JavaEEVersion javaEEversion;
084:
085: static {
086: //First found server will be used by tests
087: if (ServerType.GLASSFISH.isAutoRegistered()) {
088: REGISTERED_SERVER = ServerType.GLASSFISH;
089: } else if (ServerType.TOMCAT.isAutoRegistered()) {
090: REGISTERED_SERVER = ServerType.TOMCAT;
091: } else if (ServerType.JBOSS.isAutoRegistered()) {
092: REGISTERED_SERVER = ServerType.JBOSS;
093: } else {
094: REGISTERED_SERVER = null;
095: }
096: }
097:
098: /**
099: * Enum type to hold project specific settings (like ie. project category
100: * label, project template name, etc.)
101: */
102: protected enum ProjectType {
103:
104: JAVASE_APPLICATION, WEB, EJB, APPCLIENT, SAMPLE;
105:
106: /**
107: * Get project template category name
108: *
109: * @return category name
110: */
111: public String getCategory() {
112: switch (this ) {
113: case JAVASE_APPLICATION:
114: //Java
115: return Bundle
116: .getStringTrimmed(
117: "org.netbeans.modules.java.j2seproject.ui.wizards.Bundle",
118: "Templates/Project/Standard");
119: case WEB:
120: //Web
121: return Bundle
122: .getStringTrimmed(
123: "org.netbeans.modules.web.project.ui.wizards.Bundle",
124: "Templates/Project/Web");
125: case EJB:
126: case APPCLIENT:
127: //Enterprise
128: return Bundle
129: .getStringTrimmed(
130: "org.netbeans.modules.j2ee.ejbjarproject.ui.wizards.Bundle",
131: "Templates/Project/J2EE");
132: case SAMPLE:
133: //Samples
134: return Bundle.getStringTrimmed(
135: "org.netbeans.modules.project.ui.Bundle",
136: "Templates/Project/Samples");
137: }
138: throw new AssertionError("Unknown type: " + this ); //NOI18N
139: }
140:
141: /**
142: * Get project template project type name
143: *
144: * @return project type name
145: */
146: public String getProjectTypeName() {
147: switch (this ) {
148: case JAVASE_APPLICATION:
149: //Java Application
150: return Bundle
151: .getStringTrimmed(
152: "org.netbeans.modules.java.j2seproject.ui.wizards.Bundle",
153: "Templates/Project/Standard/emptyJ2SE.xml");
154: case WEB:
155: //Web Application
156: return Bundle
157: .getStringTrimmed(
158: "org.netbeans.modules.web.project.ui.wizards.Bundle",
159: "Templates/Project/Web/emptyWeb.xml");
160: case EJB:
161: //EJB Module
162: return Bundle
163: .getStringTrimmed(
164: "org.netbeans.modules.j2ee.ejbjarproject.ui.wizards.Bundle",
165: "Templates/Project/J2EE/emptyEjbJar.xml");
166: case APPCLIENT:
167: //Enterprise Application Client
168: return Bundle
169: .getStringTrimmed(
170: "org.netbeans.modules.j2ee.clientproject.ui.wizards.Bundle",
171: "Templates/Project/J2EE/emptyCar.xml");
172: }
173: throw new AssertionError("Unknown type: " + this ); //NOI18N
174: }
175:
176: /**
177: * Get index of Server JComboBox in new project wizard
178: *
179: * @return index of Server JComboBox or -1 if there's none
180: */
181: public int getServerComboBoxIndex() {
182: switch (this ) {
183: case JAVASE_APPLICATION:
184: return -1;
185: case WEB:
186: case EJB:
187: return 1;
188: case APPCLIENT:
189: return 0;
190: }
191: throw new AssertionError("Unknown type: " + this ); //NOI18N
192: }
193:
194: /**
195: * Get index of Java EE version JComboBox in new project wizard
196: *
197: * @return index of Java EE version JComboBox or -1 if there's none
198: */
199: public int getServerVersionComboBoxIndex() {
200: switch (this ) {
201: case JAVASE_APPLICATION:
202: return -1;
203: case WEB:
204: case APPCLIENT:
205: return 2;
206: case EJB:
207: return 0;
208: }
209: throw new AssertionError("Unknown type: " + this ); //NOI18N
210: }
211: }
212:
213: /**
214: * Enum type to hold supported JavaEE versions
215: */
216: protected enum JavaEEVersion {
217:
218: J2EE14, JAVAEE5;
219:
220: @Override
221: public String toString() {
222: switch (this ) {
223: case J2EE14:
224: //J2EE 1.4
225: return Bundle
226: .getStringTrimmed(
227: "org.netbeans.modules.web.project.ui.wizards.Bundle",
228: "J2EESpecLevel_14");
229: case JAVAEE5:
230: //Java EE 5
231: return Bundle
232: .getStringTrimmed(
233: "org.netbeans.modules.web.project.ui.wizards.Bundle",
234: "JavaEESpecLevel_50");
235: }
236: throw new AssertionError("Unknown type: " + this ); //NOI18N
237: }
238: }
239:
240: /**
241: * Enum type to hold supported servers
242: */
243: protected enum ServerType {
244:
245: SJSAS, GLASSFISH, TOMCAT, JBOSS;
246:
247: @Override
248: public String toString() {
249: switch (this ) {
250: case SJSAS:
251: //Sun Java System Application Server
252: return Bundle.getStringTrimmed(
253: "org.netbeans.modules.j2ee.sun.ide.dm.Bundle",
254: "FACTORY_DISPLAYNAME");
255: case GLASSFISH:
256: //GlassFish V2
257: String label = Bundle
258: .getStringTrimmed(
259: "org.netbeans.modules.j2ee.sun.ide.j2ee.Bundle",
260: "LBL_GLASSFISH_V2");
261: //Need only "GlassFish" to be able to handle both versions (v1, v2)
262: return label.substring(0, label.length() - 3);
263: case TOMCAT:
264: //Tomcat
265: return Bundle.getStringTrimmed(
266: "org.netbeans.modules.tomcat5.util.Bundle",
267: "LBL_DefaultDisplayName");
268: case JBOSS:
269: //JBoss Application Server
270: return Bundle.getStringTrimmed(
271: "org.netbeans.modules.j2ee.jboss4.Bundle",
272: "SERVER_NAME");
273: }
274: throw new AssertionError("Unknown type: " + this ); //NOI18N
275: }
276:
277: /**
278: * Check if given server is present in the IDE
279: *
280: * @return true if server is registered in the IDE, false otherwise
281: */
282: public boolean isAutoRegistered() {
283: switch (this ) {
284: case SJSAS:
285: case GLASSFISH:
286: return System.getProperty("com.sun.aas.installRoot") != null; //NOI18N
287: case TOMCAT:
288: return System
289: .getProperty("org.netbeans.modules.tomcat.autoregister.catalinaHome") != null; //NOI18N
290: case JBOSS:
291: return System
292: .getProperty("org.netbeans.modules.j2ee.jboss4.installRoot") != null; //NOI18N
293: }
294: throw new AssertionError("Unknown type: " + this ); //NOI18N
295: }
296: }
297:
298: /**
299: * Default constructor.
300: *
301: * @param testName name of particular test case
302: */
303: public WebServicesTestBase(String name) {
304: super (name);
305: setProjectName(getProjectName());
306: setProjectType(getProjectType());
307: setJavaEEversion(getJavaEEversion());
308: }
309:
310: /**
311: * Get the name of the project to be used by test case
312: *
313: * @return name of the project
314: */
315: protected abstract String getProjectName();
316:
317: /**
318: * Get the name of the sample project's category (ie. Web Services)
319: *
320: * @return name of the project
321: */
322: protected String getSamplesCategoryName() {
323: return "";
324: }
325:
326: /**
327: * Get a Project instance used by test case
328: *
329: * @return a Project instance
330: */
331: protected Project getProject() {
332: return project;
333: }
334:
335: /**
336: * Get <code>Node</code> for the project used by test case
337: *
338: * @return an instance of <code>ProjectRootNode</code>
339: */
340: protected ProjectRootNode getProjectRootNode() {
341: return ProjectsTabOperator.invoke().getProjectRootNode(
342: getProjectName());
343: }
344:
345: /**
346: * Java EE version set for test case, JavaEEVersion.JAVAEE5
347: * is used by default
348: * Override this method to use different Java EE version
349: *
350: * @return Java EE version set for test case
351: */
352: protected JavaEEVersion getJavaEEversion() {
353: return JavaEEVersion.JAVAEE5;
354: }
355:
356: /**
357: * Project type set for test case, ProjectType.WEB is used by default
358: * Override this method to use different ProjectType
359: *
360: * @return ProjectType set for test case
361: */
362: protected ProjectType getProjectType() {
363: return ProjectType.WEB;
364: }
365:
366: /**
367: * Method responsible for checking and setting up environment for particular
368: * test case, mainly for setting up project to be used by test case.<br/>
369: *
370: * Following logic is used for setting up a project (Note that
371: * <code>getProjectName()</code> method is used for getting correct project
372: * name):<br/>
373: * <ol>
374: * <li>look for a project in <i>projects</i> directory in data directory
375: * and if project is found there then open it in the IDE
376: * </li>
377: * <li>look for a project in <code>System.getProperty("xtest.tmpdir")</code>
378: * (if test is run by <i>XTest</i>) or
379: * in <code>System.getProperty("java.io.tmpdir")</code> directory
380: * (if internal execution is used), if project is found then open it
381: * in the IDE</li>
382: * <li>if project is not found then it will be created from scratch</li>
383: * </ol>
384: *
385: * @throws java.lang.Exception
386: */
387: @Override
388: public void setUp() throws Exception {
389: super .setUp();
390: assertNotNull("No server has been found", REGISTERED_SERVER); //NOI18N
391: if (!ProjectType.SAMPLE.equals(getProjectType())) {
392: if (ServerType.TOMCAT.equals(REGISTERED_SERVER)
393: && !ProjectType.WEB.equals(getProjectType())
394: && !ProjectType.JAVASE_APPLICATION
395: .equals(getProjectType())) {
396: fail("Tomcat does not support: "
397: + getProjectType().getProjectTypeName() + "s."); //NOI18N
398: }
399: System.out.println("######## TestCase: " + getName()
400: + " #######"); //NOI18N
401: System.out.println("######## Server: "
402: + REGISTERED_SERVER.toString() + " #######"); //NOI18N
403: File projectRoot = new File(getDataDir(), "projects/"
404: + getProjectName()); //NOI18N
405: if (projectRoot.exists()) {
406: project = (Project) ProjectSupport
407: .openProject(new File(getDataDir(), "projects/"
408: + getProjectName()));
409: } else {
410: if (System.getProperty("xtest.tmpdir") != null) { //NOI18N
411: //XTest execution
412: projectRoot = new File(System
413: .getProperty("xtest.tmpdir"),
414: getProjectName()); //NOI18N
415: } else {
416: //Internal-execution
417: projectRoot = new File(System
418: .getProperty("java.io.tmpdir"),
419: getProjectName()); //NOI18N
420: }
421: if (!projectRoot.exists()) {
422: project = createProject(projectName,
423: getProjectType(), getJavaEEversion());
424: } else {
425: FileObject fo = FileUtil.toFileObject(FileUtil
426: .normalizeFile(projectRoot));
427: assertNotNull("FO cannot be null", fo); //NOI18N
428: project = ProjectManager.getDefault().findProject(
429: fo);
430: checkMissingServer(projectName);
431: }
432: }
433: assertNotNull("Project cannot be null!", project); //NOI18N
434: }
435: }
436:
437: @Override
438: public void tearDown() throws Exception {
439: super .tearDown();
440: project = null;
441: projectName = null;
442: }
443:
444: /**
445: * Start a server
446: */
447: public void testStartServer() throws IOException {
448: J2eeServerNode serverNode = J2eeServerNode
449: .invoke(REGISTERED_SERVER.toString());
450: serverNode.start();
451: dumpOutput();
452: }
453:
454: /**
455: * Stop a server
456: */
457: public void testStopServer() throws IOException {
458: J2eeServerNode serverNode = J2eeServerNode
459: .invoke(REGISTERED_SERVER.toString());
460: serverNode.stop();
461: new EventTool().waitNoEvent(2000);
462: dumpOutput();
463: }
464:
465: /**
466: * Helper method to be used by subclasses to create new project according
467: * to given parameters. Default server registered in the IDE will be used.
468: *
469: * @param name project or sample name
470: * @param type project type
471: * @param javaeeVersion server type, can be null
472: * @return created project
473: * @throws java.io.IOException
474: */
475: protected Project createProject(String name, ProjectType type,
476: JavaEEVersion javaeeVersion) throws IOException {
477: // project category & type selection step
478: NewProjectWizardOperator npwo = NewProjectWizardOperator
479: .invoke();
480: npwo.treeCategories().setComparator(
481: new Operator.DefaultStringComparator(true, true));
482: npwo.lstProjects().setComparator(
483: new Operator.DefaultStringComparator(true, true));
484: if (ProjectType.SAMPLE.equals(type)) {
485: npwo.selectCategory(type.getCategory() + "|"
486: + getSamplesCategoryName());
487: npwo.selectProject(name);
488: name = getProjectName();
489: } else {
490: npwo.selectCategory(type.getCategory());
491: npwo.selectProject(type.getProjectTypeName());
492: }
493: npwo.next();
494: // project name & location selection step
495: NewProjectNameLocationStepOperator op = new NewProjectNameLocationStepOperator();
496: op.txtProjectName().setText(name);
497: if (ProjectType.SAMPLE.equals(type)) {
498: op.txtLocation().setText(getWorkDirPath());
499: } else {
500: File projectLocation = null;
501: if (System.getProperty("xtest.tmpdir") != null) { //NOI18N
502: //XTest execution
503: projectLocation = new File(System
504: .getProperty("xtest.tmpdir")); //NOI18N
505: } else {
506: //Internal-execution
507: projectLocation = new File(System
508: .getProperty("java.io.tmpdir")); //NOI18N
509: }
510: op.txtProjectLocation().setText(
511: projectLocation.getAbsolutePath());
512: if (!ProjectType.JAVASE_APPLICATION.equals(type)) {
513: //choose server type and Java EE version
514: JComboBoxOperator jcboServer = new JComboBoxOperator(
515: op, type.getServerComboBoxIndex());
516: jcboServer.selectItem(REGISTERED_SERVER.toString());
517: JComboBoxOperator jcboVersion = new JComboBoxOperator(
518: op, type.getServerVersionComboBoxIndex());
519: jcboVersion.selectItem(javaeeVersion.toString());
520: }
521: }
522: if (!(ProjectType.SAMPLE.equals(type) || ProjectType.JAVASE_APPLICATION
523: .equals(type))) {
524: //second panel in Web, Ejb and Ear is now mandatory
525: op.next();
526: }
527: op.finish();
528: // Opening Projects
529: String openingProjectsTitle = Bundle.getStringTrimmed(
530: "org.netbeans.modules.project.ui.Bundle",
531: "LBL_Opening_Projects_Progress");
532: waitDialogClosed(openingProjectsTitle);
533: if (ProjectType.SAMPLE.equals(type)) {
534: checkMissingServer(projectName);
535: }
536: // wait project appear in projects view
537: ProjectRootNode node = ProjectsTabOperator.invoke()
538: .getProjectRootNode(name);
539: // wait classpath scanning finished
540: ProjectSupport.waitScanFinished();
541: // get a project instance to return
542: Project p = ((org.openide.nodes.Node) node.getOpenideNode())
543: .getLookup().lookup(Project.class);
544: assertNotNull("Project instance has not been found", p);
545: return p;
546: }
547:
548: /**
549: * Helper method to be used by subclasses to create new file of given
550: * <code>fileType</code> from <i>Web Services</i> category
551: *
552: * @param p project where to create new file
553: * @param fileType file type name from web services category
554: */
555: protected void createNewWSFile(Project p, String fileType) {
556: // Web Services
557: String webServicesLabel = Bundle
558: .getStringTrimmed(
559: "org.netbeans.modules.websvc.core.client.wizard.Bundle",
560: "Templates/WebServices");
561: createNewFile(p, webServicesLabel, fileType);
562: }
563:
564: /**
565: * Helper method to be used by subclasses to create new file of given
566: * <code>fileType</code> from <code>fileCategory</code> category
567: *
568: * @param p project where to create new file
569: * @param fileType file type name from web services category
570: */
571: protected void createNewFile(Project p, String fileCategory,
572: String fileType) {
573: // file category & filetype selection step
574: NewFileWizardOperator nfwo = NewFileWizardOperator.invoke();
575: new EventTool().waitNoEvent(500);
576: nfwo.treeCategories().setComparator(
577: new Operator.DefaultStringComparator(true, true));
578: nfwo.lstFileTypes().setComparator(
579: new Operator.DefaultStringComparator(true, true));
580: nfwo.cboProject().selectItem(p.toString());
581: nfwo.selectCategory(fileCategory);
582: nfwo.selectFileType(fileType);
583: nfwo.next();
584: }
585:
586: /**
587: * Deploy a project
588: *
589: * @param projectName name of the project to be deployed
590: */
591: protected void deployProject(String projectName) throws IOException {
592: //Deploy
593: String deployProjectLabel = Bundle.getStringTrimmed(
594: "org.netbeans.modules.web.project.ui.Bundle",
595: "LBL_RedeployAction_Name");
596: performProjectAction(projectName, deployProjectLabel);
597: }
598:
599: /**
600: * Run a project
601: *
602: * @param projectName name of the project to be run
603: */
604: protected void runProject(String projectName) throws IOException {
605: //Run
606: String runLabel = Bundle.getStringTrimmed(
607: "org.netbeans.modules.java.j2seproject.ui.Bundle",
608: "LBL_RunAction_Name");
609: performProjectAction(projectName, runLabel);
610: }
611:
612: /**
613: * Undeploy a project
614: *
615: * @param projectName name of the project to be undeployed
616: */
617: protected void undeployProject(String projectName)
618: throws IOException {
619: J2eeServerNode serverNode = J2eeServerNode
620: .invoke(REGISTERED_SERVER.toString());
621: serverNode.expand();
622: //Applications
623: String applicationsLabel = Bundle
624: .getStringTrimmed(
625: "org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.Bundle",
626: "LBL_Applications");
627: //Web Applications
628: String webLabel = Bundle
629: .getStringTrimmed(
630: "org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.Bundle",
631: "LBL_WebModules");
632: //EJB Modules
633: String ejbLabel = Bundle
634: .getStringTrimmed(
635: "org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.Bundle",
636: "LBL_EjbModules");
637: //App Client Modules
638: String appclientLabel = Bundle
639: .getStringTrimmed(
640: "org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.Bundle",
641: "LBL_AppClientModules");
642: //Refresh
643: String refreshLabel = Bundle
644: .getStringTrimmed(
645: "org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.actions.Bundle",
646: "LBL_RefreshAction");
647: //Undeploy
648: String undeployLabel = Bundle
649: .getStringTrimmed(
650: "org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.Bundle",
651: "LBL_Undeploy");
652: Node appsNode = null;
653: switch (getProjectType()) {
654: case SAMPLE:
655: case WEB:
656: if (ServerType.TOMCAT.equals(REGISTERED_SERVER)) {
657: appsNode = new Node(serverNode, webLabel);
658: } else {
659: appsNode = new Node(serverNode, applicationsLabel + "|"
660: + webLabel);
661: }
662: break;
663: case EJB:
664: appsNode = new Node(serverNode, applicationsLabel + "|"
665: + ejbLabel);
666: break;
667: case APPCLIENT:
668: appsNode = new Node(serverNode, applicationsLabel + "|"
669: + appclientLabel);
670: break;
671: }
672: appsNode.expand();
673: appsNode.callPopup().pushMenu(refreshLabel);
674: if (appsNode.isChildPresent(projectName)) {
675: Node n = new Node(appsNode, projectName);
676: n.callPopup().pushMenu(undeployLabel);
677: new EventTool().waitNoEvent(2000);
678: }
679: appsNode.callPopup().pushMenu(refreshLabel);
680: new EventTool().waitNoEvent(2000);
681: dumpOutput();
682: }
683:
684: /**
685: * Save content of output tabs into test's working directory.
686: * Might be useful for diagnosing possible test failures
687: *
688: * @throws java.io.IOException
689: */
690: protected void dumpOutput() throws IOException {
691: OutputOperator oo = OutputOperator.invoke();
692: oo.requestFocus();
693: JTabbedPaneOperator jtpo = new JTabbedPaneOperator(oo);
694: for (int i = 0; i < jtpo.getTabCount(); i++) {
695: String tabTitle = jtpo.getTitleAt(i);
696: jtpo.selectPage(i);
697: OutputTabOperator oto = null;
698: if (tabTitle.indexOf("<html>") < 0) { //NOI18N
699: oto = new OutputTabOperator(tabTitle.trim());
700: } else {
701: oto = new OutputTabOperator(tabTitle.substring(9, 19)
702: .trim());
703: }
704: oto.requestFocus();
705: writeToFile(oto.getText(), new File(getWorkDir(), tabTitle
706: .trim().replace(' ', '_')
707: + ".txt")); //NOI18N
708: }
709: }
710:
711: /**
712: * Wait until dialog with title <code>dialogTitle</code> is closed
713: *
714: * @param dialogTitle title of the dialog to be closed
715: */
716: protected void waitDialogClosed(String dialogTitle) {
717: try {
718: // wait at most 60 second until progress dialog dismiss
719: JemmyProperties.setCurrentTimeout(
720: "ComponentOperator.WaitStateTimeout", 60000); //NOI18N
721: new NbDialogOperator(dialogTitle).waitClosed();
722: } catch (TimeoutExpiredException e) {
723: // ignore when progress dialog was closed before we started to wait for it
724: }
725: }
726:
727: private void performProjectAction(String projectName,
728: String actionName) throws IOException {
729: ProjectRootNode node = new ProjectsTabOperator()
730: .getProjectRootNode(projectName);
731: node.performPopupAction(actionName);
732: OutputTabOperator oto = new OutputTabOperator(projectName);
733: JemmyProperties.setCurrentTimeout(
734: "ComponentOperator.WaitStateTimeout", 300000); //NOI18N
735: oto.waitText("(total time: "); //NOI18N
736: dumpOutput();
737: assertTrue("Build failed", oto.getText().indexOf(
738: "BUILD SUCCESSFUL") > -1); //NOI18N
739: }
740:
741: private void setProjectName(String projectName) {
742: this .projectName = projectName;
743: }
744:
745: private void setJavaEEversion(JavaEEVersion javaEEversion) {
746: this .javaEEversion = javaEEversion;
747: }
748:
749: private void setProjectType(ProjectType projectType) {
750: this .projectType = projectType;
751: }
752:
753: /**
754: * Write given <code>text</code> into given <code>file</code>.
755: *
756: * @param text text to be written
757: * @param file file to be created
758: */
759: private void writeToFile(String text, File file) {
760: OutputStream os = null;
761: try {
762: os = new BufferedOutputStream(new FileOutputStream(file));
763: os.write(text.getBytes());
764: os.flush();
765: } catch (IOException ioe) {
766: } finally {
767: if (os != null) {
768: try {
769: os.close();
770: } catch (IOException ioe) {
771: }
772: }
773: }
774: }
775:
776: private void checkMissingServer(String project) {
777: // check missing target server dialog is shown
778: // "Open Project"
779: String openProjectTitle = Bundle.getString(
780: "org.netbeans.modules.j2ee.common.ui.Bundle",
781: "MSG_Broken_Server_Title");
782: boolean needToSetServer = false;
783: if (JDialogOperator.findJDialog(openProjectTitle, true, true) != null) {
784: new NbDialogOperator(openProjectTitle).close();
785: needToSetServer = true;
786: }
787: // Set as Main Project
788: String setAsMainProjectItem = Bundle.getStringTrimmed(
789: "org.netbeans.modules.project.ui.actions.Bundle",
790: "LBL_SetAsMainProjectAction_Name");
791: new Action(null, setAsMainProjectItem)
792: .perform(new ProjectsTabOperator()
793: .getProjectRootNode(project));
794: if (needToSetServer) {
795: // open project properties
796: ProjectsTabOperator.invoke().getProjectRootNode(project)
797: .properties();
798: // "Project Properties"
799: String projectPropertiesTitle = Bundle
800: .getStringTrimmed(
801: "org.netbeans.modules.web.project.ui.customizer.Bundle",
802: "LBL_Customizer_Title");
803: NbDialogOperator propertiesDialogOper = new NbDialogOperator(
804: projectPropertiesTitle);
805: // select "Run" category
806: new Node(new JTreeOperator(propertiesDialogOper), "Run")
807: .select();
808: // not display browser on run
809: // String displayBrowserLabel = Bundle.getStringTrimmed("org.netbeans.modules.web.project.ui.customizer.Bundle", "LBL_CustomizeRun_DisplayBrowser_JCheckBox");
810: // new JCheckBoxOperator(propertiesDialogOper, displayBrowserLabel).setSelected(false);
811: // set default server
812: new JComboBoxOperator(propertiesDialogOper)
813: .setSelectedIndex(0);
814: // confirm properties dialog
815: propertiesDialogOper.ok();
816: }
817: // if setting default server, it scans server jars; otherwise it continues immediatelly
818: ProjectSupport.waitScanFinished();
819: }
820: }
|