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: /*
043: * TestProjectsUtils.java
044: *
045: * Created on July 22, 2004, 11:48 AM
046: */
047:
048: package projects;
049:
050: import org.netbeans.jellytools.EditorOperator;
051: import org.netbeans.jellytools.MainWindowOperator;
052: import org.netbeans.jellytools.NbDialogOperator;
053: import org.netbeans.jellytools.ProjectsTabOperator;
054: import org.netbeans.jellytools.actions.ActionNoBlock;
055: import org.netbeans.jellytools.actions.BuildProjectAction;
056: import org.netbeans.jellytools.nodes.ProjectRootNode;
057: import org.netbeans.jemmy.operators.JButtonOperator;
058: import org.netbeans.jemmy.operators.JFileChooserOperator;
059: import org.netbeans.jemmy.operators.JTabbedPaneOperator;
060: import org.netbeans.jemmy.operators.JTextFieldOperator;
061: import org.netbeans.jemmy.operators.JTreeOperator;
062:
063: /**
064: *
065: */
066: public class TestProjectUtils {
067:
068: /**
069: * Verifies that project exists in Projects tab
070: * @param projName Name of the project
071: */
072: public static void verifyProjectExists(String projName) {
073: ProjectsTabOperator pto = new ProjectsTabOperator();
074: JTreeOperator tree = pto.tree();
075: ProjectRootNode prn = pto.getProjectRootNode(projName);
076: prn.select();
077: prn.expand();
078: }
079:
080: /**
081: * Verifies that main class was opened in editor
082: * @param mainClass Name of the main class (as shown in editor tab)
083: */
084: public static void verifyMainClassInEditor(String mainClass) {
085: EditorOperator eo = new EditorOperator(mainClass);
086: }
087:
088: /**
089: * Verifies that project can be built by action 'Build Project' on project root node
090: * @param projName Name of the project
091: */
092: public static void verifyProjectBuilds(String projName) {
093:
094: ProjectsTabOperator pto = new ProjectsTabOperator();
095: ProjectRootNode prn = pto.getProjectRootNode(projName);
096:
097: BuildProjectAction buildProjectAction = new BuildProjectAction();
098: buildProjectAction.perform(prn);
099:
100: MainWindowOperator mainWindow = MainWindowOperator.getDefault();
101: mainWindow.waitStatusText("Finished building");
102:
103: // Output should be checked for BUILD SUCCESSFUL but it is not opened by default, code upon is used insted
104: //OutputTabOperator outputOper = new OutputTabOperator(projName);
105: //outputOper.waitText("BUILD SUCCESSFUL");
106:
107: }
108:
109: public static void verifyProjectRuns() {
110:
111: }
112:
113: public static void addLibrary(String name, String[] cpEntries,
114: String[] srcEntries, String[] jdocEntries) {
115:
116: new ActionNoBlock("Tools|Library Manager", null).performMenu();
117: NbDialogOperator libManOper = new NbDialogOperator(
118: "Library Manager");
119: JButtonOperator newLibButtonOper = new JButtonOperator(
120: libManOper, "New Library");
121: newLibButtonOper.push();
122:
123: NbDialogOperator newLibOper = new NbDialogOperator(
124: "New Library");
125: JTextFieldOperator jtfo = new JTextFieldOperator(newLibOper, 0);
126: jtfo.clearText();
127: jtfo.setText(name);
128: newLibOper.ok();
129:
130: // here I should select the created library in the tree?
131:
132: JTabbedPaneOperator jtpo = new JTabbedPaneOperator(libManOper);
133:
134: jtpo.selectPage("Classpath"); // should be already selected, but just for sure
135: if (cpEntries != null || cpEntries.length > 0) {
136: JButtonOperator addJarButtonOper = new JButtonOperator(
137: jtpo, "Add JAR/Folder");
138: for (int i = 0; i < cpEntries.length; i++) {
139: addJarButtonOper.push();
140: JFileChooserOperator jfco = new JFileChooserOperator();
141: jfco.setSelectedFile(new java.io.File(cpEntries[i]));
142: JButtonOperator confirmButton = new JButtonOperator(
143: jfco, "Add JAR/Folder");
144: confirmButton.push();
145: }
146: } else {
147: // missing cp entries must be handled, e.g. by throwing Exception
148: }
149:
150: if (srcEntries != null || srcEntries.length > 0) {
151: jtpo.selectPage("Sources");
152: JButtonOperator addJarButtonOper = new JButtonOperator(
153: jtpo, "Add JAR/Folder");
154: for (int i = 0; i < srcEntries.length; i++) {
155: addJarButtonOper.push();
156: JFileChooserOperator jfco = new JFileChooserOperator();
157: jfco.setSelectedFile(new java.io.File(srcEntries[i]));
158: JButtonOperator confirmButton = new JButtonOperator(
159: jfco, "Add JAR/Folder");
160: confirmButton.push();
161: }
162: }
163:
164: if (jdocEntries != null || jdocEntries.length > 0) {
165: jtpo.selectPage("Javadoc");
166: JButtonOperator addZipButtonOper = new JButtonOperator(
167: jtpo, "Add ZIP/Folder");
168: for (int i = 0; i < jdocEntries.length; i++) {
169: addZipButtonOper.push();
170: JFileChooserOperator jfco = new JFileChooserOperator();
171: jfco.setSelectedFile(new java.io.File(jdocEntries[i]));
172: JButtonOperator confirmButton = new JButtonOperator(
173: jfco, "Add ZIP/Folder");
174: confirmButton.push();
175: }
176: }
177:
178: libManOper.ok();
179:
180: }
181:
182: public static void addPlatform(String platName, String folderPath) {
183: if (folderPath == null) {
184: return;
185: }
186: new ActionNoBlock("Tools|Java Platforms", null).performMenu();
187: NbDialogOperator platManOper = new NbDialogOperator(
188: "Java Platform Manager");
189: JButtonOperator addPlatformButtonOper = new JButtonOperator(
190: platManOper, "Add Platform");
191: addPlatformButtonOper.push();
192:
193: JFileChooserOperator jfco = new JFileChooserOperator();
194: jfco.setSelectedFile(new java.io.File(folderPath));
195:
196: NbDialogOperator nbdo = new NbDialogOperator(
197: "Add Java Platform");
198:
199: // wait for button being enabled
200: JButtonOperator nextButton = new JButtonOperator(nbdo, "Next");
201: try {
202: nextButton.waitComponentEnabled();
203: } catch (InterruptedException ie) {
204: }
205: nextButton.push();
206:
207: // wait for platform to be scanned
208: JButtonOperator finishButton = new JButtonOperator(nbdo,
209: "Finish");
210: try {
211: finishButton.waitComponentEnabled();
212: } catch (InterruptedException ie) {
213: }
214: // set name of the platform
215: JTextFieldOperator jtfo = new JTextFieldOperator(nbdo, 0);
216: jtfo.clearText();
217: jtfo.setText(platName);
218:
219: finishButton.push();
220:
221: platManOper.close();
222:
223: }
224:
225: }
|