DataSourceFactory { static Properties createPoolProperties(Map<String, String> configMap, List<ConfigProperty> props) { Properties result = new Properties(); if (props != null) { for (ConfigProperty prop : props) { if (prop.getName().toLowerCase().startsWith(POOL_PREFIX)) { String poolName = prop.getName().substring(POOL_PREFIX.length()); result.setProperty(poolName, prop.getValue()); } } } if (configMap != null) { for (Map.Entry<String, String> entry : configMap.entrySet()) { if (entry.getValue() == null || entry.getValue().equals("")) { continue; } if (entry.getKey().equals("type")) { continue; } if (entry.getKey().equals("jdbc-driver-class")) { continue; } if (entry.getKey().equals("jndi-name")) { continue; } if (entry.getKey().equals("transaction-type")) { continue; } if (entry.getKey().equals("conn-pooled-datasource-class")) { continue; } if (entry.getKey().equals("managed-conn-factory-class")) { continue; } if (entry.getKey().equals("xa-datasource-class")) { continue; } result.setProperty(entry.getKey(), entry.getValue()); } } return result; } DataSourceFactory(); DataSource getSimpleDataSource(Map configMap); ClientConnectionFactoryWrapper getManagedDataSource(Map configMap,
      List<ConfigProperty> props); DataSource getPooledDataSource(Map configMap, List<ConfigProperty> props); DataSource getTranxDataSource(Map configMap, List<ConfigProperty> props); static void setTestConnectionUrl(String url); static void setTestConnectionHost(String host); static void setTestConnectionPort(String port);  }
@Test public void creatPoolPropertiesWithNullInputReturnsEmptyOutput() { Properties output = DataSourceFactory.createPoolProperties(null, null); assertThat(output.isEmpty()).isTrue(); }
@Test public void creatPoolPropertiesWithOneConfigDataSourcePropertyReturnsEmptyOutput() { configProperties.add(new ConfigProperty("n1", "v1", null)); Properties output = DataSourceFactory.createPoolProperties(inputs, configProperties); assertThat(output.isEmpty()).isTrue(); }
@Test public void creatPoolPropertiesWithOneConfigPoolPropertyReturnsOneOutput() { configProperties.add(new ConfigProperty("pool.n1", "v1", null)); Properties output = DataSourceFactory.createPoolProperties(inputs, configProperties); assertThat(output.size()).isEqualTo(1); assertThat(output.getProperty("n1")).isEqualTo("v1"); }
@Test public void creatPoolPropertiesWithOneUpperCaseConfigPoolPropertyReturnsOneOutput() { configProperties.add(new ConfigProperty("POOL.N1", "v1", null)); Properties output = DataSourceFactory.createPoolProperties(inputs, configProperties); assertThat(output.size()).isEqualTo(1); assertThat(output.getProperty("N1")).isEqualTo("v1"); }
@Test public void creatPoolPropertiesWithEmptyInputReturnsEmptyOutput() { Properties output = DataSourceFactory.createPoolProperties(inputs, configProperties); assertThat(output.isEmpty()).isTrue(); }
@Test public void creatPoolPropertiesWithNullValueInputReturnsEmptyOutput() { inputs.put("name", null); Properties output = DataSourceFactory.createPoolProperties(inputs, configProperties); assertThat(output.isEmpty()).isTrue(); }
@Test public void creatPoolPropertiesWithEmptyStringValueInputReturnsEmptyOutput() { inputs.put("name", ""); Properties output = DataSourceFactory.createPoolProperties(inputs, configProperties); assertThat(output.isEmpty()).isTrue(); }
@Test public void creatPoolPropertiesWithOneInputReturnsOneOutput() { inputs.put("name", "value"); Properties output = DataSourceFactory.createPoolProperties(inputs, configProperties); assertThat(output.size()).isEqualTo(1); assertThat(output.getProperty("name")).isEqualTo("value"); }
@Test public void creatPoolPropertiesWithIgnoredInputKeysReturnsEmptyOutput() { inputs.put("type", "value"); inputs.put("jndi-name", "value"); inputs.put("transaction-type", "value"); inputs.put("conn-pooled-datasource-class", "value"); inputs.put("managed-conn-factory-class", "value"); inputs.put("xa-datasource-class", "value"); Properties output = DataSourceFactory.createPoolProperties(inputs, configProperties); assertThat(output.isEmpty()).isTrue(); }
@Test public void creatPoolPropertiesWithIgnoredAndValidInputsReturnsValidOutputs() { inputs.put("name1", ""); inputs.put("name2", null); inputs.put("type", "value"); inputs.put("jndi-name", "value"); inputs.put("transaction-type", "value"); inputs.put("conn-pooled-datasource-class", "value"); inputs.put("managed-conn-factory-class", "value"); inputs.put("xa-datasource-class", "value"); inputs.put("validname1", "value1"); inputs.put("validname2", "value2"); configProperties.add(new ConfigProperty("pool.n1", "v1", null)); configProperties.add(new ConfigProperty("dataSourceProp", "dataSourceValue", null)); configProperties.add(new ConfigProperty("pool.n2", "v2", null)); Properties output = DataSourceFactory.createPoolProperties(inputs, configProperties); assertThat(output.size()).isEqualTo(4); assertThat(output.getProperty("validname1")).isEqualTo("value1"); assertThat(output.getProperty("validname2")).isEqualTo("value2"); assertThat(output.getProperty("n1")).isEqualTo("v1"); assertThat(output.getProperty("n2")).isEqualTo("v2"); }