1 19 package org.netbeans.qa.form.visualDevelopment; 20 21 import java.awt.Point ; 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 63 public class AddComponents_SWING extends JellyTestCase { 64 public String FILE_NAME = "clear_JFrame"; 65 public String PACKAGE_NAME = "data"; 66 public String DATA_PROJECT_NAME = "SampleProject"; 67 public String FRAME_ROOT = "[JFrame]"; 68 69 public MainWindowOperator mainWindow; 70 public ProjectsTabOperator pto; 71 public Node formnode; 72 73 public AddComponents_SWING(String testName) { 74 super(testName); 75 } 76 77 79 80 public void testOpenDataProject(){ 81 mainWindow = MainWindowOperator.getDefault(); 82 openDataProject(); 83 } 84 85 87 88 public void testCloseDataProject(){ 89 EditorWindowOperator ewo = new EditorWindowOperator(); 91 ewo.closeDiscard(); 92 } 93 94 96 97 public void testAddAndCompile() { 98 String 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 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 String [] 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 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 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 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 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 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 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 ProjectSupport.openProject(getDataDir().getAbsolutePath() + "\\" + DATA_PROJECT_NAME); 197 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 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 226 public static void main(String [] args) { 227 System.setProperty("nbjunit.workdir","c:/z"); 228 junit.textui.TestRunner.run(suite()); 229 } 230 231 } 232 | Popular Tags |