/** * Parse properties and add any DataSources to pending configuration. DataSources will be found * if their property name starts with: {@link DatasourcePropertySet#DATASOURCE} */ protected void addDataSourcesFromProperties() { getLogger().debug("Searching properties for DataSource definitions", this.getClass().getName()); for (Map.Entry<String, String> property : getProperties().entrySet()) { String propertyName = property.getKey(); if (propertyName.startsWith(DatasourcePropertySet.DATASOURCE)) { String dataSourceProperty = property.getValue(); getLogger().debug( "Found DataSource definition: value [" + dataSourceProperty + "]", this.getClass().getName()); DataSource dataSource = new DataSourceConverter().fromPropertyString(dataSourceProperty); getDataSources().add(dataSource); } } }
/** * Test the setting of multiple properties delimited by a semicolon. */ public void testMultipleDriverPropertiesDelimitedBySemiColon() { Properties driverProperties = new Properties(); driverProperties.setProperty("user", "APP"); driverProperties.setProperty("CreateDatabase", "create"); String driverPropertyString = "user=APP;CreateDatabase=create"; String propertyString = DatasourcePropertySet.CONNECTION_PROPERTIES + "=" + driverPropertyString; DataSource ds = dataSourceConverter.fromPropertyString(propertyString); assertEquals(driverProperties, ds.getConnectionProperties()); }
/** * Test the empty driver properties getter. */ public void testGetEmptyDriverProperties() { String propertyString = ""; String driverPropertyString = DatasourcePropertySet.CONNECTION_PROPERTIES + "=" + propertyString; DataSource ds = dataSourceConverter.fromPropertyString(driverPropertyString); assertEquals(0, ds.getConnectionProperties().size()); }
/** * Test an id with a slash. */ public void testIdWithSlash() { String jndiName = "jdbc/DataSource"; String propertyString = DatasourcePropertySet.JNDI_LOCATION + "=" + jndiName; DataSource ds = dataSourceConverter.fromPropertyString(propertyString); assertEquals("DataSource", ds.getId()); }
/** * Test an id with two slashes. */ public void testIdWithTwoSlashes() { String jndiName = "jdbc/app1/DataSource"; String propertyString = DatasourcePropertySet.JNDI_LOCATION + "=" + jndiName; DataSource ds = dataSourceConverter.fromPropertyString(propertyString); assertEquals("DataSource", ds.getId()); }
/** * Test the driver properties when the username is set on datasource. */ public void testDatabaseDriverPropertiesUsernamePropertySetsUserOnDataSource() { String driverPropertyString = "user=APP;CreateDatabase=create"; String propertyString = DatasourcePropertySet.CONNECTION_PROPERTIES + "=" + driverPropertyString; DataSource ds = dataSourceConverter.fromPropertyString(propertyString); assertEquals("APP", ds.getUsername()); }
/** * Test the driver properties when the password is set on datasource. */ public void testDatabaseDriverPropertiesPasswordPropertySetsPasswordOnDataSource() { String driverPropertyString = "password=egg;CreateDatabase=create"; String propertyString = DatasourcePropertySet.CONNECTION_PROPERTIES + "=" + driverPropertyString; DataSource ds = dataSourceConverter.fromPropertyString(propertyString); assertEquals("egg", ds.getPassword()); }
/** * Test an id with a dot. */ public void testIdWithADot() { String jndiName = "jdbc.DataSource"; String propertyString = DatasourcePropertySet.JNDI_LOCATION + "=" + jndiName; DataSource ds = dataSourceConverter.fromPropertyString(propertyString); assertEquals("DataSource", ds.getId()); }
/** * Test an id without dots nor slashes. */ public void testIdWithoutDotsOrSlashes() { String jndiName = "DataSource"; String propertyString = DatasourcePropertySet.JNDI_LOCATION + "=" + jndiName; DataSource ds = dataSourceConverter.fromPropertyString(propertyString); assertEquals(jndiName, ds.getId()); }
/** * Test that an empty property string generates a <code>null</code>. */ public void testIdIsNullWhenPropertyStringIsBlank() { String propertyString = ""; DataSource ds = dataSourceConverter.fromPropertyString(propertyString); assertEquals(null, ds.getId()); }
/** * Test the driver properties when an empty password is set on datasource. */ public void testDatabaseDriverPropertiesEmptyPasswordPropertySetsPasswordOnDataSource() { String driverPropertyString = "password=;CreateDatabase=create"; String propertyString = DatasourcePropertySet.CONNECTION_PROPERTIES + "=" + driverPropertyString; DataSource ds = dataSourceConverter.fromPropertyString(propertyString); assertEquals("", ds.getPassword()); }
/** * Test an id with a dot and a slash. */ public void testIdWithADotAndASlash() { String jndiName = "jdbc.app1/DataSource"; String propertyString = DatasourcePropertySet.JNDI_LOCATION + "=" + jndiName; DataSource ds = dataSourceConverter.fromPropertyString(propertyString); assertEquals("DataSource", ds.getId()); }
/** * Test an id with a Java column. */ public void testIdWithJavaColon() { String jndiName = "java:DataSource"; String propertyString = DatasourcePropertySet.JNDI_LOCATION + "=" + jndiName; DataSource ds = dataSourceConverter.fromPropertyString(propertyString); assertEquals("DataSource", ds.getId()); } }
/** * Test the driver properties when the username and the password is set on datasource. */ public void testDatabaseDriverPropertiesUserAndPasswordPropertySetsDataSourceUserAndPassword() { String driverPropertyString = "user=APP;password=egg;CreateDatabase=create"; String propertyString = DatasourcePropertySet.CONNECTION_PROPERTIES + "=" + driverPropertyString; DataSource ds = dataSourceConverter.fromPropertyString(propertyString); assertEquals("APP", ds.getUsername()); assertEquals("egg", ds.getPassword()); }
/** * Test the driver properties to string getter. */ public void testGetDriverPropertiesAsString() { String propertyString = "user=APP;CreateDatabase=create"; String driverPropertyString = DatasourcePropertySet.CONNECTION_PROPERTIES + "=" + propertyString; DataSource ds = dataSourceConverter.fromPropertyString(driverPropertyString); try { assertEquals(propertyString, dataSourceConverter .getConnectionPropertiesAsASemicolonDelimitedString(ds)); } catch (ComparisonFailure e) { assertEquals("CreateDatabase=create;user=APP", dataSourceConverter .getConnectionPropertiesAsASemicolonDelimitedString(ds)); } }