KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > db > explorer > JDBCDriverManagerTest


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.api.db.explorer;
21
22 import java.net.URL JavaDoc;
23 import org.netbeans.modules.db.test.TestBase;
24 import org.netbeans.modules.db.test.Util;
25 import org.openide.cookies.OpenCookie;
26 import org.openide.filesystems.FileObject;
27 import org.openide.filesystems.Repository;
28 import org.openide.loaders.DataObject;
29
30 /**
31  *
32  * @author Andrei Badea
33  */

34 public class JDBCDriverManagerTest extends TestBase {
35
36     public JDBCDriverManagerTest(String JavaDoc testName) {
37         super(testName);
38     }
39
40     /**
41      * Tests that JDBCDriverManager manages the same instance that was
42      * added using the {@link JDBCDriverManager#addDriver} method.
43      */

44     public void testSameInstanceAfterAdd() throws Exception JavaDoc {
45         Util.deleteDriverFiles();
46
47         JDBCDriver driver1 = JDBCDriver.create("bar_driver", "Bar Driver", "org.bar.BarDriver", new URL JavaDoc[0]);
48         JDBCDriverManager.getDefault().addDriver(driver1);
49
50         // must recognize another XMLDataObject first, since the last one
51
// is held in XMLDataObject.sharedParserImpl and can't be GC'd
52
DataObject dobj = DataObject.find(Repository.getDefault().getDefaultFileSystem().getRoot().createData("foo.xml"));
53         dobj.getCookie(OpenCookie.class);
54
55         // this used to pass before issue 75204 was fixed
56
// we can now GC the driver's DataObject
57
// Reference ref = new WeakReference(DataObject.find(getDrivesFolder().getFileObject("org_bar_BarDriver.xml")));
58
// assertGC("Should be able to GC the driver's DataObject", ref);
59

60         System.gc();
61
62         // this used to fail as described in issue 75204
63
assertEquals(1, JDBCDriverManager.getDefault().getDrivers().length);
64         assertSame(driver1, JDBCDriverManager.getDefault().getDrivers("org.bar.BarDriver")[0]);
65     }
66 }
67
Popular Tags