KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > startup > MeasureJ2EEStartupTimeOpenedFilesPrepare


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 startup;
21
22 import java.io.PrintStream JavaDoc;
23
24 import org.netbeans.jellytools.*;
25 import org.netbeans.jellytools.actions.EditAction;
26 import org.netbeans.jellytools.actions.OpenAction;
27 import org.netbeans.jellytools.nodes.Node;
28 import org.netbeans.jellytools.nodes.SourcePackagesNode;
29
30 import org.netbeans.jemmy.operators.*;
31
32 import junit.framework.Test;
33 import junit.framework.TestSuite;
34
35 import org.netbeans.junit.NbTestSuite;
36 import org.netbeans.junit.ide.ProjectSupport;
37
38
39 /**
40  * Prepare user directory for measurement of startup time of IDE with opened files.
41  * Open 10 java files and shut down ide.
42  * Created user directory will be used to measure startup time of IDE with opened files.
43  *
44  * @author Marian.Mirilovic@sun.com
45  */

46 public class MeasureJ2EEStartupTimeOpenedFilesPrepare extends JellyTestCase {
47     
48     /** Error output from the test. */
49     protected static PrintStream JavaDoc err;
50     
51     /** Logging output from the test. */
52     protected static PrintStream JavaDoc log;
53
54     
55     
56     /** Define testcase
57      * @param testName name of the testcase
58      */

59     public MeasureJ2EEStartupTimeOpenedFilesPrepare(String JavaDoc testName) {
60         super(testName);
61     }
62
63     /** Testsuite
64      * @return testuite
65      */

66     public static Test suite() {
67         TestSuite suite = new NbTestSuite();
68         suite.addTest(new IDESetupTest("testCloseMemoryToolbar"));
69         suite.addTest(new IDESetupTest("closeAllDocuments"));
70         suite.addTest(new MeasureJ2EEStartupTimeOpenedFilesPrepare("testOpenProjects"));
71         suite.addTest(new MeasureJ2EEStartupTimeOpenedFilesPrepare("openFiles"));
72         return suite;
73     }
74     
75     
76     public void setUp() {
77 // err = System.out;
78
err = getLog();
79         log = getRef();
80     }
81
82     
83     public void testOpenProjects() {
84         ProjectSupport.openProject(System.getProperty("xtest.tmpdir")+"/startup/TestStartupApp");
85         ProjectSupport.waitScanFinished();
86         ProjectSupport.openProject(System.getProperty("xtest.tmpdir")+"/startup/TestStartupApp/TestStartupApp-ejb");
87         ProjectSupport.waitScanFinished();
88         ProjectSupport.openProject(System.getProperty("xtest.tmpdir")+"/startup/TestStartupApp/TestStartupApp-war");
89         ProjectSupport.waitScanFinished();
90         ProjectSupport.openProject(System.getProperty("xtest.tmpdir")+"/startup/TestStartupEJB1");
91         ProjectSupport.waitScanFinished();
92         ProjectSupport.openProject(System.getProperty("xtest.tmpdir")+"/startup/TestStartupEJB2");
93         ProjectSupport.waitScanFinished();
94         //waitForScan();
95
}
96     
97     private void waitForScan() {
98         // "Scanning Project Classpaths"
99
String JavaDoc titleScanning = Bundle.getString("org.netbeans.modules.javacore.Bundle", "TXT_ApplyingPathsTitle");
100         NbDialogOperator scanningDialogOper = new NbDialogOperator(titleScanning);
101         // scanning can last for a long time => wait max. 5 minutes
102
scanningDialogOper.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 300000);
103         scanningDialogOper.waitClosed();
104     }
105     
106     /**
107      * Open 10 selected files from jEdit project.
108      */

109     public void openFiles(){
110         
111         new org.netbeans.jemmy.EventTool().waitNoEvent(10000);
112         
113         String JavaDoc[][] files_path = {
114             {"TestStartupApp","Configuration Files|sun-application.xml"},
115             {"TestStartupApp-EJB","Enterprise Beans|TestSessionSB"},
116             {"TestStartupApp-EJB","Configuration Files|ejb-jar.xml"},
117             {"TestStartupApp-EJB","Configuration Files|sun-ejb-jar.xml"},
118             {"TestStartupApp-WAR","Web Pages|index.jsp"},
119             {"TestStartupApp-WAR","Configuration Files|web.xml"},
120             {"TestStartupApp-WAR","Configuration Files|sun-web.xml"},
121             {"TestStartupApp-WAR","Source Packages|test|TestServlet.java"},
122             {"TestStartupEJB1","Enterprise Beans|TestSession2SB"},
123             {"TestStartupEJB1","Enterprise Beans|TestMessageMDB"},
124             {"TestStartupEJB1","Enterprise Beans|TestEntityEB"},
125             {"TestStartupEJB2","Web Services|TestWebService1"},
126             {"TestStartupEJB2","Web Services|TestWebService2"}
127         };
128         
129         Node[] openFileNodes = new Node[files_path.length];
130         
131         for(int i=0; i<files_path.length; i++) {
132                 Node root = new ProjectsTabOperator().getProjectRootNode(files_path[i][0]);
133                 root.setComparator(new Operator.DefaultStringComparator(true, true));
134                 openFileNodes[i] = new Node(root, files_path[i][1]);
135                 // open file one by one, opening all files at once causes never ending loop (java+mdr)
136
//new OpenAction().performAPI(openFileNodes[i]);
137
}
138         
139         // try to come back and open all files at-once, rises another problem with refactoring, if you do open file and next expand folder,
140
// it doesn't finish in the real-time -> hard to reproduced by hand
141
new OpenAction().performAPI(openFileNodes);
142         
143         new org.netbeans.jemmy.EventTool().waitNoEvent(60000);
144         
145     }
146    
147
148     public static void main(java.lang.String JavaDoc[] args) {
149         junit.textui.TestRunner.run(suite());
150     }
151 }
152
Popular Tags