1 19 20 package org.netbeans.modules.db.explorer.nodes; 21 22 import java.awt.datatransfer.DataFlavor ; 23 import java.awt.datatransfer.Transferable ; 24 import java.net.URL ; 25 import java.util.HashSet ; 26 import java.util.Set ; 27 import org.netbeans.api.db.explorer.ConnectionManager; 28 import org.netbeans.api.db.explorer.DatabaseConnection; 29 import org.netbeans.api.db.explorer.JDBCDriver; 30 import org.netbeans.api.db.explorer.JDBCDriverManager; 31 import org.netbeans.modules.db.explorer.ConnectionList; 32 import org.netbeans.modules.db.explorer.DbMetaDataTransferProvider; 33 import org.netbeans.modules.db.explorer.infos.ConnectionNodeInfo; 34 import org.netbeans.modules.db.explorer.infos.DatabaseNodeInfo; 35 import org.netbeans.modules.db.test.TestBase; 36 import org.openide.util.Lookup; 37 38 42 public class TableNodeTest extends TestBase { 43 44 public TableNodeTest(String testName) { 45 super(testName); 46 } 47 48 public void testClipboardCopy() throws Exception { 49 assertNotNull("TableNode.clipboardCopy() needs an impl of DbMetaDataTransferProvider in the default lookup", Lookup.getDefault().lookup(DbMetaDataTransferProvider.class)); 50 51 JDBCDriver driver = JDBCDriver.create("foo", "Foo", "org.example.Foo", new URL [0]); 52 JDBCDriverManager.getDefault().addDriver(driver); 53 DatabaseConnection dbconn = DatabaseConnection.create(driver, "url", "user", "schema", "pwd", false); 54 ConnectionManager.getDefault().addConnection(dbconn); 55 56 TableNode tableNode = new TableNode(); 57 ConnectionNodeInfo connNodeInfo = (ConnectionNodeInfo)DatabaseNodeInfo.createNodeInfo(null, DatabaseNodeInfo.CONNECTION); 58 connNodeInfo.setDatabaseConnection(ConnectionList.getDefault().getConnections()[0]); 59 DatabaseNodeInfo tableNodeInfo = DatabaseNodeInfo.createNodeInfo(connNodeInfo, DatabaseNode.TABLE); 60 tableNode.setInfo(tableNodeInfo); 61 62 assertTrue(tableNode.canCopy()); 63 64 Transferable transferable = (Transferable )tableNode.clipboardCopy(); 65 Set mimeTypes = new HashSet (); 66 DataFlavor [] flavors = transferable.getTransferDataFlavors(); 67 for (int i = 0; i < flavors.length; i++) { 68 mimeTypes.add(flavors[i].getMimeType()); 69 } 70 assertTrue(mimeTypes.contains("application/x-java-netbeans-dbexplorer-table; class=org.netbeans.modules.db.api.explorer.DatabaseMetaDataTransfer$Table")); 71 assertTrue(mimeTypes.contains("application/x-java-openide-nodednd; mask=1; class=org.openide.nodes.Node")); 72 } 73 } 74 | Popular Tags |