PooledDatasourceHelper { protected static ConnectionFactory getConnectionFactory( IDatabaseConnection databaseConnection, String url ) { Properties props = new Properties(); props.put( "user", StringEscapeUtils.unescapeHtml( databaseConnection.getUsername() ) ); props.put( "password", StringEscapeUtils.unescapeHtml( databaseConnection.getPassword() ) ); if ( url.startsWith( "jdbc:mysql:" ) || ( url.startsWith( "jdbc:mariadb:" ) ) ) { props.put( "connectTimeout", "5000" ); } return new DriverManagerConnectionFactory( url, props ); }  static PoolingDataSource setupPooledDataSource( IDatabaseConnection databaseConnection ); static DataSource convert( IDatabaseConnection databaseConnection ); static DataSource getJndiDataSource( final String dsName );  }
@Test public void testConnectionFactory_MySQL() { IDatabaseConnection connection = mock( IDatabaseConnection.class ); doReturn( StringEscapeUtils.escapeHtml( user ) ).when( connection ).getUsername(); doReturn( StringEscapeUtils.escapeHtml( password ) ).when( connection ).getPassword(); ConnectionFactory factory = PooledDatasourceHelper.getConnectionFactory( connection, "jdbc:mysql: Properties props = (Properties) Whitebox.getInternalState( factory, "_props" ); assertEquals( user, props.getProperty( "user" ) ); assertEquals( password, props.getProperty( "password" ) ); }
@Test public void testConnectionFactory_MariaDB() { IDatabaseConnection connection = mock( IDatabaseConnection.class ); doReturn( StringEscapeUtils.escapeHtml( user ) ).when( connection ).getUsername(); doReturn( StringEscapeUtils.escapeHtml( password ) ).when( connection ).getPassword(); ConnectionFactory factory = PooledDatasourceHelper.getConnectionFactory( connection, "jdbc:mariadb: Properties props = (Properties) Whitebox.getInternalState( factory, "_props" ); assertEquals( user, props.getProperty( "user" ) ); assertEquals( password, props.getProperty( "password" ) ); }
@Test public void testConnectionFactory_MicrosoftSQL() { IDatabaseConnection connection = mock( IDatabaseConnection.class ); doReturn( StringEscapeUtils.escapeHtml( user ) ).when( connection ).getUsername(); doReturn( StringEscapeUtils.escapeHtml( password ) ).when( connection ).getPassword(); ConnectionFactory factory = PooledDatasourceHelper.getConnectionFactory( connection, "jdbc:microsoft:sqlserver: Properties props = (Properties) Whitebox.getInternalState( factory, "_props" ); assertEquals( user, props.getProperty( "user" ) ); assertEquals( password, props.getProperty( "password" ) ); }