1 19 package org.netbeans.qa.form.visualDevelopment; 20 21 import java.util.Vector ; 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 64 public class AddComponents_AWT extends JellyTestCase { 65 66 public String FILE_NAME = "clear_Frame"; 67 public String PACKAGE_NAME = "data"; 68 public String DATA_PROJECT_NAME = "SampleProject"; 69 public String FRAME_ROOT = "[Frame]"; 70 71 public MainWindowOperator mainWindow; 72 public ProjectsTabOperator pto; 73 public Node formnode; 74 75 public AddComponents_AWT(String testName) { 76 super(testName); 77 } 78 79 81 82 public void testAddAndCompile() { 83 String 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 Vector componentNames = new Vector (); 103 ComponentPaletteOperator palette = new ComponentPaletteOperator(); 104 palette.collapseBeans(); 105 palette.collapseSwingControls(); 107 palette.collapseSwingControls(); 108 palette.collapseSwingMenus(); 109 palette.collapseSwingWindows(); 110 palette.expandAWT(); 111 String [] 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 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 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 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 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 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 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 179 180 public void testCloseDataProject(){ 181 closeDataProject(); 182 } 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 e) {} 195 } 196 197 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 [] args) { 209 System.setProperty("nbjunit.workdir","c:/z"); 210 junit.textui.TestRunner.run(suite()); 211 } 212 } 213 | Popular Tags |