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 ConnectionNodeTest extends TestBase { 43 44 public ConnectionNodeTest(String testName) { 45 super(testName); 46 } 47 48 public void testClipboardCopy() throws Exception { 49 assertNotNull("ConnectionNode.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 ConnectionNode connectionNode = new ConnectionNode(); 57 ConnectionNodeInfo connNodeInfo = (ConnectionNodeInfo)DatabaseNodeInfo.createNodeInfo(null, DatabaseNodeInfo.CONNECTION); 58 connNodeInfo.setDatabaseConnection(ConnectionList.getDefault().getConnections()[0]); 59 connectionNode.setInfo(connNodeInfo); 60 61 assertTrue(connectionNode.canCopy()); 62 63 Transferable transferable = (Transferable )connectionNode.clipboardCopy(); 64 Set mimeTypes = new HashSet (); 65 DataFlavor [] flavors = transferable.getTransferDataFlavors(); 66 for (int i = 0; i < flavors.length; i++) { 67 mimeTypes.add(flavors[i].getMimeType()); 68 } 69 assertTrue(mimeTypes.contains("application/x-java-netbeans-dbexplorer-connection; class=org.netbeans.modules.db.api.explorer.DatabaseMetaDataTransfer$Connection")); 70 assertTrue(mimeTypes.contains("application/x-java-openide-nodednd; mask=1; class=org.openide.nodes.Node")); 71 } 72 } 73 | Popular Tags |