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-2006 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: package org.netbeans.qa.form.visualDevelopment;
042:
043: import java.util.Vector;
044: import org.netbeans.jellytools.ProjectsTabOperator;
045: import org.netbeans.jellytools.actions.EditAction;
046: import org.netbeans.jellytools.actions.OpenAction;
047: import org.netbeans.jellytools.nodes.ProjectRootNode;
048:
049: import org.netbeans.junit.NbTestSuite;
050:
051: import org.netbeans.jellytools.*;
052: import org.netbeans.jellytools.modules.form.*;
053: import org.netbeans.jellytools.nodes.*;
054: import org.netbeans.jellytools.actions.*;
055:
056: import org.netbeans.jemmy.operators.*;
057: import org.netbeans.junit.ide.ProjectSupport;
058: import org.netbeans.qa.form.*;
059: import java.io.*;
060:
061: /**
062: *<P>
063: *<B><BR> Test create frame.</B>
064: *
065: *<BR><BR><B>What it tests:</B><BR>
066: * Frame containing all components from Component Palette AWT category try compile.
067: *<BR><BR><B>How it works:</B><BR>
068: * Find tested form file, add all components from AWT category and compile created frame (check compile resolution).
069: *
070: *<BR><BR><B>Settings:</B><BR>
071: * Jemmy/Jelly classes, VisualDevelopmentSupport class in the classpath.
072: *
073: *<BR><BR><B>Resources:</B><BR>
074: * File (Resources.) clear_Frame(java/form) generated by NBr32(37).
075: *
076: *<BR><B>Possible reasons of failure</B>
077: * <BR><U>jelly didn't find menu or popup menu</U>
078: * <BR><U>is impossible add component or components in AWT category is another as in NB r3.2 (37)</U>
079: * <BR><U>component was't add correctly or generated source code is wrong</U>
080: *
081: * @author Marian.Mirilovic@czech.sun.com
082: * @version
083: */
084: public class AddComponents_AWT extends JellyTestCase {
085:
086: public String FILE_NAME = "clear_Frame";
087: public String PACKAGE_NAME = "data";
088: public String DATA_PROJECT_NAME = "SampleProject";
089: public String FRAME_ROOT = "[Frame]";
090:
091: public MainWindowOperator mainWindow;
092: public ProjectsTabOperator pto;
093: public Node formnode;
094:
095: public AddComponents_AWT(String testName) {
096: super (testName);
097: }
098:
099: /** Run test.
100: */
101: public void testAddAndCompile() {
102: String categoryName = "AWT";
103:
104: System.out.println(">>>" + this .getWorkDirPath() + "<<<");
105:
106: mainWindow = MainWindowOperator.getDefault();
107: pto = new ProjectsTabOperator();
108: sleep(300);
109: ProjectRootNode prn = pto.getProjectRootNode(DATA_PROJECT_NAME);
110: sleep(300);
111: prn.select();
112: formnode = new Node(prn, "Source Packages|" + PACKAGE_NAME
113: + "|" + FILE_NAME);
114: formnode.select();
115: log("Form node selected.");
116:
117: EditAction editAction = new EditAction();
118: editAction.perform(formnode);
119: log("Source Editor window opened.");
120:
121: OpenAction openAction = new OpenAction();
122: openAction.perform(formnode);
123: log("Form Editor window opened.");
124:
125: // store all component names from the category in the Vector
126: Vector componentNames = new Vector();
127: ComponentPaletteOperator palette = new ComponentPaletteOperator();
128: palette.collapseBeans();
129: // palette.collapseLayouts();
130: palette.collapseSwingControls();
131: palette.collapseSwingControls();
132: palette.collapseSwingMenus();
133: palette.collapseSwingWindows();
134: palette.expandAWT();
135: String[] componentList = { "Label", "Button", "Text Field",
136: "Text Area", "Checkbox", "Choice", "List", "Scrollbar",
137: "Scroll Pane", "Panel", "Canvas", "Menu Bar",
138: "Popup Menu" };
139: for (int i = 0; i < componentList.length; i++) {
140: log("Adding " + componentList[i]);
141: componentNames.addElement(componentList[i]);
142: }
143: ComponentInspectorOperator cio = new ComponentInspectorOperator();
144: Node inspectorRootNode = new Node(cio.treeComponents(),
145: FRAME_ROOT);
146: inspectorRootNode.select();
147: inspectorRootNode.expand();
148: // add all beans from Palette Category to form
149: Action popupAddFromPaletteAction;
150: for (int i = 0; i < componentNames.size(); i++) {
151: String itemPath = "Add From Palette|AWT|"
152: + componentNames.elementAt(i).toString();
153: log("Running " + itemPath);
154: popupAddFromPaletteAction = new Action(null, itemPath);
155: popupAddFromPaletteAction.perform(inspectorRootNode);
156: }
157:
158: log("All components from Component Palette : " + categoryName
159: + " - were added to " + FILE_NAME);
160: log("Try to save the form.");
161: new org.netbeans.jemmy.EventTool().waitNoEvent(1000);
162: editAction.perform(formnode);
163: Action saveAction;
164: saveAction = new Action("File|Save", null);
165: saveAction.perform();
166: }
167:
168: /** Run test.
169: */
170: public void testFormFile() {
171: compareFileByExt("form");
172: }
173:
174: /** Run test.
175: */
176: public void testJavaFile() {
177: compareFileByExt("java");
178: }
179:
180: private void compareFileByExt(String fileExt) {
181: String refSourceFilePath = getDataDir().getAbsolutePath()
182: + File.separatorChar + DATA_PROJECT_NAME
183: + File.separatorChar + "src" + File.separatorChar
184: + PACKAGE_NAME + File.separatorChar + FILE_NAME + "."
185: + fileExt;
186: log("refSourceFilePath:" + refSourceFilePath);
187:
188: try {
189: getRef().print(
190: VisualDevelopmentUtil
191: .readFromFile(refSourceFilePath));
192: } catch (Exception e) {
193: fail("Fail during creating ref file: " + e.getMessage());
194: }
195:
196: String javaVersionPrefix = VisualDevelopmentUtil.JAVA_VERSION
197: .substring(0, 3);
198: String passFileName = this .getName() + "_" + javaVersionPrefix
199: + ".pass";
200: log("passFileName: " + passFileName);
201:
202: compareReferenceFiles(this .getName() + ".ref", passFileName,
203: this .getName() + ".diff");
204: }
205:
206: /** Run test.
207: */
208: public void testCloseDataProject() {
209: closeDataProject();
210: // EditorWindowOperator ewo = new EditorWindowOperator();
211: // ewo.closeDiscard();
212: }
213:
214: public void closeDataProject() {
215: ProjectSupport.closeProject(DATA_PROJECT_NAME);
216: log("SampleProject closed.");
217: }
218:
219: static void sleep(int ms) {
220: try {
221: Thread.sleep(ms);
222: } catch (Exception e) {
223: }
224: }
225:
226: /** Suite
227: * @param args arguments from command line
228: */
229: public static NbTestSuite suite() {
230: NbTestSuite suite = new NbTestSuite();
231: suite.addTest(new AddComponents_AWT("testAddAndCompile"));
232: //suite.addTest(new AddComponents_AWT("testFormFile"));
233: suite.addTest(new AddComponents_AWT("testJavaFile"));
234: //suite.addTest(new AddComponents_AWT("testCloseDataProject"));
235: return suite;
236: }
237:
238: public static void main(String[] args) {
239: junit.textui.TestRunner.run(suite());
240: }
241: }
|