/** * Construct a DataSource from a single String. Note that database driver properties can be * nested as long as they are semicolon delimited Example: * <code>CreateDatabase=create;DatabaseName=TEST</code>. * * @param datasourceInformation A string, really a list of properties, representing a datasource * @return DataSource representing the string * @see org.codehaus.cargo.container.internal.util.PropertyUtils#splitPropertiesOnPipe(String) */ public DataSource fromPropertyString(String datasourceInformation) { return fromProperties(PropertyUtils.splitPropertiesOnPipe(PropertyUtils .escapeBackSlashesIfNotNull(datasourceInformation))); }
/** * Test that the {@link ConfigurationEntryType#JDBC_DRIVER} property is the driver. */ public void testDriverIsDriver() { Properties props = new Properties(); props .setProperty(DatasourcePropertySet.CONNECTION_TYPE, ConfigurationEntryType.JDBC_DRIVER); DataSource ds = dataSourceConverter.fromProperties(props); assertEquals("java.sql.Driver", ds.getConnectionType()); }
/** * Test that the default value is driver. */ public void testDefaultIsDriver() { Properties props = new Properties(); DataSource ds = dataSourceConverter.fromProperties(props); assertEquals("java.sql.Driver", ds.getConnectionType()); }
/** * Test that the default mode is {@link TransactionSupport#NO_TRANSACTION}. */ public void testDefaultIsNoTransaction() { Properties props = new Properties(); DataSource ds = dataSourceConverter.fromProperties(props); assertEquals(TransactionSupport.NO_TRANSACTION, ds.getTransactionSupport()); }
/** * @return {@link DataSource} corresponding to this {@link DataSourceFixture}'s attributes. */ public DataSource buildDataSource() { return new DataSourceConverter().fromProperties(buildDataSourceProperties()); }
/** * Test that the {@link TransactionSupport#LOCAL_TRANSACTION} mode is * {@link TransactionSupport#LOCAL_TRANSACTION}. */ public void testLocalTransactionIsLocalTransaction() { Properties props = new Properties(); props.setProperty(DatasourcePropertySet.TRANSACTION_SUPPORT, TransactionSupport.LOCAL_TRANSACTION.toString()); DataSource ds = dataSourceConverter.fromProperties(props); assertEquals(TransactionSupport.LOCAL_TRANSACTION, ds.getTransactionSupport()); }
/** * Test that the {@link TransactionSupport#XA_TRANSACTION} mode is * {@link TransactionSupport#XA_TRANSACTION}. */ public void testXATransactionIsXATransaction() { Properties props = new Properties(); props.setProperty(DatasourcePropertySet.TRANSACTION_SUPPORT, TransactionSupport.XA_TRANSACTION.toString()); DataSource ds = dataSourceConverter.fromProperties(props); assertEquals(TransactionSupport.XA_TRANSACTION, ds.getTransactionSupport()); }
/** * Test that the {@link TransactionSupport#NO_TRANSACTION} mode is * {@link TransactionSupport#NO_TRANSACTION}. */ public void testNoTransactionIsNoTransaction() { Properties props = new Properties(); props.setProperty(DatasourcePropertySet.TRANSACTION_SUPPORT, TransactionSupport.NO_TRANSACTION.toString()); DataSource ds = dataSourceConverter.fromProperties(props); assertEquals(TransactionSupport.NO_TRANSACTION, ds.getTransactionSupport()); }
/** * Test the driver properties when the username and the password is set on datasource. */ public void testDatabaseDriverPropertiesUserAndPasswordPropertyOverrideDSUserAndPassword() { String driverPropertyString = "user=APP;password=egg;CreateDatabase=create"; Properties props = new Properties(); props.setProperty(DatasourcePropertySet.USERNAME, "sa"); props.setProperty(DatasourcePropertySet.PASSWORD, ""); props.setProperty(DatasourcePropertySet.CONNECTION_PROPERTIES, driverPropertyString); DataSource ds = dataSourceConverter.fromProperties(props); assertEquals("APP", ds.getUsername()); assertEquals("egg", ds.getPassword()); }
/** * Test that the {@link DatasourcePropertySet#CONNECTION_TYPE} property can define an XA * datasource. */ public void testXADataSourceIsXADataSource() { Properties props = new Properties(); props.setProperty(DatasourcePropertySet.CONNECTION_TYPE, ConfigurationEntryType.XA_DATASOURCE); DataSource ds = dataSourceConverter.fromProperties(props); assertEquals("javax.sql.XADataSource", ds.getConnectionType()); assertEquals(TransactionSupport.XA_TRANSACTION, ds.getTransactionSupport()); }
/** * Test the {@link Properties} constructor. */ public void testPropertiesConstructor() { Properties props = new Properties(); props.setProperty(DatasourcePropertySet.ID, "rudolf"); props.setProperty(DatasourcePropertySet.TRANSACTION_SUPPORT, TransactionSupport.NO_TRANSACTION.toString()); props.setProperty(DatasourcePropertySet.JNDI_LOCATION, "jdbc/JiraDS"); props .setProperty(DatasourcePropertySet.CONNECTION_TYPE, ConfigurationEntryType.JDBC_DRIVER); props.setProperty(DatasourcePropertySet.DRIVER_CLASS, "org.hsqldb.jdbcDriver"); props.setProperty(DatasourcePropertySet.URL, "postresql:localhost:jirads"); props.setProperty(DatasourcePropertySet.USERNAME, "sa"); props.setProperty(DatasourcePropertySet.PASSWORD, ""); DataSource ds = dataSourceConverter.fromProperties(props); assertEquals(0, ds.getConnectionProperties().size()); assertEquals("", ds.getPassword()); assertEquals(props, dataSourceConverter.toProperties(ds)); }