1 19 20 package org.netbeans.test.java.gui.errorannotations; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.PrintStream ; 25 import java.io.PrintWriter ; 26 import junit.textui.TestRunner; 27 import org.netbeans.jellytools.EditorOperator; 28 import org.netbeans.jellytools.EditorWindowOperator; 29 import org.netbeans.jellytools.JellyTestCase; 30 import org.netbeans.jellytools.ProjectsTabOperator; 31 import org.netbeans.jellytools.actions.ActionNoBlock; 32 import org.netbeans.jellytools.actions.OpenAction; 33 import org.netbeans.jellytools.actions.SaveAction; 34 import org.netbeans.jellytools.nodes.Node; 35 import org.netbeans.jemmy.JemmyProperties; 36 import org.netbeans.jemmy.TestOut; 37 import org.netbeans.junit.NbTestSuite; 38 import org.netbeans.test.java.Utilities; 39 40 41 42 46 public class ErrorAnnotations extends JellyTestCase { 47 48 private static final int ACTION_TIMEOUT = 6000; 50 51 private static final String TEST_PROJECT_NAME = "default"; 53 54 private static final String TEST_PACKAGE_PATH = 56 "org.netbeans.test.java.gui.errorannotations"; 57 58 private static final String TEST_PACKAGE_NAME = TEST_PACKAGE_PATH+".test"; 60 61 private static final String TEST_CLASS_NAME = "TestClass"; 63 64 67 protected static PrintStream err; 68 69 72 protected static PrintStream log; 73 74 private String workDir = "/tmp"; 76 77 private static String projectDir; 79 80 84 public ErrorAnnotations(String name) { 85 super(name); 86 } 87 88 92 public static NbTestSuite suite() { 93 NbTestSuite suite = new NbTestSuite(); 94 suite.addTest(new ErrorAnnotations("testAnnotationsSimple")); 96 suite.addTest(new ErrorAnnotations("testUndo")); 97 suite.addTest(new ErrorAnnotations("testAnnotationsSimple2")); 98 suite.addTest(new ErrorAnnotations("testAnnotationsSimple3")); 99 suite.addTest(new ErrorAnnotations("testChangeCloseDiscart")); 100 101 return suite; 102 } 103 104 108 public static void main(java.lang.String [] args) { 109 TestRunner.run(suite()); 110 } 111 112 115 public void setUp() { 116 System.out.println("######## "+getName()+" #######"); 117 err = getLog(); 118 log = getRef(); 119 JemmyProperties.getProperties().setOutput(new TestOut(null, 120 new PrintWriter (err, true), new PrintWriter (err, false), null)); 121 try { 122 File wd = getWorkDir(); 123 workDir = wd.toString(); 124 } catch (IOException e) { } 125 } 126 127 130 public void testAnnotationsSimple() { 131 Node pn = new ProjectsTabOperator().getProjectRootNode( 132 TEST_PROJECT_NAME); 133 pn.select(); 134 135 Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString( 136 "org.netbeans.modules.java.j2seproject.Bundle", 137 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|" 138 +TEST_CLASS_NAME); 139 140 n.select(); 141 new OpenAction().perform(); 142 143 EditorWindowOperator ewo = new EditorWindowOperator(); 145 EditorOperator editor = ewo.getEditor(TEST_CLASS_NAME); 146 editor.insert(" ", 11, 3); 147 148 Utilities.takeANap(ACTION_TIMEOUT); 149 150 log(editor.getText()); 151 Object [] annots = editor.getAnnotations(); 152 assertNotNull(annots); 153 assertEquals(1, annots.length); 154 assertEquals("org-netbeans-spi-editor-hints-parser_annotation_err", 155 EditorOperator.getAnnotationType(annots[0])); 156 assertEquals("class or interface expected", 157 EditorOperator.getAnnotationShortDescription(annots[0])); 158 } 159 160 163 public void testUndo() { 164 new ActionNoBlock("Edit|Undo", null).perform(); 166 167 Utilities.takeANap(ACTION_TIMEOUT); 168 169 EditorWindowOperator ewo = new EditorWindowOperator(); 170 EditorOperator editor = ewo.getEditor(TEST_CLASS_NAME); 171 log(editor.getText()); 172 Object [] annots = editor.getAnnotations(); 173 174 assertEquals(annots.length, 0); 176 } 177 178 181 public void testAnnotationsSimple2() { 182 Node pn = new ProjectsTabOperator().getProjectRootNode( 183 TEST_PROJECT_NAME); 184 pn.select(); 185 186 Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString( 187 "org.netbeans.modules.java.j2seproject.Bundle", 188 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|" 189 +TEST_CLASS_NAME); 190 191 n.select(); 192 new OpenAction().perform(); 193 194 EditorWindowOperator ewo = new EditorWindowOperator(); 196 EditorOperator editor = ewo.getEditor(TEST_CLASS_NAME); 197 editor.replace("class", "klasa"); 198 199 Utilities.takeANap(ACTION_TIMEOUT); 200 log(editor.getText()); 201 Object [] annots = editor.getAnnotations(); 203 assertNotNull("There are not any annotations.", annots); 204 assertEquals("There are not one annotation", 2, annots.length); 205 assertEquals("Wrong annotation type ", "org-netbeans-spi-editor-hints-parser_annotation_err", 206 EditorOperator.getAnnotationType(annots[0])); 207 assertEquals("Wrong annotation short description","class or interface expected", 208 EditorOperator.getAnnotationShortDescription(annots[0])); 209 assertEquals("Wrong annotation type ", "org-netbeans-spi-editor-hints-parser_annotation_err", 210 EditorOperator.getAnnotationType(annots[1])); 211 assertEquals("Wrong annotation short description","class or interface expected", 212 EditorOperator.getAnnotationShortDescription(annots[1])); 213 new ActionNoBlock("Edit|Undo", null).perform(); 214 Utilities.takeANap(ACTION_TIMEOUT); 215 ewo.closeDiscard(); 216 } 217 218 221 public void testAnnotationsSimple3() { 222 Node pn = new ProjectsTabOperator().getProjectRootNode( 223 TEST_PROJECT_NAME); 224 pn.select(); 225 226 Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString( 227 "org.netbeans.modules.java.j2seproject.Bundle", 228 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|" 229 +TEST_CLASS_NAME); 230 231 n.select(); 232 new OpenAction().perform(); 233 234 EditorWindowOperator ewo = new EditorWindowOperator(); 236 EditorOperator editor = ewo.getEditor(TEST_CLASS_NAME); 237 editor.replace(TEST_CLASS_NAME, TEST_CLASS_NAME+"xxx", 3); 238 239 Utilities.takeANap(ACTION_TIMEOUT); 240 log(editor.getText()); 241 Object [] annots = editor.getAnnotations(); 243 assertNotNull("There are not any annotations.", annots); 244 assertEquals("There are more than one annotation: "+String.valueOf(annots.length), 1, annots.length); 245 assertEquals("Wrong annotation type: "+EditorOperator.getAnnotationType(annots[0]), 246 "org-netbeans-spi-editor-hints-parser_annotation_err", 247 EditorOperator.getAnnotationType(annots[0])); 248 assertEquals("Wrong annotation short description: "+EditorOperator.getAnnotationShortDescription(annots[0]), 249 "invalid method declaration; return type required", 250 EditorOperator.getAnnotationShortDescription(annots[0])); 251 System.out.println(EditorOperator.getAnnotationType(annots[0])); 252 System.out.println(EditorOperator.getAnnotationShortDescription(annots[0])); 253 new ActionNoBlock("Edit|Undo", null).perform(); 254 Utilities.takeANap(ACTION_TIMEOUT); 255 ewo.closeDiscard(); 256 } 257 258 public void testChangeCloseDiscart() { 259 Node pn = new ProjectsTabOperator().getProjectRootNode(TEST_PROJECT_NAME); 260 pn.select(); 261 262 Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString( 263 "org.netbeans.modules.java.j2seproject.Bundle", 264 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|" 265 +TEST_CLASS_NAME); 266 267 n.select(); 268 new OpenAction().perform(); 269 270 271 EditorWindowOperator ewo = new EditorWindowOperator(); 272 EditorOperator editor = ewo.getEditor(TEST_CLASS_NAME); 273 String context = "" + 274 "/*\n" + 275 " * TestClass.java \n" + 276 " *\n" + 277 " */\n" + 278 "\n" + 279 "package org.netbeans.test.java.gui.errorannotations.test;\n" + 280 "\n" + 281 "/**\n" + 282 " *\n" + 283 " */\n" + 284 "public class TestClass {\n" + 285 " \n" + 286 " /** Creates a new instance of TestClass */\n" + 287 " public TestClass() {\n" + 288 " }\n" + 289 " \n" + 290 "}\n"; 291 292 editor.delete(0,editor.getText().length()); 293 editor.insert(context); new SaveAction().perform(); 295 296 editor.insert(" ", 11,3); 297 Utilities.takeANap(ACTION_TIMEOUT); 298 log(editor.getText()); 299 Object [] annots = editor.getAnnotations(); 300 assertNotNull("There are not any annotations.", annots); 301 assertEquals("There are annotations: "+String.valueOf(annots.length), 1, annots.length); 302 ewo.closeDiscard(); 303 n.select(); 304 new OpenAction().perform(); 305 editor = ewo.getEditor(TEST_CLASS_NAME); 306 annots = editor.getAnnotations(); 307 assertEquals(0,annots.length); ewo.closeDiscard(); 309 } 310 311 312 313 } 314 | Popular Tags |