KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > action > OpenJ2EEFiles


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 package gui.action;
21
22 import java.util.HashMap JavaDoc;
23 import org.netbeans.jellytools.EditorOperator;
24 import org.netbeans.jellytools.ProjectsTabOperator;
25 import org.netbeans.jellytools.TopComponentOperator;
26 import org.netbeans.jellytools.actions.SaveAllAction;
27 import org.netbeans.jellytools.nodes.Node;
28 import org.netbeans.jellytools.nodes.ProjectRootNode;
29
30 import org.netbeans.jemmy.operators.ComponentOperator;
31 import org.netbeans.jemmy.operators.JPopupMenuOperator;
32 import org.netbeans.jemmy.operators.JTreeOperator;
33 import org.netbeans.jemmy.operators.Operator;
34 import org.netbeans.modules.editor.java.JavaKit;
35 import org.netbeans.modules.editor.options.BaseOptions;
36
37 /**
38  * Test of opening files.
39  *
40  * @author lmartinek@netbeans.org
41  */

42 public class OpenJ2EEFiles extends org.netbeans.performance.test.utilities.PerformanceTestCase {
43     
44     /** Node to be opened/edited */
45     public static Node openNode ;
46     
47     /** Folder with data */
48     public static String JavaDoc fileProject;
49     
50     /** Folder with data */
51     public static String JavaDoc filePath;
52     
53     /** Name of file to open */
54     public static String JavaDoc editorTitle;
55     
56     /** Menu item name that opens the editor */
57     public static String JavaDoc menuItem;
58     
59     protected static String JavaDoc OPEN = org.netbeans.jellytools.Bundle.getStringTrimmed("org/openide/actions/Bundle", "Open");
60     
61     protected static String JavaDoc EDIT = org.netbeans.jellytools.Bundle.getStringTrimmed("org/openide/actions/Bundle", "Edit");
62     
63     /**
64      * Creates a new instance of OpenFiles
65      * @param testName the name of the test
66      */

67     public OpenJ2EEFiles(String JavaDoc testName) {
68         super(testName);
69         expectedTime = WINDOW_OPEN;
70     }
71     
72     /**
73      * Creates a new instance of OpenFiles
74      * @param testName the name of the test
75      * @param performanceDataName measured values will be saved under this name
76      */

77     public OpenJ2EEFiles(String JavaDoc testName, String JavaDoc performanceDataName) {
78         super(testName, performanceDataName);
79         expectedTime = WINDOW_OPEN;
80     }
81     
82     public void testOpeningJava(){
83         WAIT_AFTER_OPEN = 4000;
84         //MEASURE_PAINT_NUMBER = 1;
85
setJavaEditorCaretFilteringOn();
86         fileProject = "TestApplication-EJBModule";
87         filePath = "Source Packages|test|TestSessionRemote.java";
88         editorTitle = "TestSessionRemote.java";
89         menuItem = OPEN;
90         repaintManager().setOnlyEditor(true);
91         doMeasurement();
92     }
93     
94     public void testOpeningSessionBean(){
95         WAIT_AFTER_OPEN = 4000;
96         //MEASURE_PAINT_NUMBER = 1;
97
setJavaEditorCaretFilteringOn();
98         fileProject = "TestApplication-EJBModule";
99         filePath = "Enterprise Beans|TestSessionSB";
100         editorTitle = "TestSessionBean.java";
101         menuItem = OPEN;
102         repaintManager().setOnlyEditor(true);
103         doMeasurement();
104     }
105
106     public void testOpeningEntityBean(){
107         WAIT_AFTER_OPEN = 4000;
108         //MEASURE_PAINT_NUMBER = 1;
109
setJavaEditorCaretFilteringOn();
110         fileProject = "TestApplication-EJBModule";
111         filePath = "Enterprise Beans|TestEntityEB";
112         editorTitle = "TestEntityBean.java";
113         menuItem = OPEN;
114         repaintManager().setOnlyEditor(true);
115         doMeasurement();
116     }
117     
118     public void testOpeningEjbJarXml(){
119         WAIT_AFTER_OPEN = 3000;
120         //MEASURE_PAINT_NUMBER = 1;
121
setJavaEditorCaretFilteringOn();
122         fileProject = "TestApplication-EJBModule";
123         filePath = "Configuration Files|ejb-jar.xml";
124         editorTitle = "ejb-jar.xml";
125         menuItem = OPEN;
126         repaintManager().setOnlyEditor(false);
127         doMeasurement();
128     }
129     
130     public void testOpeningSunEjbJarXml(){
131         WAIT_AFTER_OPEN = 3000;
132         //MEASURE_PAINT_NUMBER = 1;
133
setJavaEditorCaretFilteringOn();
134         fileProject = "TestApplication-EJBModule";
135         filePath = "Configuration Files|sun-ejb-jar.xml";
136         editorTitle = "sun-ejb-jar.xml";
137         menuItem = OPEN;
138         repaintManager().setOnlyEditor(false);
139         doMeasurement();
140     }
141
142     public void testOpeningApplicationXml(){
143         WAIT_AFTER_OPEN = 2000;
144         //MEASURE_PAINT_NUMBER = 1;
145
setJavaEditorCaretFilteringOn();
146         fileProject = "TestApplication";
147         filePath = "Configuration Files|application.xml";
148         editorTitle = "application.xml";
149         menuItem = EDIT;
150         repaintManager().setOnlyEditor(true);
151         doMeasurement();
152     }
153     
154     public void testOpeningSunApplicationXml(){
155         WAIT_AFTER_OPEN = 2000;
156         //MEASURE_PAINT_NUMBER = 1;
157
setJavaEditorCaretFilteringOn();
158         fileProject = "TestApplication";
159         filePath = "Configuration Files|sun-application.xml";
160         editorTitle = "sun-application.xml";
161         menuItem = OPEN;
162         repaintManager().setOnlyEditor(false);
163         doMeasurement();
164     }
165     
166     public void initialize(){
167         //repaintManager().setOnlyEditor(true);
168
EditorOperator.closeDiscardAll();
169         BaseOptions options = BaseOptions.getOptions(JavaKit.class);
170         options.setStatusBarCaretDelay(0);
171         HashMap JavaDoc props = new HashMap JavaDoc();
172         props.put(org.netbeans.editor.SettingsNames.CODE_FOLDING_ENABLE, Boolean.FALSE);
173         options.setCodeFoldingProps(props);
174         /* TODO doesn't work after retouche integration
175         JavaSettings java_settings = JavaSettings.getDefault();
176         java_settings.setShowOverriding(false);
177         java_settings.enableCompileStatus(false);
178          */

179     }
180
181     public void shutdown(){
182         repaintManager().setOnlyEditor(false);
183         EditorOperator.closeDiscardAll();
184     }
185     
186     public void prepare(){
187         JTreeOperator tree = new ProjectsTabOperator().tree();
188         tree.setComparator(new Operator.DefaultStringComparator(true, true));
189         this.openNode = new Node(new ProjectRootNode(tree, fileProject), filePath);
190         
191         if (this.openNode == null) {
192             throw new Error JavaDoc ("Cannot find node ["+ filePath + "] in project [" + fileProject + "]");
193         }
194         log("========== Open file path ="+this.openNode.getPath());
195     }
196     
197     public ComponentOperator open(){
198         JPopupMenuOperator popup = this.openNode.callPopup();
199         if (popup == null) {
200             throw new Error JavaDoc ("Cannot get context menu for node ["+ filePath + "] in project [" + fileProject + "]");
201         }
202         log("------------------------- after popup invocation ------------");
203         try {
204             popup.pushMenu(this.menuItem);
205         }
206         catch (org.netbeans.jemmy.TimeoutExpiredException tee) {
207             throw new Error JavaDoc ("Cannot push menu item "+this.menuItem+" of node ["+ filePath + "] in project [" + fileProject + "]");
208         }
209         log("------------------------- after open ------------");
210         return new TopComponentOperator(this.editorTitle);
211     }
212     
213     public void close(){
214         if (testedComponentOperator != null) {
215             // HACK
216
new SaveAllAction().performAPI();
217             ((TopComponentOperator)testedComponentOperator).close();
218             /*
219             if (getName().equals("testOpeningSunApplicationXml")) {
220                 ((TopComponentOperator)testedComponentOperator).close();
221             } else {
222                 ((TopComponentOperator)testedComponentOperator).closeDiscard();
223             }
224             */

225         }
226         else {
227             throw new Error JavaDoc ("no component to close");
228         }
229     }
230     
231 }
232
Popular Tags