KickJava   Java API By Example, From Geeks To Geeks.

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


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