KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > api > explorer > DbMetaDataTransferProviderImplTest


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.api.explorer;
21
22 import java.net.URL JavaDoc;
23 import org.netbeans.api.db.explorer.DatabaseConnection;
24 import org.netbeans.api.db.explorer.JDBCDriver;
25 import org.netbeans.junit.NbTestCase;
26 import org.netbeans.modules.db.explorer.DbMetaDataTransferProvider;
27 import org.openide.filesystems.XMLFileSystem;
28 import org.openide.loaders.DataFolder;
29 import org.openide.loaders.DataObject;
30 import org.openide.loaders.FolderLookup;
31 import org.openide.util.Lookup;
32
33 /**
34  *
35  * @author Andrei Badea
36  */

37 public class DbMetaDataTransferProviderImplTest extends NbTestCase {
38
39     public DbMetaDataTransferProviderImplTest(String JavaDoc testName) {
40         super(testName);
41     }
42
43     /**
44      * Tests the layer contains is an instance of DbMetaDataTransferProvider in
45      * the Services folder and that it works correctly.
46      */

47     public void testBasic() throws Exception JavaDoc {
48         JDBCDriver driver = JDBCDriver.create("foo", "Foo", "org.example.Foo", new URL JavaDoc[0]);
49         DatabaseConnection dbconn = DatabaseConnection.create(driver, "url", "user", "schema", "pwd", false);
50
51         XMLFileSystem layerFs = new XMLFileSystem(DbMetaDataTransferProviderImplTest.class.getClassLoader().getResource("org/netbeans/modules/dbapi/resources/layer.xml"));
52         DataFolder services = DataFolder.findFolder(layerFs.getRoot().getFileObject("Services"));
53         FolderLookup lookup = new FolderLookup(services);
54
55         DbMetaDataTransferProvider dbTransferProvider = (DbMetaDataTransferProvider)lookup.getLookup().lookup(DbMetaDataTransferProvider.class);
56         assertNotNull(dbTransferProvider);
57
58         assertSame(DatabaseMetaDataTransfer.TABLE_FLAVOR, dbTransferProvider.getTableDataFlavor());
59
60         DatabaseMetaDataTransfer.Table table = (DatabaseMetaDataTransfer.Table)dbTransferProvider.createTableData(dbconn, driver, "SOME_TABLE");
61         assertSame(dbconn, table.getDatabaseConnection());
62         assertSame(driver, table.getJDBCDriver());
63         assertSame("SOME_TABLE", table.getTableName());
64     }
65 }
66
Popular Tags