KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > util > DatabaseExplorerInternalUIsTest


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

33 public class DatabaseExplorerInternalUIsTest extends TestBase {
34
35     private JDBCDriver driver1 = null;
36     private JDBCDriver driver2 = null;
37
38     public DatabaseExplorerInternalUIsTest(String JavaDoc testName) {
39         super(testName);
40     }
41
42     private void setUpDrivers() throws Exception JavaDoc {
43         removeDrivers();
44
45         driver1 = JDBCDriver.create("foo_driver", "FooDriver", "org.foo.FooDriver", new URL JavaDoc[0]);
46         JDBCDriverManager.getDefault().addDriver(driver1);
47         driver2 = JDBCDriver.create("bar_driver", "BarDriver", "org.bar.BarDriver", new URL JavaDoc[0]);
48         JDBCDriverManager.getDefault().addDriver(driver2);
49         assertEquals(2, JDBCDriverManager.getDefault().getDrivers().length);
50     }
51
52     private void removeDrivers() throws Exception JavaDoc {
53         FileObject driversFO = Util.getDriversFolder();
54         FileObject[] children = driversFO.getChildren();
55         for (int i = 0; i < children.length; i++) {
56             children[i].delete();
57         }
58         assertEquals(0, JDBCDriverManager.getDefault().getDrivers().length);
59     }
60
61     public void testEmptyComboboxContent() throws Exception JavaDoc {
62         removeDrivers();
63         JComboBox JavaDoc combo = new JComboBox JavaDoc();
64         DatabaseExplorerInternalUIs.connect(combo, JDBCDriverManager.getDefault());
65
66         assertTrue("Wrong number of items in the empty combobox", combo.getItemCount() == 1);
67     }
68
69     public void testComboboxWithDrivers() throws Exception JavaDoc {
70         setUpDrivers();
71         JComboBox JavaDoc combo = new JComboBox JavaDoc();
72         DatabaseExplorerInternalUIs.connect(combo, JDBCDriverManager.getDefault());
73
74         assertTrue("Wrong number of items in the combobox", combo.getItemCount() == 4);
75         assertSame(driver2, combo.getItemAt(0));
76         assertSame(driver1, combo.getItemAt(1));
77     }
78
79     public void testComboBoxWithDriverClass() throws Exception JavaDoc {
80         setUpDrivers();
81         JComboBox JavaDoc combo = new JComboBox JavaDoc();
82         DatabaseExplorerInternalUIs.connect(combo, JDBCDriverManager.getDefault(), "org.bar.BarDriver");
83
84         assertTrue("Wrong number of items in the combobox", combo.getItemCount() == 1);
85         assertSame(driver2, combo.getItemAt(0));
86     }
87 }
88
Popular Tags