001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package memory;
043:
044: import footprint.VWPFootprintUtilities;
045: import gui.window.PaletteComponentOperator;
046: import gui.window.WebFormDesignerOperator;
047: import org.netbeans.jellytools.EditorOperator;
048: import org.netbeans.jellytools.NbDialogOperator;
049: import org.netbeans.jellytools.NewProjectNameLocationStepOperator;
050: import org.netbeans.jellytools.NewProjectWizardOperator;
051: import org.netbeans.jellytools.PaletteOperator;
052: import org.netbeans.jellytools.ProjectsTabOperator;
053: import org.netbeans.jellytools.actions.CloseAllDocumentsAction;
054: import org.netbeans.jellytools.properties.Property;
055: import org.netbeans.jellytools.properties.PropertySheetOperator;
056: import org.netbeans.jemmy.JemmyProperties;
057: import org.netbeans.jemmy.TimeoutExpiredException;
058: import org.netbeans.jemmy.operators.ComponentOperator;
059: import org.netbeans.jemmy.operators.JTableOperator;
060: import org.netbeans.junit.NbTestSuite;
061:
062: /**
063: *
064: * @author mkhramov@netbeans.org
065: */
066: public class StyleBuilderMemTest extends
067: org.netbeans.performance.test.utilities.MemoryFootprintTestCase {
068:
069: private String category, project, project_name, project_type;
070: private NewProjectNameLocationStepOperator wizard_location;
071:
072: private PaletteComponentOperator palette;
073: private WebFormDesignerOperator surface;
074: private String categoryName;
075: private String componentName;
076:
077: private PropertySheetOperator pto;
078: private Property property;
079: private NbDialogOperator styleDialog;
080: private String componentID;
081:
082: public StyleBuilderMemTest(String testName) {
083: super (testName);
084: repeat_memory = 1; // Perform single test pass
085:
086: }
087:
088: public StyleBuilderMemTest(String testName,
089: String performanceDataName) {
090: super (testName, performanceDataName);
091: repeat_memory = 1; // Perform single test pass
092: }
093:
094: @Override
095: public void initialize() {
096:
097: EditorOperator.closeDiscardAll();
098: ProjectsTabOperator.invoke();
099:
100: category = org.netbeans.jellytools.Bundle.getStringTrimmed(
101: "org.netbeans.modules.web.project.ui.wizards.Bundle",
102: "Templates/Project/Web");
103: project = "Web Application";
104: project_type = "JSFWebProject";
105: createProject();
106: log("Created project named: " + project_name);
107: System.out.println("Created project named: " + project_name);
108:
109: long oldTimeout = JemmyProperties.getCurrentTimeouts()
110: .getTimeout("ComponentOperator.WaitStateTimeout");
111: JemmyProperties.getCurrentTimeouts().setTimeout(
112: "ComponentOperator.WaitStateTimeout", 120000);
113:
114: waitProjectCreatingDialogClosed();
115:
116: JemmyProperties.getCurrentTimeouts().setTimeout(
117: "ComponentOperator.WaitStateTimeout", oldTimeout);
118: log("Project Creation dialog passed");
119: System.out.println("Project Creation dialog passed");
120:
121: try {
122: surface = WebFormDesignerOperator
123: .findWebFormDesignerOperator("Page1");
124: log("Page1 page opened");
125: System.out.println("Page1 page opened");
126: } catch (Exception se) {
127: surface = null;
128: }
129:
130: }
131:
132: @Override
133: public void prepare() {
134: try {
135: if (surface == null) {
136: System.out.println("Null surface");
137: surface = WebFormDesignerOperator
138: .findWebFormDesignerOperator("Page1");
139: log("Page1 page opened");
140: }
141:
142: } catch (Exception exception) {
143: fail("Unable to initialize testing component surface");
144: }
145: System.out.println("Invoking palette");
146: PaletteOperator.invoke();
147: log("Components palette invoked");
148: palette = new PaletteComponentOperator();
149: palette.getCategoryListOperator(categoryName).selectItem(
150: componentName);
151:
152: surface.clickOnSurface(20, 20);
153: //surface.clickOnSurface();
154: log("Component added to surface");
155: System.out.println("Component added to surface");
156:
157: pto = PropertySheetOperator.invoke();
158:
159: surface.clickOnSurface(25, 25);
160: componentID = new Property(pto, "id").getValue();
161: property = new Property(pto, "style"); // NOI18N
162:
163: }
164:
165: @Override
166: public ComponentOperator open() {
167:
168: for (int i = 0; i < 100; i++) {
169: System.out.println("Attempt: " + i);
170: property.openEditor();
171: styleDialog = new NbDialogOperator(componentID);
172: styleDialog.close();
173: }
174: return null;
175:
176: }
177:
178: @Override
179: public void close() {
180: log("::close");
181:
182: try {
183: surface.closeDiscard();
184: new CloseAllDocumentsAction().performAPI(); //avoid issue 68671 - editors are not closed after closing project by ProjectSupport
185: } catch (Exception ex) {
186: log("Exception catched on CloseAllDocuments action: "
187: + ex.getMessage());
188: }
189: try {
190: VWPFootprintUtilities.deleteProject(project_name);
191: } catch (Exception ee) {
192: log("Exception during project deletion: " + ee.getMessage());
193: }
194: }
195:
196: @Override
197: public void shutdown() {
198: super .shutdown();
199: }
200:
201: private void createProject() {
202: NewProjectWizardOperator wizard = NewProjectWizardOperator
203: .invoke();
204: wizard.selectCategory(category);
205: wizard.selectProject(project);
206: wizard.next();
207: wizard_location = new NewProjectNameLocationStepOperator();
208:
209: String directory = System.getProperty("xtest.tmpdir");
210: log("================= Destination directory={" + directory
211: + "}");
212: wizard_location.txtProjectLocation().setText("");
213: waitNoEvent(1000);
214: wizard_location.txtProjectLocation().setText(directory);
215:
216: project_name = project_type + "_" + System.currentTimeMillis();
217: log("================= Project name=" + project_name + "}");
218: wizard_location.txtProjectName().setText("");
219: waitNoEvent(1000);
220: wizard_location.txtProjectName().typeText(project_name);
221:
222: wizard_location.next();
223:
224: JTableOperator frameworkselector = new JTableOperator(wizard);
225: frameworkselector.selectCell(0, 0);
226: wizard_location.finish();
227:
228: }
229:
230: private void waitProjectCreatingDialogClosed() {
231: String dlgName = org.netbeans.jellytools.Bundle.getString(
232: "org.netbeans.modules.visualweb.project.jsf.ui.Bundle",
233: "CAP_Opening_Projects");
234: try {
235: NbDialogOperator dlg = new NbDialogOperator(dlgName);
236: dlg.waitClosed();
237: } catch (TimeoutExpiredException tex) {
238: //
239: }
240:
241: }
242:
243: public void testMem() {
244: doMeasurement();
245: }
246:
247: /** Creates suite from particular test cases. You can define order of testcases here. */
248: public static NbTestSuite suite() {
249: NbTestSuite suite = new NbTestSuite();
250: suite.addTest(new StyleBuilderMemTest("testMem",
251: "Memory footprint test"));
252: return suite;
253: }
254:
255: /* Method allowing test execution directly from the IDE. */
256: public static void main(java.lang.String[] args) {
257: junit.textui.TestRunner.run(suite());
258:
259: }
260:
261: }
|