KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gui > action > OpenServletFile


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

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

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

56     /**
57      * Creates a new instance of OpenFiles
58      * @param testName the name of the test
59      */

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

70     public OpenServletFile(String JavaDoc testName, String JavaDoc performanceDataName) {
71         super(testName, performanceDataName);
72         expectedTime = WINDOW_OPEN;
73     }
74     
75     public void testOpeningServletFile(){
76         WAIT_AFTER_OPEN = 6000;
77         repaintManager().setOnlyEditor(true);
78         setJavaEditorCaretFilteringOn();
79         fileProject = "TestWebProject";
80         filePackage = "test";
81         fileName = "TestServlet.java";
82         menuItem = OPEN;
83         doMeasurement();
84     }
85     
86     public void testOpeningJavaFile(){
87         WAIT_AFTER_OPEN = 6000;
88         repaintManager().setOnlyEditor(true);
89         setJavaEditorCaretFilteringOn();
90         fileProject = "TestWebProject";
91         filePackage = "test";
92         fileName = "Main.java";
93         menuItem = OPEN;
94         doMeasurement();
95     }
96     
97     public void initialize(){
98         EditorOperator.closeDiscardAll();
99     }
100
101     public void shutdown(){
102         EditorOperator.closeDiscardAll();
103     }
104     
105     public void prepare(){
106         this.openNode = new Node(new ProjectsTabOperator().getProjectRootNode(fileProject),"Source Packages" + '|' + filePackage + '|' + fileName);
107         
108         if (this.openNode == null) {
109             fail ("Cannot find node ["+"Source Packages" + '|' + filePackage + '|' + fileName + "] in project [" + fileProject + "]");
110         }
111         log("========== Open file path ="+this.openNode.getPath());
112     }
113     
114     public ComponentOperator open(){
115         JPopupMenuOperator popup = this.openNode.callPopup();
116         if (popup == null) {
117             fail ("Cannot get context menu for node ["+"Source Packages" + '|' + filePackage + '|' + fileName + "] in project [" + fileProject + "]");
118         }
119         log("------------------------- after popup invocation ------------");
120         try {
121             popup.pushMenu(this.menuItem);
122         }
123         catch (org.netbeans.jemmy.TimeoutExpiredException tee) {
124             fail ("Cannot push menu item "+this.menuItem+" of node ["+"Source Packages" + '|' + filePackage + '|' + fileName + "] in project [" + fileProject + "]");
125         }
126         log("------------------------- after open ------------");
127         return new EditorOperator(this.fileName);
128     }
129     
130     public void close(){
131         if (testedComponentOperator != null) {
132             ((EditorOperator)testedComponentOperator).closeDiscard();
133         }
134         else {
135             fail ("no component to close");
136         }
137     }
138     
139 }
140
Popular Tags