KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > common > DatasourceUIHelperTest


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.j2ee.common;
21
22 import java.util.HashSet JavaDoc;
23 import java.util.Set JavaDoc;
24 import javax.swing.JComboBox JavaDoc;
25 import org.netbeans.junit.NbTestCase;
26 import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
27
28 /**
29  *
30  * @author Libor Kotouc
31  */

32 public class DatasourceUIHelperTest extends NbTestCase {
33     
34     private DatasourceImpl mds1;
35     private DatasourceImpl mds2;
36     private DatasourceImpl mds3;
37     private DatasourceImpl sds1;
38     private DatasourceImpl sds2;
39     private DatasourceImpl sds3;
40     private DatasourceImpl sds4;
41     
42     J2eeModuleProviderImpl provider;
43     
44     public DatasourceUIHelperTest(String JavaDoc testName) {
45         super(testName);
46     }
47
48     protected void setUp() throws Exception JavaDoc {
49     }
50
51     private void initDatasources() {
52         mds1 = new DatasourceImpl("mds1", "mds1_url", "mds1_user", "mds1_pass", "mds1_clz"); // NOI18N
53
mds2 = new DatasourceImpl("mds2", "mds2_url", "mds2_user", "mds2_pass", "mds2_clz"); // NOI18N
54
mds3 = new DatasourceImpl("mds3", "mds3_url", "mds3_user", "mds3_pass", "mds3_clz"); // NOI18N
55
Set JavaDoc<Datasource> moduleDatasources = new HashSet JavaDoc<Datasource>();
56         moduleDatasources.add(mds1);
57         moduleDatasources.add(mds2);
58         moduleDatasources.add(mds3);
59         sds1 = new DatasourceImpl("sds1", "sds1_url", "sds1_user", "sds1_pass", "sds1_clz"); // NOI18N
60
sds2 = new DatasourceImpl("sds2", "sds2_url", "sds2_user", "sds2_pass", "sds2_clz"); // NOI18N
61
sds3 = new DatasourceImpl("sds3", "sds3_url", "sds3_user", "sds3_pass", "sds3_clz"); // NOI18N
62
//copy of mds3 for merging verification
63
sds4 = new DatasourceImpl("mds3", "mds3_url", "mds3_user", "mds3_pass", "mds3_clz"); // NOI18N
64
Set JavaDoc<Datasource> serverDatasources = new HashSet JavaDoc<Datasource>();
65         serverDatasources.add(sds1);
66         serverDatasources.add(sds2);
67         serverDatasources.add(sds3);
68         serverDatasources.add(sds4);
69         
70         provider = new J2eeModuleProviderImpl(moduleDatasources, serverDatasources);
71     }
72     
73     private JComboBox JavaDoc connect() {
74         JComboBox JavaDoc combo = new JComboBox JavaDoc();
75         DatasourceUIHelper.connect(provider, combo);
76         return combo;
77     }
78
79     public void testEmptyComboboxContentWithCreation() {
80         provider = new J2eeModuleProviderImpl(new HashSet JavaDoc<Datasource>(), new HashSet JavaDoc<Datasource>());
81         
82         JComboBox JavaDoc combo = connect();
83         
84         assertTrue("Wrong number of items in the empty combobox", combo.getItemCount() == 1);
85         assertTrue("null is not selected by default.", combo.getSelectedItem() == null);
86         assertTrue("NEW_ITEM must be the only item in the empty combobox", combo.getItemAt(0) == DatasourceUIHelper.NEW_ITEM);
87         
88     }
89
90     public void testEmptyComboboxContentWithoutCreation() {
91         provider = new J2eeModuleProviderImpl(new HashSet JavaDoc<Datasource>(), new HashSet JavaDoc<Datasource>(), false);//do not allow creation of new data source
92

93         JComboBox JavaDoc combo = connect();
94         
95         assertTrue("Wrong number of items in the empty combobox", combo.getItemCount() == 0);
96     
97     }
98     
99     public void testNonEmptyCombobox() {
100         
101         initDatasources();
102         
103         JComboBox JavaDoc combo = connect();
104         
105         assertTrue("Wrong number of items in the empty combobox", combo.getItemCount() == 8);
106         for (int i = 0; i < 5; i++) { // number of items w/o separator and add new... == 6
107
String JavaDoc jndiName_i = ((Datasource)combo.getItemAt(i)).getJndiName();
108             String JavaDoc jndiName_ipp = ((Datasource)combo.getItemAt(i+1)).getJndiName();
109             assertTrue("Items in combobox are not alphabetically ordered by JNDI name", jndiName_i.compareToIgnoreCase(jndiName_ipp) < 0);
110         }
111         
112     }
113     
114     protected boolean runInEQ() {
115         return true;
116     }
117     
118 }
119
Popular Tags