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 ColumnNodeTest extends TestBase { 43 44 public ColumnNodeTest(String testName) { 45 super(testName); 46 } 47 48 public void testClipboardCopy() throws Exception { 49 assertNotNull("ColumnNode.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 ColumnNode columnNode = new ColumnNode(); 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 DatabaseNodeInfo columnNodeInfo = DatabaseNodeInfo.createNodeInfo(tableNodeInfo, DatabaseNode.COLUMN); 61 columnNode.setInfo(columnNodeInfo); 62 63 assertTrue(columnNode.canCopy()); 64 65 Transferable transferable = (Transferable )columnNode.clipboardCopy(); 66 Set mimeTypes = new HashSet (); 67 DataFlavor [] flavors = transferable.getTransferDataFlavors(); 68 for (int i = 0; i < flavors.length; i++) { 69 mimeTypes.add(flavors[i].getMimeType()); 70 } 71 assertTrue(mimeTypes.contains("application/x-java-netbeans-dbexplorer-column; class=org.netbeans.modules.db.api.explorer.DatabaseMetaDataTransfer$Column")); 72 assertTrue(mimeTypes.contains("application/x-java-openide-nodednd; mask=1; class=org.openide.nodes.Node")); 73 } 74 } 75 | Popular Tags |