1 19 20 package org.netbeans.test.java.gui.fiximports; 21 22 import java.awt.event.KeyEvent ; 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.io.PrintStream ; 26 import java.io.PrintWriter ; 27 import javax.swing.ComboBoxModel ; 28 import javax.swing.JComboBox ; 29 import javax.swing.table.TableModel ; 30 import org.netbeans.jellytools.EditorOperator; 31 import org.netbeans.jellytools.JellyTestCase; 32 import org.netbeans.jellytools.MainWindowOperator; 33 import org.netbeans.jellytools.ProjectsTabOperator; 34 import org.netbeans.jellytools.actions.OpenAction; 35 import org.netbeans.jellytools.modules.java.FixImportsOperator; 36 import org.netbeans.jellytools.nodes.Node; 37 import org.netbeans.jemmy.JemmyProperties; 38 import org.netbeans.jemmy.TestOut; 39 import org.netbeans.junit.NbTestSuite; 40 import org.netbeans.test.java.Utilities; 41 import org.netbeans.test.java.gui.GuiUtilities; 42 43 44 48 public class FixImportsTest extends JellyTestCase { 49 50 private static final String TEST_PROJECT_NAME = "default"; 52 53 private static final String TEST_PACKAGE_PATH = 55 "org.netbeans.test.java.gui.fiximports"; 56 57 private static final String TEST_PACKAGE_NAME = TEST_PACKAGE_PATH+".test"; 59 60 private static final String TEST_CLASS_NAME = "TestClass"; 62 63 66 protected static PrintStream err; 67 68 71 protected static PrintStream log; 72 73 private String workDir = "/tmp"; 75 76 private static String projectDir; 78 79 83 public static NbTestSuite suite() { 84 NbTestSuite suite = new NbTestSuite(); 85 suite.addTest(new FixImportsTest("testFixImports")); 87 suite.addTest(new FixImportsTest("testFixImportsComplex")); 88 return suite; 89 } 90 91 95 public static void main(String [] args) { 96 junit.textui.TestRunner.run(suite()); 97 } 98 99 102 public void setUp() { 103 System.out.println("######## "+getName()+" #######"); 104 err = getLog(); 105 log = getRef(); 106 JemmyProperties.getProperties().setOutput(new TestOut(null, 107 new PrintWriter (err, true), new PrintWriter (err, false), null)); 108 try { 109 File wd = getWorkDir(); 110 workDir = wd.toString(); 111 } catch (IOException e) { } 112 } 113 114 118 public FixImportsTest(String testName) { 119 super(testName); 120 } 121 122 125 public void testCreateProjectAndPackageAndClass() { 126 projectDir = GuiUtilities.createProjectAndPackageAndClass( 127 TEST_PROJECT_NAME, TEST_PACKAGE_NAME, TEST_CLASS_NAME, workDir); 128 } 129 130 133 public void testFixImports() { 134 Node pn = new ProjectsTabOperator().getProjectRootNode( 135 TEST_PROJECT_NAME); 136 pn.select(); 137 138 Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString( 139 "org.netbeans.modules.java.j2seproject.Bundle", 140 "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|" 141 +TEST_CLASS_NAME); 142 143 n.select(); 144 new OpenAction().perform(); 145 146 EditorOperator editor = new EditorOperator(TEST_CLASS_NAME); 148 editor.insert("Vector v = new Vector();\n", 15, 1); 149 Utilities.takeANap(1000); 150 151 MainWindowOperator.getDefault().pushKey(KeyEvent.VK_F, 152 KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK); 153 FixImportsOperator fio = new FixImportsOperator(); 154 fio.ok(); 155 for (int i=0; i<10; i++) { 157 Utilities.takeANap(1000); 158 if(editor.getText().contains("import java.util.Vector;")) break; 159 System.out.println(MainWindowOperator.getDefault().getStatusText()); 160 } 161 162 ref(editor.getText()); 163 164 compareReferenceFiles(); 165 } 166 167 170 public void testFixImportsComplex() { 171 EditorOperator editor = new EditorOperator(TEST_CLASS_NAME); 173 editor.insert("List l = new List();\n", 17, 1); 174 175 Utilities.takeANap(1000); 176 177 MainWindowOperator.getDefault().pushKey(KeyEvent.VK_F, 179 KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK); 180 181 FixImportsOperator fio = new FixImportsOperator(); 182 183 TableModel tm = fio.tabHtmlTheFollowingClassNamesWereFoundInMoreThanOnePackageSelectTheFullyQualifiedNameToUseInTheImportStatementHtml().getModel(); 184 JComboBox jcb = (JComboBox ) tm.getValueAt(0, 1); 185 186 ComboBoxModel cbm = jcb.getModel(); 187 int in; 188 for(in=0;in<cbm.getSize();in++) { 189 if(cbm.getElementAt(in).equals("java.util.List")) { 190 jcb.setSelectedIndex(in); 191 break; 192 } 193 } 194 assertTrue("java.util.List not listed",in<cbm.getSize()); 195 fio.ok(); 196 197 for (int i=0; i<10; i++) { 199 Utilities.takeANap(1000); 200 if (editor.getText().contains("import java.util.List;")) break; 201 System.out.println(MainWindowOperator.getDefault().getStatusText()); 202 } 203 204 ref(editor.getText()); 205 206 compareReferenceFiles(); 207 208 EditorOperator.closeDiscardAll(); 209 } 210 211 } 212 | Popular Tags |