1 19 20 package org.netbeans.modules.dbapi; 21 22 import java.net.URL ; 23 import org.netbeans.api.db.explorer.DatabaseConnection; 24 import org.netbeans.api.db.explorer.JDBCDriver; 25 import org.netbeans.junit.NbTestCase; 26 import org.netbeans.modules.db.api.explorer.MetaDataListener; 27 import org.netbeans.modules.db.explorer.DbMetaDataListener; 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileSystem; 30 import org.openide.filesystems.FileUtil; 31 import org.openide.filesystems.Repository; 32 33 37 public class DbMetaDataListenerImplTest extends NbTestCase { 38 39 public DbMetaDataListenerImplTest(String testName) { 40 super(testName); 41 } 42 43 47 public void testListenerFired() throws Exception { 48 JDBCDriver driver = JDBCDriver.create("foo", "Foo", "org.example.Foo", new URL [0]); 49 DatabaseConnection dbconn = DatabaseConnection.create(driver, "url", "user", "schema", "pwd", false); 50 51 class TestListener implements MetaDataListener { 52 53 DatabaseConnection dbconn; 54 String tableName; 55 56 public void tablesChanged(DatabaseConnection dbconn) { 57 this.dbconn = dbconn; 58 } 59 60 public void tableChanged(DatabaseConnection dbconn, String tableName) { 61 this.dbconn = dbconn; 62 this.tableName = tableName; 63 } 64 } 65 66 FileSystem sfs = Repository.getDefault().getDefaultFileSystem(); 67 FileObject listenersFO = FileUtil.createFolder(sfs.getRoot(), DbMetaDataListenerImpl.REFRESH_LISTENERS_PATH); 68 FileObject listenerFO = listenersFO.createData("TestListener", "instance"); 69 TestListener listener = new TestListener(); 70 listenerFO.setAttribute("instanceCreate", listener); 71 72 DbMetaDataListener dbListener = new DbMetaDataListenerImpl(); 73 74 assertNull(listener.dbconn); 75 dbListener.tablesChanged(dbconn); 76 assertSame(dbconn, listener.dbconn); 77 78 listener.dbconn = null; 79 assertNull(listener.dbconn); 80 assertNull(listener.tableName); 81 dbListener.tableChanged(dbconn, "TABLE"); 82 assertSame(dbconn, listener.dbconn); 83 assertEquals("TABLE", listener.tableName); 84 } 85 } 86 | Popular Tags |