KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > explorer > nodes > ConnectionNodeTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.db.explorer.nodes;
21
22 import java.awt.datatransfer.DataFlavor JavaDoc;
23 import java.awt.datatransfer.Transferable JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Set JavaDoc;
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 /**
39  *
40  * @author Andrei Badea
41  */

42 public class ConnectionNodeTest extends TestBase {
43
44     public ConnectionNodeTest(String JavaDoc testName) {
45         super(testName);
46     }
47
48     public void testClipboardCopy() throws Exception JavaDoc {
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 JavaDoc[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 JavaDoc transferable = (Transferable JavaDoc)connectionNode.clipboardCopy();
64         Set JavaDoc mimeTypes = new HashSet JavaDoc();
65         DataFlavor JavaDoc[] 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