1 19 20 package org.netbeans.modules.j2ee.common; 21 22 import java.util.HashSet ; 23 import java.util.Set ; 24 import javax.swing.JComboBox ; 25 import org.netbeans.junit.NbTestCase; 26 import org.netbeans.modules.j2ee.deployment.common.api.Datasource; 27 28 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 testName) { 45 super(testName); 46 } 47 48 protected void setUp() throws Exception { 49 } 50 51 private void initDatasources() { 52 mds1 = new DatasourceImpl("mds1", "mds1_url", "mds1_user", "mds1_pass", "mds1_clz"); mds2 = new DatasourceImpl("mds2", "mds2_url", "mds2_user", "mds2_pass", "mds2_clz"); mds3 = new DatasourceImpl("mds3", "mds3_url", "mds3_user", "mds3_pass", "mds3_clz"); Set <Datasource> moduleDatasources = new HashSet <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"); sds2 = new DatasourceImpl("sds2", "sds2_url", "sds2_user", "sds2_pass", "sds2_clz"); sds3 = new DatasourceImpl("sds3", "sds3_url", "sds3_user", "sds3_pass", "sds3_clz"); sds4 = new DatasourceImpl("mds3", "mds3_url", "mds3_user", "mds3_pass", "mds3_clz"); Set <Datasource> serverDatasources = new HashSet <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 connect() { 74 JComboBox combo = new JComboBox (); 75 DatasourceUIHelper.connect(provider, combo); 76 return combo; 77 } 78 79 public void testEmptyComboboxContentWithCreation() { 80 provider = new J2eeModuleProviderImpl(new HashSet <Datasource>(), new HashSet <Datasource>()); 81 82 JComboBox 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 <Datasource>(), new HashSet <Datasource>(), false); 93 JComboBox 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 combo = connect(); 104 105 assertTrue("Wrong number of items in the empty combobox", combo.getItemCount() == 8); 106 for (int i = 0; i < 5; i++) { String jndiName_i = ((Datasource)combo.getItemAt(i)).getJndiName(); 108 String 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 |