KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > qa > form > visualDevelopment > AddComponents_SWING


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 package org.netbeans.qa.form.visualDevelopment;
20
21 import java.awt.Point JavaDoc;
22
23 import org.netbeans.junit.NbTestSuite;
24 import org.netbeans.jemmy.TimeoutExpiredException;
25 import org.netbeans.jemmy.operators.JPopupMenuOperator;
26
27 import org.netbeans.jellytools.*;
28 import org.netbeans.jellytools.modules.form.*;
29 import org.netbeans.jellytools.modules.form.properties.editors.*;
30 import org.netbeans.jellytools.nodes.*;
31 import org.netbeans.jellytools.properties.*;
32 import org.netbeans.jellytools.actions.*;
33
34 import org.netbeans.jemmy.operators.*;
35 import java.util.*;
36 import org.netbeans.junit.ide.ProjectSupport;
37 import org.netbeans.qa.form.*;
38 import java.io.*;
39
40 /**
41  *<P>
42  *<B><BR> Test create frame.</B>
43  *
44  *<BR><BR><B>What it tests:</B><BR>
45  * Frame containing all components from Component Palette SWING category try compile.
46  *<BR><BR><B>How it works:</B><BR>
47  * Find tested form file, add all components from SWING category and compile created frame (check compile resolution).
48  *
49  *<BR><BR><B>Settings:</B><BR>
50  * Jemmy/Jelly classes, VisualDevelopmentSupport class in the classpath.
51  *
52  *<BR><BR><B>Resources:</B><BR>
53  * File (Resources.) clear_Frame(java/form) generated by NBr32(37).
54  *
55  *<BR><B>Possible reasons of failure</B>
56  * <BR><U>jelly didn't find menu or popup menu</U>
57  * <BR><U>is impossible add component or components in SWING category is another as in NB r3.2 (37)</U>
58  * <BR><U>component was't add correctly or generated source code is wrong</U>
59  *
60  * @author Marian.Mirilovic@czech.sun.com
61  * @version
62  */

63 public class AddComponents_SWING extends JellyTestCase {
64     public String JavaDoc FILE_NAME = "clear_JFrame";
65     public String JavaDoc PACKAGE_NAME = "data";
66     public String JavaDoc DATA_PROJECT_NAME = "SampleProject";
67     public String JavaDoc FRAME_ROOT = "[JFrame]";
68     
69     public MainWindowOperator mainWindow;
70     public ProjectsTabOperator pto;
71     public Node formnode;
72     
73     public AddComponents_SWING(String JavaDoc testName) {
74         super(testName);
75     }
76     
77     /** Run test.
78      */

79     
80     public void testOpenDataProject(){
81         mainWindow = MainWindowOperator.getDefault();
82         openDataProject();
83     }
84     
85     /** Run test.
86      */

87     
88     public void testCloseDataProject(){
89 // closeDataProject();
90
EditorWindowOperator ewo = new EditorWindowOperator();
91         ewo.closeDiscard();
92     }
93     
94     /** Run test.
95      */

96     
97     public void testAddAndCompile() {
98         String JavaDoc categoryName = "Swing Controls";
99         
100         pto = new ProjectsTabOperator();
101         ProjectRootNode prn = pto.getProjectRootNode(DATA_PROJECT_NAME);
102         prn.select();
103         formnode = new Node(prn, "Source Packages|" + PACKAGE_NAME + "|" + FILE_NAME);
104         formnode.select();
105         log("Form node selected.");
106         
107         EditAction editAction = new EditAction();
108         editAction.perform(formnode);
109         log("Source Editor window opened.");
110         
111         OpenAction openAction = new OpenAction();
112         openAction.perform(formnode);
113         log("Form Editor window opened.");
114         
115         // store all component names from the category in the Vector
116
Vector componentNames = new Vector();
117         ComponentPaletteOperator palette = new ComponentPaletteOperator();
118         palette.collapseBeans();
119         palette.collapseSwingContainers();
120         palette.collapseSwingMenus();
121         palette.collapseSwingWindows();
122         palette.collapseAWT();
123         palette.expandSwingControls();
124         //JListOperator list = palette.lstComponents(); //selectPage(categoryName);
125
// System.out.println("LLL " + list.getModel());
126
//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"};
127
String JavaDoc [] componentList = {"Label", "Button", "Toggle Button", "Check Box", "Radio Button", "Button Group", "Combo Box", "List", "Text Field", "Text Area", "Scroll Bar", "Slider", "Progress Bar", "Formatted Field", "Password Field", "Spinner", "Separator", "Text Pane", "Editor Pane", "Tree", "Table"};
128         for (int i=0; i<componentList.length; i++) {
129             componentNames.addElement(componentList[i]);
130         }
131         
132         ComponentInspectorOperator cio = new ComponentInspectorOperator();
133         Node inspectorRootNode = new Node(cio.treeComponents(), FRAME_ROOT);
134         inspectorRootNode.select();
135         inspectorRootNode.expand();
136         
137         // add all beans from Palette Category to form
138
Action popupAddFromPaletteAction;
139         for(int i = 0; i < componentNames.size(); i++){
140             popupAddFromPaletteAction = new Action(null, "Add From Palette|Swing Controls|" + componentNames.elementAt(i).toString());
141             popupAddFromPaletteAction.perform(inspectorRootNode);
142         }
143         
144         log("All components from Swing Controls Palette : " + categoryName + " - were added to " + FILE_NAME);
145         
146         log("Try to save the form.");
147         editAction.perform(formnode);
148         Action saveAction;
149         saveAction = new Action("File|Save", null);
150         saveAction.perform();
151         
152     }
153     
154     /** Run test.
155      */

156     public void testFormFile() {
157         try {
158             getRef().print(
159             VisualDevelopmentUtil.readFromFile(
160             getDataDir().getAbsolutePath() + File.separatorChar + DATA_PROJECT_NAME + File.separatorChar + "src" + File.separatorChar + PACKAGE_NAME + File.separatorChar + FILE_NAME + ".form")
161             );
162         } catch (Exception JavaDoc e) {
163             fail("Fail during create reffile: " + e.getMessage());
164         }
165         System.out.println("reffile: " + this.getName()+".ref");
166         try {
167             System.out.println("workdir: " + getWorkDir());
168         } catch (Exception JavaDoc e) {
169             System.out.println("e:" + e.getMessage() );
170         }
171         if (System.getProperty("java.version").startsWith("1.3")) {
172             compareReferenceFiles(this.getName()+".ref",this.getName()+"_13.pass",this.getName()+".diff");
173         } else
174             compareReferenceFiles();
175     }
176     
177     /** Run test.
178      */

179     public void testJavaFile() {
180         try {
181             getRef().print(
182             VisualDevelopmentUtil.readFromFile(
183             getDataDir().getAbsolutePath() + File.separatorChar + DATA_PROJECT_NAME + File.separatorChar + "src" + File.separatorChar + PACKAGE_NAME + File.separatorChar + FILE_NAME + ".java")
184             );
185         } catch (Exception JavaDoc e) {
186             fail("Fail during create reffile: " + e.getMessage());
187         }
188         if (System.getProperty("java.version").startsWith("1.3")) {
189             compareReferenceFiles(this.getName()+".ref",this.getName()+"_13.pass",this.getName()+".diff");
190         } else
191             compareReferenceFiles();
192     }
193     
194     public void openDataProject(){
195         //if running internally then ide must be ran with the switch -J-Dxtest.data=${SampleProject location}
196
ProjectSupport.openProject(getDataDir().getAbsolutePath() + "\\" + DATA_PROJECT_NAME);
197 // NbDialogOperator scanningDialogOper = new NbDialogOperator("Scanning");
198
// log(scanningDialogOper.getTitle() + " opened.");
199
// scanningDialogOper.waitClosed();
200
// log(scanningDialogOper.getTitle() + " closed.");
201
pto = new ProjectsTabOperator();
202     }
203     
204     public void closeDataProject(){
205         ProjectSupport.closeProject(DATA_PROJECT_NAME);
206         log("SampleProject closed.");
207     }
208     
209     void sleep(int ms) {
210         try {Thread.sleep(ms);} catch (Exception JavaDoc e) {}
211     }
212     public static NbTestSuite suite() {
213         NbTestSuite suite = new NbTestSuite();
214         suite.addTest(new AddComponents_SWING("testOpenDataProject"));
215         suite.addTest(new AddComponents_SWING("testAddAndCompile"));
216         suite.addTest(new AddComponents_SWING("testFormFile"));
217         suite.addTest(new AddComponents_SWING("testJavaFile"));
218         suite.addTest(new AddComponents_SWING("testCloseDataProject"));
219         
220         return suite;
221     }
222     
223     /** Test could be executed internaly in Forte
224      * @param args arguments from command line
225      */

226     public static void main(String JavaDoc[] args) {
227         System.setProperty("nbjunit.workdir","c:/z");
228         junit.textui.TestRunner.run(suite());
229     }
230     
231 }
232
Popular Tags