KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

81     
82     public void testAddAndCompile() {
83         String JavaDoc categoryName = "AWT";
84         
85         mainWindow = MainWindowOperator.getDefault();
86         pto = new ProjectsTabOperator();
87         ProjectRootNode prn = pto.getProjectRootNode(DATA_PROJECT_NAME);
88         prn.select();
89         formnode = new Node(prn, "Source Packages|" + PACKAGE_NAME + "|" + FILE_NAME);
90         formnode.select();
91         log("Form node selected.");
92         
93         EditAction editAction = new EditAction();
94         editAction.perform(formnode);
95         log("Source Editor window opened.");
96         
97         OpenAction openAction = new OpenAction();
98         openAction.perform(formnode);
99         log("Form Editor window opened.");
100         
101         // store all component names from the category in the Vector
102
Vector JavaDoc componentNames = new Vector JavaDoc();
103         ComponentPaletteOperator palette = new ComponentPaletteOperator();
104         palette.collapseBeans();
105         // palette.collapseLayouts();
106
palette.collapseSwingControls();
107         palette.collapseSwingControls();
108         palette.collapseSwingMenus();
109         palette.collapseSwingWindows();
110         palette.expandAWT();
111         String JavaDoc[] componentList = {"Label", "Button", "Text Field", "Text Area", "Checkbox", "Choice", "List", "Scrollbar", "Scroll Pane", "Panel", "Canvas", "Menu Bar", "Popup Menu"};
112         for (int i=0;i < componentList.length; i++) {
113             componentNames.addElement(componentList[i]);
114         }
115         ComponentInspectorOperator cio = new ComponentInspectorOperator();
116         Node inspectorRootNode = new Node(cio.treeComponents(), FRAME_ROOT);
117         inspectorRootNode.select();
118         inspectorRootNode.expand();
119         // add all beans from Palette Category to form
120
Action popupAddFromPaletteAction;
121         for(int i = 0; i < componentNames.size(); i++){
122             popupAddFromPaletteAction = new Action(null, "Add From Palette|AWT|" + componentNames.elementAt(i).toString());
123             popupAddFromPaletteAction.perform(inspectorRootNode);
124         }
125         
126         log("All components from Component Palette : " + categoryName + " - were added to " + FILE_NAME);
127         log("Try to save the form.");
128         editAction.perform(formnode);
129         Action saveAction;
130         saveAction = new Action("File|Save", null);
131         saveAction.perform();
132         
133     }
134     
135     
136     /** Run test.
137      */

138     public void testFormFile() {
139         try {
140             getRef().print(
141                     VisualDevelopmentUtil.readFromFile(
142                     getDataDir().getAbsolutePath() + File.separatorChar + DATA_PROJECT_NAME + File.separatorChar + "src" + File.separatorChar + PACKAGE_NAME + File.separatorChar + FILE_NAME + ".form")
143                     );
144         } catch (Exception JavaDoc e) {
145             fail("Fail during create reffile: " + e.getMessage());
146         }
147         System.out.println("reffile: " + this.getName()+".ref");
148         try {
149             System.out.println("workdir: " + getWorkDir());
150         } catch (Exception JavaDoc e) {
151             System.out.println("e:" + e.getMessage() );
152         }
153         if (System.getProperty("java.version").startsWith("1.3")) {
154             System.out.println("XXXX " + this.getName()+"_13.pass");
155             compareReferenceFiles(this.getName()+".ref",this.getName()+"_13.pass",this.getName()+".diff");
156         } else
157             compareReferenceFiles();
158     }
159     
160     /** Run test.
161      */

162     public void testJavaFile() {
163         try {
164             getRef().print(
165                     VisualDevelopmentUtil.readFromFile(
166                     getDataDir().getAbsolutePath() + File.separatorChar + DATA_PROJECT_NAME + File.separatorChar + "src" + File.separatorChar + PACKAGE_NAME + File.separatorChar + FILE_NAME + ".java")
167                     );
168         } catch (Exception JavaDoc e) {
169             fail("Fail during create reffile: " + 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             System.out.println("XXX " + this.getName()+".ref");
175         compareReferenceFiles();
176     }
177     /** Run test.
178      */

179     
180     public void testCloseDataProject(){
181         closeDataProject();
182         // EditorWindowOperator ewo = new EditorWindowOperator();
183
// ewo.closeDiscard();
184
}
185     
186     public void closeDataProject(){
187         ProjectSupport.closeProject(DATA_PROJECT_NAME);
188         log("SampleProject closed.");
189     }
190     
191     
192     
193     static void sleep(int ms) {
194         try {Thread.sleep(ms);} catch (Exception JavaDoc e) {}
195     }
196     
197     /** Suite
198      * @param args arguments from command line
199      */

200     public static NbTestSuite suite() {
201         NbTestSuite suite = new NbTestSuite();
202         suite.addTest(new AddComponents_AWT("testAddAndCompile"));
203         suite.addTest(new AddComponents_AWT("testFormFile"));
204         suite.addTest(new AddComponents_AWT("testJavaFile"));
205         suite.addTest(new AddComponents_AWT("testCloseDataProject"));
206         return suite;
207     }
208     public static void main(String JavaDoc[] args) {
209         System.setProperty("nbjunit.workdir","c:/z");
210         junit.textui.TestRunner.run(suite());
211     }
212 }
213
Popular Tags