KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > action > OpenWebFiles


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 import org.netbeans.jellytools.EditorOperator;
22 import org.netbeans.jellytools.ProjectsTabOperator;
23 import org.netbeans.jellytools.nodes.Node;
24
25 import org.netbeans.jemmy.operators.ComponentOperator;
26 import org.netbeans.jemmy.operators.JPopupMenuOperator;
27 import org.netbeans.test.web.performance.WebPerformanceTestCase;
28
29 /**
30  * Test of opening files.
31  *
32  * @author mmirilovic@netbeans.org
33  */

34 public class OpenWebFiles extends WebPerformanceTestCase {
35     
36     /** Node to be opened/edited */
37     public static Node openNode ;
38     
39     /** Folder with data */
40     public static String JavaDoc fileProject;
41  
42     /** Folder with data */
43     public static String JavaDoc fileFolder;
44     
45     /** Name of file to open */
46     public static String JavaDoc fileName;
47     
48     /** Menu item name that opens the editor */
49     public static String JavaDoc menuItem;
50     
51     protected static String JavaDoc OPEN = "Open"; //NOI18N
52

53     protected static String JavaDoc EDIT = "Edit"; //NOI18N
54

55     protected static String JavaDoc WEB_PAGES = "Web Pages"; //NOI18N
56

57     private boolean wrappedEditorOperator = false;
58     
59     /**
60      * Creates a new instance of OpenFiles
61      * @param testName the name of the test
62      */

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

73     public OpenWebFiles(String JavaDoc testName, String JavaDoc performanceDataName) {
74         super(testName, performanceDataName);
75         expectedTime = WINDOW_OPEN;
76     }
77     
78     public void testOpeningWebXmlFile(){
79         WAIT_AFTER_OPEN = 3000;
80         repaintManager().setOnlyEditor(false);
81         setXMLEditorCaretFilteringOn();
82         fileProject = "TestWebProject";
83         fileFolder = "WEB-INF";
84         fileName = "web.xml";
85         menuItem = EDIT;
86         setWrappedClonableEditor(true);
87         doMeasurement();
88         setWrappedClonableEditor(false);
89     }
90
91     public void testOpeningContextXmlFile(){
92         WAIT_AFTER_OPEN = 3000;
93         repaintManager().setOnlyEditor(true);
94         setXMLEditorCaretFilteringOn();
95         fileProject = "TestWebProject";
96         fileFolder = "META-INF";
97         fileName = "context.xml";
98         menuItem = EDIT;
99         doMeasurement();
100     }
101
102     public void testOpeningJSPFile(){
103         WAIT_AFTER_OPEN = 3000;
104         repaintManager().setOnlyEditor(true);
105         setXMLEditorCaretFilteringOn();
106         fileProject = "TestWebProject";
107         fileFolder = "";
108         fileName = "Test.jsp";
109         menuItem = OPEN;
110         doMeasurement();
111     }
112
113     public void testOpeningBigJSPFile(){
114         WAIT_AFTER_OPEN = 3000;
115         repaintManager().setOnlyEditor(true);
116         setXMLEditorCaretFilteringOn();
117         fileProject = "TestWebProject";
118         fileFolder = "";
119         fileName = "BigJSP.jsp";
120         menuItem = OPEN;
121         doMeasurement();
122     }
123     
124     public void testOpeningHTMLFile(){
125         WAIT_AFTER_OPEN = 3000;
126         repaintManager().setOnlyEditor(true);
127         setXMLEditorCaretFilteringOn();
128         fileProject = "TestWebProject";
129         fileFolder = "";
130         fileName = "HTML.html";
131         menuItem = OPEN;
132         doMeasurement();
133     }
134
135     public void testOpeningTagFile(){
136         WAIT_AFTER_OPEN = 3000;
137         repaintManager().setOnlyEditor(true);
138         setXMLEditorCaretFilteringOn();
139         fileProject = "TestWebProject";
140         fileFolder = "WEB-INF|tags";
141         fileName = "mytag.tag";
142         menuItem = OPEN;
143         doMeasurement();
144     }
145
146     public void testOpeningTldFile(){
147         WAIT_AFTER_OPEN = 3000;
148         repaintManager().setOnlyEditor(true);
149         setXMLEditorCaretFilteringOn();
150         fileProject = "TestWebProject";
151         fileFolder = "WEB-INF";
152         fileName = "MyTLD.tld";
153         menuItem = OPEN;
154         doMeasurement();
155     }
156     
157     public void initialize(){
158         EditorOperator.closeDiscardAll();
159     }
160
161     public void shutdown(){
162         EditorOperator.closeDiscardAll();
163         repaintManager().setOnlyEditor(false);
164     }
165     
166     public void prepare(){
167         System.out.println("PREPARE: "+WEB_PAGES + (fileFolder.equals("")?"":"|") + fileFolder + '|' + fileName);
168         this.openNode = new Node(new ProjectsTabOperator().getProjectRootNode(fileProject),WEB_PAGES + (fileFolder.equals("")?"":"|") + fileFolder + '|' + fileName);
169         
170         if (this.openNode == null) {
171             fail ("Cannot find node ["+WEB_PAGES + (fileFolder.equals("")?"":"|") + fileFolder + '|' + fileName + "] in project [" + fileProject + "]");
172         }
173         log("========== Open file path ="+this.openNode.getPath());
174     }
175     
176     public ComponentOperator open(){
177         JPopupMenuOperator popup = this.openNode.callPopup();
178         if (popup == null) {
179             fail ("Cannot get context menu for node ["+WEB_PAGES + (fileFolder.equals("")?"":"|") + fileFolder + '|' + fileName + "] in project [" + fileProject + "]");
180         }
181         log("------------------------- after popup invocation ------------");
182         try {
183             popup.pushMenu(this.menuItem);
184         }
185         catch (org.netbeans.jemmy.TimeoutExpiredException tee) {
186             fail ("Cannot push menu item "+this.menuItem+" of node ["+WEB_PAGES + (fileFolder.equals("")?"":"|") + fileFolder + '|' + fileName + "] in project [" + fileProject + "]");
187         }
188         log("------------------------- after open ------------");
189 // // XXX wrappedEditorOperator hack for web.xml editor
190
// if (wrappedEditorOperator) {
191
// return new TopComponentOperator(this.fileName);
192
// } else {
193
return null;
194 // }
195
}
196     
197     public void close(){
198         EditorOperator edior = new EditorOperator(this.fileName);
199         if (edior == null) {
200             edior.closeDiscard();
201         }
202 // else {
203
// fail ("no component to close");
204
// }
205
repaintManager().setOnlyEditor(false);
206     }
207     
208     private void setWrappedClonableEditor(boolean value) {
209         wrappedEditorOperator = value;
210     }
211     
212 }
213
Popular Tags