KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > projects > TestProjectUtils


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * TestProjectsUtils.java
22  *
23  * Created on July 22, 2004, 11:48 AM
24  */

25
26 package projects;
27
28 import org.netbeans.jellytools.EditorOperator;
29 import org.netbeans.jellytools.MainWindowOperator;
30 import org.netbeans.jellytools.NbDialogOperator;
31 import org.netbeans.jellytools.OutputTabOperator;
32 import org.netbeans.jellytools.ProjectsTabOperator;
33 import org.netbeans.jellytools.actions.ActionNoBlock;
34 import org.netbeans.jellytools.actions.BuildProjectAction;
35 import org.netbeans.jellytools.nodes.ProjectRootNode;
36 import org.netbeans.jemmy.EventTool;
37 import org.netbeans.jemmy.operators.JButtonOperator;
38 import org.netbeans.jemmy.operators.JFileChooserOperator;
39 import org.netbeans.jemmy.operators.JTabbedPaneOperator;
40 import org.netbeans.jemmy.operators.JTextFieldOperator;
41 import org.netbeans.jemmy.operators.JTreeOperator;
42
43 /**
44  *
45  */

46 public class TestProjectUtils {
47     
48     /** Creates a new instance of TestProjectsUtils */
49     public TestProjectUtils() {
50     }
51     
52     /**
53      * Verifies that project exists in Projects tab
54      * @param projName Name of the project
55      */

56     public static void verifyProjectExists(String JavaDoc projName) {
57         ProjectsTabOperator pto = new ProjectsTabOperator();
58         JTreeOperator tree = pto.tree();
59         ProjectRootNode prn = pto.getProjectRootNode(projName);
60         prn.select();
61         prn.expand();
62     }
63     
64     /**
65      * Verifies that main class was opened in editor
66      * @param mainClass Name of the main class (as shown in editor tab)
67      */

68     public static void verifyMainClassInEditor(String JavaDoc mainClass) {
69         EditorOperator eo = new EditorOperator(mainClass);
70     }
71     
72     /**
73      * Verifies that project can be built by action 'Build Project' on project root node
74      * @param projName Name of the project
75      */

76     public static void verifyProjectBuilds(String JavaDoc projName) {
77         
78         ProjectsTabOperator pto = new ProjectsTabOperator();
79         ProjectRootNode prn = pto.getProjectRootNode(projName);
80         
81         BuildProjectAction buildProjectAction = new BuildProjectAction();
82         buildProjectAction.perform(prn);
83         
84         MainWindowOperator mainWindow = MainWindowOperator.getDefault();
85         mainWindow.waitStatusText("Finished building");
86         
87         // Output should be checked for BUILD SUCCESSFUL but it is not opened by default, code upon is used insted
88
//OutputTabOperator outputOper = new OutputTabOperator(projName);
89
//outputOper.waitText("BUILD SUCCESSFUL");
90

91     }
92     
93     public static void verifyProjectRuns() {
94         
95     }
96     
97     public static void addLibrary(String JavaDoc name, String JavaDoc[] cpEntries, String JavaDoc[] srcEntries, String JavaDoc[] jdocEntries) {
98         
99         new ActionNoBlock("Tools|Library Manager", null).performMenu();
100         NbDialogOperator libManOper = new NbDialogOperator("Library Manager");
101         JButtonOperator newLibButtonOper = new JButtonOperator(libManOper, "New Library");
102         newLibButtonOper.push();
103         
104         NbDialogOperator newLibOper = new NbDialogOperator("New Library");
105         JTextFieldOperator jtfo = new JTextFieldOperator(newLibOper, 0);
106         jtfo.clearText();
107         jtfo.setText(name);
108         newLibOper.ok();
109         
110         // here I should select the created library in the tree?
111

112         JTabbedPaneOperator jtpo = new JTabbedPaneOperator(libManOper);
113         
114         jtpo.selectPage("Classpath"); // should be already selected, but just for sure
115
if (cpEntries != null || cpEntries.length > 0) {
116             JButtonOperator addJarButtonOper = new JButtonOperator(jtpo, "Add JAR/Folder");
117             for (int i = 0; i < cpEntries.length; i++) {
118                 addJarButtonOper.push();
119                 JFileChooserOperator jfco = new JFileChooserOperator();
120                 jfco.setSelectedFile(new java.io.File JavaDoc(cpEntries[i]));
121                 JButtonOperator confirmButton = new JButtonOperator(jfco, "Add JAR/Folder");
122                 confirmButton.push();
123             }
124         } else {
125             // missing cp entries must be handled, e.g. by throwing Exception
126
}
127         
128         if (srcEntries != null || srcEntries.length > 0) {
129             jtpo.selectPage("Sources");
130             JButtonOperator addJarButtonOper = new JButtonOperator(jtpo, "Add JAR/Folder");
131             for (int i = 0; i < srcEntries.length; i++) {
132                 addJarButtonOper.push();
133                 JFileChooserOperator jfco = new JFileChooserOperator();
134                 jfco.setSelectedFile(new java.io.File JavaDoc(srcEntries[i]));
135                 JButtonOperator confirmButton = new JButtonOperator(jfco, "Add JAR/Folder");
136                 confirmButton.push();
137             }
138         }
139         
140         if (jdocEntries != null || jdocEntries.length > 0) {
141             jtpo.selectPage("Javadoc");
142             JButtonOperator addZipButtonOper = new JButtonOperator(jtpo, "Add ZIP/Folder");
143             for (int i = 0; i < jdocEntries.length; i++) {
144                 addZipButtonOper.push();
145                 JFileChooserOperator jfco = new JFileChooserOperator();
146                 jfco.setSelectedFile(new java.io.File JavaDoc(jdocEntries[i]));
147                 JButtonOperator confirmButton = new JButtonOperator(jfco, "Add ZIP/Folder");
148                 confirmButton.push();
149             }
150         }
151         
152         libManOper.ok();
153         
154     }
155     
156     public static void addPlatform(String JavaDoc platName, String JavaDoc folderPath) {
157         
158         new ActionNoBlock("Tools|Java Platform Manager", null).performMenu();
159         NbDialogOperator platManOper = new NbDialogOperator("Java Platform Manager");
160         JButtonOperator addPlatformButtonOper = new JButtonOperator(platManOper, "Add Platform");
161         addPlatformButtonOper.push();
162         
163         JFileChooserOperator jfco = new JFileChooserOperator();
164         jfco.setSelectedFile(new java.io.File JavaDoc(folderPath));
165         
166         NbDialogOperator nbdo = new NbDialogOperator("Add Java Platform");
167         
168         // wait for button being enabled
169
JButtonOperator nextButton = new JButtonOperator(nbdo, "Next");
170         try { nextButton.waitComponentEnabled(); }
171             catch (InterruptedException JavaDoc ie) {}
172         nextButton.push();
173         
174         // wait for platform to be scanned
175
JButtonOperator finishButton = new JButtonOperator(nbdo, "Finish");
176         try { finishButton.waitComponentEnabled(); }
177             catch (InterruptedException JavaDoc ie) {}
178         // set name of the platform
179
JTextFieldOperator jtfo = new JTextFieldOperator(nbdo, 0);
180         jtfo.clearText();
181         jtfo.setText(platName);
182         
183         finishButton.push();
184         
185         platManOper.close();
186         
187     }
188     
189 }
190
Popular Tags