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.awt.Point;
044:
045: import org.netbeans.junit.NbTestSuite;
046: import org.netbeans.jemmy.TimeoutExpiredException;
047: import org.netbeans.jemmy.operators.JPopupMenuOperator;
048:
049: import org.netbeans.jellytools.*;
050: import org.netbeans.jellytools.modules.form.*;
051: import org.netbeans.jellytools.modules.form.properties.editors.*;
052: import org.netbeans.jellytools.nodes.*;
053: import org.netbeans.jellytools.properties.*;
054: import org.netbeans.jellytools.actions.*;
055:
056: import org.netbeans.jemmy.operators.*;
057: import java.util.*;
058: import org.netbeans.junit.ide.ProjectSupport;
059: import org.netbeans.qa.form.*;
060: import java.io.*;
061:
062: /**
063: *<P>
064: *<B><BR> Test create frame.</B>
065: *
066: *<BR><BR><B>What it tests:</B><BR>
067: * Frame containing all components from Component Palette SWING category try compile.
068: *<BR><BR><B>How it works:</B><BR>
069: * Find tested form file, add all components from SWING category and compile created frame (check compile resolution).
070: *
071: *<BR><BR><B>Settings:</B><BR>
072: * Jemmy/Jelly classes, VisualDevelopmentSupport class in the classpath.
073: *
074: *<BR><BR><B>Resources:</B><BR>
075: * File (Resources.) clear_Frame(java/form) generated by NBr32(37).
076: *
077: *<BR><B>Possible reasons of failure</B>
078: * <BR><U>jelly didn't find menu or popup menu</U>
079: * <BR><U>is impossible add component or components in SWING category is another as in NB r3.2 (37)</U>
080: * <BR><U>component was't add correctly or generated source code is wrong</U>
081: *
082: * @author Marian.Mirilovic@czech.sun.com
083: * @version
084: */
085: public class AddComponents_SWING extends JellyTestCase {
086: public String FILE_NAME = "clear_JFrame";
087: public String PACKAGE_NAME = "data";
088: public String DATA_PROJECT_NAME = "SampleProject";
089: public String FRAME_ROOT = "[JFrame]";
090:
091: public MainWindowOperator mainWindow;
092: public ProjectsTabOperator pto;
093: public Node formnode;
094:
095: public AddComponents_SWING(String testName) {
096: super (testName);
097: }
098:
099: /** Run test.
100: */
101:
102: public void testOpenDataProject() {
103: mainWindow = MainWindowOperator.getDefault();
104: openDataProject();
105: }
106:
107: /** Run test.
108: */
109:
110: public void testCloseDataProject() {
111: // closeDataProject();
112: EditorWindowOperator ewo = new EditorWindowOperator();
113: ewo.closeDiscard();
114: }
115:
116: /** Run test.
117: */
118:
119: public void testAddAndCompile() {
120: String categoryName = "Swing Controls";
121:
122: pto = new ProjectsTabOperator();
123: ProjectRootNode prn = pto.getProjectRootNode(DATA_PROJECT_NAME);
124: prn.select();
125: formnode = new Node(prn, "Source Packages|" + PACKAGE_NAME
126: + "|" + FILE_NAME);
127: formnode.select();
128: log("Form node selected.");
129:
130: EditAction editAction = new EditAction();
131: editAction.perform(formnode);
132: log("Source Editor window opened.");
133:
134: OpenAction openAction = new OpenAction();
135: openAction.perform(formnode);
136: log("Form Editor window opened.");
137:
138: // store all component names from the category in the Vector
139: Vector componentNames = new Vector();
140: ComponentPaletteOperator palette = new ComponentPaletteOperator();
141: palette.collapseBeans();
142: palette.collapseSwingContainers();
143: palette.collapseSwingMenus();
144: palette.collapseSwingWindows();
145: palette.collapseAWT();
146: palette.expandSwingControls();
147: //JListOperator list = palette.lstComponents(); //selectPage(categoryName);
148: // System.out.println("LLL " + list.getModel());
149: //String [] componentList = {"JLabel", "JButton", "JToggleButton", "JCheckBox", "JRadioButton", "ButtonGroup", "JComboBox", "JList", "JTextField", "JTextArea", "JPanel", "JTabbedPane", "JScrollBar", "JScrollPane", "JMenuBar", "JPopupMenu", "JSlider", "JProgressBar", "JSplitPane", "JFormattedTextField", "JPasswordField", "JSpinner", "JSeparator", "JTextPane", "JEditorPane", "JTree", "JTable", "JToolBar", "JInternalFrame", "JLayeredPane", "JDesktopPane", "JOptionPane", "JColorChooser", "JFileChooser", "JFrame", "JDialog"};
150: String[] componentList = { "Label", "Button", "Toggle Button",
151: "Check Box", "Radio Button", "Button Group",
152: "Combo Box", "List", "Text Field", "Text Area",
153: "Scroll Bar", "Slider", "Progress Bar",
154: "Formatted Field", "Password Field", "Spinner",
155: "Separator", "Text Pane", "Editor Pane", "Tree",
156: "Table" };
157: for (int i = 0; i < componentList.length; i++) {
158: componentNames.addElement(componentList[i]);
159: }
160:
161: ComponentInspectorOperator cio = new ComponentInspectorOperator();
162: Node inspectorRootNode = new Node(cio.treeComponents(),
163: FRAME_ROOT);
164: inspectorRootNode.select();
165: inspectorRootNode.expand();
166:
167: // add all beans from Palette Category to form
168: Action popupAddFromPaletteAction;
169: for (int i = 0; i < componentNames.size(); i++) {
170: popupAddFromPaletteAction = new Action(null,
171: "Add From Palette|Swing Controls|"
172: + componentNames.elementAt(i).toString());
173: popupAddFromPaletteAction.perform(inspectorRootNode);
174: }
175:
176: log("All components from Swing Controls Palette : "
177: + categoryName + " - were added to " + FILE_NAME);
178:
179: log("Try to save the form.");
180: new org.netbeans.jemmy.EventTool().waitNoEvent(1000);
181: editAction.perform(formnode);
182: Action saveAction;
183: saveAction = new Action("File|Save", null);
184: saveAction.perform();
185:
186: }
187:
188: /** Run test.
189: */
190: public void testFormFile() {
191: compareFileByExt("form");
192: }
193:
194: /** Run test.
195: */
196: public void testJavaFile() {
197: compareFileByExt("java");
198: }
199:
200: private void compareFileByExt(String fileExt) {
201: String refSourceFilePath = getDataDir().getAbsolutePath()
202: + File.separatorChar + DATA_PROJECT_NAME
203: + File.separatorChar + "src" + File.separatorChar
204: + PACKAGE_NAME + File.separatorChar + FILE_NAME + "."
205: + fileExt;
206: log("refSourceFilePath:" + refSourceFilePath);
207:
208: try {
209: getRef().print(
210: VisualDevelopmentUtil
211: .readFromFile(refSourceFilePath));
212: } catch (Exception e) {
213: fail("Fail during creating ref file: " + e.getMessage());
214: }
215:
216: String javaVersionPrefix = VisualDevelopmentUtil.JAVA_VERSION
217: .substring(0, 3);
218: String passFileName = this .getName() + "_" + javaVersionPrefix
219: + ".pass";
220: log("passFileName: " + passFileName);
221:
222: compareReferenceFiles(this .getName() + ".ref", passFileName,
223: this .getName() + ".diff");
224: }
225:
226: public void openDataProject() {
227: //if running internally then ide must be ran with the switch -J-Dxtest.data=${SampleProject location}
228: ProjectSupport.openProject(getDataDir().getAbsolutePath()
229: + "\\" + DATA_PROJECT_NAME);
230: // NbDialogOperator scanningDialogOper = new NbDialogOperator("Scanning");
231: // log(scanningDialogOper.getTitle() + " opened.");
232: // scanningDialogOper.waitClosed();
233: // log(scanningDialogOper.getTitle() + " closed.");
234: pto = new ProjectsTabOperator();
235: }
236:
237: public void closeDataProject() {
238: ProjectSupport.closeProject(DATA_PROJECT_NAME);
239: log("SampleProject closed.");
240: }
241:
242: void sleep(int ms) {
243: try {
244: Thread.sleep(ms);
245: } catch (Exception e) {
246: }
247: }
248:
249: public static NbTestSuite suite() {
250: NbTestSuite suite = new NbTestSuite();
251: suite.addTest(new AddComponents_SWING("testOpenDataProject"));
252: suite.addTest(new AddComponents_SWING("testAddAndCompile"));
253: suite.addTest(new AddComponents_SWING("testFormFile"));
254: suite.addTest(new AddComponents_SWING("testJavaFile"));
255: //suite.addTest(new AddComponents_SWING("testCloseDataProject"));
256:
257: return suite;
258: }
259:
260: /** Test could be executed internaly in Forte
261: * @param args arguments from command line
262: */
263: public static void main(String[] args) {
264: System.setProperty("nbjunit.workdir", "c:/z");
265: junit.textui.TestRunner.run(suite());
266: }
267:
268: }
|