1 19 20 package org.netbeans.modules.db.util; 21 22 import java.net.URL ; 23 import javax.swing.JComboBox ; 24 import org.netbeans.api.db.explorer.*; 25 import org.netbeans.modules.db.test.TestBase; 26 import org.netbeans.modules.db.test.Util; 27 import org.openide.filesystems.FileObject; 28 29 33 public class DatabaseExplorerInternalUIsTest extends TestBase { 34 35 private JDBCDriver driver1 = null; 36 private JDBCDriver driver2 = null; 37 38 public DatabaseExplorerInternalUIsTest(String testName) { 39 super(testName); 40 } 41 42 private void setUpDrivers() throws Exception { 43 removeDrivers(); 44 45 driver1 = JDBCDriver.create("foo_driver", "FooDriver", "org.foo.FooDriver", new URL [0]); 46 JDBCDriverManager.getDefault().addDriver(driver1); 47 driver2 = JDBCDriver.create("bar_driver", "BarDriver", "org.bar.BarDriver", new URL [0]); 48 JDBCDriverManager.getDefault().addDriver(driver2); 49 assertEquals(2, JDBCDriverManager.getDefault().getDrivers().length); 50 } 51 52 private void removeDrivers() throws Exception { 53 FileObject driversFO = Util.getDriversFolder(); 54 FileObject[] children = driversFO.getChildren(); 55 for (int i = 0; i < children.length; i++) { 56 children[i].delete(); 57 } 58 assertEquals(0, JDBCDriverManager.getDefault().getDrivers().length); 59 } 60 61 public void testEmptyComboboxContent() throws Exception { 62 removeDrivers(); 63 JComboBox combo = new JComboBox (); 64 DatabaseExplorerInternalUIs.connect(combo, JDBCDriverManager.getDefault()); 65 66 assertTrue("Wrong number of items in the empty combobox", combo.getItemCount() == 1); 67 } 68 69 public void testComboboxWithDrivers() throws Exception { 70 setUpDrivers(); 71 JComboBox combo = new JComboBox (); 72 DatabaseExplorerInternalUIs.connect(combo, JDBCDriverManager.getDefault()); 73 74 assertTrue("Wrong number of items in the combobox", combo.getItemCount() == 4); 75 assertSame(driver2, combo.getItemAt(0)); 76 assertSame(driver1, combo.getItemAt(1)); 77 } 78 79 public void testComboBoxWithDriverClass() throws Exception { 80 setUpDrivers(); 81 JComboBox combo = new JComboBox (); 82 DatabaseExplorerInternalUIs.connect(combo, JDBCDriverManager.getDefault(), "org.bar.BarDriver"); 83 84 assertTrue("Wrong number of items in the combobox", combo.getItemCount() == 1); 85 assertSame(driver2, combo.getItemAt(0)); 86 } 87 } 88 | Popular Tags |