1 19 20 package org.netbeans.test.java.gui.wizards; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.PrintStream ; 25 import java.io.PrintWriter ; 26 import org.netbeans.jellytools.EditorOperator; 27 import org.netbeans.jellytools.JellyTestCase; 28 import org.netbeans.jellytools.NbDialogOperator; 29 import org.netbeans.jellytools.ProjectsTabOperator; 30 import org.netbeans.jellytools.actions.OpenAction; 31 import org.netbeans.jellytools.actions.SaveAction; 32 import org.netbeans.jellytools.nodes.Node; 33 import org.netbeans.jemmy.EventTool; 34 import org.netbeans.jemmy.JemmyProperties; 35 import org.netbeans.jemmy.TestOut; 36 import org.netbeans.jemmy.operators.JButtonOperator; 37 import org.netbeans.jemmy.operators.JComboBoxOperator; 38 import org.netbeans.jemmy.operators.JTextFieldOperator; 39 import org.netbeans.junit.NbTestSuite; 40 import org.netbeans.test.java.Utilities; 41 42 43 44 48 public class JavaElementsTest extends JellyTestCase { 49 50 private static final int ACTION_TIMEOUT = 5000; 52 53 private static final String TEST_PROJECT_NAME = "default"; 55 56 private static final String TEST_PACKAGE_PATH = 58 "org.netbeans.test.java.gui.wizards"; 59 60 private static final String TEST_PACKAGE_NAME = TEST_PACKAGE_PATH+".test"; 62 63 private static final String TEST_CLASS_NAME = "TestClass"; 65 66 private static final String TEST_FIELD_NAME = "testField"; 68 69 private static final String TEST_PARAMETER_NAME = "testParameter"; 71 72 private static final String TEST_METHOD_NAME = "testMethod"; 74 75 private static final String TEST_INNER_CLASS_NAME = "testInnerClass"; 77 78 private static final String TEST_INNER_INTERFACE_NAME = 80 "testInnerInterface"; 81 82 85 protected static PrintStream err; 86 89 protected static PrintStream log; 90 91 private String workDir = "/tmp"; 93 94 private static String projectDir; 95 96 100 public static NbTestSuite suite() { 101 NbTestSuite suite = new NbTestSuite(); 102 suite.addTest(new JavaElementsTest("testNewInitializer")); 103 suite.addTest(new JavaElementsTest("testNewField")); 104 suite.addTest(new JavaElementsTest("testNewConstructor")); 105 suite.addTest(new JavaElementsTest("testNewMethod")); 106 suite.addTest(new JavaElementsTest("testNewInnerClass")); 107 suite.addTest(new JavaElementsTest("testNewInnerInterface")); 108 return suite; 109 } 110 111 115 public static void main(String [] args) { 116 junit.textui.TestRunner.run(suite()); 117 } 118 119 122 public void setUp() { 123 System.out.println("######## "+getName()+" #######"); 124 err = getLog(); 125 log = getRef(); 126 JemmyProperties.getProperties().setOutput(new TestOut(null, 127 new PrintWriter (err, true), new PrintWriter (err, false), null)); 128 try { 129 File wd = getWorkDir(); 130 workDir = wd.toString(); 131 } catch (IOException e) { } 132 } 133 134 138 public JavaElementsTest(String testName) { 139 super(testName); 140 } 141 142 145 public void testNewInitializer() { 146 Node pn = new ProjectsTabOperator().getProjectRootNode( 147 TEST_PROJECT_NAME); 148 pn.select(); 149 150 Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString( 151 "org.netbeans.modules.java.j2seproject.Bundle", 152 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|" 153 +TEST_CLASS_NAME); 154 155 n.select(); 156 new OpenAction().perform(); 157 158 new EventTool().waitNoEvent(ACTION_TIMEOUT); 159 160 Node n2 = new Node(pn, org.netbeans.jellytools.Bundle.getString( 161 "org.netbeans.modules.java.j2seproject.Bundle", 162 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|" 163 +TEST_CLASS_NAME+"|"+TEST_CLASS_NAME); 164 n2.select(); 165 166 n2.performPopupAction(org.netbeans.jellytools.Bundle.getString( 168 "org.netbeans.modules.java.ui.nodes.elements.Bundle", "LAB_Add")+"|"+ 169 org.netbeans.jellytools.Bundle.getString( 170 "org.netbeans.modules.java.ui.nodes.elements.Bundle", "MENU_CREATE_BLOCK")); 171 172 String text = new EditorOperator(TEST_CLASS_NAME).getText(); 174 log(text); 175 179 assertTrue("Static block not found.", text.matches("(?s).*static\\s*\\{\\s*\\}.*")); 180 n2.select(); 182 Utilities.takeANap(5000); EditorOperator editor = new EditorOperator(TEST_CLASS_NAME); 185 String s = editor.getText(); 186 editor.save(); 187 } 188 189 192 public void testNewField() { 193 Node pn = new ProjectsTabOperator().getProjectRootNode( 194 TEST_PROJECT_NAME); 195 pn.select(); 196 197 Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString( 198 "org.netbeans.modules.java.j2seproject.Bundle", 199 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|" 200 +TEST_CLASS_NAME+"|"+TEST_CLASS_NAME); 201 n.select(); 202 203 n.performPopupActionNoBlock(org.netbeans.jellytools.Bundle.getString( 205 "org.netbeans.modules.java.ui.nodes.elements.Bundle", "LAB_Add")+"|" 206 +org.netbeans.jellytools.Bundle.getString( 207 "org.netbeans.modules.java.ui.nodes.elements.Bundle", "MENU_CREATE_VARIABLE")); 208 209 NbDialogOperator nb = new NbDialogOperator( 210 org.netbeans.jellytools.Bundle.getString( 211 "org.netbeans.modules.java.ui.nodes.elements.Bundle", 212 "TIT_NewField")); 213 214 JTextFieldOperator tfp = new JTextFieldOperator(nb, 0); 215 tfp.setText(TEST_FIELD_NAME); 216 217 nb.ok(); 218 219 String text = new EditorOperator(TEST_CLASS_NAME).getText(); 221 log(text); 222 assertTrue("New field not found.", text.matches("(?s).*int\\s+"+TEST_FIELD_NAME+".*")); 225 226 EditorOperator editor = new EditorOperator(TEST_CLASS_NAME); 228 String s = editor.getText(); 229 editor.save(); 230 231 } 232 233 236 public void testNewConstructor() { 237 Node pn = new ProjectsTabOperator().getProjectRootNode( 238 TEST_PROJECT_NAME); 239 pn.select(); 240 241 Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString( 242 "org.netbeans.modules.java.j2seproject.Bundle", 243 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|" 244 +TEST_CLASS_NAME+"|"+TEST_CLASS_NAME); 245 n.select(); 246 247 n.performPopupActionNoBlock(org.netbeans.jellytools.Bundle.getString( 249 "org.netbeans.modules.java.ui.nodes.elements.Bundle", "LAB_Add")+"|" 250 +org.netbeans.jellytools.Bundle.getString( 251 "org.netbeans.modules.java.ui.nodes.elements.Bundle", 252 "MENU_CREATE_CONSTRUCTOR")); 253 254 NbDialogOperator nb = new NbDialogOperator( 255 org.netbeans.jellytools.Bundle.getString( 256 "org.netbeans.modules.java.ui.nodes.elements.Bundle", 257 "TIT_NewConstructor")); 258 259 JButtonOperator jbo = new JButtonOperator(nb, 260 org.netbeans.jellytools.Bundle.getString( 261 "org.netbeans.modules.java.ui.nodes.editors.Bundle", 262 "CTL_Add")); 263 264 jbo.pushNoBlock(); 265 266 NbDialogOperator nb2 = new NbDialogOperator( 268 org.netbeans.jellytools.Bundle.getString( 269 "org.netbeans.modules.java.ui.nodes.editors.Bundle", 270 "LAB_EnterParameter")); 271 272 JComboBoxOperator jco = new JComboBoxOperator(nb2); 273 jco.selectItem("String"); 274 275 JTextFieldOperator jtfo2 = new JTextFieldOperator(nb2, 1); 276 jtfo2.setText(TEST_PARAMETER_NAME); 277 278 nb2.ok(); 279 280 nb.ok(); 281 282 String text = new EditorOperator(TEST_CLASS_NAME).getText(); 284 log(text); 285 289 assertTrue("New constructor not found.", text.matches("(?s).*"+TEST_CLASS_NAME+"\\s*\\(String\\s+"+TEST_PARAMETER_NAME+"\\s*\\).*")); 290 EditorOperator editor = new EditorOperator(TEST_CLASS_NAME); 292 String s = editor.getText(); 293 editor.save(); 294 } 295 296 299 public void testNewMethod() { 300 Node pn = new ProjectsTabOperator().getProjectRootNode( 301 TEST_PROJECT_NAME); 302 pn.select(); 303 304 Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString( 305 "org.netbeans.modules.java.j2seproject.Bundle", 306 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|" 307 +TEST_CLASS_NAME+"|"+TEST_CLASS_NAME); 308 n.select(); 309 310 n.performPopupActionNoBlock(org.netbeans.jellytools.Bundle.getString( 312 "org.netbeans.modules.java.ui.nodes.elements.Bundle", "LAB_Add")+"|" 313 +org.netbeans.jellytools.Bundle.getString( 314 "org.netbeans.modules.java.ui.nodes.elements.Bundle", 315 "MENU_CREATE_METHOD")); 316 317 NbDialogOperator nb = new NbDialogOperator( 318 org.netbeans.jellytools.Bundle.getString( 319 "org.netbeans.modules.java.ui.nodes.elements.Bundle", 320 "TIT_NewMethod")); 321 322 JButtonOperator jbo = new JButtonOperator(nb, 323 org.netbeans.jellytools.Bundle.getString( 324 "org.netbeans.modules.java.ui.nodes.editors.Bundle", 325 "CTL_Add")); 326 jbo.pushNoBlock(); 327 328 NbDialogOperator nb2 = new NbDialogOperator( 330 org.netbeans.jellytools.Bundle.getString( 331 "org.netbeans.modules.java.ui.nodes.editors.Bundle", 332 "LAB_EnterParameter")); 333 334 JComboBoxOperator jco = new JComboBoxOperator(nb2); 335 jco.selectItem("String"); 336 337 JTextFieldOperator jtfo2 = new JTextFieldOperator(nb2, 1); 338 jtfo2.setText(TEST_PARAMETER_NAME); 339 340 nb2.ok(); 341 342 JTextFieldOperator jtfo3 = new JTextFieldOperator(nb, 0); 343 jtfo3.setText(TEST_METHOD_NAME); 344 345 nb.ok(); 346 347 String text = new EditorOperator(TEST_CLASS_NAME).getText(); 349 log(text); 350 354 assertTrue("New method not found.", text.matches("(?s).*"+TEST_METHOD_NAME+"\\s*\\(String\\s+"+TEST_PARAMETER_NAME+"\\s*\\).*")); 355 EditorOperator editor = new EditorOperator(TEST_CLASS_NAME); 357 String s = editor.getText(); 358 editor.save(); 359 } 360 361 364 public void testNewInnerClass() { 365 Node pn = new ProjectsTabOperator().getProjectRootNode( 366 TEST_PROJECT_NAME); 367 pn.select(); 368 369 Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString( 370 "org.netbeans.modules.java.j2seproject.Bundle", 371 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|" 372 +TEST_CLASS_NAME+"|"+TEST_CLASS_NAME); 373 n.select(); 374 375 n.performPopupActionNoBlock(org.netbeans.jellytools.Bundle.getString( 377 "org.netbeans.modules.java.ui.nodes.elements.Bundle", "LAB_Add")+"|" 378 +org.netbeans.jellytools.Bundle.getString( 379 "org.netbeans.modules.java.ui.nodes.elements.Bundle", 380 "MENU_CREATE_INNERCLASS")); 381 382 NbDialogOperator nb = new NbDialogOperator( 383 org.netbeans.jellytools.Bundle.getString( 384 "org.netbeans.modules.java.ui.nodes.elements.Bundle", 385 "TIT_NewInnerClass")); 386 387 JTextFieldOperator jtfo3 = new JTextFieldOperator(nb, 0); 389 jtfo3.setText(TEST_INNER_CLASS_NAME); 390 391 nb.ok(); 392 393 String text = new EditorOperator(TEST_CLASS_NAME).getText(); 395 log(text); 396 assertTrue("New inner class not found.", text.matches("(?s).*class\\s+"+TEST_INNER_CLASS_NAME+"\\s+.*")); 399 400 EditorOperator editor = new EditorOperator(TEST_CLASS_NAME); 402 String s = editor.getText(); 403 editor.save(); 404 } 405 406 409 public void testNewInnerInterface() { 410 Node pn = new ProjectsTabOperator().getProjectRootNode( 411 TEST_PROJECT_NAME); 412 pn.select(); 413 414 Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString( 415 "org.netbeans.modules.java.j2seproject.Bundle", 416 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|" 417 +TEST_CLASS_NAME+"|"+TEST_CLASS_NAME); 418 n.select(); 419 420 n.performPopupActionNoBlock(org.netbeans.jellytools.Bundle.getString( 422 "org.netbeans.modules.java.ui.nodes.elements.Bundle", "LAB_Add")+"|" 423 +org.netbeans.jellytools.Bundle.getString( 424 "org.netbeans.modules.java.ui.nodes.elements.Bundle", 425 "MENU_CREATE_INNERINTERFACE")); 426 427 NbDialogOperator nb = new NbDialogOperator( 428 org.netbeans.jellytools.Bundle.getString( 429 "org.netbeans.modules.java.ui.nodes.elements.Bundle", 430 "TIT_NewInnerInterface")); 431 432 JTextFieldOperator jtfo3 = new JTextFieldOperator(nb, 0); 434 jtfo3.setText(TEST_INNER_INTERFACE_NAME); 435 436 nb.ok(); 437 438 String text = new EditorOperator(TEST_CLASS_NAME).getText(); 440 log(text); 441 assertTrue("New inner interface not found.", text.matches("(?s).*interface\\s+"+TEST_INNER_INTERFACE_NAME+"\\s+.*")); 444 445 EditorOperator editor = new EditorOperator(TEST_CLASS_NAME); 447 String s = editor.getText(); 448 editor.save(); 449 } 450 451 } 452 | Popular Tags |