1 19 20 package org.netbeans.test.editor.suites.abbrevs; 21 22 import java.awt.event.KeyEvent ; 23 import java.io.File ; 24 import org.netbeans.jellytools.*; 25 import org.netbeans.jellytools.EditorOperator; 26 import org.netbeans.jellytools.actions.OpenAction; 27 import org.netbeans.jellytools.modules.editor.Abbreviations; 28 import org.netbeans.jellytools.nodes.Node; 29 import org.netbeans.jemmy.EventTool; 30 import org.netbeans.test.editor.LineDiff; 31 32 37 public class AbbreviationsAddRemovePerformer extends JellyTestCase { 38 39 40 public static final String SRC_PACKAGES_PATH = 41 Bundle.getString("org.netbeans.modules.java.j2seproject.Bundle", 42 "NAME_src.dir"); 43 44 private static final String editor = "Java Editor"; 45 private boolean isInFramework; 46 47 48 public AbbreviationsAddRemovePerformer(String name) { 49 super(name); 50 isInFramework = false; 51 } 52 53 public EditorOperator openFile() { 54 Node pn = new ProjectsTabOperator().getProjectRootNode( 55 "editor_test"); 56 pn.select(); 57 Node n = new Node(pn, SRC_PACKAGES_PATH + "|" + "abbrev" + "|" + "Test"); 59 n.select(); 60 new OpenAction().perform(); 61 new EventTool().waitNoEvent(500); 62 63 return new EditorOperator("Test"); 64 } 65 66 private void checkAbbreviation(String abbreviation) throws Exception { 67 System.out.println("### Checking abbreviation \"" + abbreviation + "\""); 69 EditorOperator editor = openFile(); 70 71 editor.setCaretPosition(24, 1); 74 75 editor.txtEditorPane().typeText(abbreviation); 77 editor.pushTabKey(); 79 ref(editor.getText(editor.getLineNumber())); 81 editor.select(editor.getLineNumber()); 83 editor.pushKey(KeyEvent.VK_DELETE, 0); 84 editor.pushKey(KeyEvent.VK_S, KeyEvent.CTRL_MASK); 85 editor.closeDiscard(); 86 } 87 88 91 public void doTest() throws Exception { 92 log("doTest start"); 93 Object backup = Utilities.saveAbbreviationsState(); 94 95 try { 96 Abbreviations.addAbbreviation(editor, "ts", "Thread.dumpStack();"); 98 Abbreviations.addAbbreviation(editor, "tst", "Thread.sleep(1000);"); 99 100 checkAbbreviation("ts"); 101 checkAbbreviation("tst"); 102 103 boolean remove0 = Abbreviations.removeAbbreviation(editor, "ts"); 105 System.out.println("remove0: " + remove0); 106 assertTrue("Previously added \"ts\" abbrev could not be removed.", remove0); 107 108 boolean remove1 = Abbreviations.removeAbbreviation(editor, "ts"); 110 System.out.println("remove1: "+ remove1); 111 assertFalse("Previously removed \"ts\" abbrev should not be aviable.", remove1); 112 113 checkAbbreviation("ts"); 114 checkAbbreviation("tst"); 115 System.out.println("remove0: "+Abbreviations.removeAbbreviation(editor, "tst")); 116 System.out.println("remove1: "+Abbreviations.removeAbbreviation(editor, "tst")); 117 checkAbbreviation("ts"); 118 checkAbbreviation("tst"); 119 120 } catch (Exception ex) { 121 log("Bug in test: "+ex.getMessage()+" by "+ex.getClass()); 122 ex.printStackTrace(getLog()); 123 } finally { 124 Utilities.restoreAbbreviationsState(backup); 125 log("doTest finished"); 126 } 127 } 128 129 146 147 public void setUp() { 148 isInFramework = true; 149 log("Starting abbreviations add/remove test."); 150 log("Test name=" + getName()); 151 try { 152 EditorOperator.closeDiscardAll(); 153 log("Closed Welcome screen."); 154 } catch (Exception ex) { 155 } 156 } 157 158 public void tearDown() throws Exception { 159 log("Finishing abbreviations add/remove test."); 160 assertFile("Output does not match golden file.", getGoldenFile(), new File (getWorkDir(), this.getName() + ".ref"), 161 new File (getWorkDir(), this.getName() + ".diff"), new LineDiff(false)); 162 isInFramework = false; 163 } 164 165 public void testAddRemove() throws Exception { 166 doTest(); 167 } 168 169 public static void main(String [] args) throws Exception { 170 new AbbreviationsAddRemovePerformer("testAddRemove").doTest(); 171 } 172 173 } 174 | Popular Tags |